Przeglądaj źródła

Apply the --divide_by option to the profile before saving it. (#504)

This allows averaging profiles by using:
pprof -proto output --divide_by <n> profile1.pb.gz ... profilen.pb.gz
Raul Silvera 5 lat temu
rodzic
commit
d4f498aebe
1 zmienionych plików z 18 dodań i 1 usunięć
  1. 18
    1
      internal/report/report.go

+ 18
- 1
internal/report/report.go Wyświetl plik

@@ -102,7 +102,7 @@ func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error {
102 102
 	case Tags:
103 103
 		return printTags(w, rpt)
104 104
 	case Proto:
105
-		return rpt.prof.Write(w)
105
+		return printProto(w, rpt)
106 106
 	case TopProto:
107 107
 		return printTopProto(w, rpt)
108 108
 	case Dis:
@@ -291,6 +291,23 @@ func (rpt *Report) newGraph(nodes graph.NodeSet) *graph.Graph {
291 291
 	return graph.New(rpt.prof, gopt)
292 292
 }
293 293
 
294
+// printProto writes the incoming proto via thw writer w.
295
+// If the divide_by option has been specified, samples are scaled appropriately.
296
+func printProto(w io.Writer, rpt *Report) error {
297
+	p, o := rpt.prof, rpt.options
298
+
299
+	// Apply the sample ratio to all samples before saving the profile.
300
+	if r := o.Ratio; r > 0 && r != 1 {
301
+		for _, sample := range p.Sample {
302
+			for i, v := range sample.Value {
303
+				sample.Value[i] = int64(float64(v) * r)
304
+			}
305
+		}
306
+	}
307
+	return p.Write(w)
308
+}
309
+
310
+// printTopProto writes a list of the hottest routines in a profile as a profile.proto.
294 311
 func printTopProto(w io.Writer, rpt *Report) error {
295 312
 	p := rpt.prof
296 313
 	o := rpt.options