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) }