()
| 780 | } |
| 781 | |
| 782 | func getMemUsage() int { |
| 783 | if runtime.GOOS != "linux" { |
| 784 | pid := os.Getpid() |
| 785 | cmd := fmt.Sprintf("ps -ao rss,pid | grep %v", pid) |
| 786 | c1, err := exec.Command("bash", "-c", cmd).Output() |
| 787 | if err != nil { |
| 788 | // In case of error running the command, resort to go way |
| 789 | var ms runtime.MemStats |
| 790 | runtime.ReadMemStats(&ms) |
| 791 | megs := ms.Alloc |
| 792 | return int(megs) |
| 793 | } |
| 794 | |
| 795 | rss := strings.Split(string(c1), " ")[0] |
| 796 | kbs, err := strconv.Atoi(rss) |
| 797 | if err != nil { |
| 798 | return 0 |
| 799 | } |
| 800 | |
| 801 | megs := kbs << 10 |
| 802 | return megs |
| 803 | } |
| 804 | |
| 805 | contents, err := os.ReadFile("/proc/self/stat") |
| 806 | if err != nil { |
| 807 | glog.Errorf("Can't read the proc file. Err: %v\n", err) |
| 808 | return 0 |
| 809 | } |
| 810 | |
| 811 | cont := strings.Split(string(contents), " ") |
| 812 | // 24th entry of the file is the RSS which denotes the number of pages |
| 813 | // used by the process. |
| 814 | if len(cont) < 24 { |
| 815 | glog.Errorln("Error in RSS from stat") |
| 816 | return 0 |
| 817 | } |
| 818 | |
| 819 | rss, err := strconv.Atoi(cont[23]) |
| 820 | if err != nil { |
| 821 | glog.Errorln(err) |
| 822 | return 0 |
| 823 | } |
| 824 | |
| 825 | return rss * os.Getpagesize() |
| 826 | } |
| 827 | |
| 828 | func JemallocHandler(w http.ResponseWriter, r *http.Request) { |
| 829 | AddCorsHeaders(w) |
no test coverage detected