{"id":6347,"date":"2017-09-29T15:46:02","date_gmt":"2017-09-29T07:46:02","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=6347"},"modified":"2017-09-29T15:46:02","modified_gmt":"2017-09-29T07:46:02","slug":"%e7%94%a8pyflame%e6%9d%a5%e5%81%9apython%e7%a8%8b%e5%ba%8f%e7%9a%84%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/6347.html","title":{"rendered":"\u7528pyflame\u6765\u505apython\u7a0b\u5e8f\u7684\u6027\u80fd\u5206\u6790"},"content":{"rendered":"<p>pyflame\u662fuber\u5b98\u65b9\u5f00\u6e90\u7684python\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u4f18\u70b9\u662f\u4e0d\u7528\u4fee\u6539\u4f60\u7684Python\u4ee3\u7801\uff0c\u76f4\u63a5\u7528\u547d\u4ee4\u884c\u5bf9\u4f60\u7684Python\u8fdb\u7a0b\u8fdb\u884cprofile\uff0c\u62ff\u5230\u7ed3\u679c\u770b\u56fe\u8868\u5c31\u597d\u4e86\u3002<\/p>\n<p>\u6309\u7167\u5b98\u65b9\u6587\u6863\u8fdb\u884c\u5b89\u88c5\uff1ahttps:\/\/github.com\/uber\/pyflame<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install autoconf automake autotools-dev g++ pkg-config python-dev python3-dev libtool make\r\n\r\ngit clone https:\/\/github.com\/uber\/pyflame.git\r\ncd pyflame\r\n\r\n.\/autogen.sh\r\n.\/configure\r\nmake\r\n\r\n<\/pre>\n<p>\u5b89\u88c5\u597d\u540e\u53ef\u6267\u884c\u6587\u4ef6\u5728 .\/src\/pyflame \u4e2d\u3002<\/p>\n<p>\u7b80\u5355\u7684\u4f7f\u7528\u8bf4\u660e\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\n# Attach to PID 12345 and profile it for 1 second\r\npyflame -p 12345\r\n\r\n# Attach to PID 768 and profile it for 5 seconds, sampling every 0.01 seconds\r\npyflame -s 5 -r 0.01 -p 768\r\n\r\n# Run py.test against tests\/, emitting sample data to prof.txt\r\npyflame -o prof.txt -t py.test tests\/\r\n<\/pre>\n<p>\u8f93\u51fa\u7684profile\u7ed3\u679c\u662f flamegraph.pl \u683c\u5f0f\u7684\uff0cflamegraph.pl\u662f\u4e00\u4e2aperl\u811a\u672c\uff0c\u7528\u4e8e\u628a\u4e0a\u8ff0\u8f93\u51fa\u7ed3\u679c\u751f\u6210svg\u53ef\u89c6\u5316\u56fe\u50cf\u7684\u3002<\/p>\n<p>\u6240\u4ee5\u4f60\u53ef\u4ee5\u76f4\u63a5\u8fd9\u6837\u8c03\u7528<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nwget &quot;https:\/\/raw.githubusercontent.com\/brendangregg\/FlameGraph\/master\/flamegraph.pl&quot;\r\nchmod +x flamegraph.pl\r\n\r\n# Generate flame graph for pid 12345; assumes flamegraph.pl is in your $PATH.\r\npyflame -s 5 -r 0.01 -p 768 | flamegraph.pl &gt; myprofile.svg\r\n<\/pre>\n<p>\u751f\u6210\u7684\u706b\u7130\u56fe\u53ef\u4ee5\u7528chrome\u6253\u5f00\uff0c\u80fd\u8fdb\u884c\u7f29\u653e\u548c\u9009\u62e9\u64cd\u4f5c\u3002<\/p>\n<p>\u706b\u7130\u56fe\u7684\u5177\u4f53\u542b\u4e49\u53ef\u4ee5\u53c2\u8003\u962e\u4e00\u5cf0\u8001\u5e08\u7684\u6587\u7ae0\uff1ahttp:\/\/www.ruanyifeng.com\/blog\/2017\/09\/flame-graph.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pyflame\u662fuber\u5b98\u65b9\u5f00\u6e90\u7684python\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u4f18\u70b9\u662f\u4e0d\u7528\u4fee\u6539\u4f60\u7684Python\u4ee3\u7801\uff0c\u76f4\u63a5\u7528\u547d\u4ee4\u884c\u5bf9 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-6347","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6347","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=6347"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6347\/revisions"}],"predecessor-version":[{"id":6348,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/6347\/revisions\/6348"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=6347"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=6347"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=6347"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}