{"action":"created","issue":{"url":"https://api.github.com/repos/iovisor/bcc/issues/387","repository_url":"https://api.github.com/repos/iovisor/bcc","labels_url":"https://api.github.com/repos/iovisor/bcc/issues/387/labels{/name}","comments_url":"https://api.github.com/repos/iovisor/bcc/issues/387/comments","events_url":"https://api.github.com/repos/iovisor/bcc/issues/387/events","html_url":"https://github.com/iovisor/bcc/issues/387","id":133892876,"number":387,"title":"ktrace","user":{"login":"brendangregg","id":1101211,"avatar_url":"https://avatars.githubusercontent.com/u/1101211?v=3","gravatar_id":"","url":"https://api.github.com/users/brendangregg","html_url":"https://github.com/brendangregg","followers_url":"https://api.github.com/users/brendangregg/followers","following_url":"https://api.github.com/users/brendangregg/following{/other_user}","gists_url":"https://api.github.com/users/brendangregg/gists{/gist_id}","starred_url":"https://api.github.com/users/brendangregg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/brendangregg/subscriptions","organizations_url":"https://api.github.com/users/brendangregg/orgs","repos_url":"https://api.github.com/users/brendangregg/repos","events_url":"https://api.github.com/users/brendangregg/events{/privacy}","received_events_url":"https://api.github.com/users/brendangregg/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":14,"created_at":"2016-02-16T05:56:23Z","updated_at":"2016-02-17T17:30:15Z","closed_at":null,"body":"Or \"trace\". A simple tool to trace kernel functions and print selected arguments. Possible user-level as well (or have a separate \"utrace\").\r\n\r\nThis would be used primarily for debugging. Prior examples of such tools include https://github.com/brendangregg/perf-tools/blob/master/examples/kprobe_example.txt and https://github.com/brendangregg/perf-tools/blob/master/examples/uprobe_example.txt. This ticket is a follow on from #385.\r\n\r\nPossible usage:\r\n\r\n1. ktrace do_sys_open\r\n2. ktrace r:do_sys_return\r\n3. ktrace 'do_sys_open \"%s\", %si'\r\n4. ktrace 'do_sys_open \"%s %d\", %si, %di'\r\n5. ktrace 'do_sys_open \"%s\", filename' \r\n6. ktrace 'do_sys_open (%di == 42) \"%s\", filename' \r\n7. ktrace 'do_sys_open \"%s\", %si' 'r:do_sys_open'\r\n\r\nI've dropped the \"printf()\", \"if\" syntax, and p: to make entry tracing the default. 'r:' for return tracing. The principle here is that it should be a simple tool that does:\r\n\r\n> Trace A, if B, print C.\r\n\r\nAs simple as possible, and where B & C are optional.\r\n\r\nIf such shortcuts are just too strange, then we could be explicit:\r\n\r\n1. ktrace p:do_sys_open\r\n2. ktrace r:do_sys_open\r\n3. ktrace 'p:do_sys_open printf(\"%s\", %si)'\r\n4. ktrace 'p:do_sys_open printf(\"\"%s %d\", %si, %di)'\r\n5. ktrace 'p:do_sys_open printf(\"%s\", filename)' \r\n6. ktrace 'p:do_sys_open if (%di == 42) { printf(\"%s\", filename); }' \r\n7. ktrace 'p:do_sys_open printf(\"%s\", %si)' 'r:do_sys_open'\r\n\r\nAlthough this is starting to look like a programming language, and a user may then try declaring variables and calling other functions, only to be disappointed that only \"if\" and \"printf\" are supported. This particular tool shouldn't be a do-everything programming language: just trace A, if B, print C.\r\n\r\nOutput columns could be TIME(s), PID, COMM, FUNC, where FUNC == function name traced. If arguments are printed, an extra column ARGS is added. If a return probe is traced, an RVAL column is added."},"comment":{"url":"https://api.github.com/repos/iovisor/bcc/issues/comments/185314474","html_url":"https://github.com/iovisor/bcc/issues/387#issuecomment-185314474","issue_url":"https://api.github.com/repos/iovisor/bcc/issues/387","id":185314474,"user":{"login":"goldshtn","id":1685437,"avatar_url":"https://avatars.githubusercontent.com/u/1685437?v=3","gravatar_id":"","url":"https://api.github.com/users/goldshtn","html_url":"https://github.com/goldshtn","followers_url":"https://api.github.com/users/goldshtn/followers","following_url":"https://api.github.com/users/goldshtn/following{/other_user}","gists_url":"https://api.github.com/users/goldshtn/gists{/gist_id}","starred_url":"https://api.github.com/users/goldshtn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/goldshtn/subscriptions","organizations_url":"https://api.github.com/users/goldshtn/orgs","repos_url":"https://api.github.com/users/goldshtn/repos","events_url":"https://api.github.com/users/goldshtn/events{/privacy}","received_events_url":"https://api.github.com/users/goldshtn/received_events","type":"User","site_admin":false},"created_at":"2016-02-17T17:30:15Z","updated_at":"2016-02-17T17:30:15Z","body":"@brendangregg I'd appreciate your feedback so far: https://github.com/goldshtn/bcc/tree/trace\r\n\r\nBefore opening a PR I'd like to see if there are any low-hanging fruits that I should take care of.\r\n\r\n```\r\n# ./trace.py '__kmalloc (arg1>100 && arg1<200) \"allocating %d bytes\", arg1' 'r:__kmalloc (retval==0) \"kmalloc failed!\"'\r\np:`__kmalloc FLT=(ctx->di>100 && ctx->di<200) ACT=['d']/[' ctx->di']\r\nr:`__kmalloc FLT=(ctx->ax==0) ACT=[]/[]\r\nTIME       PID    COMM         FUNC         MSG\r\n09:27:43   22406  python       __kmalloc    allocating 176 bytes\r\n09:27:43   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n09:27:45   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n09:27:47   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n09:27:50   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n09:27:52   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n09:27:54   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n09:27:56   22330  kworker/3:0  __kmalloc    allocating 152 bytes\r\n^C\r\n```"}}