Skip to content
This repository has been archived by the owner on Feb 24, 2020. It is now read-only.

rkt: Add --cpuprofile --memprofile for profiling the rkt #2887

Merged
merged 2 commits into from
Jul 19, 2016

Conversation

yifan-gu
Copy link
Contributor

@yifan-gu yifan-gu commented Jul 7, 2016

Add two hidden global flags to enable profiling rkt.
Also add documentation about how to build and use the flags.

func parseProfileFlags(cmdRkt *cobra.Command) {}

func startProfile() (cpufile *os.File, memfile *os.File, err error) {
return nil, nil, nil
Copy link
Contributor

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.

Copy link
Contributor Author

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.

@jonboulle
Copy link
Contributor

Why do we need to hide this behind a build flag - wouldn't a runtime flag be enough?

@yifan-gu
Copy link
Contributor Author

yifan-gu commented Jul 8, 2016

@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.
Given that, I'd like to hide the flags to reduce flag noises.

@yifan-gu
Copy link
Contributor Author

yifan-gu commented Jul 8, 2016

@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.

@euank
Copy link
Member

euank commented Jul 8, 2016

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:

  1. slightly smaller executable for users
  2. allows it to be printed for dev builds / shown as a configure flag (possibly preferable to hidden or runtime)
  3. paves the way for further profile gated things, like structured logging or call analysis etc, some of which could have stronger reasons to not compile in normally (e.g. performance hit)

Reasons for runtime flag:

  1. Easier to ask users to provide dumps / information from this
  2. Easier for developers to not have to deal with build flags and
  3. Slightly less autotools 🔥

I'm indifferent overall on which we go with though.

@yifan-gu
Copy link
Contributor Author

yifan-gu commented Jul 8, 2016

@euank I don't know we can do hidden flags, that one sounds like a middle ground.

@jonboulle
Copy link
Contributor

@alban view?

@alban
Copy link
Member

alban commented Jul 12, 2016

@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.

@lucab
Copy link
Member

lucab commented Jul 12, 2016

@yifan-gu #2868 has landed so you can rebase on top of it. I also agree with above reviewers that an hidden CLI should be enough at this point, given the small amount of additional code.

@jonboulle
Copy link
Contributor

IMHO let's go with a hidden flag

@yifan-gu yifan-gu changed the title rkt: Add --enable-profile build options rkt: Add --cpuprofile --memprofile for profiling the rkt Jul 13, 2016
@yifan-gu yifan-gu force-pushed the profile branch 2 times, most recently from b9ee190 to 5ce9960 Compare July 13, 2016 01:09
@yifan-gu
Copy link
Contributor Author

Updated the PR to use hidden flags.

@alban
Copy link
Member

alban commented Jul 13, 2016

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)
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with stderr.PrintE

@yifan-gu
Copy link
Contributor Author

The hidden flags are documented in Documentation/commands.md with the other global options. Should they be in a separate table instead? /cc @joshix

I added a hint saying this is a hidden flag. Open to suggestions.
Maybe remove them at all and only mention in the profiling documentation?

}

