{"id":10020847,"date":"2025-06-23T22:25:26","date_gmt":"2025-06-23T14:25:26","guid":{"rendered":"https:\/\/itmax.cn\/?p=10020847"},"modified":"2025-06-23T22:25:26","modified_gmt":"2025-06-23T14:25:26","slug":"%e7%94%a8-py-spy-%e5%af%b9-python-%e7%a8%8b%e5%ba%8f%e8%bf%9b%e8%a1%8c%e6%80%a7%e8%83%bd%e7%9b%91%e6%8e%a7%ef%bc%8c%e5%b9%b6%e4%bc%98%e5%8c%96","status":"publish","type":"post","link":"https:\/\/itmax.cn\/?p=10020847","title":{"rendered":"\u7528 py-spy \u5bf9 python \u7a0b\u5e8f\u8fdb\u884c\u6027\u80fd\u76d1\u63a7\uff0c\u5e76\u4f18\u5316"},"content":{"rendered":"<p>py-spy<\/p>\n<h2>\u5b89\u88c5<\/h2>\n<pre><code class=\"shell\"># pip install py-spy -i  https:\/\/mirrors.aliyun.com\/pypi\/simple\/<\/code><\/pre>\n<p>\u8f93\u51fa<\/p>\n<pre><code>sh-4.2# pip install py-spy -i  https:\/\/mirrors.aliyun.com\/pypi\/simple\/\nDEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https:\/\/pip.pypa.io\/en\/latest\/development\/release-process\/#python-2-support pip 21.0 will remove support for this functionality.\nLooking in indexes: https:\/\/mirrors.aliyun.com\/pypi\/simple\/\nCollecting py-spy\n  Downloading https:\/\/mirrors.aliyun.com\/pypi\/packages\/c9\/c1\/5e012669ebb687e546dc99fcfc4861ebfcf3a337b7a41af945df23140bb5\/py_spy-0.4.0-py2.py3-none-manylinux_2_5_x86_64.manylinux1_x86_64.whl (2.7 MB)\n     |\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588| 2.7 MB 1.1 MB\/s \nInstalling collected packages: py-spy\nSuccessfully installed py-spy-0.4.0<\/code><\/pre>\n<h2>\u4f7f\u7528<\/h2>\n<p>\u7528top \u627e\u5230\u5360\u7528cpu\u9ad8\u7684\u7a0b\u5e8f<\/p>\n<pre><code># top<\/code><\/pre>\n<p>\u8f93\u51fa<\/p>\n<pre><code>top - 10:38:44 up 287 days, 12:34,  0 users,  load average: 12.57, 10.92, 10.09\nTasks:  27 total,   4 running,  23 sleeping,   0 stopped,   0 zombie\n%Cpu(s): 20.3 us,  3.9 sy,  0.0 ni, 73.1 id,  0.0 wa,  0.0 hi,  2.7 si,  0.0 st\nKiB Mem : 26381324+total,  6515296 free, 21381326+used, 43484692 buff\/cache\nKiB Swap:        0 total,        0 free,        0 used. 46831644 avail Mem \n\n    PID USER      PR  NI    VIRT    RES    SHR S  %CPU %MEM     TIME+ COMMAND   \n     19 root      20   0 1469452 164264  10836 R 101.0  0.1   3:18.40 python    \n     28 root      20   0 1488212 152292  12160 R 101.0  0.1   3:19.60 python    \n     29 root      20   0 1504032 166216  16440 R 100.3  0.1   3:17.54 python    \n    445 root      20   0 1811540 148344  16556 S  12.3  0.1   0:00.76 python    \n     21 root      20   0 1504656  42840  16204 S   8.3  0.0   0:16.91 python    \n     30 root      20   0 2797244  34032  10720 S   8.3  0.0   0:17.09 python    \n     24 root      20   0 1487544  39276  12320 S   8.0  0.0   0:14.84 python    \n     25 root      20   0 2602332  38744  15152 S   8.0  0.0   0:15.25 python    \n     27 root      20   0 1496984  38784  14920 S   8.0  0.0   0:16.31 python    \n     22 root      20   0 1469752  33660  11168 S   5.0  0.0   0:09.68 python    \n     26 root      20   0 1487900  35288  11876 S   5.0  0.0   0:09.80 python    \n     13 root      20   0 1750800  50184  16708 S   1.3  0.0   0:02.37 python    \n     14 root      20   0 1750800  47872  16728 S   1.3  0.0   0:02.25 python    \n     16 root      20   0 1750800  49836  16628 S   1.3  0.0   0:02.39 python    \n     17 root      20   0 1750800  48208  16580 S   1.3  0.0   0:02.33 python    \n     15 root      20   0 1750800  52168  16932 S   1.0  0.0   0:02.30 python    \n     11 root      20   0  122540  19120   3388 S   0.7  0.0   0:03.97 supervis+ <\/code><\/pre>\n<p>\u4e0a\u9762\u8fdb\u7a0b\u53f7 19\uff0c28\uff0c 29\u90fd\u5f88\u9ad8, py-spy \u51fa\u573a<\/p>\n<pre><code># py-spy top --pid 19<\/code><\/pre>\n<p>\u8f93\u51fa<\/p>\n<pre><code>Collecting samples from '\/usr\/local\/bin\/python -u message_consumer.py action_message mygroupid111' (python v2.7.17)\nTotal Samples 4281\nGIL: 98.00%, Active: 100.00%, Threads: 1\n\n  %Own   %Total  OwnTime  TotalTime  Function (filename)                        \n 47.00%  47.00%   20.52s    20.52s   raw_decode (json\/decoder.py)\n 21.00% 100.00%   10.34s    42.81s   &lt;module&gt; (message_consumer.py)\n 20.00%  20.00%    6.54s     6.54s   decode (encodings\/utf_8.py)\n  9.00%  56.00%    4.21s    24.73s   decode (json\/decoder.py)\n  3.00%  59.00%    1.20s    25.93s   loads (json\/__init__.py)\n\n\nPress Control-C to quit, or ? for help.<\/code><\/pre>\n<p>\u4e0a\u9762\u53ef\u4ee5\u770b\u5230\u6027\u80fd\u74f6\u9888\u5728json decoder\u4e0a<\/p>\n<p>\u628a\u8f93\u51fa\u585e\u7ed9AI, \u52a0\u4e0a\u6e90\u4ee3\u7801\uff0c\u9a6c\u4e0a\u5f97\u5230\u4f18\u5316\u65b9\u6309\uff0c\u7528ujson\u66ff\u4ee3json, \u52a0\u4e0a\u5176\u4ed6\u7684\u7f13\u5b58\uff0c\u95ee\u9898\u89e3\u51b3\uff01<\/p>\n<p><a href=\"https:\/\/segmentfault.com\/a\/1190000046792747\">https:\/\/segmentfault.com\/a\/1190000046792747<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>py-spy \u5b89\u88c5 # pip install py-spy -i https:\/\/mirrors.aliyu [&hellip;]<\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[4],"tags":[],"class_list":["post-10020847","post","type-post","status-publish","format-standard","hentry","category-share"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020847","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10020847"}],"version-history":[{"count":0,"href":"https:\/\/itmax.cn\/index.php?rest_route=\/wp\/v2\/posts\/10020847\/revisions"}],"wp:attachment":[{"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10020847"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10020847"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itmax.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10020847"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}