{"id":865,"date":"2021-12-18T23:21:38","date_gmt":"2021-12-18T15:21:38","guid":{"rendered":"https:\/\/blog.cauchyschwarz.com\/?p=865"},"modified":"2021-12-18T23:37:37","modified_gmt":"2021-12-18T15:37:37","slug":"kernel-tracing-techniques","status":"publish","type":"post","link":"https:\/\/blog.cauchyschwarz.com\/?p=865","title":{"rendered":"kernel tracing techniques"},"content":{"rendered":"\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-right counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-69e0eb19607cb\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-69e0eb19607cb\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#Install_debug_symbols\" >Install debug symbols<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#Install_kernel_source\" >[Install kernel source]<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#Perf_probe\" >Perf probe<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#kprobe\" >kprobe<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#ftrace\" >ftrace<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#ebpf\" >ebpf<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.cauchyschwarz.com\/?p=865\/#SystemTap\" >SystemTap<\/a><\/li><\/ul><\/nav><\/div>\n<h1 class=\"wp-block-heading\" id=\"install-debug-symbols\"><span class=\"ez-toc-section\" id=\"Install_debug_symbols\"><\/span><a href=\"https:\/\/wiki.ubuntu.com\/Debug%20Symbol%20Packages\">Install debug symbols<\/a><span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>And read&nbsp;<a href=\"https:\/\/askubuntu.com\/a\/197057\/580128\">this SO answer<\/a>.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"install-kernel-source\"><span class=\"ez-toc-section\" id=\"Install_kernel_source\"><\/span>[Install kernel source]<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">sudo apt install linux-source-4.15.0\n<\/code><\/pre>\n\n\n\n<p>Then go to&nbsp;<em>\/usr\/src\/linux-source-4.15.0<\/em>&nbsp;to uncompress the kernel source files.<\/p>\n\n\n\n<p>The kernel source version 4.15.0 is not 100 percent matched with&nbsp;<code>uname -r<\/code>&nbsp;output, but it doesn&#8217;t seem to be a big problem.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"perf-probe\"><span class=\"ez-toc-section\" id=\"Perf_probe\"><\/span>Perf probe<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>Now you can trace kernel functions with&nbsp;<code>perf probe<\/code>&nbsp;command.<\/p>\n\n\n\n<p><code>perf probe -s \/usr\/src\/linux-source-4.15.0 -vvv -L tcp_sendmsg<\/code><\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>\u5f88\u591a\u65f6\u5019\uff0c\u51fa\u4e8edebug\u6216\u8005\u89c2\u6d4b\u7684\u76ee\u7684\uff0c\u6211\u4eec\u9700\u8981\u80fd\u591ftrace\u5185\u6838\u7684\u6267\u884c\u6d41\u7a0b\u548c\u5185\u90e8\u72b6\u6001\u53d8\u5316\u3002\u56e0\u6b64\u8fd9\u91cc\u6c47\u603b\u4e0b\u5e38\u7528\u7684Linux Kernel Tracing\u6280\u672f\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"kprobe\"><span class=\"ez-toc-section\" id=\"kprobe\"><\/span>kprobe<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p>\u5173\u4e8ekprobe\u7684\u4ecb\u7ecd\u548c\u5165\u95e8\u6559\u7a0b\u53ef\u4ee5\u5b66\u4e60<a href=\"https:\/\/blog.csdn.net\/luckyapple1028\/article\/details\/52972315\">\u8fd9\u7bc7csdn\u4e0a\u535a\u5ba2<\/a>\u3002\u8fd9\u7bc7\u535a\u5ba2\u5199\u7684\u771f\u662f\u592a\u597d\u4e86\uff0c\u4e0d\u50cf\u5927\u591a\u6570csdn\u4e0a\u7684\u5176\u4ed6\u6587\u7ae0\uff0c\u90fd\u662f\u8f6c\u8f7d\u8fd8\u4e0d\u6ce8\u660e\u51fa\u5904\u7684\u5783\u573e\u3002\u4e0d\u8fc7\u91cc\u9762\u4f8b\u5b50\u91cc\u7684<code>do_fork<\/code>\u51fd\u6570\u5e94\u8be5\u662f<code>_do_fork<\/code>\u51fd\u6570\u624d\u5bf9\uff0c\u6211\u4e0d\u77e5\u9053\u662f\u4f5c\u8005\u7b14\u8bef\u8fd8\u662f\u56e0\u4e3a\u51fd\u6570\u540d\u79f0\u5728Linux\u7684\u7248\u672c\u66f4\u8fed\u4e2d\u53d8\u4e86\uff0c\u6ca1\u6709\u53bb\u67e5\u8bc1\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ftrace\"><span class=\"ez-toc-section\" id=\"ftrace\"><\/span>ftrace<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<p><a href=\"https:\/\/www.apriorit.com\/dev-blog\/544-hooking-linux-functions-1\">\u4e00\u7bc7ftrace\u7684\u5165\u95e8\u6559\u7a0b<\/a>\u3002\u8fd9\u7bc7\u6587\u7ae0\u4e5f\u8bb2\u4e86\u53e6\u5916\u51e0\u79cd\u6280\u672f\uff0c\u540e\u9762\u4e00\u4e00\u4ecb\u7ecd\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"ebpf\"><span class=\"ez-toc-section\" id=\"ebpf\"><\/span>ebpf<span class=\"ez-toc-section-end\"><\/span><\/h1>\n\n\n\n<h1 class=\"wp-block-heading\" id=\"systemtap\"><span class=\"ez-toc-section\" id=\"SystemTap\"><\/span>SystemTap<span class=\"ez-toc-section-end\"><\/span><\/h1>\n","protected":false},"excerpt":{"rendered":"<p>Install debug symbols And read&nbsp;this SO answer. [Install kernel source] Then go to&nbsp;\/usr\/src&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[37],"class_list":["post-865","post","type-post","status-publish","format-standard","hentry","category-10","tag-kernel"],"_links":{"self":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/865","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=865"}],"version-history":[{"count":2,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/865\/revisions"}],"predecessor-version":[{"id":868,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=\/wp\/v2\/posts\/865\/revisions\/868"}],"wp:attachment":[{"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=865"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=865"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.cauchyschwarz.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=865"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}