Browse Source

Add flag to append a comment to a profile. (#221)

Add a flag to append a comment to a profile.
Alexey Alexandrov 7 years ago
parent
commit
41ac4e1c27

+ 7
- 2
internal/driver/cli.go View File

34
 	Timeout      int
34
 	Timeout      int
35
 	Symbolize    string
35
 	Symbolize    string
36
 	HTTPHostport string
36
 	HTTPHostport string
37
+	Comment      string
37
 }
38
 }
38
 
39
 
39
 // Parse parses the command lines through the specified flags package
40
 // Parse parses the command lines through the specified flags package
43
 	flag := o.Flagset
44
 	flag := o.Flagset
44
 	// Comparisons.
45
 	// Comparisons.
45
 	flagBase := flag.StringList("base", "", "Source for base profile for comparison")
46
 	flagBase := flag.StringList("base", "", "Source for base profile for comparison")
46
-	// Internal options.
47
+	// Source options.
47
 	flagSymbolize := flag.String("symbolize", "", "Options for profile symbolization")
48
 	flagSymbolize := flag.String("symbolize", "", "Options for profile symbolization")
48
 	flagBuildID := flag.String("buildid", "", "Override build id for first mapping")
49
 	flagBuildID := flag.String("buildid", "", "Override build id for first mapping")
50
+	flagTimeout := flag.Int("timeout", -1, "Timeout in seconds for fetching a profile")
51
+	flagAddComment := flag.String("add_comment", "", "Annotation string to record in the profile")
49
 	// CPU profile options
52
 	// CPU profile options
50
 	flagSeconds := flag.Int("seconds", -1, "Length of time for dynamic profiles")
53
 	flagSeconds := flag.Int("seconds", -1, "Length of time for dynamic profiles")
51
 	// Heap profile options
54
 	// Heap profile options
59
 	flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region")
62
 	flagMeanDelay := flag.Bool("mean_delay", false, "Display mean delay at each region")
60
 	flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames")
63
 	flagTools := flag.String("tools", os.Getenv("PPROF_TOOLS"), "Path for object tool pathnames")
61
 
64
 
62
-	flagTimeout := flag.Int("timeout", -1, "Timeout in seconds for fetching a profile")
63
 	flagHTTP := flag.String("http", "", "Present interactive web based UI at the specified http host:port")
65
 	flagHTTP := flag.String("http", "", "Present interactive web based UI at the specified http host:port")
64
 
66
 
65
 	// Flags used during command processing
67
 	// Flags used during command processing
135
 		Timeout:      *flagTimeout,
137
 		Timeout:      *flagTimeout,
136
 		Symbolize:    *flagSymbolize,
138
 		Symbolize:    *flagSymbolize,
137
 		HTTPHostport: *flagHTTP,
139
 		HTTPHostport: *flagHTTP,
140
+		Comment:      *flagAddComment,
138
 	}
141
 	}
139
 
142
 
140
 	for _, s := range *flagBase {
143
 	for _, s := range *flagBase {
278
 	"    -seconds              Duration for time-based profile collection\n" +
281
 	"    -seconds              Duration for time-based profile collection\n" +
279
 	"    -timeout              Timeout in seconds for profile collection\n" +
282
 	"    -timeout              Timeout in seconds for profile collection\n" +
280
 	"    -buildid              Override build id for main binary\n" +
283
 	"    -buildid              Override build id for main binary\n" +
284
+	"    -add_comment          Free-form annotation to add to the profile\n" +
285
+	"                          Displayed on some reports or with pprof -comments\n" +
281
 	"    -base source          Source of profile to use as baseline\n" +
286
 	"    -base source          Source of profile to use as baseline\n" +
282
 	"    profile.pb.gz         Profile in compressed protobuf format\n" +
287
 	"    profile.pb.gz         Profile in compressed protobuf format\n" +
283
 	"    legacy_profile        Profile in legacy pprof format\n" +
288
 	"    legacy_profile        Profile in legacy pprof format\n" +

+ 3
- 3
internal/driver/driver_test.go View File

73
 		{"dot,unit=minimum", "heap_sizetags"},
73
 		{"dot,unit=minimum", "heap_sizetags"},
74
 		{"dot,addresses,flat,ignore=[X3]002,focus=[X1]000", "contention"},
74
 		{"dot,addresses,flat,ignore=[X3]002,focus=[X1]000", "contention"},
75
 		{"dot,files,cum", "contention"},
75
 		{"dot,files,cum", "contention"},
76
-		{"comments", "cpu"},
76
+		{"comments,add_comment=some-comment", "cpu"},
77
 		{"comments", "heap"},
77
 		{"comments", "heap"},
78
 		{"tags", "cpu"},
78
 		{"tags", "cpu"},
79
 		{"tags,tagignore=tag[13],tagfocus=key[12]", "cpu"},
79
 		{"tags,tagignore=tag[13],tagfocus=key[12]", "cpu"},
153
 			addFlags(&f, flags[:1])
153
 			addFlags(&f, flags[:1])
154
 			solution = solutionFilename(tc.source, &f)
154
 			solution = solutionFilename(tc.source, &f)
155
 		}
155
 		}
156
+		// The add_comment flag is not idempotent so only apply it on the first run.
157
+		delete(f.strings, "add_comment")
156
 
158
 
157
 		// Second pprof invocation to read the profile from profile.proto
159
 		// Second pprof invocation to read the profile from profile.proto
158
 		// and generate a report.
160
 		// and generate a report.
401
 		}
403
 		}
402
 	case "heap_tags":
404
 	case "heap_tags":
403
 		p = heapProfile()
405
 		p = heapProfile()
404
-
405
 		for i := 0; i < len(p.Sample); i += 2 {
406
 		for i := 0; i < len(p.Sample); i += 2 {
406
 			s := p.Sample[i]
407
 			s := p.Sample[i]
407
 			if s.Label == nil {
408
 			if s.Label == nil {
410
 			s.NumLabel["request"] = s.NumLabel["bytes"]
411
 			s.NumLabel["request"] = s.NumLabel["bytes"]
411
 			s.Label["key1"] = []string{"tag"}
412
 			s.Label["key1"] = []string{"tag"}
412
 		}
413
 		}
413
-
414
 	case "contention":
414
 	case "contention":
415
 		p = contentionProfile()
415
 		p = contentionProfile()
416
 	case "symbolz":
416
 	case "symbolz":

+ 4
- 0
internal/driver/fetch.go View File

83
 	p.RemoveUninteresting()
83
 	p.RemoveUninteresting()
84
 	unsourceMappings(p)
84
 	unsourceMappings(p)
85
 
85
 
86
+	if s.Comment != "" {
87
+		p.Comments = append(p.Comments, s.Comment)
88
+	}
89
+
86
 	// Save a copy of the merged profile if there is at least one remote source.
90
 	// Save a copy of the merged profile if there is at least one remote source.
87
 	if save {
91
 	if save {
88
 		dir, err := setTmpDir(o.UI)
92
 		dir, err := setTmpDir(o.UI)

+ 1
- 0
internal/driver/testdata/pprof.cpu.comments View File

1
+some-comment