-
Notifications
You must be signed in to change notification settings - Fork 884
rkt: Add --cpuprofile
--memprofile
for profiling the rkt
#2887
Conversation
func parseProfileFlags(cmdRkt *cobra.Command) {} | ||
|
||
func startProfile() (cpufile *os.File, memfile *os.File, err error) { | ||
return nil, nil, nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest to write out a log entry for the user as a hint, that profiling was disabled at compile time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, maybe in the debugging mode.
Why do we need to hide this behind a build flag - wouldn't a runtime flag be enough? |
@jonboulle I think this should be a development feature, general users normally should not bother profiling rkt. Instead, they should be able to benchmark rkt though, which we already provided some facilities. |
@jonboulle But on the other side, the benefit of enabling the profiling flag unconditionally is that when a user reports some "high cpu usage" issue, we can ask them to provide the profiling result easily without rebuilding the rkt. |
If it is a runtime flag, we could also make it a hidden flag that can only be found via developer documentation if that's a concern. Reasons for build-flag:
Reasons for runtime flag:
I'm indifferent overall on which we go with though. |
@euank I don't know we can do hidden flags, that one sounds like a middle ground. |
@alban view? |
@jonboulle I prefer a runtime flag for simplicity, but it's not a strong preference. The profiling code does not seem to include any new dependencies that would be difficult to package in Debian, so a runtime flag should not be a problem. |
IMHO let's go with a hidden flag |
--enable-profile
build options--cpuprofile
--memprofile
for profiling the rkt
b9ee190
to
5ce9960
Compare
Updated the PR to use hidden flags. |
The hidden flags are documented in Documentation/commands.md with the other global options. Should they be in a separate table instead? /cc @joshix |
// runWrapper returns a func(cmd *cobra.Command, args []string) that internally | ||
// will add command function return code and the reinsertion of the "--" flag | ||
// terminator. | ||
func runWrapper(cf func(cmd *cobra.Command, args []string) (exit int)) func(cmd *cobra.Command, args []string) { | ||
return func(cmd *cobra.Command, args []string) { | ||
cpufile, memfile, err := startProfile() | ||
if err != nil { | ||
stderr.Printf("cannot setup profiling %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could this use stderr.PrintE()
to be consistent with the rest? Or is it too early and --debug
isn't parsed yet?
If stderr.PrintE()
cannot be used, there should be a :
before the %v
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Replaced with stderr.PrintE
I added a hint saying this is a hidden flag. Open to suggestions. |
} | ||
|
||
func stopProfile(cpuprofile, memprofile *os.File) { | ||
pprof.StopCPUProfile() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrap in either nil
or flag checks in case they weren't enabled? I think WriteHeapProfile
might do work whenever it's called, so we should avoid calling it if it's not enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@euank good catch, thanks.
|
||
```shell | ||
$ sudo /usr/bin/rkt --cpuprofile=/tmp/cpu.profile --memprofile=/tmp/mem.profile gc --grace-period=0 | ||
$ go tools pprof /usr/bin/rkt /tmp/cpu.profile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/tools/tool/
One nit but LGTM after that. |
Fixed the typos. |
These are hidden flags, so users will not find them in the help.
cc @steveej |
LGTM and tests failures are not related |
Add two hidden global flags to enable profiling rkt.
Also add documentation about how to build and use the flags.