{"id":202732,"date":"2025-05-22T08:32:16","date_gmt":"2025-05-22T00:32:16","guid":{"rendered":"https:\/\/server.hk\/cnblog\/202732\/"},"modified":"2025-05-22T08:32:16","modified_gmt":"2025-05-22T00:32:16","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-profiling-%e5%b7%a5%e5%85%b7%e5%88%86%e6%9e%90-java-%e5%87%bd%e6%95%b0%e6%80%a7%e8%83%bd","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/202732\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 profiling \u5de5\u5177\u5206\u6790 Java \u51fd\u6570\u6027\u80fd"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u5982\u4f55\u4f7f\u7528 profiling \u5de5\u5177\u5206\u6790 Java \u51fd\u6570\u6027\u80fd<\/h1>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5982\u4f55\u4f7f\u7528 profiling \u5de5\u5177\u5206\u6790 Java \u51fd\u6570\u6027\u80fd\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p>\u4f7f\u7528 Java \u4e2d\u7684 JProfiler \u5de5\u5177\u8fdb\u884c\u6027\u80fd\u5206\u6790\uff0c\u53ef\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a\u5b89\u88c5 JProfiler \u5e76\u914d\u7f6e\u4e3a\u4f7f\u7528 Java \u5e94\u7528\u7a0b\u5e8f\uff1b\u5f55\u5236\u6027\u80fd\u6570\u636e\uff1b\u4f7f\u7528 Flame Graph \u786e\u5b9a\u6700\u957f\u7684\u8c03\u7528\u8def\u5f84\u6216\u8017\u65f6\u6700\u957f\u7684\u51fd\u6570\uff1b\u4f18\u5316\u4ee3\u7801\u4ee5\u6d88\u9664\u74f6\u9888\uff1b\u91cd\u590d\u6027\u80fd\u5206\u6790\u4ee5\u9a8c\u8bc1\u6539\u8fdb\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241026\/1729937431671cc0173f56b.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528 Profiling \u5de5\u5177\u5206\u6790 Java \u51fd\u6570\u6027\u80fd<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u6027\u80fd\u662f\u4efb\u4f55\u5e94\u7528\u7a0b\u5e8f\u7684\u5173\u952e\u65b9\u9762\uff0c\u5c24\u5176\u662f\u5728\u5927\u89c4\u6a21\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u3002\u5bf9\u4e8e Java \u5e94\u7528\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528 profiling \u5de5\u5177\u6df1\u5165\u4e86\u89e3\u51fd\u6570\u7684\u6027\u80fd\uff0c\u4ece\u800c\u8bc6\u522b\u74f6\u9888\u5e76\u8fdb\u884c\u4f18\u5316\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528 Java \u4e2d\u7684 profiling \u5de5\u5177\u6765\u5206\u6790\u51fd\u6570\u6027\u80fd\u3002<\/p>\n<p><strong>\u4f7f\u7528 JProfiler<\/strong><\/p>\n<p>JProfiler \u662f\u4e00\u4e2a\u6d41\u884c\u7684 Java profiling \u5de5\u5177\uff0c\u53ef\u4ee5\u63d0\u4f9b\u6df1\u5165\u7684\u6027\u80fd\u5206\u6790\u3002\u8981\u4f7f\u7528 JProfiler\uff0c\u60a8\u9700\u8981\u5b89\u88c5\u5b83\u5e76\u5c06\u5176\u914d\u7f6e\u4e3a\u4f7f\u7528\u60a8\u7684 Java \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<pre>\/\/ \u5b89\u88c5 JProfiler\nwget https:\/\/www.ej-technologies.com\/download_jprofiler_latest.html\n\/\/ \u542f\u52a8 JProfiler\n.\/jprofiler-x86_64_10.1.0.bin \n\/\/ \u914d\u7f6e Java \u5e94\u7528\u7a0b\u5e8f\n\u70b9\u51fb \"File\" -&gt; \"Configure Java Application\"<\/pre>\n<p><strong>\u5b9e\u6218\u6848\u4f8b<\/strong><\/p>\n<p>\u8ba9\u6211\u4eec\u8003\u8651\u4e00\u4e2a\u7b80\u5355\u7684\u6c42\u548c\u51fd\u6570\uff0c\u7528\u4e8e\u5bf9\u6570\u7ec4\u4e2d\u7684\u6570\u5b57\u6c42\u548c\uff1a<\/p>\n<pre>public static int sum(int[] arr) {\n    int sum = 0;\n    for (int num : arr) {\n        sum += num;\n    }\n    return sum;\n}<\/pre>\n<p>\u8981\u5206\u6790\u8fd9\u4e2a\u51fd\u6570\u7684\u6027\u80fd\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528 JProfiler \u7684 <strong>Flame Graph<\/strong> \u5de5\u5177\u3002\u5b83\u63d0\u4f9b\u4e86\u6309\u8c03\u7528\u6b21\u6570\u548c\u65f6\u95f4\u5212\u5206\u7684\u51fd\u6570\u5c42\u6b21\u7ed3\u6784\u7684\u53ef\u89c6\u5316\u89c6\u56fe\u3002<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u5f55\u5236\u6027\u80fd\u6570\u636e<\/strong><\/p>\n<p>\u542f\u52a8 JProfiler \u5e76\u542f\u52a8\u5f85\u5206\u6790\u7684 Java \u5e94\u7528\u7a0b\u5e8f\u3002\u6267\u884c sum() \u51fd\u6570\u5e76\u8bb0\u5f55\u6027\u80fd\u6570\u636e\u3002<\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u5206\u6790 Flame Graph<\/strong><\/p>\n<p>\u8f6c\u5230 JProfiler \u4e2d\u7684 <strong>Flame Graph<\/strong> \u9009\u9879\u5361\u3002\u8be5\u89c6\u56fe\u5c06\u663e\u793a\u51fd\u6570\u8c03\u7528\u6811\uff0c\u5176\u4e2d\u989c\u8272\u4ee3\u7801\u8868\u793a\u8c03\u7528\u6b21\u6570\u548c\u65f6\u95f4\u3002<\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u8bc6\u522b\u74f6\u9888<\/strong><\/p>\n<p>\u67e5\u770b\u706b\u7130\u56fe\uff0c\u5bfb\u627e\u6700\u957f\u7684\u8def\u5f84\u6216\u8017\u65f6\u6700\u957f\u7684\u51fd\u6570\u3002\u8fd9\u8868\u660e\u8fd9\u4e9b\u533a\u57df\u662f\u5e94\u7528\u7a0b\u5e8f\u6027\u80fd\u7684\u6f5c\u5728\u74f6\u9888\u3002<\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u4f18\u5316\u4ee3\u7801<\/strong><\/p>\n<p>\u6839\u636e\u706b\u7130\u56fe\u4e2d\u786e\u5b9a\u7684\u74f6\u9888\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u4f18\u5316\u4ee3\u7801\u3002\u8fd9\u53ef\u80fd\u5305\u62ec\u91cd\u6784\u4ee3\u7801\u3001\u4f7f\u7528\u5e76\u884c\u5904\u7406\u6216\u4f7f\u7528\u66f4\u6709\u6548\u7684\u7b97\u6cd5\u3002<\/p>\n<p><strong>\u91cd\u590d profiling<\/strong><\/p>\n<p>\u4f18\u5316\u540e\uff0c\u5e94\u518d\u6b21\u8fd0\u884c profiling \u4ee5\u9a8c\u8bc1\u6539\u8fdb\u5e76\u786e\u4fdd\u6027\u80fd\u5df2\u5f97\u5230\u63d0\u5347\u3002\u901a\u8fc7\u91cd\u590d\u8fd9\u4e2a\u8fc7\u7a0b\uff0c\u60a8\u53ef\u4ee5\u9010\u6b65\u4f18\u5316\u5e94\u7528\u7a0b\u5e8f\u5e76\u6700\u5927\u5316\u5176\u6027\u80fd\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u4f7f\u7528 profiling \u5de5\u5177\u5206\u6790 Java \u51fd\u6570\u6027\u80fd\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u4f7f\u7528 profiling \u5de5&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-202732","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202732","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=202732"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/202732\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=202732"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=202732"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=202732"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}