關於Go語言MemoryProfile的一些問題

來源:互聯網
上載者:User

標籤:http   檔案中   設定   cpu   cts   byte   棧幀   cache   profiler   

關於如何使用pprof進行profiling的問題,請參考https://studygolang.com/articles/7069,本文僅做一些補充。

 

  1. http://xxx:6060/debug/pprof/heap?debug=1頁面的解釋

heap profile: 219: 286339776 [29791: 2945785336] @ heap/1048576

其中 219 —— 當前快照中看到的尚存活的堆對象的數量
   286339776 —— 當前快照中看到的尚存活的堆對象的位元組數
  29791 —— 當前快照中看到的分配過的堆對象(包括已經釋放的)的數量

  29791 —— 當前快照中看到的分配過的堆對象(包括已經釋放的)的位元組數
   1048576 —— MemProfileRate * 2

對於每個具體的對象,資料格式為
8: 62062592 [12: 93093888] @ 0x8fd38f 0x8fe4fa 0x8fa5f0 0x90714e 0x909b36 0x46bc31

其中, 8 —— 當前callstack上尚存活的對象數
   62062592 —— 當前callstack上尚存活的對象佔用位元組數
   12 —— 當前callstack上總過分配過的(包括已釋放的)對象數
   93093888 ——當前callstack上總過分配過的(包括已釋放的)對象佔用的位元組數
   @後面的內容 —— 當前callstack的棧幀,和下面解析的的callstack一致


這些內容都是在pprof.go檔案中輸出的,具體參看代碼
fmt.Fprintf(w, "heap profile: %d: %d [%d: %d] @ heap/%d\n",total.InUseObjects(), total.InUseBytes(),total.AllocObjects, total.AllocBytes,2*runtime.MemProfileRate)for i := range p {r := &p[i]fmt.Fprintf(w, "%d: %d [%d: %d] @",r.InUseObjects(), r.InUseBytes(),r.AllocObjects, r.AllocBytes)for _, pc := range r.Stack() {fmt.Fprintf(w, " %#x", pc)}fmt.Fprintf(w, "\n")printStackRecord(w, r.Stack(), false)}// Print memstats information too.// Pprof will ignore, but useful for peoples := new(runtime.MemStats)runtime.ReadMemStats(s)fmt.Fprintf(w, "\n# runtime.MemStats\n")fmt.Fprintf(w, "# Alloc = %d\n", s.Alloc)fmt.Fprintf(w, "# TotalAlloc = %d\n", s.TotalAlloc)fmt.Fprintf(w, "# Sys = %d\n", s.Sys)fmt.Fprintf(w, "# Lookups = %d\n", s.Lookups)fmt.Fprintf(w, "# Mallocs = %d\n", s.Mallocs)fmt.Fprintf(w, "# Frees = %d\n", s.Frees)fmt.Fprintf(w, "# HeapAlloc = %d\n", s.HeapAlloc)fmt.Fprintf(w, "# HeapSys = %d\n", s.HeapSys)fmt.Fprintf(w, "# HeapIdle = %d\n", s.HeapIdle)fmt.Fprintf(w, "# HeapInuse = %d\n", s.HeapInuse)fmt.Fprintf(w, "# HeapReleased = %d\n", s.HeapReleased)fmt.Fprintf(w, "# HeapObjects = %d\n", s.HeapObjects)fmt.Fprintf(w, "# Stack = %d / %d\n", s.StackInuse, s.StackSys)fmt.Fprintf(w, "# MSpan = %d / %d\n", s.MSpanInuse, s.MSpanSys)fmt.Fprintf(w, "# MCache = %d / %d\n", s.MCacheInuse, s.MCacheSys)fmt.Fprintf(w, "# BuckHashSys = %d\n", s.BuckHashSys)fmt.Fprintf(w, "# GCSys = %d\n", s.GCSys)fmt.Fprintf(w, "# OtherSys = %d\n", s.OtherSys)fmt.Fprintf(w, "# NextGC = %d\n", s.NextGC)fmt.Fprintf(w, "# LastGC = %d\n", s.LastGC)fmt.Fprintf(w, "# PauseNs = %d\n", s.PauseNs)fmt.Fprintf(w, "# PauseEnd = %d\n", s.PauseEnd)fmt.Fprintf(w, "# NumGC = %d\n", s.NumGC)fmt.Fprintf(w, "# NumForcedGC = %d\n", s.NumForcedGC)fmt.Fprintf(w, "# GCCPUFraction = %v\n", s.GCCPUFraction)fmt.Fprintf(w, "# DebugGC = %v\n", s.DebugGC)

  

如果覺得heap profile中列印的活躍對象數和HeapObjects數量差別太大,可以將MemProfileRate設定為一個更小的值(預設為512*1024),設定為1,快照中就可以看到完整的堆對象分配情況。





關於Go語言MemoryProfile的一些問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.