{"id":75474,"date":"2024-02-29T17:54:29","date_gmt":"2024-02-29T09:54:29","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=75474"},"modified":"2024-02-29T17:54:45","modified_gmt":"2024-02-29T09:54:45","slug":"c%e8%af%ad%e8%a8%80%e6%80%a7%e8%83%bd%e5%88%86%e6%9e%90%e6%9c%89%e5%93%aa%e4%ba%9b%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/75474.html","title":{"rendered":"C\u8bed\u8a00\u6027\u80fd\u5206\u6790\u6709\u54ea\u4e9b\u5de5\u5177"},"content":{"rendered":"<p style=\"text-align:center;\" ><img fetchpriority=\"high\" decoding=\"async\" class=\"alignnone size-full wp-image-75475\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/02\/generated_00-128.png?x-oss-process=image\/auto-orient,1\/format,webp\" width=\"600\" height=\"342\" alt=\"C\u8bed\u8a00\u6027\u80fd\u5206\u6790\u6709\u54ea\u4e9b\u5de5\u5177\" \/><\/p>\n<h2><strong># C\u8bed\u8a00\u6027\u80fd\u5206\u6790\u6709\u54ea\u4e9b\u5de5\u5177<\/strong><\/h2>\n<p>\u5728\u8c08\u8bbaC\u8bed\u8a00\u6027\u80fd\u5206\u6790\u5de5\u5177\u65f6\uff0c<strong>\u6211\u4eec\u4e3b\u8981\u5173\u6ce8\u4ee5\u4e0b\u51e0\u70b9\uff1a\u7f16\u8bd1\u5668\u5185\u7f6e\u5de5\u5177\u3001\u7b2c\u4e09\u65b9\u6027\u80fd\u5206\u6790\u5de5\u5177\u3001\u53ef\u89c6\u5316\u5206\u6790\u5de5\u5177<\/strong>\u3002\u8fd9\u4e9b\u5de5\u5177\u5e2e\u52a9\u5f00\u53d1\u8005\u8bc6\u522b\u7a0b\u5e8f\u4e2d\u7684\u6027\u80fd\u74f6\u9888\u3001\u4f18\u5316\u4ee3\u7801\u548c\u63d0\u9ad8\u6267\u884c\u6548\u7387\u3002\u5176\u4e2d\uff0c<strong>\u7f16\u8bd1\u5668\u5185\u7f6e\u5de5\u5177<\/strong>\u662f\u6700\u76f4\u63a5\u4e14\u6613\u4e8e\u83b7\u53d6\u7684\u6027\u80fd\u5206\u6790\u624b\u6bb5\uff0c\u5b83\u4eec\u4e0e\u7f16\u8bd1\u5668\u7d27\u5bc6\u96c6\u6210\uff0c\u80fd\u591f\u63d0\u4f9b\u5e95\u5c42\u6027\u80fd\u6570\u636e\u548c\u4f18\u5316\u5efa\u8bae\u3002<\/p>\n<p>## \u4e00\u3001\u7f16\u8bd1\u5668\u5185\u7f6e\u5de5\u5177<\/p>\n<p>\u7f16\u8bd1\u5668\u5185\u7f6e\u5de5\u5177\u662f\u6bcf\u4e2aC\u7a0b\u5e8f\u5458\u7684\u8d77\u70b9\u3002\u4f8b\u5982\uff0cGCC\u548cClang\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u6027\u80fd\u5206\u6790\u9009\u9879\uff0c\u5982`-pg`\u7528\u4e8e\u751f\u6210gprof\u5206\u6790\u6240\u9700\u7684\u4fe1\u606f\u3002<\/p>\n<p><strong>GCC\u7684GPROF<\/strong>\uff1aGCC\u7f16\u8bd1\u5668\u9644\u5e26\u7684gprof\u5de5\u5177\u53ef\u4ee5\u5206\u6790\u7a0b\u5e8f\u6267\u884c\u65f6\u7684\u65f6\u95f4\u6d88\u8017\u3002\u4f7f\u7528gprof\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u4e86\u89e3\u51fd\u6570\u8c03\u7528\u6b21\u6570\u548c\u51fd\u6570\u6267\u884c\u65f6\u95f4\uff0c\u4ece\u800c\u627e\u51fa\u7a0b\u5e8f\u4e2d\u7684\u6027\u80fd\u74f6\u9888\u3002<\/p>\n<p>&#8211; <strong>\u8be6\u7ec6\u4f7f\u7528\u65b9\u6cd5<\/strong>\uff1a\u9996\u5148\uff0c\u9700\u8981\u5728\u7f16\u8bd1\u65f6\u52a0\u4e0a`-pg`\u9009\u9879\u6765\u751f\u6210\u989d\u5916\u7684\u5206\u6790\u4fe1\u606f\u3002\u7a0b\u5e8f\u8fd0\u884c\u5b8c\u6210\u540e\uff0c\u4f1a\u751f\u6210\u4e00\u4e2a`gmon.out`\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528`gprof`\u547d\u4ee4\u6765\u5206\u6790\u8fd9\u4e2a\u6587\u4ef6\uff0c\u5b83\u4f1a\u5c55\u793a\u4e00\u4e2a\u51fd\u6570\u8c03\u7528\u56fe\u548c\u5404\u4e2a\u51fd\u6570\u7684\u6267\u884c\u65f6\u95f4\u7edf\u8ba1\u3002<\/p>\n<p>&#8211; <strong>\u4f18\u5316\u7b56\u7565<\/strong>\uff1a\u901a\u8fc7\u5206\u6790gprof\u7684\u8f93\u51fa\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8bc6\u522b\u51fa\u7a0b\u5e8f\u4e2d\u8017\u65f6\u6700\u591a\u7684\u51fd\u6570\uff0c\u5e76\u9488\u5bf9\u8fd9\u4e9b\u51fd\u6570\u8fdb\u884c\u4f18\u5316\u3002\u8fd9\u53ef\u80fd\u6d89\u53ca\u7b97\u6cd5\u6539\u8fdb\u3001\u5faa\u73af\u4f18\u5316\u6216\u8005\u51cf\u5c11\u4e0d\u5fc5\u8981\u7684\u51fd\u6570\u8c03\u7528\u3002<\/p>\n<p>## \u4e8c\u3001\u7b2c\u4e09\u65b9\u6027\u80fd\u5206\u6790\u5de5\u5177<\/p>\n<p>\u9664\u4e86\u7f16\u8bd1\u5668\u5185\u7f6e\u5de5\u5177\u5916\uff0c\u8fd8\u6709\u8bb8\u591a\u7b2c\u4e09\u65b9\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u8fd9\u4e9b\u5de5\u5177\u63d0\u4f9b\u4e86\u66f4\u591a\u529f\u80fd\u548c\u66f4\u8be6\u7ec6\u7684\u6027\u80fd\u6570\u636e\u3002<\/p>\n<p><strong>Valgrind\u7684Callgrind<\/strong>\uff1aCallgrind\u662fValgrind\u5de5\u5177\u96c6\u7684\u4e00\u90e8\u5206\uff0c\u5b83\u53ef\u4ee5\u68c0\u6d4b\u7a0b\u5e8f\u4e2d\u7684\u6bcf\u4e2a\u51fd\u6570\u8c03\u7528\u3001\u6307\u4ee4\u6267\u884c\u6b21\u6570\u4ee5\u53ca\u7f13\u5b58\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n<p>&#8211; <strong>\u7279\u70b9<\/strong>\uff1aCallgrind\u63d0\u4f9b\u7684\u6570\u636e\u6bd4gprof\u66f4\u4e3a\u8be6\u5c3d\uff0c\u5305\u62ec\u7a0b\u5e8f\u7684\u5206\u652f\u9884\u6d4b\u6548\u7387\u548c\u6307\u4ee4\u7684\u7f13\u5b58\u547d\u4e2d\u7387\u3002\u8fd9\u4e9b\u6570\u636e\u5bf9\u4e8e\u4f18\u5316\u9ad8\u6027\u80fd\u5e94\u7528\u5c24\u4e3a\u91cd\u8981\u3002<\/p>\n<p>&#8211; <strong>\u4f7f\u7528\u65b9\u6cd5<\/strong>\uff1a\u901a\u8fc7Valgrind\u5de5\u5177\u8fd0\u884c\u7a0b\u5e8f\uff0c\u5e76\u6307\u5b9aCallgrind\u4f5c\u4e3a\u5206\u6790\u5de5\u5177\u3002\u5206\u6790\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528KCachegrind\u6216\u8005\u5176\u4ed6\u517c\u5bb9\u5de5\u5177\u6765\u53ef\u89c6\u5316\u5206\u6790\u7ed3\u679c\u3002<\/p>\n<p><strong>Intel VTune Profiler<\/strong>\uff1a\u5bf9\u4e8e\u9700\u8981\u6df1\u5165\u786c\u4ef6\u5c42\u9762\u6027\u80fd\u5206\u6790\u7684\u5f00\u53d1\u8005\uff0cIntel\u7684VTune Profiler\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u529f\u80fd\u3002<\/p>\n<p>&#8211; <strong>\u4f18\u52bf<\/strong>\uff1aVTune\u80fd\u591f\u5206\u6790CPU\u5229\u7528\u7387\u3001\u5185\u5b58\u8bbf\u95ee\u6a21\u5f0f\u4ee5\u53ca\u591a\u7ebf\u7a0b\u6027\u80fd\u95ee\u9898\u3002\u5b83\u7279\u522b\u9002\u5408\u4e8e\u4f18\u5316\u8ba1\u7b97\u5bc6\u96c6\u578b\u5e94\u7528\u548c\u5e76\u884c\u8ba1\u7b97\u7a0b\u5e8f\u3002<\/p>\n<p>&#8211; <strong>\u5e94\u7528\u573a\u666f<\/strong>\uff1a\u901a\u8fc7VTune\uff0c\u5f00\u53d1\u8005\u53ef\u4ee5\u8bc6\u522b\u51faCPU\u74f6\u9888\u3001\u5185\u5b58\u8bbf\u95ee\u70ed\u70b9\u4ee5\u53ca\u7ebf\u7a0b\u7ade\u4e89\u7b49\u95ee\u9898\uff0c\u4e3a\u7a0b\u5e8f\u4f18\u5316\u63d0\u4f9b\u4e86\u91cd\u8981\u4f9d\u636e\u3002<\/p>\n<p>## \u4e09\u3001\u53ef\u89c6\u5316\u5206\u6790\u5de5\u5177<\/p>\n<p>\u53ef\u89c6\u5316\u5206\u6790\u5de5\u5177\u4f7f\u5f97\u6027\u80fd\u5206\u6790\u7ed3\u679c\u66f4\u5bb9\u6613\u7406\u89e3\uff0c\u5b83\u4eec\u901a\u5e38\u4ee5\u56fe\u5f62\u754c\u9762\u5c55\u793a\u6570\u636e\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u5feb\u901f\u5b9a\u4f4d\u95ee\u9898\u3002<\/p>\n<p><strong>KCachegrind\/QCachegrind<\/strong>\uff1a\u8fd9\u662f\u4e00\u79cd\u53ef\u89c6\u5316\u5de5\u5177\uff0c\u7528\u4e8e\u5c55\u793aCallgrind\u751f\u6210\u7684\u6027\u80fd\u6570\u636e\u3002<\/p>\n<p>&#8211; <strong>\u7279\u70b9<\/strong>\uff1aKCachegrind\/QCachegrind\u901a\u8fc7\u56fe\u8868\u548c\u56fe\u5f62\u5c55\u793a\u51fd\u6570\u8c03\u7528\u5173\u7cfb\u3001\u6267\u884c\u65f6\u95f4\u6bd4\u4f8b\u4ee5\u53ca\u5404\u79cd\u6027\u80fd\u6307\u6807\uff0c\u4f7f\u5f97\u6027\u80fd\u5206\u6790\u7ed3\u679c\u4e00\u76ee\u4e86\u7136\u3002<\/p>\n<p>&#8211; **\u4f18\u5316\u7b56\u7565<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p><strong>\u54ea\u4e9b\u5de5\u5177\u53ef\u4ee5\u7528\u4e8eC\u8bed\u8a00\u6027\u80fd\u5206\u6790\uff1f<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528Valgrind\u5de5\u5177\u6765\u8fdb\u884c\u5185\u5b58\u6cc4\u9732\u548c\u6027\u80fd\u5206\u6790\u3002Valgrind\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u68c0\u6d4b\u5185\u5b58\u6cc4\u6f0f\u3001\u4e0d\u5339\u914d\u7684\u91ca\u653e\u4ee5\u53ca\u6027\u80fd\u95ee\u9898\uff0c\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u8005\u66f4\u597d\u5730\u4f18\u5316\u4ee3\u7801\u3002<\/p>\n<p><strong>\u53e6\u5916\uff0c\u8fd8\u53ef\u4ee5\u4f7f\u7528Gprof\u6765\u8fdb\u884cC\u8bed\u8a00\u6027\u80fd\u5206\u6790\u3002<\/strong> Gprof\u662f\u4e00\u4e2aGNU\u9879\u76ee\u63d0\u4f9b\u7684\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u751f\u6210\u7a0b\u5e8f\u7684\u6027\u80fd\u7edf\u8ba1\u4fe1\u606f\uff0c\u5e2e\u52a9\u6211\u4eec\u627e\u51fa\u4ee3\u7801\u4e2d\u6267\u884c\u65f6\u95f4\u5360\u6bd4\u8f83\u9ad8\u7684\u51fd\u6570\uff0c\u4ece\u800c\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n<p><strong>\u9664\u6b64\u4e4b\u5916\uff0c\u8fd8\u6709\u4e00\u4e9b\u4e13\u95e8\u7528\u4e8e\u6027\u80fd\u5206\u6790\u7684\u5de5\u5177\uff0c\u6bd4\u5982Perf\u548cCallgrind\u3002<\/strong> Perf\u662f\u4e00\u4e2aLinux\u7cfb\u7edf\u4e0a\u7684\u6027\u80fd\u5206\u6790\u5de5\u5177\uff0c\u53ef\u4ee5\u76d1\u89c6\u7cfb\u7edf\u8d44\u6e90\u7684\u4f7f\u7528\u60c5\u51b5\uff0c\u5e2e\u52a9\u5f00\u53d1\u8005\u627e\u51fa\u4ee3\u7801\u4e2d\u7684\u6027\u80fd\u74f6\u9888\uff1b\u800cCallgrind\u662fValgrind\u5de5\u5177\u96c6\u7684\u4e00\u90e8\u5206\uff0c\u53ef\u4ee5\u8fdb\u884c\u51fd\u6570\u7ea7\u522b\u7684\u6027\u80fd\u5206\u6790\uff0c\u8be6\u7ec6\u8bb0\u5f55\u51fd\u6570\u8c03\u7528\u5173\u7cfb\u548c\u8c03\u7528\u6b21\u6570\uff0c\u5e2e\u52a9\u4f18\u5316\u4ee3\u7801\u903b\u8f91\u7ed3\u6784\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"# C\u8bed\u8a00\u6027\u80fd\u5206\u6790\u6709\u54ea\u4e9b\u5de5\u5177 \u5728\u8c08\u8bbaC\u8bed\u8a00\u6027\u80fd\u5206\u6790\u5de5\u5177\u65f6\uff0c\u6211\u4eec\u4e3b\u8981\u5173\u6ce8\u4ee5\u4e0b\u51e0\u70b9\uff1a\u7f16\u8bd1\u5668\u5185\u7f6e\u5de5\u5177\u3001\u7b2c\u4e09\u65b9\u6027\u80fd\u5206\u6790 [&hellip;]","protected":false},"author":1,"featured_media":75477,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/75474"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=75474"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/75474\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/75477"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=75474"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=75474"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=75474"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}