{"action":"created","issue":{"url":"https://api.github.com/repos/iovisor/bcc/issues/136","labels_url":"https://api.github.com/repos/iovisor/bcc/issues/136/labels{/name}","comments_url":"https://api.github.com/repos/iovisor/bcc/issues/136/comments","events_url":"https://api.github.com/repos/iovisor/bcc/issues/136/events","html_url":"https://github.com/iovisor/bcc/issues/136","id":101561342,"number":136,"title":"Easier trace_pipe handling","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":"closed","locked":false,"assignee":{"login":"drzaeus77","id":3770556,"avatar_url":"https://avatars.githubusercontent.com/u/3770556?v=3","gravatar_id":"","url":"https://api.github.com/users/drzaeus77","html_url":"https://github.com/drzaeus77","followers_url":"https://api.github.com/users/drzaeus77/followers","following_url":"https://api.github.com/users/drzaeus77/following{/other_user}","gists_url":"https://api.github.com/users/drzaeus77/gists{/gist_id}","starred_url":"https://api.github.com/users/drzaeus77/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/drzaeus77/subscriptions","organizations_url":"https://api.github.com/users/drzaeus77/orgs","repos_url":"https://api.github.com/users/drzaeus77/repos","events_url":"https://api.github.com/users/drzaeus77/events{/privacy}","received_events_url":"https://api.github.com/users/drzaeus77/received_events","type":"User","site_admin":false},"milestone":null,"comments":6,"created_at":"2015-08-18T03:21:41Z","updated_at":"2015-08-22T19:46:04Z","closed_at":"2015-08-22T19:46:04Z","body":"Some code I'm commonly using (Python):\r\n\r\n```python\r\nb = BPF(...)\r\n\r\n# open trace pipe\r\ntry:\r\n\ttrace = open(\"/sys/kernel/debug/tracing/trace_pipe\", \"r\")\r\nexcept:\r\n\tprint >> sys.stderr, \"ERROR: opening trace_pipe\"\r\n\texit(1)\r\n\r\n# format output\r\nwhile 1:\r\n\ttry:\r\n\t\tline = trace.readline().rstrip()\r\n\texcept KeyboardInterrupt:\r\n\t\tpass; exit()\r\n```\r\n\r\nThis could be improved. Eg:\r\n\r\n```python\r\nb = BPF(...)\r\n\r\n# format output\r\nwhile 1:\r\n\ttry:\r\n\t\tline = b.read_trace_pipe()\r\n\texcept KeyboardInterrupt:\r\n\t\tpass; exit()\r\n```\r\n\r\nBPF can provide a read_trace_pipe() function to perform a readline() and rstrip() from the trace_pipe. It can open the trace_pipe if it wasn't already open (therefore the trace_pipe isn't opened unless the user explicitly uses the BPF.read_trace_pipe() function).\r\n\r\nPerhaps the implementation could also use trace instances (see Instances in https://github.com/torvalds/linux/blob/master/Documentation/trace/ftrace.txt), so that multiple concurrent users would use separate trace_pipes."},"comment":{"url":"https://api.github.com/repos/iovisor/bcc/issues/comments/133745189","html_url":"https://github.com/iovisor/bcc/issues/136#issuecomment-133745189","issue_url":"https://api.github.com/repos/iovisor/bcc/issues/136","id":133745189,"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},"created_at":"2015-08-22T19:46:04Z","updated_at":"2015-08-22T19:46:04Z","body":"Thanks, #156 should so I'll close this ticket (I'll add some comments to #156)."}}