{"id":191797,"date":"2020-05-31T10:00:40","date_gmt":"2020-05-31T02:00:40","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=191797"},"modified":"2020-05-19T09:11:43","modified_gmt":"2020-05-19T01:11:43","slug":"linux-cpu-top","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/linux-cpu-top.html","title":{"rendered":"\u9047\u89c1Linux\u7cfb\u7edfCPU\u4f7f\u7528\u7387\u8fc7\u9ad8\u600e\u4e48\u529e\uff1f"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\n\u5bf9\u4e8e\u65b0\u624b\u6765\u8bf4\uff0c\u53ef\u80fd\u5404\u79cd\u8fdb\u7a0b\u7ba1\u7406\u5de5\u5177\u7528\u7684\u8fd8\u4e0d\u7b97\u719f\u6089\uff0c\u90a3\u4e48\u9047\u89c1Linux\u7cfb\u7edfCPU\u7cfb\u7edf\u4f7f\u7528\u7387\u8fc7\u9ad8\u600e\u4e48\u529e\uff1f\u90a3\u4e48\u5c31\u5b66\u4e60\u4e00\u4e0b\u5427\u3002<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"\"<\/p>\n

\u67e5\u770bCPU\u4f7f\u7528<\/strong><\/span><\/div>\n

\u5728 Linux \u7cfb\u7edf\u4e0b\uff0c\u4f7f\u7528 top \u547d\u4ee4\u67e5\u770b CPU \u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n

\"\"<\/p>\n

%Cpu(s): 0.3 us, 0.1 sy, 0.0 ni, 99.6 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st<\/pre>\n

CPU\u5404\u7c7b\u578b\u5360\u7528\u8be6\u89e3\uff1a<\/strong><\/p>\n

    \n
  • us(user)\uff1a\u8868\u793a CPU \u5728\u7528\u6237\u8fd0\u884c\u7684\u65f6\u95f4\u767e\u5206\u6bd4\uff0c\u901a\u5e38\u7528\u6237 CPU \u9ad8\u8868\u793a\u6709\u5e94\u7528\u7a0b\u5e8f\u6bd4\u8f83\u7e41\u5fd9\u3002\u5178\u578b\u7684\u7528\u6237\u7a0b\u5e8f\u6709\uff1a\u6570\u636e\u5e93\u3001Web \u670d\u52a1\u5668\u7b49\u3002<\/li>\n
  • sy(sys)\uff1a\u8868\u793a CPU \u5728\u5185\u6838\u6001\u8fd0\u884c\u7684\u65f6\u95f4\u767e\u5206\u6bd4\uff08\u4e0d\u5305\u62ec\u4e2d\u65ad\uff09\uff0c\u901a\u5e38\u5185\u6838\u6001 CPU \u8d8a\u4f4e\u8d8a\u597d\uff0c\u5426\u5219\u8868\u793a\u7cfb\u7edf\u5b58\u5728\u67d0\u4e9b\u74f6\u9888\u3002<\/li>\n
  • ni(nice)\uff1a\u8868\u793a\u7528 nice \u4fee\u6b63\u8fdb\u7a0b\u4f18\u5148\u7ea7\u7684\u7528\u6237\u8fdb\u7a0b\u6267\u884c\u7684 CPU \u65f6\u95f4\u3002nice \u662f\u4e00\u4e2a\u8fdb\u7a0b\u4f18\u5148\u7ea7\u7684\u4fee\u6b63\u503c\uff0c\u5982\u679c\u8fdb\u7a0b\u901a\u8fc7\u5b83\u4fee\u6539\u4e86\u4f18\u5148\u7ea7\uff0c\u5219\u4f1a\u5355\u72ec\u7edf\u8ba1 CPU \u5f00\u9500\u3002<\/li>\n
  • id(idle)\uff1a\u8868\u793a CPU \u5904\u4e8e\u7a7a\u95f2\u6001\u7684\u65f6\u95f4\u5360\u6bd4\uff0c\u6b64\u65f6\uff0cCPU \u4f1a\u6267\u884c\u4e00\u4e2a\u7279\u5b9a\u7684\u865a\u62df\u8fdb\u7a0b\uff0c\u540d\u4e3a System Idle Process\u3002<\/li>\n
  • wa(iowait)\uff1a\u8868\u793a CPU \u5728\u7b49\u5f85 I\/O \u64cd\u4f5c\u5b8c\u6210\u6240\u82b1\u8d39\u7684\u65f6\u95f4\uff0c\u901a\u5e38\u8be5\u6307\u6807\u8d8a\u4f4e\u8d8a\u597d\uff0c\u5426\u5219\u8868\u793a I\/O \u5b58\u5728\u74f6\u9888\uff0c\u53ef\u4ee5\u7528 iostat \u7b49\u547d\u4ee4\u505a\u8fdb\u4e00\u6b65\u5206\u6790\u3002<\/li>\n
  • hi(hardirq)\uff1a\u8868\u793a CPU \u5904\u7406\u786c\u4e2d\u65ad\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u3002\u786c\u4e2d\u65ad\u662f\u7531\u5916\u8bbe\u786c\u4ef6\uff08\u5982\u952e\u76d8\u63a7\u5236\u5668\u3001\u786c\u4ef6\u4f20\u611f\u5668\u7b49\uff09\u53d1\u51fa\u7684\uff0c\u9700\u8981\u6709\u4e2d\u65ad\u63a7\u5236\u5668\u53c2\u4e0e\uff0c\u7279\u70b9\u662f\u5feb\u901f\u6267\u884c\u3002<\/li>\n
  • si(softirq)\uff1a\u8868\u793a CPU \u5904\u7406\u8f6f\u4e2d\u65ad\u6240\u82b1\u8d39\u7684\u65f6\u95f4\u3002\u8f6f\u4e2d\u65ad\u662f\u7531\u8f6f\u4ef6\u7a0b\u5e8f\uff08\u5982\u7f51\u7edc\u6536\u53d1\u3001\u5b9a\u65f6\u8c03\u5ea6\u7b49\uff09\u53d1\u51fa\u7684\u4e2d\u65ad\u4fe1\u53f7\uff0c\u7279\u70b9\u662f\u5ef6\u8fdf\u6267\u884c\u3002<\/li>\n
  • st(steal)\uff1a\u8868\u793a CPU \u88ab\u5176\u4ed6\u865a\u62df\u673a\u5360\u7528\u7684\u65f6\u95f4\uff0c\u4ec5\u51fa\u73b0\u5728\u591a\u865a\u62df\u673a\u573a\u666f\u3002\u5982\u679c\u8be5\u6307\u6807\u8fc7\u9ad8\uff0c\u53ef\u4ee5\u68c0\u67e5\u4e0b\u5bbf\u4e3b\u673a\u6216\u5176\u4ed6\u865a\u62df\u673a\u662f\u5426\u5f02\u5e38\u3002<\/li>\n<\/ul>\n
    \u6392\u67e5\u7528\u6237 CPU \u4f7f\u7528\u7387\u9ad8<\/strong><\/span><\/div>\n

    \u7528\u6237 CPU \u4f7f\u7528\u7387\u53cd\u6620\u4e86\u5e94\u7528\u7a0b\u5e8f\u7684\u7e41\u5fd9\u7a0b\u5ea6\uff0c\u901a\u5e38\u4e0e\u6211\u4eec\u81ea\u5df1\u5199\u7684\u4ee3\u7801\u606f\u606f\u76f8\u5173\u3002
    \n\u64cd\u4f5c\u6b65\u9aa4\uff1a
    \n1)\u3001\u901a\u8fc7 top \u547d\u4ee4\u627e\u5230 CPU \u6d88\u8017\u6700\u591a\u7684\u8fdb\u7a0b\u53f7\uff1b<\/strong><\/p>\n

    \"\"<\/p>\n

    2)\u3001\u901a\u8fc7 top -Hp \u8fdb\u7a0b\u53f7\u547d\u4ee4\u627e\u5230 CPU \u6d88\u8017\u6700\u591a\u7684\u7ebf\u7a0b\u53f7\uff08\u5217\u540d\u4ecd\u7136\u4e3a PID\uff09\uff1b<\/strong><\/p>\n

    \"\"<\/p>\n

    3)\u3001\u901a\u8fc7printf \"%x\\n\" \u7ebf\u7a0b\u53f7\u547d\u4ee4\u8f93\u51fa\u8be5\u7ebf\u7a0b\u53f7\u5bf9\u5e94\u7684 16 \u8fdb\u5236\u6570\u5b57\uff1b<\/strong><\/p>\n

    \"\"<\/p>\n

    4)\u3001PID\u8fdb\u7a0b\u5728\u5185\u6838\u8c03\u7528\u60c5\u51b5\u3002\u5982\u679c\u662fJava\u5e94\u7528\u53ef\u901a\u8fc7 jstack \u8fdb\u7a0b\u53f7 | grep 16\u8fdb\u5236\u7ebf\u7a0b\u53f7 -A 10 \u547d\u4ee4\u627e\u5230 CPU \u6d88\u8017\u6700\u591a\u7684\u7ebf\u7a0b\u65b9\u6cd5\u5806\u6808\u3002<\/strong><\/p>\n

    \u975e Java \u5e94\u7528\u53ef\u4f7f\u7528 perf\u67e5\u770b\uff1a<\/p>\n

    perf top -p 7574<\/pre>\n

    \u5982\u679c\u63d0\u793aperf: command not found\uff0c\u4f7f\u7528yum install perf\u5b89\u88c5\u3002<\/p>\n

    \"\"<\/p>\n

    perf\u662fLinux 2.6+\u5185\u6838\u4e2d\u7684\u4e00\u4e2a\u5de5\u5177\uff0c\u5728\u5185\u6838\u6e90\u7801\u5305\u4e2d\u7684\u4f4d\u7f6e tools\/perf\u3002
    \nperf\u5229\u7528Linux\u7684trace\u7279\u6027\uff0c\u53ef\u4ee5\u7528\u4e8e\u5b9e\u65f6\u8ddf\u8e2a\uff0c\u7edf\u8ba1event\u8ba1\u6570(perf stat)\uff1b\u6216\u8005\u4f7f\u7528\u91c7\u6837(perf record)\uff0c\u62a5\u544a(perf report|script|annotate)\u7684\u4f7f\u7528\u65b9\u5f0f\u8fdb\u884c\u8bca\u65ad\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

    \u5728 Linux \u7cfb\u7edf\u4e0b\uff0c\u4f7f\u7528 top \u547d\u4ee4\u67e5\u770b CPU \u4f7f\u7528\u60c5\u51b5\u3002 %Cpu(s): 0.3 us, 0.1 […]<\/p>\n","protected":false},"author":317,"featured_media":176247,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-191797","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191797","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/users\/317"}],"replies":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/comments?post=191797"}],"version-history":[{"count":4,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191797\/revisions"}],"predecessor-version":[{"id":191824,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/posts\/191797\/revisions\/191824"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media\/176247"}],"wp:attachment":[{"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/media?parent=191797"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/categories?post=191797"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lrxjmw.cn\/wp-json\/wp\/v2\/tags?post=191797"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}