{"action":"created","issue":{"url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2151","labels_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2151/labels{/name}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2151/comments","events_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2151/events","html_url":"https://github.com/ethereum/go-ethereum/pull/2151","id":128982675,"number":2151,"title":"debugging: debug APIs for profiling and tracing","user":{"login":"fjl","id":6915,"avatar_url":"https://avatars.githubusercontent.com/u/6915?v=3","gravatar_id":"","url":"https://api.github.com/users/fjl","html_url":"https://github.com/fjl","followers_url":"https://api.github.com/users/fjl/followers","following_url":"https://api.github.com/users/fjl/following{/other_user}","gists_url":"https://api.github.com/users/fjl/gists{/gist_id}","starred_url":"https://api.github.com/users/fjl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fjl/subscriptions","organizations_url":"https://api.github.com/users/fjl/orgs","repos_url":"https://api.github.com/users/fjl/repos","events_url":"https://api.github.com/users/fjl/events{/privacy}","received_events_url":"https://api.github.com/users/fjl/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/ethereum/go-ethereum/labels/review","name":"review","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2016-01-27T00:05:38Z","updated_at":"2016-01-28T10:25:00Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2151","html_url":"https://github.com/ethereum/go-ethereum/pull/2151","diff_url":"https://github.com/ethereum/go-ethereum/pull/2151.diff","patch_url":"https://github.com/ethereum/go-ethereum/pull/2151.patch"},"body":"The debugging package provides an RPC API for most of the useful debugging\r\nfacilities of the Go runtime. They can be triggered through both command\r\nline flags and the IPC listener.\r\n\r\nExample (debugging startup performance using tracing)\r\n\r\n```text\r\n$ geth --trace=startup.trace\r\nI0127 01:09:15.764960 debugging/trace.go:47] trace started, writing to startup.trace\r\nI0127 01:09:15.765766 ethdb/database.go:71] Alloted 16MB cache to /Users/fjl/Library/Ethereum/chaindata\r\nI0127 01:09:15.800470 ethdb/database.go:71] Alloted 16MB cache to /Users/fjl/Library/Ethereum/dapp\r\nI0127 01:09:15.806210 eth/backend.go:163] Protocol Versions: [63 62 61], Network Id: 1\r\nI0127 01:09:15.806372 eth/backend.go:191] Blockchain DB Version: 3\r\n...\r\n```\r\n\r\nAfter a while, turn off trace writing through the console:\r\n\r\n```text\r\n$ geth attach\r\ninstance: Geth/v1.4.0-unstable-2cd229b6/darwin/go1.5.3\r\ncoinbase: 0xbd50b8b63e0dc0d4bbeecacaff26a63e6f41e6fb\r\nat block: 908705 (Tue, 26 Jan 2016 19:54:58 CET)\r\n> debug.stopTrace()\r\nnull\r\n```\r\n\r\n```text\r\nI0127 01:11:09.282044 debugging/trace.go:59] done writing trace to startup.trace\r\n```\r\n\r\nThen analyse the trace in your browser:\r\n\r\n```text\r\n$ go tool trace $(which geth) startup.trace\r\n```\r\n\r\nExample 2 (taking a CPU profile from the console)\r\n\r\n```text\r\n$ geth attach\r\ninstance: Geth/v1.4.0-unstable-2cd229b6/darwin/go1.5.3\r\ncoinbase: 0xbd50b8b63e0dc0d4bbeecacaff26a63e6f41e6fb\r\nat block: 908705 (Tue, 26 Jan 2016 19:54:58 CET)\r\n> debug.cpuProfile(\"cpu.out\", 10)\r\n... hangs for 10s...\r\nnull\r\n> exit\r\n$ go tool pprof $(which geth) cpu.out\r\nEntering interactive mode (type \"help\" for commands)\r\n(pprof) top10\r\n110ms of 110ms total (  100%)\r\nShowing top 10 nodes out of 54 (cum >= 20ms)\r\n      flat  flat%   sum%        cum   cum%\r\n      30ms 27.27% 27.27%       30ms 27.27%  runtime.mCentral_Grow\r\n      30ms 27.27% 54.55%       30ms 27.27%  runtime.mach_semaphore_signal\r\n      30ms 27.27% 81.82%       30ms 27.27%  runtime.usleep\r\n      20ms 18.18%   100%       20ms 18.18%  runtime.kevent\r\n         0     0%   100%       10ms  9.09%  crypto/cipher.NewCTR\r\n         0     0%   100%       10ms  9.09%  github.com/ethereum/go-ethereum/crypto/ecies.Encrypt\r\n         0     0%   100%       10ms  9.09%  github.com/ethereum/go-ethereum/crypto/ecies.symEncrypt\r\n         0     0%   100%       10ms  9.09%  github.com/ethereum/go-ethereum/eth.(*ProtocolManager).(github.com/ethereum/go-ethereum/eth.removePeer)-fm\r\n         0     0%   100%       10ms  9.09%  github.com/ethereum/go-ethereum/eth.(*ProtocolManager).removePeer\r\n         0     0%   100%       20ms 18.18%  github.com/ethereum/go-ethereum/eth.(*ProtocolManager).synchronise\r\n(pprof)\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/ethereum/go-ethereum/issues/comments/176109416","html_url":"https://github.com/ethereum/go-ethereum/pull/2151#issuecomment-176109416","issue_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2151","id":176109416,"user":{"login":"fjl","id":6915,"avatar_url":"https://avatars.githubusercontent.com/u/6915?v=3","gravatar_id":"","url":"https://api.github.com/users/fjl","html_url":"https://github.com/fjl","followers_url":"https://api.github.com/users/fjl/followers","following_url":"https://api.github.com/users/fjl/following{/other_user}","gists_url":"https://api.github.com/users/fjl/gists{/gist_id}","starred_url":"https://api.github.com/users/fjl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fjl/subscriptions","organizations_url":"https://api.github.com/users/fjl/orgs","repos_url":"https://api.github.com/users/fjl/repos","events_url":"https://api.github.com/users/fjl/events{/privacy}","received_events_url":"https://api.github.com/users/fjl/received_events","type":"User","site_admin":false},"created_at":"2016-01-28T10:25:00Z","updated_at":"2016-01-28T10:25:00Z","body":"@karalabe @obscuren Can you give your opinion on moving the package to `internal/debugging` instead? The reason being that it is probably not useful for anyone else. The package basically bridges the CLI framework, our RPC implementation and tracing. The RPC API is exposed through the `node` package (it registers the RPC API with the framework), so anyone using `node` will get it anyway."}}