{"id":1950,"date":"2012-08-19T00:57:28","date_gmt":"2012-08-18T16:57:28","guid":{"rendered":"https:\/\/kyle.ai\/blog\/?p=1950"},"modified":"2013-11-21T18:28:04","modified_gmt":"2013-11-21T10:28:04","slug":"%e5%88%a9%e7%94%a8xdebug%e4%b8%8ekcachegrind%e8%bf%9b%e8%a1%8cphp%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/1950.html","title":{"rendered":"\u5229\u7528XDebug\u4e0eKCachegrind\u8fdb\u884cPHP\u6027\u80fd\u5206\u6790"},"content":{"rendered":"<p>xdebug\u662fphp\u7684\u4e00\u4e2a\u8c03\u8bd5\u5de5\u5177\uff0c\u4f46\u662f\u8fd8\u6709\u4e00\u4e2a\u529f\u80fd\u5c31\u662fprofiler\uff0c\u53ef\u4ee5\u7528\u6765\u5206\u6790\u6027\u80fd\u74f6\u9888(bottleneck)\u3002<\/p>\n<p>\u5f15\u7528\u5b98\u65b9\u7684\u4ecb\u7ecd http:\/\/xdebug.org\/docs\/profiler\uff1a<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nXdebug's Profiler is a powerful tool that gives you the ability to analyze your PHP code\r\nand determine bottlenecks or generally see which parts of your code are slow and could use a speed boost.\r\nThe profiler in Xdebug 2 outputs profiling information in the form of a cachegrind compatible file.\r\nThis allows you to use the excellent KCacheGrind tool (Linux\/Windows, KDE) to analyse your profiling data.\r\nIf you are on Linux you can install KCacheGrind with your favourite package manager;\r\nif you are on Windows you can get precompiled binaries of KCacheGrind at SourceForge.\r\n<\/pre>\n<p>\u5728ubuntu\u4e2d\u7528\u547d\u4ee4\u5b89\u88c5php\u7684xdebug\u6269\u5c55\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install php5-xdebug\r\n<\/pre>\n<p>\u5b89\u88c5\u5b8c\u540e\uff0c\u9700\u8981\u5728php.ini\u4e2d\u914d\u7f6e\u4e00\u4e0bxdebug\u53c2\u6570\uff0c\u5728 ubuntu \u4e2d\u5c31\u662f \/etc\/php5\/conf.d\/xdebug.ini\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nzend_extension=\/usr\/lib\/php5\/20090626\/xdebug.so\r\n; profiler settings\r\nxdebug.profiler_append=1\r\nxdebug.profiler_enable=0                               #\u9ed8\u8ba4\u4e0d\u5f00\u542fprofile\u529f\u80fd\uff0c\u7531\u4e0b\u9762\u7684trigger\u53c2\u6570\u8bbe\u7f6e\u6210\u7531\u53c2\u6570\u6765\u89e6\u53d1\r\nxdebug.profiler_enable_trigger=1\r\nxdebug.profiler_output_name=cachegrind.out.%s.%H       #\u8f93\u51faprofiler\u6587\u4ef6\u7684\u547d\u540d\u89c4\u5219\r\nxdebug.profiler_output_dir=&quot;\/home\/chenming\/xdebug\/&quot;    #\u8f93\u51faprofiler\u6587\u4ef6\u7684\u4f4d\u7f6e\uff0c\u8981\u6709\u53ef\u8bfb\u5199\u6743\u9650\r\nxdebug.trace_output_dir=&quot;\/home\/chenming\/xdebug\/&quot;\r\nxdebug.remote_enable=true\r\nxdebug.remote_host=127.0.0.1\r\nxdebug.remote_port=9000\r\nxdebug.remote_handler=dbgp\r\n<\/pre>\n<p>\u6211\u4eec\u4e0a\u9762\u8bbe\u7f6e\u7684profiler_enable_trigger\u53c2\u6570\uff0c\u8868\u793a\u901a\u8fc7XDEBUG_PROFILE\u8fd9\u4e2aGET\u6216POST\u53c2\u6570\u624b\u52a8\u6765\u89e6\u53d1proflile\u529f\u80fd\u3002<br \/>\n\u5728chrome\u91cc\u9762\u6709\u4e2a\u65b9\u4fbf\u7684\u63d2\u4ef6\uff0cxdebug helper\uff0c\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u5f00\u542fxdebug\u7684\u5404\u79cd\u529f\u80fd\u3002<\/p>\n<p><a href=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/08\/0819001.png\"><img loading=\"lazy\" decoding=\"async\" title=\"0819001\" src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/08\/0819001.png\" alt=\"\" width=\"575\" height=\"326\" \/><\/a><\/p>\n<p>\u4e0a\u56fe\u4e2d\u7684\u65f6\u949f\u4e00\u6837\u7684\u5c0f\u56fe\u6807\uff0c\u5c31\u8868\u793a\u5f00\u542fprofile\u3002<br \/>\n\u8fd0\u884c\u540e\u5c31\u4f1a\u5728\u6211\u4eec\u8bbe\u7f6e\u7684\u76ee\u5f55\u91cc\u9762\u751f\u6210\u4e00\u4e2aout\u6587\u4ef6\uff1acachegrind.out._home_chenming_www_weborbit_coreHander_php.localhost<\/p>\n<p>\u8fd9\u65f6\u5019\u5149\u6709\u8fd9\u4e2a\u6587\u4ef6\u770b\u4e0d\u51fa\u4ec0\u4e48\u540d\u5802\u3002\u6211\u4eec\u9700\u8981\u4e00\u4e2a\u5c06\u6570\u636e\u53ef\u89c6\u5316\u7684\u5de5\u5177\uff1aKCachegrind<\/p>\n<p>\u5728ubuntu\u4e2d\u901a\u8fc7\u4e0b\u9762\u547d\u4ee4\u6765\u5b89\u88c5KCachegrind\uff1a<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nsudo apt-get install kcachegrind\r\n<\/pre>\n<p>\u5b89\u88c5\u597d\u540e\u542f\u52a8\uff0c\u6253\u5f00\u6211\u4eec\u521a\u751f\u6210\u7684out\u6587\u4ef6\uff0c\u5c31\u6709\u4e86\u53ef\u89c6\u5316\u754c\u9762\uff1a<\/p>\n<p><a href=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/08\/0819002.png\"><img loading=\"lazy\" decoding=\"async\" title=\"0819002\" src=\"https:\/\/kyle.ai\/blog\/wp-content\/uploads\/2012\/08\/0819002.png\" alt=\"\" width=\"1366\" height=\"744\" \/><\/a><\/p>\n<p>\u5bf9\u754c\u9762\u7684\u4e00\u4e9b\u8bf4\u660e\u3002\u5de6\u8fb9\u7684\u51fd\u6570\u5217\u8868\u4e2d\uff0c\u5217\u51fa\u4e86\u8c03\u7528\u8fc7\u7684\u6bcf\u4e2a\u51fd\u6570\uff0c\u5176\u4e2dphp\u5185\u7f6e\u51fd\u6570\u7528php::\u6807\u8bc6\u51fa\u6765\u4e86\u7684\u3002\u5176\u4e2dself\u680f\u8868\u672a\u8be5\u51fd\u6570\u81ea\u8eab\u82b1\u8d39\u4e86\u591a\u5c11\u65f6\u95f4(\u767e\u5206\u6bd4)\uff0ccalled\u8868\u793a\u603b\u5171\u88ab\u8c03\u7528\u4e86\u591a\u5c11\u6b21\u3002<br \/>\n\u53f3\u8fb9\u7684\u56fe\u8868\uff0c\u4e0a\u534a\u90e8\u8868\u793a\u5f53\u524d\u51fd\u6570\u8c03\u7528\u4e86\u54ea\u4e9b\u5b50\u51fd\u6570\uff0c\u548c\u4e2a\u5b50\u51fd\u6570\u82b1\u8d39\u7684\u65f6\u95f4\u6bd4\u4f8b\u662f\u600e\u6837\u7684\u3002\u4e0b\u534a\u90e8\u8868\u793a\u8c03\u7528\u5c42\u6b21\u7ed3\u6784\u56fe\u3002<br \/>\n\u5728\u6700\u4e0b\u9762\u7684\u72b6\u6001\u680f\u4e2d\uff0c\u6709\u663e\u793a\u5f53\u524d\u6267\u884c\u603b\u5171\u7528\u4e86\u591a\u5c11\u65f6\u95f4\u3002<\/p>\n<p>\u53e6\u5916KCachegrind\u8fd9\u4e2a\u5de5\u5177\u4e0d\u4ec5\u4ec5\u662f\u9488\u5bf9php\u7684\u54e6\uff0c\u5176\u5b83\u50cfc\u3001c++\u3001python\u7b49\u90fd\u53ef\u4ee5\u7528\u5b83\u6765\u8fdb\u884c\u6027\u80fd\u5206\u6790\uff0c\u5185\u5b58\u6cc4\u9732\u5206\u6790\u7b49\u3002<br \/>\n\u6bd4\u5982\uff0c<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhttp:\/\/stackoverflow.com\/questions\/1896032\/using-cprofile-results-with-kcachegrind\r\n<\/pre>\n<p>\u8fd9\u91cc\u5c31\u6709\u8ba8\u8bbapython\u3002<br \/>\n\u8fd9\u91cc\uff0c<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nhttp:\/\/blog.dccmx.com\/2011\/01\/callgrind\/\r\n<\/pre>\n<p>\u5c31\u6709\u8ba8\u8bbaC\u7684\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>xdebug\u662fphp\u7684\u4e00\u4e2a\u8c03\u8bd5\u5de5\u5177\uff0c\u4f46\u662f\u8fd8\u6709\u4e00\u4e2a\u529f\u80fd\u5c31\u662fprofiler\uff0c\u53ef\u4ee5\u7528\u6765\u5206\u6790\u6027\u80fd\u74f6\u9888(bottlen [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1950","post","type-post","status-publish","format-standard","hentry","category-skill"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1950","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=1950"}],"version-history":[{"count":7,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1950\/revisions"}],"predecessor-version":[{"id":5018,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/1950\/revisions\/5018"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=1950"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=1950"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=1950"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}