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

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)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ù)據(jù)庫(kù)/sql) database/sql/driver(數(shù)據(jù)庫(kù)/sql/driver) debug debug/dwarf(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/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(錯(cuò)誤) 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(調(diào)色板) 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(正則表達(dá)式) regexp/syntax runtime runtime(運(yùn)行時(shí)) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競(jìng)爭(zhēng)) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測(cè)試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時(shí)間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "runtime/pprof"

  • 概況

  • 索引

  • 子目錄

概況

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

分析 Go 程序

分析 Go 程序的第一步是啟用分析。支持使用標(biāo)準(zhǔn)測(cè)試包構(gòu)建的性能分析基準(zhǔn)測(cè)試。例如,以下命令在當(dāng)前目錄中運(yùn)行基準(zhǔn)測(cè)試并將 CPU 和內(nèi)存配置文件寫入 cpu.prof 和 mem.prof:

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

要為獨(dú)立程序添加等效分析支持,請(qǐng)將以下代碼添加到主函數(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()    }}

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

import _ "net/http/pprof"

有關(guān)更多詳細(xì)信息,請(qǐng)參閱 net / http / pprof 軟件包。

配置文件可以通過 pprof 工具進(jìn)行可視化處理:

go tool pprof cpu.prof

pprof 命令行提供了許多命令。通常使用的命令包括打印頂部程序熱點(diǎn)摘要的“top”和打開熱點(diǎn)及其調(diào)用圖的交互圖的“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))

使用添加到父標(biāo)簽映射中的給定標(biāo)簽的父上下文副本調(diào)用 f 。標(biāo)簽中的每個(gè)鍵/值對(duì)都按照提供的順序插入到標(biāo)簽貼圖中,覆蓋同一個(gè)鍵的任何以前的值。增強(qiáng)標(biāo)簽貼圖將在 f 調(diào)用期間設(shè)置,并在 f 返回時(shí)恢復(fù)。

func ForLabels

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

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

func Label

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

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

func Profiles

func Profiles() []*Profile

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

func SetGoroutineLabels

func SetGoroutineLabels(ctx context.Context)

SetGoroutineLabels 將當(dāng)前 goroutine 的標(biāo)簽設(shè)置為與 ctx 匹配。這是比 Do 更低級(jí)別的 API,應(yīng)盡可能使用它。

func StartCPUProfile

func StartCPUProfile(w io.Writer) error

StartCPUProfile 啟用當(dāng)前進(jìn)程的 CPU 分析。分析時(shí),配置文件將被緩沖并寫入 w 。如果分析已啟用,則 StartCPUProfile 將返回錯(cuò)誤。

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

func StopCPUProfile

func StopCPUProfile()

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

func WithLabels

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

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

func WriteHeapProfile

func WriteHeapProfile(w io.Writer) error

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

type LabelSet

LabelSet 是一組標(biāo)簽。

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

func Labels

func Labels(args ...string) LabelSet

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

type Profile

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

配置文件的方法可以同時(shí)從多個(gè) goroutine 調(diào)用。

每個(gè)配置文件都有唯一的名稱。一些配置文件是預(yù)定義的:

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

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

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

CPU 配置文件不可用作配置文件。它有一個(gè)特殊的 API,StartCPUProfile 和 StopCPUProfile 函數(shù),因?yàn)樗诜治鲞^程中將輸出流輸出到一個(gè)寫入器。

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)建一個(gè)新的配置文件。如果具有該名稱的配置文件已存在,則 NewProfile 會(huì)發(fā)生混亂。該慣例是使用“導(dǎo)入/路徑”。前綴為每個(gè)包創(chuàng)建單獨(dú)的名稱空間。為了與讀取 pprof 數(shù)據(jù)的各種工具兼容,配置文件名稱不應(yīng)包含空格。

func (*Profile) Add

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

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

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

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

跳過 skip = 0時(shí),會(huì)在調(diào)用 Add rpc.NewClient 時(shí)添加堆棧跟蹤。在 skip mypkg.Run 中調(diào)用 NewClient 時(shí),skip skip = 1開始堆棧跟蹤。

func (*Profile) Count

func (p *Profile) Count() int

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

func (*Profile) Name

func (p *Profile) Name() string

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

func (*Profile) Remove

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

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

func (*Profile) WriteTo

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

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

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

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

Bugs

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

子目錄

Name

Synopsis

Previous article: Next article: