{"id":597995,"date":"2023-01-16T05:50:26","date_gmt":"2023-01-16T11:50:26","guid":{"rendered":"https:\/\/news.sellorbuyhomefast.com\/index.php\/2023\/01\/16\/trace-your-python-process-line-by-line-with-minimal-overhead\/"},"modified":"2023-01-16T05:50:26","modified_gmt":"2023-01-16T11:50:26","slug":"trace-your-python-process-line-by-line-with-minimal-overhead","status":"publish","type":"post","link":"https:\/\/newsycanuse.com\/index.php\/2023\/01\/16\/trace-your-python-process-line-by-line-with-minimal-overhead\/","title":{"rendered":"Trace your Python process line by line with minimal overhead!"},"content":{"rendered":"<div data-target=\"readme-toc.content\">\n<article itemprop=\"text\">\n<div dir=\"auto\">\n<p><a target=\"_blank\" rel=\"noopener noreferrer\" href=\"http:\/\/github.com\/furkanonder\/beetrace\/blob\/main\/assets\/logo\/beetrace.png\"><img decoding=\"async\" src=\"http:\/\/github.com\/furkanonder\/beetrace\/raw\/main\/assets\/logo\/beetrace.png\" width=\"500px\"><\/a><\/p>\n<h2 dir=\"auto\">Trace your python process line by line with low overhead!<\/h2>\n<\/div>\n<p dir=\"auto\"><em>beetrace<\/em> allows you to trace a Python process line by line or the functions&#8217; entries<br \/>\nand returns. It uses USDT(User Statically-Defined Tracing) probes with<br \/>\n<a href=\"https:\/\/github.com\/iovisor\/bpftrace\/\">bpftrace<\/a>.<\/p>\n<h2 dir=\"auto\">Dependencies<\/h2>\n<ul dir=\"auto\">\n<li>\n<p dir=\"auto\">This package is only available for Linux and requires bpftrace. You can look at the<br \/>\nbpftrace installation<br \/>\n<a href=\"https:\/\/github.com\/iovisor\/bpftrace\/blob\/master\/INSTALL.md\">here<\/a>.<\/p>\n<\/li>\n<li>\n<p dir=\"auto\">CPython must be<br \/>\n<a href=\"https:\/\/docs.python.org\/3\/using\/configure.html#cmdoption-with-dtrace\" rel=\"nofollow\">configured with the &#8211;with-dtrace option<\/a>.<\/p>\n<\/li>\n<\/ul>\n<h2 dir=\"auto\">Installation<\/h2>\n<h2 dir=\"auto\">Usage &#038; Example<\/h2>\n<p dir=\"auto\">To trace the Python process, use the -p parameter to pass the pid value.<\/p>\n<div dir=\"auto\" data-snippet-clipboard-copy-content=\"beetrace -p {pid of process}\">\n<pre>beetrace -p {pid of process}<\/pre>\n<\/div>\n<p dir=\"auto\">Let&#8217;s take a look at the quick example.<\/p>\n<hr>\n<div dir=\"auto\" data-snippet-clipboard-copy-content=\"$ cat -n example.py\n1 import os\n2 from time import sleep\n3\n4\n5 def c():\n6     x = 1\n7\n8 def b():\n9     y = 2\n10    c()\n11\n12\n13 def a():\n14     z = 1\n15     b()\n16\n17\n18 while True:\n19     print(f\"PID of program: {os.getpid()}\")\n20     sleep(1)\n21     print(\"Sleep 1 second\")\n22     a()\"><\/p>\n<pre>$ cat -n example.py\n1 import os\n2 from <span>time<\/span> import sleep\n3\n4\n5 def <span>c<\/span>():\n6     x = 1\n7\n8 def <span>b<\/span>():\n9     y = 2\n10    <span>c<\/span>()\n11\n12\n13 def <span>a<\/span>():\n14     z = 1\n15     <span>b<\/span>()\n16\n17\n18 <span>while<\/span> True:\n19     print(f<span><span>\"<\/span>PID of program: {os.getpid()}<span>\"<\/span><\/span>)\n20     sleep(1)\n21     print(<span><span>\"<\/span>Sleep 1 second<span>\"<\/span><\/span>)\n22     <span>a<\/span>()<\/pre>\n<\/div>\n<p dir=\"auto\">Output:<\/p>\n<div dir=\"auto\" data-snippet-clipboard-copy-content=\"PID of program: 17988\nSleep 1 second\nPID of program: 17988\nSleep 1 second\nPID of program: 17988\nSleep 1 second\nPID of program: 17988\n...\n...\n...\"><\/p>\n<pre>PID of program: 17988\nSleep 1 second\nPID of program: 17988\nSleep 1 second\nPID of program: 17988\nSleep 1 second\nPID of program: 17988\n...\n...\n...<\/pre>\n<\/div>\n<div dir=\"auto\" data-snippet-clipboard-copy-content=\"$ beetrace -p 17988\n___  ____ ____ ___ ____ ____ ____ ____\n|__] |___ |___  |  |__\/ |__| |    |___\n|__] |___ |___  |  |   |  | |___ |___\n\nPID: 17988 | Tracing from: python3 example.py\n\nPress Control-C to quit.\n\nPath                                   File:Line                                          Function\n\/tmp                                   example.py:18                                      <module><br \/>\n\/tmp                                   example.py:19                                      <module><br \/>\n\/tmp                                   example.py:20                                      <module><br \/>\n\/tmp                                   example.py:21                                      <module><br \/>\n\/tmp                                   example.py:22                                      <module><br \/>\n\/tmp                                   example.py:14                                      a<br \/>\n\/tmp                                   example.py:15                                      a<br \/>\n\/tmp                                   example.py:9                                       b<br \/>\n\/tmp                                   example.py:10                                      b<br \/>\n\/tmp                                   example.py:6                                       c<br \/>\n\/tmp                                   example.py:18                                      <module><br \/>\n\/tmp                                   example.py:19                                      <module><br \/>\n\/tmp                                   example.py:20                                      <module><br \/>\n\/tmp                                   example.py:21                                      <module><br \/>\n\/tmp                                   example.py:22                                      <module><br \/>\n\/tmp                                   example.py:14                                      a<br \/>\n\/tmp                                   example.py:15                                      a<br \/>\n\/tmp                                   example.py:9                                       b<br \/>\n\/tmp                                   example.py:10                                      b<br \/>\n\/tmp                                   example.py:6                                       c<br \/>\n\/tmp                                   example.py:18                                      <module><br \/>\n\/tmp                                   example.py:19                                      <module><br \/>\n\/tmp                                   example.py:20                                      <module><br \/>\n&#8230;                                    &#8230;                                                &#8230;<br \/>\n&#8230;                                    &#8230;                                                &#8230;<br \/>\n&#8230;                                    &#8230;                                                &#8230;&#8221;><\/p>\n<pre>$ beetrace -p 17988\n___  ____ ____ ___ ____ ____ ____ ____\n<span>|<\/span>__] <span>|<\/span>___ <span>|<\/span>___  <span>|<\/span>  <span>|<\/span>__\/ <span>|<\/span>__<span>|<\/span> <span>|<\/span>    <span>|<\/span>___\n<span>|<\/span>__] <span>|<\/span>___ <span>|<\/span>___  <span>|<\/span>  <span>|<\/span>  <span> <\/span><span>|<\/span>  <span>|<\/span> <span>|<\/span>___ <span>|<\/span>___\n\nPID: 17988 <span>|<\/span> Tracing from: python3 example.py\n\nPress Control-C to quit.\n\nPath                                   File:Line                                          Function\n\/tmp                                   example.py:18                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:19                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:20                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:21                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:22                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:14                                      a\n\/tmp                                   example.py:15                                      a\n\/tmp                                   example.py:9                                       b\n\/tmp                                   example.py:10                                      b\n\/tmp                                   example.py:6                                       c\n\/tmp                                   example.py:18                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:19                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:20                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:21                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:22                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:14                                      a\n\/tmp                                   example.py:15                                      a\n\/tmp                                   example.py:9                                       b\n\/tmp                                   example.py:10                                      b\n\/tmp                                   example.py:6                                       c\n\/tmp                                   example.py:18                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:19                                      <span><<\/span>module<span>><\/span>\n\/tmp                                   example.py:20                                      <span><<\/span>module<span>><\/span>\n...                                    ...                                                ...\n...                                    ...                                                ...\n...                                    ...                                                ...<\/pre>\n<\/div>\n<details open>\n<summary>\n<p>    <span aria-label=\"Video description beetrace.mp4\">beetrace.mp4<\/span><br \/>\n    <span><\/span><br \/>\n  <\/summary>\n<p>  <video src=\"https:\/\/user-images.githubusercontent.com\/24194934\/212464397-0bf66a4a-4114-4d5f-b500-b7a7f7ca0eca.mp4\" data-canonical-src=\"https:\/\/user-images.githubusercontent.com\/24194934\/212464397-0bf66a4a-4114-4d5f-b500-b7a7f7ca0eca.mp4\" controls=\"controls\" muted=\"muted\"><\/p>\n<p>  <\/video><br \/>\n<\/details>\n<\/p><\/div>\n<p><a href=\"https:\/\/github.com\/furkanonder\/beetrace\" class=\"button purchase\" rel=\"nofollow noopener\" target=\"_blank\">Read More<\/a><br \/>\n Nancie Pecora<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trace your python process line by line with low overhead! beetrace allows you to trace a Python process line by line or the functions&#8217; entries and returns. It uses USDT(User Statically-Defined Tracing) probes with bpftrace. Dependencies This package is only available for Linux and requires bpftrace. You can look at the bpftrace installation here. CPython<\/p>\n","protected":false},"author":1,"featured_media":597996,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32994,46,3897],"tags":[],"class_list":["post-597995","post","type-post","status-publish","format-standard","has-post-thumbnail","category-python","category-technology","category-trace"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/posts\/597995","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/comments?post=597995"}],"version-history":[{"count":0,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/posts\/597995\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/media\/597996"}],"wp:attachment":[{"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/media?parent=597995"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/categories?post=597995"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/newsycanuse.com\/index.php\/wp-json\/wp\/v2\/tags?post=597995"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}