{"id":5260,"date":"2022-05-19T09:19:10","date_gmt":"2022-05-19T01:19:10","guid":{"rendered":"https:\/\/ixyzero.com\/blog\/?p=5260"},"modified":"2022-05-19T09:19:10","modified_gmt":"2022-05-19T01:19:10","slug":"macos%e4%b8%8a%e5%a6%82%e4%bd%95%e8%bf%bd%e8%b8%aa%e5%ae%9a%e4%bd%8d%e6%96%87%e4%bb%b6%e7%b3%bb%e7%bb%9f%e7%9a%84%e6%b4%bb%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/5260.html","title":{"rendered":"macOS\u4e0a\u5982\u4f55\u8ffd\u8e2a\u5b9a\u4f4d\u6587\u4ef6\u7cfb\u7edf\u7684\u6d3b\u52a8"},"content":{"rendered":"\n<p>=Start=<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u7f18\u7531\uff1a<\/h4>\n\n\n\n<p>\u5b66\u4e60\u8bb0\u5f55\u4e00\u4e0bmacOS\u7cfb\u7edf\u4e0a\u8ffd\u8e2a\u5b9a\u4f4d\u5f02\u5e38\u884c\u4e3a\u7684\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u65b9\u4fbf\u540e\u9762\u6709\u9700\u8981\u7684\u65f6\u5019\u53c2\u8003\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u6b63\u6587\uff1a<\/h4>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u89e3\u7b54\uff1a<\/h5>\n\n\n\n<p>\u7b80\u5355\u76f4\u63a5\u6839\u636emanual\u548c\u7f51\u4e0a\u7684\u4e00\u4e9b\u6587\u7ae0\u8fd8\u6709\u5b9e\u9645\u7684\u6d4b\u8bd5\u6574\u7406\u7684\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u4f7f\u7528\u6837\u4f8b\n\n\u76d1\u63a7\u9664fs_usage\u7b49\u51e0\u4e2a\u9ed8\u8ba4\u6392\u9664\u8fdb\u7a0b\u7684\u6587\u4ef6\u7cfb\u7edf\u6d3b\u52a8\uff08\u5982\u679c\u4f60\u7535\u8111\u4e0a\u5b89\u88c5\u548c\u8fd0\u884c\u7684\u5e94\u7528\u6bd4\u8f83\u591a\u7684\u8bdd\uff0c\u8f93\u51fa\u53ef\u80fd\u4f1a\u975e\u5e38\u591a\uff09\n$ sudo fs_usage\n&#91;then ctrl-C to cancel]\n\n\u76d1\u63a7 iTunes \u7684\u6587\u4ef6\u7cfb\u7edf\u6d3b\u52a8\n$ sudo fs_usage iTunes\n\n\u53ea\u76d1\u63a7\u7f51\u7edc\u76f8\u5173\u7684\u4e8b\u4ef6\n$ sudo fs_usage -f network\n\n\u53ea\u8bb0\u5f55\u548cword\u76f8\u5173\u7684\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u7684\u884c\u4e3a\u5e76\u5c06\u5185\u5bb9\u5148\u8f93\u51fa\u5230\u7279\u5b9a\u6587\u4ef6\u4e2d\n$ sudo fs_usage -f filesys \"Microsoft Word\" >.\/fs_usage-filesys-word.txt\n\n\u8be6\u7ec6\u663e\u793a\u9009\u9879\uff0c\u4e0d\u8003\u8651\u7a97\u53e3\u5bbd\u5ea6\u5927\u5c0f\u5c06\u8be6\u7ec6\u4fe1\u606f\u5c55\u793a\u51fa\u6765\uff0c\u5185\u5bb9\u8fc7\u591a\u65f6\u81ea\u52a8\u6362\u884c\n$ sudo fs_usage -w\n \n\u53ea\u663e\u793a\u7279\u5b9a\u8fdb\u7a0b\u540d\u79f0\u7684\u4e8b\u4ef6\uff08\u8fdb\u7a0b\u540d\u79f0\u53ef\u4ee5\u4eceps\u547d\u4ee4\u4e2d\u83b7\u53d6\uff0c\u4e5f\u53ef\u4ee5\u4ece\u300c\u6d3b\u52a8\u76d1\u89c6\u5668\u300d\u4e2d\u7684\u300c\u8fdb\u7a0b\u540d\u79f0\u300d\u90a3\u4e00\u5217\u8fdb\u884c\u67e5\u770b\uff09\n$ sudo fs_usage \"process name\"\n\n\u53ea\u663e\u793a\u7279\u5b9a\u8fdb\u7a0bpid\u7684\u4e8b\u4ef6\n$ sudo fs_usage 3968\n\n\u5148\u6839\u636e\u7279\u5b9a\u5173\u952e\u5b57\u5bf9\u5168\u91cf\u8f93\u51fa\u8fdb\u884c\u8fc7\u6ee4\u770b\u770b\u60c5\u51b5\u518d\u8bf4\n$ sudo fs_usage | grep \"Activity Monitor\"\n\n\u76d1\u63a7\u8fdb\u7a0b\u540d\u79f0\u662fMail\u7684\u6587\u4ef6\u7cfb\u7edf\u76f8\u5173\u6d3b\u52a8\uff0c\u5e76\u572810\u79d2\u540e\u81ea\u52a8\u9000\u51fa\/\u505c\u6b62\n$ sudo fs_usage -w -f filesys -t 10 Mail<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>fs_usage \u2013 \u5b9e\u65f6\u62a5\u544a\u4e0e\u6587\u4ef6\u7cfb\u7edf\u6d3b\u52a8\u76f8\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u548c\u9875\u9762\u9519\u8bef\n\n\u6982\u8981\nfs_usage &#91;-e] &#91;-w] &#91;-f mode] &#91;-b] &#91;-t seconds] &#91;-R rawfile &#91;-S start_time -E end_time]] &#91;pid | cmd &#91;pid | cmd &#91;...]]]\n\n\u547d\u4ee4\u8bf4\u660e\n\nfs_usage\u547d\u4ee4\u53ef\u6301\u7eed\u663e\u793a\u4e0e\u6587\u4ef6\u7cfb\u7edf\u6d3b\u52a8\u6709\u5173\u7684\u7cfb\u7edf\u8c03\u7528\u4fe1\u606f\u3002\u56e0\u4e3a\u5b83\u4f7f\u7528\u5185\u6838\u8ddf\u8e2a\u5de5\u5177\u8fdb\u884c\u64cd\u4f5c\uff0c\u6240\u4ee5\u5b83\u9700\u8981root\u6743\u9650\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u88ab\u76d1\u63a7\u7684\u6d3b\u52a8\u5305\u62ec\u9664\u6b63\u5728\u8fd0\u884c\u7684fs_usage\u8fdb\u7a0b\u3001Terminal\u3001telnetd\u3001telnet\u3001sshd\u3001rlogind\u3001tcsh\u3001csh\u3001sh\u548czsh\u5916\u7684\u6240\u6709\u7cfb\u7edf\u8fdb\u7a0b\u3002\u4e0d\u8fc7\u8fd9\u4e9b\u9ed8\u8ba4\u503c\u53ef\u4ee5\u88ab\u8986\u76d6\u66f4\u65b0\uff0c\u8fd9\u6837\u8f93\u51fa\u53ef\u4ee5\u88ab\u9650\u5236\u4e3a\u5305\u542b\u6216\u6392\u9664\u7531\u7528\u6237\u6307\u5b9a\u7684\u8fdb\u7a0b\u5217\u8868\u3002\n\nfs_usage\u547d\u4ee4\u7684\u8f93\u51fa\u9ed8\u8ba4\u662f\u6839\u636e\u60a8\u7684\u7a97\u53e3\u5927\u5c0f\u683c\u5f0f\u5316\u7684\uff0c\u7a84\u7a97\u53e3\u5c06\u663e\u793a\u66f4\u5c11\u7684\u6570\u636e\u5217\uff0c\u4f7f\u7528\u5bbd\u7a97\u53e3\u6700\u5927\u9650\u5ea6\u5730\u663e\u793a\u6570\u636e\u3002\u60a8\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528-w\u9009\u9879\u5f3a\u5236\u5bbd\u663e\u793a\u6765\u8986\u76d6\u7a97\u53e3\u5927\u5c0f\u9650\u5236\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u5f53\u7a97\u53e3\u4e0d\u591f\u5bbd\u65f6\uff0c\u663e\u793a\u7684\u6570\u636e\u5c06\u81ea\u52a8\u6362\u884c\u3002\n\n\u547d\u4ee4\u9009\u9879\u4ecb\u7ecd\n\n-e      \u6392\u9664\u9009\u9879\uff0c\u7528\u4e8e\u6307\u5b9a\u4e0d\u5bf9\u54ea\u4e9bpid\u6216\u547d\u4ee4\u8fdb\u884c\u91c7\u6837\u3002\n\n-w      \u8be6\u7ec6\u663e\u793a\u9009\u9879\uff0c\u4e0d\u8003\u8651\u7a97\u53e3\u5bbd\u5ea6\u5927\u5c0f\u5c06\u8be6\u7ec6\u4fe1\u606f\u5c55\u793a\u51fa\u6765\uff0c\u5185\u5bb9\u8fc7\u591a\u65f6\u81ea\u52a8\u6362\u884c\u3002\n\n-f      \u8f93\u51fa\u8fc7\u6ee4\u9009\u9879\uff0c\u9ed8\u8ba4\u4e0d\u8fdb\u884c\u8f93\u51fa\u8fc7\u6ee4\uff0c\u652f\u6301\u7684\u8fc7\u6ee4\u6a21\u5f0f\u6709 network\/filesys\/pathname\/exec\/diskio\/cachehit \u5206\u522b\u6307\u4ee3 \u7f51\u7edc\/\u6587\u4ef6\u7cfb\u7edf\/\u8def\u5f84\/exec\u548cspawn\/\u78c1\u76d8io\/\u7f13\u5b58\u547d\u4e2d \u7684\u4e8b\u4ef6\u3002\n\n-b      \u4e3a\u78c1\u76d8IO\u6dfb\u52a0BootCache\u6ce8\u89e3\u4fe1\u606f\u7684\u9009\u9879\uff08\u5982\u679c\u652f\u6301\u7684\u8bdd\uff09\u3002\n\n-t seconds \u8fd0\u884c\u65f6\u95f4\u9009\u9879\uff0c\u6307\u5b9afs_usage\u547d\u4ee4\u8fd0\u884c\u4e0d\u8d85\u8fc7\u6307\u5b9a\u7684\u79d2\u6570\u3002\n\n-R raw_file\n     Specifies a raw trace file to process.\n\n-S start_time\n     If -R is selected, specifies the start time in microseconds to begin processing entries from the raw trace file.  Entries with timestamps before the specified start time will be skipped.\n\n-E end_time\n     If -R is selected, specifies the ending time in microseconds to stop processing entries from the raw trace file.  Entries with timestamps beyond the specified ending time will be skipped.\n\npid | cmd \u7528\u4e8e\u9650\u5236fs_usage\u547d\u4ee4\u4ec5\u5bf9\u6307\u5b9a\u7684pid\/cmd\u8fdb\u884c\u91c7\u6837\uff0c\u548c-e\u9009\u9879\u521a\u597d\u662f\u53cd\u8fc7\u6765\u7684\u3002\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\u663e\u793a\u5217\u4ecb\u7ecd\n\nThe data columns displayed are as follows:\n\nTIMESTAMP\n        TOD when call occurred.  Wide mode will have microsecond granularity.\n\nCALL    The name of the network or filesystem related call, page-in, page-out, or physical disk access.\n\nFILE DESCRIPTOR\n        Of the form F=x, x is a file descriptor.  Depending on the type of system call, this will be either an input value or a return value.\n\nBYTE COUNT\n        Of the form B=x, x is the number of bytes requested by the call.\n\n&#91;ERRNO]\n        On error, the errno is displayed in brackets.\n\nPATHNAME\n        Pathname of the file accessed (up to the last 28 bytes).\n\nFAULT ADDRESS\n        Of the form A=0xnnnnnnnn, where 0xnnnnnnnn is the address being faulted.\n\nDISK BLOCK NUMBER\n        Of the form D=0xnnnnnnnn, where 0xnnnnnnnn is the block number of the physical disk block being read or written.\n\nOFFSET  Of the form O=0xnnnnnnnn, where 0xnnnnnnnn is a file offset.\n\nSELECT RETURN\n        Of the form S=x, x is the number of ready descriptors returned by the select(2) system call.  If S=0, the time limit expired.\n\nTIME INTERVAL(W)\n        The elapsed time spent in the system call.  A \u2018W\u2019 after the elapsed time indicates the process was scheduled out during this file activity.  In this case, the elapsed\n        time includes the wait time.\n\nPROCESS NAME\n        The process that made the system call.  Wide mode will append the thread id to the process name (i.e Mail.nnn).<\/code><\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h5 class=\"wp-block-heading\">\u53c2\u8003\u94fe\u63a5\uff1a<\/h5>\n\n\n\n<p>fs_usage &#8211; Filesystem usage (process\/pathname) Requires root privileges due to the kernel tracing facility it uses to operate.<br><a href=\"https:\/\/ss64.com\/osx\/fs_usage.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/ss64.com\/osx\/fs_usage.html<\/a><\/p>\n\n\n\n<p>Mac OS X: Using fs_usage as a Troubleshooting Tool<br><a href=\"https:\/\/www.macobserver.com\/tmo\/article\/os_x_using_fs_usage_as_a_troubleshooting_tool\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/www.macobserver.com\/tmo\/article\/os_x_using_fs_usage_as_a_troubleshooting_tool<\/a><\/p>\n\n\n\n<p>fs_usage \u2013 trace file system calls on Mac OS X<br><a href=\"https:\/\/mohit.io\/blog\/fs_usage-trace-file-system-calls-on-mac-os-x\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/mohit.io\/blog\/fs_usage-trace-file-system-calls-on-mac-os-x\/<\/a><\/p>\n\n\n\n<p>View Filesystem Access in Real Time on Mac OS X<br><a href=\"https:\/\/superuser.com\/questions\/97980\/view-filesystem-access-in-real-time-on-mac-os-x\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/superuser.com\/questions\/97980\/view-filesystem-access-in-real-time-on-mac-os-x<\/a><\/p>\n\n\n\n<p>File-System Performance Guidelines<br><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/FileSystem\/Articles\/FileSystemCalls.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/FileSystem\/Articles\/FileSystemCalls.html<\/a><\/p>\n\n\n\n<p>Monitor I\/O<br><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/power_efficiency_guidelines_osx\/MinimizingIO.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/power_efficiency_guidelines_osx\/MinimizingIO.html<\/a><\/p>\n\n\n\n<p>Monitor Usage Regularly<br><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/power_efficiency_guidelines_osx\/MonitoringEnergyUsage.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/power_efficiency_guidelines_osx\/MonitoringEnergyUsage.html<\/a><\/p>\n\n\n\n<p>Performance Tools<br><a href=\"https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/PerformanceOverview\/PerformanceTools\/PerformanceTools.html\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/developer.apple.com\/library\/archive\/documentation\/Performance\/Conceptual\/PerformanceOverview\/PerformanceTools\/PerformanceTools.html<\/a><\/p>\n\n\n\n<p>=END=<\/p>\n","protected":false},"excerpt":{"rendered":"<p>=Start= \u7f18\u7531\uff1a \u5b66\u4e60\u8bb0\u5f55\u4e00\u4e0bmacOS\u7cfb\u7edf\u4e0a\u8ffd\u8e2a\u5b9a\u4f4d\u5f02\u5e38\u884c\u4e3a\u7684\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u65b9\u4fbf\u540e\u9762\u6709\u9700\u8981\u7684\u65f6\u5019\u53c2\u8003\u3002  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,12],"tags":[1818,559,1780,1819],"class_list":["post-5260","post","type-post","status-publish","format-standard","hentry","category-knowledgebase-2","category-tools","tag-fs_usage","tag-mac","tag-macos","tag-trace"],"views":3654,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5260","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=5260"}],"version-history":[{"count":1,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5260\/revisions"}],"predecessor-version":[{"id":5261,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/5260\/revisions\/5261"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=5260"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=5260"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=5260"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}