diff --git a/internal/driver/cli.go b/internal/driver/cli.go index 7b8c3fc607..a18ec1597e 100644 --- a/internal/driver/cli.go +++ b/internal/driver/cli.go @@ -36,7 +36,7 @@ type source struct { Symbolize string HTTPHostport string HTTPDisableBrowser bool - Comment string + Comments []string AllFrames bool } @@ -52,7 +52,7 @@ func parseFlags(o *plugin.Options) (*source, []string, error) { flagSymbolize := flag.String("symbolize", "", "Options for profile symbolization") flagBuildID := flag.String("buildid", "", "Override build id for first mapping") flagTimeout := flag.Int("timeout", -1, "Timeout in seconds for fetching a profile") - flagAddComment := flag.String("add_comment", "", "Free-form annotation to add to the profile") + flagAddComment := flag.StringList("add_comment", "", "Free-form annotation to add to the profile") flagAllFrames := flag.Bool("all_frames", false, "Ignore drop_frames and keep_frames regexps") // CPU profile options flagSeconds := flag.Int("seconds", -1, "Length of time for dynamic profiles") @@ -146,7 +146,7 @@ func parseFlags(o *plugin.Options) (*source, []string, error) { Symbolize: *flagSymbolize, HTTPHostport: *flagHTTP, HTTPDisableBrowser: *flagNoBrowser, - Comment: *flagAddComment, + Comments: dropEmpty(*flagAddComment), AllFrames: *flagAllFrames, } diff --git a/internal/driver/driver_test.go b/internal/driver/driver_test.go index d4efa75703..9540ac3dc0 100644 --- a/internal/driver/driver_test.go +++ b/internal/driver/driver_test.go @@ -80,6 +80,7 @@ func TestParse(t *testing.T) { {"dot,addresses,flat,ignore=[X3]002,focus=[X1]000", "contention"}, {"dot,files,cum", "contention"}, {"comments,add_comment=some-comment", "cpu"}, + {"comments,add_comment=comment1,add_comment=comment2", "cpu"}, {"comments", "heap"}, {"tags", "cpu"}, {"tags,tagignore=tag[13],tagfocus=key[12]", "cpu"}, @@ -251,6 +252,11 @@ func addFlags(f *testFlags, flags []string) { f.ints[fields[0]] = i } else { f.strings[fields[0]] = fields[1] + // Add support for string lists + if f.stringLists == nil { + f.stringLists = make(map[string][]string) + } + f.stringLists[fields[0]] = append(f.stringLists[fields[0]], fields[1]) } } } @@ -285,6 +291,9 @@ func solutionFilename(source string, f *testFlags) string { if f.strings["unit"] != "minimum" { name = addString(name, f, []string{"unit"}) } + if len(f.stringLists["add_comment"]) > 1 { + name = append(name, "multiple_comments") + } return strings.Join(name, ".") } diff --git a/internal/driver/fetch.go b/internal/driver/fetch.go index 6d967a2037..14e003d3a3 100644 --- a/internal/driver/fetch.go +++ b/internal/driver/fetch.go @@ -89,8 +89,8 @@ func fetchProfiles(s *source, o *plugin.Options) (*profile.Profile, error) { p.RemoveUninteresting() unsourceMappings(p) - if s.Comment != "" { - p.Comments = append(p.Comments, s.Comment) + if len(s.Comments) > 0 { + p.Comments = append(p.Comments, s.Comments...) } // Save a copy of the merged profile if there is at least one remote source. diff --git a/internal/driver/testdata/pprof.cpu.comments.multiple_comments b/internal/driver/testdata/pprof.cpu.comments.multiple_comments new file mode 100644 index 0000000000..639c501eff --- /dev/null +++ b/internal/driver/testdata/pprof.cpu.comments.multiple_comments @@ -0,0 +1,2 @@ +comment1 +comment2