亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

目錄 搜索
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據結構heap) container/list(容器數(shù)據結構list) container/ring(容器數(shù)據結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據庫/sql) database/sql/driver(數(shù)據庫/sql/driver) debug debug/dwarf(調試/dwarf) debug/elf(調試/elf) debug/gosym(調試/gosym) debug/macho(調試/macho) debug/pe(調試/pe) debug/plan9obj(調試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "runtime/pprof"

  • 概況

  • 索引

  • 子目錄

概況

軟件包 pprof 以 pprof 可視化工具所期望的格式寫入運行時分析數(shù)據。

分析 Go 程序

分析 Go 程序的第一步是啟用分析。支持使用標準測試包構建的性能分析基準測試。例如,以下命令在當前目錄中運行基準測試并將 CPU 和內存配置文件寫入 cpu.prof 和 mem.prof:

go test -cpuprofile cpu.prof -memprofile mem.prof -bench .

要為獨立程序添加等效分析支持,請將以下代碼添加到主函數(shù)中:

var cpuprofile = flag.String("cpuprofile", "", "write cpu profile `file`")var memprofile = flag.String("memprofile", "", "write memory profile to `file`")func main() {
    flag.Parse()    if *cpuprofile != "" {
        f, err := os.Create(*cpuprofile)        if err != nil {
            log.Fatal("could not create CPU profile: ", err)        }        if err := pprof.StartCPUProfile(f); err != nil {
            log.Fatal("could not start CPU profile: ", err)        }
        defer pprof.StopCPUProfile()    }    // ... rest of the program ...    if *memprofile != "" {
        f, err := os.Create(*memprofile)        if err != nil {
            log.Fatal("could not create memory profile: ", err)        }
        runtime.GC() // get up-to-date statistics        if err := pprof.WriteHeapProfile(f); err != nil {
            log.Fatal("could not write memory profile: ", err)        }
        f.Close()    }}

還有一個標準的 HTTP 接口來分析數(shù)據。添加以下行將在 / debug / pprof / URL 下安裝處理程序以下載實時配置文件:

import _ "net/http/pprof"

有關更多詳細信息,請參閱 net / http / pprof 軟件包。

配置文件可以通過 pprof 工具進行可視化處理:

go tool pprof cpu.prof

pprof 命令行提供了許多命令。通常使用的命令包括打印頂部程序熱點摘要的“top”和打開熱點及其調用圖的交互圖的“web”。使用“help”獲取所有 pprof 命令的信息。

索引

  • func Do(ctx context.Context, labels LabelSet, f func(context.Context))

  • func ForLabels(ctx context.Context, f func(key, value string) bool)

  • func Label(ctx context.Context, key string) (string, bool)

  • func Profiles() []*Profile

  • func SetGoroutineLabels(ctx context.Context)

  • func StartCPUProfile(w io.Writer) error

  • func StopCPUProfile()

  • func WithLabels(ctx context.Context, labels LabelSet) context.Context

  • func WriteHeapProfile(w io.Writer) error

  • type LabelSet

  • func Labels(args ...string) LabelSet

  • type Profile

  • func Lookup(name string) *Profile

  • func NewProfile(name string) *Profile

  • func (p *Profile) Add(value interface{}, skip int)

  • func (p *Profile) Count() int

  • func (p *Profile) Name() string

  • func (p *Profile) Remove(value interface{})

  • func (p *Profile) WriteTo(w io.Writer, debug int) error

  • Bugs

包文件

elf.go label.go map.go pprof.go proto.go protobuf.go protomem.go runtime.go

func Do

func Do(ctx context.Context, labels LabelSet, f func(context.Context))

使用添加到父標簽映射中的給定標簽的父上下文副本調用 f 。標簽中的每個鍵/值對都按照提供的順序插入到標簽貼圖中,覆蓋同一個鍵的任何以前的值。增強標簽貼圖將在 f 調用期間設置,并在 f 返回時恢復。

func ForLabels

func ForLabels(ctx context.Context, f func(key, value string) bool)

ForLabels 通過在上下文中設置每個標簽來調用 f 。函數(shù) f 應該返回 true 來繼續(xù)迭代或 false 以盡早停止迭代。

func Label

func Label(ctx context.Context, key string) (string, bool)

Label 用 ctx 上的給定關鍵字返回標簽的值,以及指示該標簽是否存在的布爾值。

func Profiles

func Profiles() []*Profile

Profiles 文件返回所有已知配置文件的一部分,按名稱排序。

func SetGoroutineLabels

func SetGoroutineLabels(ctx context.Context)

SetGoroutineLabels 將當前 goroutine 的標簽設置為與 ctx 匹配。這是比 Do 更低級別的 API,應盡可能使用它。

func StartCPUProfile

func StartCPUProfile(w io.Writer) error

StartCPUProfile 啟用當前進程的 CPU 分析。分析時,配置文件將被緩沖并寫入 w 。如果分析已啟用,則 StartCPUProfile 將返回錯誤。

在類 Unix 系統(tǒng)上,默認情況下,StartCPUProfile 對于使用 -buildmode = c-archive 或 -buildmode = c-shared 構建的 Go 代碼不起作用。StartCPUProfile 依賴于 SIGPROF 信號,但該信號將被傳送到主程序的 SIGPROF 信號處理程序(如果有)而不是 Go 所使用的信號處理程序。要使其工作,請為 syscall.SIGPROF 調用 os / signal.Notify,但請注意,這樣做可能會破壞主程序執(zhí)行的任何分析。

