@@ -332,16 +332,25 @@ func (s *Shell) Profile(c *cli.Context) error {
332332 genDir := filepath .Join (baseDir , "debuginfo-" + time .Now ().Format (time .RFC3339 ))
333333
334334 vitals := c .StringSlice ("vitals" )
335- allVitals := []string {
335+ // supportsDeltaVitals contains profiles that can be run with or without seconds param.
336+ // (see https://pkg.go.dev/net/http/pprof#hdr-Parameters)
337+ supportsDeltaVitals := []string {
336338 "allocs" , // A sampling of all past memory allocations
337339 "block" , // Stack traces that led to blocking on synchronization primitives
338340 "cmdline" , // The command line invocation of the current program
339341 "goroutine" , // Stack traces of all current goroutines
340342 "heap" , // A sampling of memory allocations of live objects.
341343 "mutex" , // Stack traces of holders of contended mutexes
342- "profile" , // CPU profile.
343344 "threadcreate" , // Stack traces that led to the creation of new OS threads
344- "trace" , // A trace of execution of the current program.
345+ }
346+ // durationOnlyVitals contains profiles that can be run only with the seconds param.
347+ durationOnlyVitals := []string {
348+ "profile" , // CPU profile.
349+ "trace" , // A trace of execution of the current program.
350+ }
351+ allVitals := supportsDeltaVitals
352+ if seconds > 0 {
353+ allVitals = append (allVitals , durationOnlyVitals ... )
345354 }
346355 if len (vitals ) == 0 {
347356 vitals = slices .Clone (allVitals )
@@ -436,7 +445,10 @@ func (s *Shell) profile(ctx context.Context, genDir string, name string, vitals
436445 defer wgPprof .Done ()
437446 ctx , cancel := context .WithTimeout (ctx , time .Duration (max (seconds , 0 )+ web .PPROFOverheadSeconds )* time .Second )
438447 defer cancel ()
439- uri := fmt .Sprintf (path + "/debug/pprof/%s?seconds=%d" , vt , seconds )
448+ uri := fmt .Sprintf (path + "/debug/pprof/%s" , vt )
449+ if seconds > 0 {
450+ uri += fmt .Sprintf ("?seconds=%d" , seconds )
451+ }
440452 resp , err := s .HTTP .Get (ctx , uri )
441453 if err != nil {
442454 errs <- fmt .Errorf ("error collecting %s: %w" , uri , err )
0 commit comments