|
@@ -60,6 +60,10 @@ func (c *command) help(name string) string {
|
60
|
60
|
return message + "\n"
|
61
|
61
|
}
|
62
|
62
|
|
|
63
|
+// AddCommand adds an additional command to the set of commands
|
|
64
|
+// accepted by pprof. This enables extensions to add new commands for
|
|
65
|
+// specialized visualization formats. If the command specified already
|
|
66
|
+// exists, it is overwritten.
|
63
|
67
|
func AddCommand(cmd string, format int, post PostProcessor, desc, usage string) {
|
64
|
68
|
pprofCommands[cmd] = &command{format, post, false, desc, usage}
|
65
|
69
|
}
|
|
@@ -196,9 +200,9 @@ var pprofVariables = variables{
|
196
|
200
|
"For memory profiles, report average memory per allocation.",
|
197
|
201
|
"For time-based profiles, report average time per event.")},
|
198
|
202
|
"sample_index": &variable{stringKind, "", "", helpText(
|
199
|
|
- "Sample value to report",
|
|
203
|
+ "Sample value to report (0-based index or name)",
|
200
|
204
|
"Profiles contain multiple values per sample.",
|
201
|
|
- "Use sample_value=index to select the ith value or select it by name.")},
|
|
205
|
+ "Use sample_index=i to select the ith value (starting at 0).")},
|
202
|
206
|
|
203
|
207
|
// Data sorting criteria
|
204
|
208
|
"flat": &variable{boolKind, "t", "cumulative", helpText("Sort entries based on own weight")},
|
|
@@ -325,9 +329,9 @@ func browsers() []string {
|
325
|
329
|
case "windows":
|
326
|
330
|
return append(cmds, "cmd /c start")
|
327
|
331
|
default:
|
328
|
|
- user_browser := os.Getenv("BROWSER")
|
329
|
|
- if user_browser != "" {
|
330
|
|
- cmds = append([]string{user_browser, "sensible-browser"}, cmds...)
|
|
332
|
+ userBrowser := os.Getenv("BROWSER")
|
|
333
|
+ if userBrowser != "" {
|
|
334
|
+ cmds = append([]string{userBrowser, "sensible-browser"}, cmds...)
|
331
|
335
|
} else {
|
332
|
336
|
cmds = append([]string{"sensible-browser"}, cmds...)
|
333
|
337
|
}
|
|
@@ -439,6 +443,13 @@ func invokeVisualizer(format PostProcessor, suffix string, visualizers []string)
|
439
|
443
|
// profile sample types.
|
440
|
444
|
func locateSampleIndex(p *profile.Profile, sampleIndex string) (int, error) {
|
441
|
445
|
if sampleIndex == "" {
|
|
446
|
+ if dst := p.DefaultSampleType; dst != "" {
|
|
447
|
+ for i, t := range sampleTypes(p) {
|
|
448
|
+ if t == dst {
|
|
449
|
+ return i, nil
|
|
450
|
+ }
|
|
451
|
+ }
|
|
452
|
+ }
|
442
|
453
|
// By default select the last sample value
|
443
|
454
|
return len(p.SampleType) - 1, nil
|
444
|
455
|
}
|
|
@@ -453,15 +464,21 @@ func locateSampleIndex(p *profile.Profile, sampleIndex string) (int, error) {
|
453
|
464
|
// "inuse_space" and "inuse_objects" for profiles containing types
|
454
|
465
|
// "space" and "objects".
|
455
|
466
|
noInuse := strings.TrimPrefix(sampleIndex, "inuse_")
|
456
|
|
- sampleTypes := make([]string, len(p.SampleType))
|
457
|
467
|
for i, t := range p.SampleType {
|
458
|
468
|
if t.Type == sampleIndex || t.Type == noInuse {
|
459
|
469
|
return i, nil
|
460
|
470
|
}
|
461
|
|
- sampleTypes[i] = t.Type
|
462
|
471
|
}
|
463
|
472
|
|
464
|
|
- return 0, fmt.Errorf("sample_index %q must be one of: %v", sampleIndex, sampleTypes)
|
|
473
|
+ return 0, fmt.Errorf("sample_index %q must be one of: %v", sampleIndex, sampleTypes(p))
|
|
474
|
+}
|
|
475
|
+
|
|
476
|
+func sampleTypes(p *profile.Profile) []string {
|
|
477
|
+ types := make([]string, len(p.SampleType))
|
|
478
|
+ for i, t := range p.SampleType {
|
|
479
|
+ types[i] = t.Type
|
|
480
|
+ }
|
|
481
|
+ return types
|
465
|
482
|
}
|
466
|
483
|
|
467
|
484
|
// variables describe the configuration parameters recognized by pprof.
|