func StopCPUProfile

func StopCPUProfile()

StopCPUProfile 停止當前 CPU 配置文件(如果有)。StopCPUProfile 僅在配置文件的所有寫入完成后才會返回。

func WithLabels

func WithLabels(ctx context.Context, labels LabelSet) context.Context

WithLabels 返回一個新的 context.Context,添加了給定的標簽。標簽使用相同的密鑰覆蓋先前的標簽。

func WriteHeapProfile

func WriteHeapProfile(w io.Writer) error

WriteHeapProfile 是 Lookup(“heap”)的縮寫。WriteTo(w,0)。它是為了向后兼容而保存的。

type LabelSet

LabelSet 是一組標簽。

type LabelSet struct {        // contains filtered or unexported fields}

func Labels

func Labels(args ...string) LabelSet

Labels 需要偶數(shù)個表示鍵值對的字符串,并使 LabelSet 包含它們。標簽使用相同的密鑰覆蓋先前的標簽。

type Profile

配置文件是堆棧跟蹤的集合,顯示導致特定事件實例(例如分配)的調用序列。包可以創(chuàng)建和維護自己的配置文件; 最常見的用途是跟蹤必須明確關閉的資源,例如文件或網絡連接。

配置文件的方法可以同時從多個 goroutine 調用。

每個配置文件都有唯一的名稱。一些配置文件是預定義的:

goroutine    - stack traces of all current goroutines
heap         - a sampling of all heap allocations
threadcreate - stack traces that led to the creation of new OS threads
block        - stack traces that led to blocking on synchronization primitives
mutex        - stack traces of holders of contended mutexes

這些預定義的配置文件在明確的 Add 或 Remove 方法調用中保持自己和恐慌。

堆概要報告最近完成的垃圾收集的統(tǒng)計數(shù)據; 它避免了最近的分配,以避免將配置文件從實時數(shù)據轉向垃圾。如果根本沒有垃圾回收,則堆配置文件會報告所有已知的分配。此異常主要用于在未啟用垃圾回收的情況下運行的程序,通常用于調試目的。

CPU 配置文件不可用作配置文件。它有一個特殊的 API,StartCPUProfile 和 StopCPUProfile 函數(shù),因為它在分析過程中將輸出流輸出到一個寫入器。

type Profile struct {        // contains filtered or unexported fields}

func Lookup

func Lookup(name string) *Profile

Lookup  將返回具有給定名稱的配置文件,如果不存在此類配置文件,則返回 nil 。

func NewProfile

func NewProfile(name string) *Profile

NewProfile 使用給定的名稱創(chuàng)建一個新的配置文件。如果具有該名稱的配置文件已存在,則 NewProfile 會發(fā)生混亂。該慣例是使用“導入/路徑”。前綴為每個包創(chuàng)建單獨的名稱空間。為了與讀取 pprof 數(shù)據的各種工具兼容,配置文件名稱不應包含空格。

func (*Profile) Add

func (p *Profile) Add(value interface{}, skip int)

Add 將當前執(zhí)行堆棧添加到與值關聯(lián)的配置文件。將商店值添加到內部映射中,因此值必須適合用作映射鍵,并且在相應的調用 Remove 之前不會進行垃圾收集。如果配置文件已經包含值的堆棧,則添加恐慌。

skip 參數(shù)的含義與 runtime.Caller 的 skip 和 controls 開始的地方相同。跳過 skip = 0開始追加函數(shù)的追蹤。例如,給定這個執(zhí)行堆棧:

Add
called from rpc.NewClient
called from mypkg.Run
called from main.main

跳過 skip = 0時,會在調用 Add rpc.NewClient 時添加堆棧跟蹤。在 skip mypkg.Run 中調用 NewClient 時,skip skip = 1開始堆棧跟蹤。

func (*Profile) Count

func (p *Profile) Count() int

Count 返回配置文件中當前執(zhí)行堆棧的數(shù)量。

func (*Profile) Name

func (p *Profile) Name() string

Name 返回此配置文件的名稱,該名稱可以傳遞給查找以重新獲取配置文件。

func (*Profile) Remove

func (p *Profile) Remove(value interface{})

Remove 從配置文件中刪除與值關聯(lián)的執(zhí)行堆棧。如果該值不在配置文件中,則它是無操作的。

func (*Profile) WriteTo

func (p *Profile) WriteTo(w io.Writer, debug int) error

WriteTo 將配置文件的 pprof 格式的快照寫入 w 。如果寫入 w 返回錯誤,則 WriteTo 返回該錯誤。否則,WriteTo 返回 nil 。

調試參數(shù)啟用額外的輸出。傳遞 debug = 0僅打印 pprof 所需的十六進制地址。傳遞 debug = 1會添加將地址轉換為函數(shù)名和行號的注釋,以便程序員可以在不使用工具的情況下讀取配置文件。

預定義的配置文件可以為其他調試值指定含義; 例如,在打印“goroutine”配置文件時,debug = 2意味著打印 goroutine 堆棧的格式與 Go 程序由于未發(fā)現(xiàn)的恐慌而死時使用的格式相同。

Bugs

  • ?   配置文件與用于生成它們的內核支持一樣好。

子目錄

Name

Synopsis

上一篇: 下一篇: