當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Profile.Function方法代碼示例

本文整理匯總了Golang中cmd/internal/pprof/profile.Profile.Function方法的典型用法代碼示例。如果您正苦於以下問題:Golang Profile.Function方法的具體用法?Golang Profile.Function怎麽用?Golang Profile.Function使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在cmd/internal/pprof/profile.Profile的用法示例。


在下文中一共展示了Profile.Function方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Symbolize

// Symbolize symbolizes profile p by parsing data returned by a
// symbolz handler. syms receives the symbolz query (hex addresses
// separated by '+') and returns the symbolz output in a string. It
// symbolizes all locations based on their addresses, regardless of
// mapping.
func Symbolize(source string, syms func(string, string) ([]byte, error), p *profile.Profile) error {
	if source = symbolz(source, p); source == "" {
		// If the source is not a recognizable URL, do nothing.
		return nil
	}

	// Construct query of addresses to symbolize.
	var a []string
	for _, l := range p.Location {
		if l.Address != 0 && len(l.Line) == 0 {
			a = append(a, fmt.Sprintf("%#x", l.Address))
		}
	}

	if len(a) == 0 {
		// No addresses to symbolize.
		return nil
	}
	lines := make(map[uint64]profile.Line)
	functions := make(map[string]*profile.Function)
	if b, err := syms(source, strings.Join(a, "+")); err == nil {
		buf := bytes.NewBuffer(b)
		for {
			l, err := buf.ReadString('\n')

			if err != nil {
				if err == io.EOF {
					break
				}
				return err
			}

			if symbol := symbolzRE.FindStringSubmatch(l); len(symbol) == 3 {
				addr, err := strconv.ParseUint(symbol[1], 0, 64)
				if err != nil {
					return fmt.Errorf("unexpected parse failure %s: %v", symbol[1], err)
				}

				name := symbol[2]
				fn := functions[name]
				if fn == nil {
					fn = &profile.Function{
						ID:         uint64(len(p.Function) + 1),
						Name:       name,
						SystemName: name,
					}
					functions[name] = fn
					p.Function = append(p.Function, fn)
				}

				lines[addr] = profile.Line{Function: fn}
			}
		}
	}

	for _, l := range p.Location {
		if line, ok := lines[l.Address]; ok {
			l.Line = []profile.Line{line}
			if l.Mapping != nil {
				l.Mapping.HasFunctions = true
			}
		}
	}

	return nil
}
開發者ID:2thetop,項目名稱:go,代碼行數:71,代碼來源:symbolz.go


注:本文中的cmd/internal/pprof/profile.Profile.Function方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。