本文整理匯總了Golang中github.com/google/pprof/profile.Profile.Function方法的典型用法代碼示例。如果您正苦於以下問題:Golang Profile.Function方法的具體用法?Golang Profile.Function怎麽用?Golang Profile.Function使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/google/pprof/profile.Profile
的用法示例。
在下文中一共展示了Profile.Function方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: printTopProto
func printTopProto(w io.Writer, rpt *Report) error {
p := rpt.prof
o := rpt.options
g, _, _, _ := rpt.newTrimmedGraph()
rpt.selectOutputUnit(g)
out := profile.Profile{
SampleType: []*profile.ValueType{
{Type: "cum", Unit: o.OutputUnit},
{Type: "flat", Unit: o.OutputUnit},
},
TimeNanos: p.TimeNanos,
DurationNanos: p.DurationNanos,
PeriodType: p.PeriodType,
Period: p.Period,
}
var flatSum int64
for i, n := range g.Nodes {
name, flat, cum := n.Info.PrintableName(), n.Flat, n.Cum
flatSum += flat
f := &profile.Function{
ID: uint64(i + 1),
Name: name,
SystemName: name,
}
l := &profile.Location{
ID: uint64(i + 1),
Line: []profile.Line{
{
Function: f,
},
},
}
fv, _ := measurement.Scale(flat, o.SampleUnit, o.OutputUnit)
cv, _ := measurement.Scale(cum, o.SampleUnit, o.OutputUnit)
s := &profile.Sample{
Location: []*profile.Location{l},
Value: []int64{int64(cv), int64(fv)},
}
out.Function = append(out.Function, f)
out.Location = append(out.Location, l)
out.Sample = append(out.Sample, s)
}
return out.Write(w)
}
示例2: symbolizeMapping
// symbolizeMapping symbolizes locations belonging to a Mapping by querying
// a symbolz handler. An offset is applied to all addresses to take care of
// normalization occured for merged Mappings.
func symbolizeMapping(source string, offset int64, syms func(string, string) ([]byte, error), m *profile.Mapping, p *profile.Profile) error {
// Construct query of addresses to symbolize.
var a []string
for _, l := range p.Location {
if l.Mapping == m && l.Address != 0 && len(l.Line) == 0 {
// Compensate for normalization.
addr := int64(l.Address) + offset
if addr < 0 {
return fmt.Errorf("unexpected negative adjusted address, mapping %v source %d, offset %d", l.Mapping, l.Address, offset)
}
a = append(a, fmt.Sprintf("%#x", addr))
}
}
if len(a) == 0 {
// No addresses to symbolize.
return nil
}
lines := make(map[uint64]profile.Line)
functions := make(map[string]*profile.Function)
b, err := syms(source, strings.Join(a, "+"))
if err != nil {
return err
}
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.ParseInt(symbol[1], 0, 64)
if err != nil {
return fmt.Errorf("unexpected parse failure %s: %v", symbol[1], err)
}
if addr < 0 {
return fmt.Errorf("unexpected negative adjusted address, source %s, offset %d", symbol[1], offset)
}
// Reapply offset expected by the profile.
addr -= offset
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[uint64(addr)] = profile.Line{Function: fn}
}
}
for _, l := range p.Location {
if l.Mapping != m {
continue
}
if line, ok := lines[l.Address]; ok {
l.Line = []profile.Line{line}
}
}
return nil
}