Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions core/cmd/admin_commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,16 +332,25 @@ func (s *Shell) Profile(c *cli.Context) error {
genDir := filepath.Join(baseDir, "debuginfo-"+time.Now().Format(time.RFC3339))

vitals := c.StringSlice("vitals")
allVitals := []string{
// supportsDeltaVitals contains profiles that can be run with or without seconds param.
// (see https://pkg.go.dev/net/http/pprof#hdr-Parameters)
supportsDeltaVitals := []string{
"allocs", // A sampling of all past memory allocations
"block", // Stack traces that led to blocking on synchronization primitives
"cmdline", // The command line invocation of the current program
"goroutine", // Stack traces of all current goroutines
"heap", // A sampling of memory allocations of live objects.
"mutex", // Stack traces of holders of contended mutexes
"profile", // CPU profile.
"threadcreate", // Stack traces that led to the creation of new OS threads
"trace", // A trace of execution of the current program.
}
// durationOnlyVitals contains profiles that can be run only with the seconds param.
durationOnlyVitals := []string{
"profile", // CPU profile.
"trace", // A trace of execution of the current program.
}
allVitals := supportsDeltaVitals
if seconds > 0 {
allVitals = append(allVitals, durationOnlyVitals...)
Comment thread
pavel-raykov marked this conversation as resolved.
}
if len(vitals) == 0 {
vitals = slices.Clone(allVitals)
Expand Down Expand Up @@ -436,7 +445,10 @@ func (s *Shell) profile(ctx context.Context, genDir string, name string, vitals
defer wgPprof.Done()
ctx, cancel := context.WithTimeout(ctx, time.Duration(max(seconds, 0)+web.PPROFOverheadSeconds)*time.Second)
defer cancel()
uri := fmt.Sprintf(path+"/debug/pprof/%s?seconds=%d", vt, seconds)
uri := fmt.Sprintf(path+"/debug/pprof/%s", vt)
if seconds > 0 {
uri += fmt.Sprintf("?seconds=%d", seconds)
}
resp, err := s.HTTP.Get(ctx, uri)
if err != nil {
errs <- fmt.Errorf("error collecting %s: %w", uri, err)
Expand Down
2 changes: 1 addition & 1 deletion testdata/scripts/admin/profile/multi-chain-loopp.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ exec curl --retry 10 --retry-max-time 60 --retry-connrefused $NODEURL
exec chainlink --remote-node-url $NODEURL admin login -file creds --bypass-version-check

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

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

Expand Down
33 changes: 33 additions & 0 deletions testdata/scripts/admin/profile/test-seconds.txtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# start node
exec sh -c 'eval "echo \"$(cat config.toml.tmpl)\" > config.toml"'
exec chainlink node -c config.toml start -p password -a creds &

# initialize client
env NODEURL=http://localhost:$PORT
exec curl --retry 10 --retry-max-time 60 --retry-connrefused $NODEURL
exec chainlink --remote-node-url $NODEURL admin login -file creds --bypass-version-check

# seconds=0: no CPU and trace profiles are created
exec chainlink --remote-node-url $NODEURL admin profile -seconds 0 -output_dir ./profiles
stderr 'Collecting profiles: \[allocs block cmdline goroutine heap mutex threadcreate\]'

# seconds=1: CPU and trace profiles are created
exec chainlink --remote-node-url $NODEURL admin profile -seconds 1 -output_dir ./profiles
stderr 'Collecting profiles: \[allocs block cmdline goroutine heap mutex threadcreate profile trace\]'
Comment thread
pavel-raykov marked this conversation as resolved.

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

-- testdb.txt --
CL_DATABASE_URL
-- testport.txt --
PORT

-- password --
T.tLHkcmwePT/p,]sYuntjwHKAsrhm#4eRs4LuKHwvHejWYAC2JP4M8HimwgmbaZ
-- creds --
notreal@fakeemail.ch
fj293fbBnlQ!f9vNs

-- config.toml.tmpl --
[Webserver]
HTTPPort = $PORT
Loading