macOS の標準*1パフォーマンス分析ツールを Brendan Gregg のスライドでざっと調べてみた。
ツール
Activity Monitor.app
- [ウインドウ]-[アクティビティモニタ]、[CPU使用率]、[CPUの履歴]でウインドウの表示/非表示を切替える。
- アクティビティモニタでプロセスを選択して、[表示]-[プロセスの詳細を表示]
- アクティビティモニタでプロセスを選択して、[表示]-[プロセスのサンプルを収集]
uptime
$ uptime 17:38 up 1 day, 7:05, 1 user, load averages: 1.79 2.10 2.56
top
$ top -o cpu Processes: 303 total, 2 running, 301 sleeping, 1697 threads 17:40:05 Load Avg: 2.40, 2.20, 2.54 CPU usage: 15.85% user, 7.31% sys, 76.82% idle SharedLibs: 149M resident, 42M data, 74M linkedit. MemRegions: 59858 total, 6021M resident, 151M private, 3008M shared. PhysMem: 16G used (2306M wired), 226M unused. VM: 823G vsize, 627M framework vsize, 72657(0) swapins, 95531(0) swapouts. Networks: packets: 767009/623M in, 679460/181M out. Disks: 782083/24G read, 382735/9943M written. PID COMMAND %CPU TIME #TH #WQ #PORTS MEM PURG CMPRS PGRP PPID STATE BOOSTS %CPU_ME %CPU_OTHRS UID FAULTS COW MSGSENT MSGRECV SYSBSD SYSMACH 12555 Microsoft Ou 25.2 21:33.78 43 31 15148+ 1481M+ 290M 0B 12555 1 sleeping *0[4038] 0.64662 0.00000 1037328352 2268449+ 10594 3311268+ 1257213+ 22280995+ 7447771+ 14181 Google Chrom 12.8 01:54.42 16 1 148 363M+ 0B 0B 1919 1919 sleeping *0[1] 0.00000 0.00000 1037328352 283212+ 1601 225873+ 15276+ 641869+ 2287322+ 1051 jamfAgent 12.0 02:55.65 4 3 64 6068K 0B 0B 1051 1 sleeping *0[1] 0.21362 0.00000 0 6670 218 55684+ 31971+ 603555+ 150024+ 0 kernel_task 7.0 17:12.96 129/4 0 2 1152M+ 0B 0B 0 0 running 0[0] 0.00000 0.00000 0 95289 0 54129734+ 51758498+ 0 0 13876 iTerm2 4.7 00:27.87 11 5 283 74M+ 1464K 0B 13876 1 sleeping *0[1282+] 0.10389 0.06503 1037328352 554414+ 1849 121834+ 40506+ 445150+ 272151+ 1919 Google Chrom 2.8 11:59.27 44 5 736 164M 4304K 2692K 1919 1 sleeping *0[6177] 0.00000 0.00000 1037328352 1716077 5037 4238431+ 1292194+ 16897037+ 23244409+ 14511 top 2.3 00:00.47 1/1 0 20 3300K 0B 0B 14511 13879 running *0[1] 0.00000 0.00000 0 5026+ 115 209532+ 104759+ 11246+ 128306+ 161 mDNSResponde 2.2 03:16.65 6 4 99 3800K 0B 36K 161 1 sleeping *0[1] 0.00000 0.00000 65 6686 159 249506+ 319874+ 15091358+ 329850+ 116 hidd 2.2 04:41.81 7 4 222 2700K 0B 0B 116 1 sleeping *0[1] 0.00000 0.00000 261 102387 181 5464519+ 2985797+ 8617680+ 7987882+ 99 securityd 2.0 02:02.02 7 3 224+ 4908K 0B 48K 99 1 sleeping *0[1] 0.67463 0.00000 0 378333+ 196 1580562+ 97314+ 5375325+ 9439277+
vm_stat
$ vm_stat 1 Mach Virtual Memory Statistics: (page size of 4096 bytes) free active specul inactive throttle wired prgable faults copy 0fill reactive purged file-backed anonymous cmprssed cmprssor dcomprs comprs pageins pageout swapins swapouts 81761 1941557 4845 1555659 0 584538 633902 77598904 2786572 36178726 1090282 800963 549601 2952460 99718 25665 1470331 2795334 5794930 18186 72657 95531 81411 1949655 4845 1555659 0 576453 635641 967 0 243 0 0 549601 2960558 99718 25665 0 0 0 0 0 0 81725 1942542 4845 1555659 0 583570 631950 186 0 140 0 0 549601 2953445 99718 25665 0 0 0 0 0 0 81601 1949782 4845 1555659 0 576376 635619 177 0 176 0 0 549601 2960685 99718 25665 0 0 0 0 0 0 81595 1949782 4847 1555659 0 576376 642064 156 0 155 0 0 549603 2960685 99718 25665 0 0 0 0 0 0 81272 1949774 4847 1555659 0 576376 642064 133 0 133 0 0 549603 2960677 99718 25665 0 0 0 0 0 0
iostat
$ iostat 1 disk0 cpu load average KB/t tps MB/s us sy id 1m 5m 15m 30.40 10 0.31 17 10 74 3.28 2.89 2.76 6.00 2 0.01 18 5 77 3.28 2.89 2.76 0.00 0 0.00 17 5 78 3.28 2.89 2.76 6.00 6 0.04 15 4 81 3.28 2.89 2.76 0.00 0 0.00 17 5 78 3.28 2.89 2.76 0.00 0 0.00 20 5 75 3.18 2.88 2.76
netstat
$ netstat 1 input (Total) output packets errs bytes packets errs bytes colls 36 0 24346 32 0 10190 0 12 0 11938 10 0 3592 0 33 0 27327 28 0 9033 0 22 0 11766 20 0 7109 0 38 0 27328 27 0 8142 0
DTrace
- スクリプトをリストアップする。
$ man -kP cat dtrace Tcl_CommandTraceInfo(3tcl), Tcl_TraceCommand(3tcl), Tcl_UntraceCommand(3tcl) - monitor renames and deletes of a command bitesize.d(1m) - analyse disk I/O size by process. Uses DTrace cpuwalk.d(1m) - Measure which CPUs a process runs on. Uses DTrace creatbyproc.d(1m) - snoop creat()s by process name. Uses DTrace dappprof(1m) - profile user and lib function usage. Uses DTrace dapptrace(1m) - trace user and library function usage. Uses DTrace diskhits(1m) - disk access by file offset. Uses DTrace dispqlen.d(1m) - dispatcher queue length by CPU. Uses DTrace dtrace(1) - generic front-end to the DTrace facility dtruss(1m) - process syscall details. Uses DTrace errinfo(1m) - print errno for syscall fails. Uses DTrace execsnoop(1m) - snoop new process execution. Uses DTrace fddist(1m) - file descriptor usage distributions. Uses DTrace filebyproc.d(1m) - snoop opens by process name. Uses DTrace hotspot.d(1m) - print disk event by location. Uses DTrace httpdstat.d(1m) - realtime httpd statistics. Uses DTrace iofile.d(1m) - I/O wait time by file and process. Uses DTrace iofileb.d(1m) - I/O bytes by file and process. Uses DTrace iopattern(1m) - print disk I/O pattern. Uses DTrace iopending(1m) - plot number of pending disk events. Uses DTrace iosnoop(1m) - snoop I/O events as they occur. Uses DTrace iotop(1m) - display top disk I/O events by process. Uses DTrace kill.d(1m) - snoop process signals as they occur. Uses DTrace lastwords(1m) - print syscalls before exit. Uses DTrace loads.d(1m) - print load averages. Uses DTrace newproc.d(1m) - snoop new processes. Uses DTrace opensnoop(1m) - snoop file opens as they occur. Uses DTrace pathopens.d(1m) - full pathnames opened ok count. Uses DTrace perldtrace(1) - Perl's support for DTrace pidpersec.d(1m) - print new PIDs per sec. Uses DTrace plockstat(1) - front-end to DTrace to print statistics about POSIX mutexes and read/write locks priclass.d(1m) - priority distribution by scheduling class. Uses DTrace pridist.d(1m) - process priority distribution. Uses DTrace procsystime(1m) - analyse system call times. Uses DTrace runocc.d(1m) - run queue occupancy by CPU. Uses DTrace rwbypid.d(1m) - read/write calls by PID. Uses DTrace rwbytype.d(1m) - read/write bytes by vnode type. Uses DTrace rwsnoop(1m) - snoop read/write events. Uses DTrace sampleproc(1m) - sample processes on the CPUs. Uses DTrace seeksize.d(1m) - print disk event seek report. Uses DTrace setuids.d(1m) - snoop setuid calls as they occur. Uses DTrace sigdist.d(1m) - signal distribution by process. Uses DTrace syscallbypid.d(1m) - syscalls by process ID. Uses DTrace syscallbyproc.d(1m) - syscalls by process name. Uses DTrace syscallbysysc.d(1m) - syscalls by syscall. Uses DTrace topsyscall(1m) - top syscalls by syscall name. Uses DTrace topsysproc(1m) - top syscalls by process name. Uses DTrace weblatency.d(1m) - website latency statistics. Uses DTrace
- DTrace のスクリプトを使ってみる。
$ sudo cpuwalk.d dtrace: system integrity protection is on, some features will not be available Sampling... Hit Ctrl-C to end. ^C ... PID: 1919 CMD: Google Chrome value ------------- Distribution ------------- count < 0 | 0 0 |@@@@@@@@@@@@@@ 10 1 |@@@@@@ 4 2 |@@@@@@@@@@@@@@@@@@@ 14 3 |@ 1 4 | 0 PID: 172 CMD: coreaudiod value ------------- Distribution ------------- count < 0 | 0 0 |@@@@@@@@@ 18 1 |@@@@@@@@@ 17 2 |@@@@@@@@@@@@@ 25 3 |@@@@@@@@ 16 4 | 0 PID: 12555 CMD: Microsoft Outloo value ------------- Distribution ------------- count < 0 | 0 0 |@@@@@@@@@@@@@@@@ 125 1 |@@@@@ 37 2 |@@@@@@@@@@@@@@@ 119 3 |@@@@@ 41 4 | 0