{"action":"created","issue":{"url":"https://api.github.com/repos/iovisor/bcc/issues/327","repository_url":"https://api.github.com/repos/iovisor/bcc","labels_url":"https://api.github.com/repos/iovisor/bcc/issues/327/labels{/name}","comments_url":"https://api.github.com/repos/iovisor/bcc/issues/327/comments","events_url":"https://api.github.com/repos/iovisor/bcc/issues/327/events","html_url":"https://github.com/iovisor/bcc/issues/327","id":129832851,"number":327,"title":"USDT probes","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":[{"url":"https://api.github.com/repos/iovisor/bcc/labels/prio:high","name":"prio:high","color":"fad8c7"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":38,"created_at":"2016-01-29T17:34:30Z","updated_at":"2016-03-31T04:41:49Z","closed_at":null,"body":"User-level statically defined tracing probes have been placed in various applications and runtimes, including Java, Node.js, MySQL, and PostgreSQL. These allow API-stable scripts to be written, that do not depend on tracing raw user-level functions (uprobes).\r\n\r\nAs an example of hacking in USDT tracing using ftrace, see: http://www.brendangregg.com/blog/2015-07-03/hacking-linux-usdt-ftrace.html . The unpublished script I referred to is: https://gist.github.com/brendangregg/f1b3d09c14088522065b\r\n\r\nFor a simple example to trace:\r\n\r\n##### 1. Create tick-dtrace.d:\r\n```\r\nprovider tick {\r\n        probe loop(int);\r\n}\r\n\r\n#pragma D attributes Evolving/Evolving/ISA provider node provider\r\n#pragma D attributes Private/Private/Unknown provider node module\r\n#pragma D attributes Private/Private/Unknown provider node function\r\n#pragma D attributes Private/Private/ISA provider node name\r\n#pragma D attributes Evolving/Evolving/ISA provider node args\r\n```\r\n\r\n##### 2. Then create an object file:\r\n\r\n```\r\n# apt-get install -y systemtap-sdt-dev        # adds \"dtrace\"\r\n# dtrace -G -s tick-dtrace.d -o tick-dtrace.o\r\n```\r\n\r\n##### 3. Create the target program, tick-main.c:\r\n\r\n```\r\n#include <stdio.h>\r\n#include <unistd.h>\r\n/* from systemtap-sdt */\r\n#include <sys/sdt.h>\r\n\r\nint\r\nmain(int argc, char *argv[])\r\n{\r\n        int i;\r\n\r\n        for (i = 0; i < 5; i++) {\r\n                DTRACE_PROBE1(tick, loop, i);\r\n                printf(\"hi: %d\\n\", i);\r\n                sleep(1);\r\n        }\r\n\r\n        return (0);\r\n}\r\n```\r\n\r\n##### 4. Compile tick-main:\r\n\r\n```\r\ngcc -c tick-main.c\r\ngcc -o tick tick-main.o tick-dtrace.o\r\n```\r\n\r\n##### 5. Check it has USDT probes:\r\n\r\n```\r\nreadelf -n tick\r\n\r\nNotes at offset 0x0000021c with length 0x00000020:\r\n  Owner                 Data size       Description\r\n  GNU                  0x00000010       NT_GNU_ABI_TAG (ABI version tag)\r\n    OS: Linux, ABI: 2.6.35\r\n\r\nNotes at offset 0x0000023c with length 0x00000024:\r\n  Owner                 Data size       Description\r\n  GNU                  0x00000014       NT_GNU_BUILD_ID (unique build ID bitstring)\r\n    Build ID: 2b94c0e7c684a001a34d685c862b33aa51ff7672\r\n\r\nNotes at offset 0x00000a08 with length 0x00000044:\r\n  Owner                 Data size       Description\r\n  stapsdt              0x0000002e       NT_STAPSDT (SystemTap probe descriptors)\r\n    Provider: tick\r\n    Name: loop\r\n    Location: 0x0000000000400558, Base: 0x0000000000400628, Semaphore: 0x0000000000000000\r\n    Arguments: -4@-4(%rbp)\r\n```\r\n\r\nSee NT_STAPSDT etc.\r\n\r\nThis is a basic probe. There is another type, isenabled, which I discussed in the blog post, and requires a semaphore to activate."},"comment":{"url":"https://api.github.com/repos/iovisor/bcc/issues/comments/203749822","html_url":"https://github.com/iovisor/bcc/issues/327#issuecomment-203749822","issue_url":"https://api.github.com/repos/iovisor/bcc/issues/327","id":203749822,"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-03-31T04:41:49Z","updated_at":"2016-03-31T04:41:49Z","body":"@brendangregg: forgot to mention, I just did `dnf install java` on fc22 and got a libjvm with probes. "}}