func stopProfile(cpuprofile, memprofile *os.File) {
pprof.StopCPUProfile()
Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/tools/tool/

@iaguis
Copy link
Member

iaguis commented Jul 18, 2016

One nit but LGTM after that.

@yifan-gu
Copy link
Contributor Author

Fixed the typos.

Yifan Gu added 2 commits July 18, 2016 11:36
@yifan-gu
Copy link
Contributor Author

19:02:44 === RUN   TestNetDefaultRestrictedConnectivity
19:02:51 --- FAIL: TestNetDefaultRestrictedConnectivity (6.69s)
19:02:51    rkt_tests.go:115: Running command: /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/tmp/functional/rkt --dir=/tmp/datadir-255390103 --local-config=/tmp/localdir-290079242 --system-config=/tmp/systemdir-688845793 --user-config=/tmp/userdir-616822732 --debug --insecure-options=image run --net=default-restricted --mds-register=false /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/tmp/functional/test-tmp/rkt-inspect-networking.aci
19:02:51    goroutineassistant.go:64: Error encountered - shutting down
19:02:51    goroutineassistant.go:65: Get http://172.16.28.2:49152: dial tcp 172.16.28.2:49152: getsockopt: connection refused
19:02:51        
19:02:51 panic: Failed to remove temporary data directory "/tmp/datadir-255390103": remove /tmp/datadir-255390103/pods/run/17421b97-926e-4b25-be37-4cecf1fb0bc1/stage1/rootfs/sys: device or resource busy [recovered]
19:02:51    panic: Failed to remove temporary data directory "/tmp/datadir-255390103": remove /tmp/datadir-255390103/pods/run/17421b97-926e-4b25-be37-4cecf1fb0bc1/stage1/rootfs/sys: device or resource busy
19:02:51 
19:02:51 goroutine 481 [running]:
19:02:51 panic(0xa3b480, 0xc8203954b0)
19:02:51    /usr/lib/go-1.6/src/runtime/panic.go:481 +0x3e6
19:02:51 testing.tRunner.func1(0xc8204126c0)
19:02:51    /usr/lib/go-1.6/src/testing/testing.go:467 +0x192
19:02:51 panic(0xa3b480, 0xc8203954b0)
19:02:51    /usr/lib/go-1.6/src/runtime/panic.go:443 +0x4e9
19:02:51 github.com/coreos/rkt/tests/testutils.(*dirDesc).cleanup(0xc8202491c0)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/testutils/ctx.go:67 +0x27c
19:02:51 github.com/coreos/rkt/tests/testutils.(*RktRunCtx).Cleanup(0xc8202492c0)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/testutils/ctx.go:173 +0x1be
19:02:51 runtime.Goexit()
19:02:51    /usr/lib/go-1.6/src/runtime/panic.go:340 +0xfb
19:02:51 testing.(*common).FailNow(0xc8204126c0)
19:02:51    /usr/lib/go-1.6/src/testing/testing.go:346 +0x36
19:02:51 testing.(*common).Fatal(0xc8204126c0, 0xc820209c28, 0x1, 0x1)
19:02:51    /usr/lib/go-1.6/src/testing/testing.go:383 +0x6f
19:02:51 github.com/coreos/rkt/tests/testutils.(*GoroutineAssistant).Wait(0xc8203e0d20)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/testutils/goroutineassistant.go:65 +0x195
19:02:51 github.com/coreos/rkt/tests.NewTestNetDefaultRestrictedConnectivity.func1.1(0xce9de0, 0x18)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/rkt_net_test.go:353 +0xbf0
19:02:51 github.com/coreos/rkt/tests.NewTestNetDefaultRestrictedConnectivity.func1(0xc8204126c0)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/rkt_net_test.go:355 +0x92
19:02:51 github.com/coreos/rkt/tests/testutils.TestFunc.Execute(0xdb47f0, 0xc8204126c0)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/testutils/test.go:31 +0x26
19:02:51 github.com/coreos/rkt/tests.TestNetDefaultRestrictedConnectivity(0xc8204126c0)
19:02:51    /home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/gopath/src/github.com/coreos/rkt/tests/rkt_net_nspawn_test.go:76 +0x3f
19:02:51 testing.tRunner(0xc8204126c0, 0x1238550)
19:02:51    /usr/lib/go-1.6/src/testing/testing.go:473 +0x98
19:02:51 created by testing.RunTests
19:02:51    /usr/lib/go-1.6/src/testing/testing.go:582 +0x892
19:02:51 exit status 2
19:02:51 FAIL   github.com/coreos/rkt/tests 1199.008s
19:02:51 tests/functional.mk:82: recipe for target '/home/admin/workspace/rkt-github-ci/os_type/debian-8/stage1_flavor/coreos/builds/build-rkt-coreos/build-rkt-1.10.0+git/stamps/__tests_functional_mk_functional_tests.stamp' failed

cc @steveej

@iaguis
Copy link
Member

iaguis commented Jul 19, 2016

LGTM and tests failures are not related

@iaguis iaguis merged commit e61deb2 into rkt:master Jul 19, 2016
@yifan-gu yifan-gu deleted the profile branch July 20, 2016 16:03
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants