Skip to content

Commit a4863d6

Browse files
committed
Minor.
1 parent 6f7cb9b commit a4863d6

3 files changed

Lines changed: 50 additions & 5 deletions

File tree

core/cmd/admin_commands.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

testdata/scripts/admin/profile/multi-chain-loopp.txtar

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ exec curl --retry 10 --retry-max-time 60 --retry-connrefused $NODEURL
1111
exec chainlink --remote-node-url $NODEURL admin login -file creds --bypass-version-check
1212

1313
exec chainlink --remote-node-url $NODEURL admin profile -seconds 1 -output_dir ./profiles
14-
stderr 'Collecting profiles from host and 8 plugins: \[allocs block cmdline goroutine heap mutex profile threadcreate trace\]'
14+
stderr 'Collecting profiles from host and 8 plugins: \[allocs block cmdline goroutine heap mutex threadcreate profile trace\]'
1515

1616
exec sh -c 'eval "ls -R $WORK"'
1717

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# start node
2+
exec sh -c 'eval "echo \"$(cat config.toml.tmpl)\" > config.toml"'
3+
exec chainlink node -c config.toml start -p password -a creds &
4+
5+
# initialize client
6+
env NODEURL=http://localhost:$PORT
7+
exec curl --retry 10 --retry-max-time 60 --retry-connrefused $NODEURL
8+
exec chainlink --remote-node-url $NODEURL admin login -file creds --bypass-version-check
9+
10+
# seconds=0: no CPU and trace profiles are created
11+
exec chainlink --remote-node-url $NODEURL admin profile -seconds 0 -output_dir ./profiles
12+
stderr 'Collecting profiles: \[allocs block cmdline goroutine heap mutex threadcreate\]'
13+
14+
# seconds=1: CPU and trace profiles are created
15+
exec chainlink --remote-node-url $NODEURL admin profile -seconds 1 -output_dir ./profiles
16+
stderr 'Collecting profiles: \[allocs block cmdline goroutine heap mutex threadcreate profile trace\]'
17+
18+
exec sh -c 'eval "ls -R $WORK"'
19+
20+
-- testdb.txt --
21+
CL_DATABASE_URL
22+
-- testport.txt --
23+
PORT
24+
25+
-- password --
26+
T.tLHkcmwePT/p,]sYuntjwHKAsrhm#4eRs4LuKHwvHejWYAC2JP4M8HimwgmbaZ
27+
-- creds --
28+
notreal@fakeemail.ch
29+
fj293fbBnlQ!f9vNs
30+
31+
-- config.toml.tmpl --
32+
[Webserver]
33+
HTTPPort = $PORT

0 commit comments

Comments
 (0)