Linux性能测试工具之CPU(一)

CPUs

1.1 uptime

load-average

Load averages 的三个值分别代表最近 1/5/15 分钟的平均系统负载。在多核系统中,这些值有可能经常大于1,比如四核系统的 100% 负载为 4,八核系统的 100% 负载为 8。

Loadavg 有它固有的一些缺陷:

  • uninterruptible的进程,无法区分它是在等待 CPU 还是 IO。无法精确评估单个资源的竞争程度;
  • 最短的时间粒度是 1 分钟,以 5 秒间隔采样。很难精细化管理资源竞争毛刺和短期过度使用;
  • 结果以进程数量呈现,还要结合 cpu 数量运算,很难直观判断当前系统资源是否紧张,是否影响任务吞吐量

PSI - Pressure Stall Information

每类资源的压力信息都通过 proc 文件系统的独立文件来提供,路径为 /proc/pressure/ – cpu, memory, and io.

其中 CPU 压力信息格式如下:

some avg10=2.98 avg60=2.81 avg300=1.41 total=268109926

memory 和 io 格式如下:

some avg10=0.30 avg60=0.12 avg300=0.02 total=4170757

full avg10=0.12 avg60=0.05 avg300=0.01 total=1856503

avg10、avg60、avg300 分别代表 10s、60s、300s 的时间周期内的阻塞时间百分比。total 是总累计时间,以毫秒为单位。

some 这一行,代表至少有一个任务在某个资源上阻塞的时间占比,full 这一行,代表所有的非idle任务同时被阻塞的时间占比,这期间 cpu 被完全浪费,会带来严重的性能问题。我们以 IO 的 some 和 full 来举例说明,假设在 60 秒的时间段内,系统有两个 task,在 60 秒的周期内的运行情况如下图所示:

image-20201230105704128

红色阴影部分表示任务由于等待 IO 资源而进入阻塞状态。Task A 和 Task B 同时阻塞的部分为 full,占比 16.66%;至少有一个任务阻塞(仅 Task B 阻塞的部分也计算入内)的部分为 some,占比 50%。

some 和 full 都是在某一时间段内阻塞时间占比的总和,阻塞时间不一定连续,如下图所示:

image-20201230105720099

IO 和 memory 都有 some 和 full 两个维度,那是因为的确有可能系统中的所有任务都阻塞在 IO 或者 memory 资源,同时 CPU 进入 idle 状态。

但是 CPU 资源不可能出现这个情况:不可能全部的 runnable 的任务都等待 CPU 资源,至少有一个 runnable 任务会被调度器选中占有 CPU 资源,因此 CPU 资源没有 full 维度的 PSI 信息呈现。

通过这些阻塞占比数据,我们可以看到短期以及中长期一段时间内各种资源的压力情况,可以较精确的确定时延抖动原因,并制定对应的负载管理策略。

1.2 vmstat

显示虚拟内存使用情况的工具

用法:

Usage:
 vmstat [options] [delay [count]]

Options:
 -a, --active           active/inactive memory
 -f, --forks            number of forks since boot
 -m, --slabs            slabinfo
 -n, --one-header       do not redisplay header
 -s, --stats            event counter statistics
 -d, --disk             disk statistics
 -D, --disk-sum         summarize disk statistics
 -p, --partition <dev>  partition specific statistics
 -S, --unit <char>      define display unit   #设置显示数值的单位(k,K,m,M)
 -w, --wide             wide output
 -t, --timestamp        show timestamp

 -h, --help     display this help and exit
 -V, --version  output version information and exit

For more details see vmstat(8).
[root@localhost /]# vmstat -Sm 1 2
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
 r  b   swpd   free   buff  cache   si   so    bi    bo   in   cs us sy id wa st
 3  0   2269  71344    341  56880    0    0    77    48    1    1  4  2 93  1  0
 3  0   2269  71343    341  56880    0    0     0    24 29804 37752  4  2 94  0  0

默认是KiB为单位,可以通过参数-SM来指定以MB为单位显示。

rThe number of runnable processes (running or waiting for run time).procs
bThe number of processes in uninterruptible sleep.
swpdthe amount of virtual memory used.memory
freethe amount of idle memory.
buffthe amount of memory used as buffers.
cachethe amount of memory used as cache.
activethe amount of active memory. (-a option)
inactivethe amount of inactive memory. (-a option)
siAmount of memory swapped in from disk (/s).swap
soAmount of memory swapped to disk (/s).
biBlocks received from a block device (blocks/s).io
boBlocks sent to a block device (blocks/s).
inThe number of interrupts per second, including the clock.system
csThe number of context switches per second.
usTime spent running non-kernel code. (user time, including nice time)cpu
(以下都是占cpu time的百分比值)
syTime spent running kernel code. (system time)
idTime spent idle.
waTime spent waiting for IO.
stTime stolen from a virtual machine.
1.3 mpstat

查看处理器的活动状态,依赖/proc/stat文件

image-20201230151900613

CPU: Processor number. The keyword all indicates that statistics are calculated as averages among all processors.

%usr: Show the percentage of CPU utilization that occurred while executing at the user level (application).

%nice: Show the percentage of CPU utilization that occurred while executing at the user level with nice priority.

%sys: Show  the  percentage  of CPU utilization that occurred while executing at the system level (kernel). Note that this does not include time spent servicing hardware and software interrupts.

%iowait: Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.

%irq: Show the percentage of time spent by the CPU or CPUs to service hardware interrupts.

%soft: Show the percentage of time spent by the CPU or CPUs to service software interrupts.

%steal: Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.

%guest: Show the percentage of time spent by the CPU or CPUs to run a virtual processor.

%gnice: Show the percentage of time spent by the CPU or CPUs to run a niced guest.

%idle: Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.
1.4 pidstat

pidstat用来显示系统的活动的进程信息。

# 比如每隔2秒、总共3次的显示page fault和内存使用情况
root@ubuntu:~# pidstat -r 2 3
Linux 5.4.0-58-generic (ubuntu) 	2021年01月05日 	_x86_64_	(2 CPU)

11时38分43秒   UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
11时38分45秒     0     21733    799.00      0.00   20864    8360   0.42  pidstat

11时38分45秒   UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
11时38分47秒  1000      1777      0.50      0.00 3918948  178616   8.90  gnome-shell
11时38分47秒  1000      2064      8.50      0.00    2608    1524   0.08  bd-qimpanel.wat
11时38分47秒  1000      2135    185.00      0.00  412584   32120   1.60  sogouImeService
11时38分47秒     0     21733     52.50      0.00   20864    8888   0.44  pidstat
11时38分47秒  1000     21741     42.50      0.00   11152     516   0.03  sleep

11时38分47秒   UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
11时38分49秒     0       355      0.50      0.00   62488   20988   1.05  systemd-journal
11时38分49秒  1000      2064      8.50      0.00    2608    1524   0.08  bd-qimpanel.wat
11时38分49秒  1000      2135    188.50      0.00  412584   32120   1.60  sogouImeService
11时38分49秒     0     21733      1.50      0.00   20864    8888   0.44  pidstat
11时38分49秒  1000     21749     42.50      0.00   11152     580   0.03  sleep

Average:      UID       PID  minflt/s  majflt/s     VSZ     RSS   %MEM  Command
Average:        0       355      0.17      0.00   62488   20988   1.05  systemd-journal
Average:     1000      1777      0.17      0.00 3918948  178616   8.90  gnome-shell
Average:     1000      2064      5.66      0.00    2608    1524   0.08  bd-qimpanel.wat
Average:     1000      2135    124.29      0.00  412584   32120   1.60  sogouImeService
Average:        0     21733    285.19      0.00   20864    8712   0.43  pidstat
Average:     1000     21749     14.14      0.00   11152     580   0.03  sleep
1.5 turbostat

turbostat - Report processor frequency and idle statistics.

reports processor topology, frequency, idle power-state statistics, temperature and power on X86 processors.  There are two ways to invoke turbostat.  The first method is to supply a command, which is forked and statistics are printed in one-shot upon its completion.  The second method is to omit the command, and turbostat displays statistics every 5 seconds interval.  The 5-second interval can be changed using the --interval option.
  • Core
    處理器核心編號.
  • CPU
    CPU邏輯處理器號碼,0,1 代表 CPU 的邏輯處理器號碼, – 代表所有處理器的總合. .
  • Package
    processor package number??
  • Avg_MHz
    CPU 平均工作頻率.
  • Busy%
    CPU 在 C0 (Operating State) 狀態的平均時間百分比,關於 CPU C State 請參考 http://benjr.tw/99146 .
  • Bzy_MHz
    CPU 在 C0 (Operating State) 狀態的平均工作頻率 P stat.
  • TSC_MHz
    處理器最高的運行速度(不包含 Turbo Mode).
  • IRQ
    在測量間隔期間由該 CPU 提供服務的中斷 Interrupt Request (IRQ) 數量.
  • SMI
    在測量間隔期間由 CPU 提供服務的系統管理中斷 system management interrupt (SMI) 數量.
  • C1 , C3 , C6 , C7
    在測量間隔期間請求 C1 (Halt), C3 (Sleep) , C6 (Deep Power Down) , C7 (C6 + LLC may be flushed ) 等狀態的次數,.
  • C1% , C3% , C6%, C7%
    在測量間隔期間請求 C1 (Halt), C3 (Sleep) , C6 (Deep Power Down) , C7 (C6 + LLC may be flushed ) 等狀態的百分比.
  • CPU%c1, CPU%c3, CPU%c6, CPU%c7
    在測量間隔期間請求 C1 (Halt), C3 (Sleep) , C6 (Deep Power Down) , C7 (C6 + LLC may be flushed ) 等狀態的百分比.
  • CoreTmp
    CPU 核心 Core 溫度感測器回傳的溫度值.
  • PkgTtmp
    CPU Package 溫度感測器回傳的溫度值.
  • GFX%rc6
    在測量間隔期間 GPU 處於 render C6 (rc6) 狀態的時間百分比.
  • GFXMHz
    測量間隔 GPU 工作頻率.
  • Pkg%pc2, Pkg%pc3, Pkg%pc6, Pkg%pc7?
  • PkgWatt
    CPU package 消耗的瓦特數.
  • CorWatt
    CPU Core 消耗的瓦特數.
  • GFXWatt
    GPU 消耗的瓦特數.
  • RAMWatt
    DRAM DIMM 消耗的瓦特數.
  • PKG_%
    CPU Package 處於 Running Average Power Limit (RAPL) 活動狀態的時間百分比.
  • RAM_%
    DRAM 處於 Running Average Power Limit (RAPL) 活動狀態的時間百分比.

image-20210105114551948

1.6 perf

perf分析CPU的常用命令:

采样:

perf record -F 99 [command]  # 运行执行命令command并以99Hz的频率对on-CPU函数进行采样
perf record -F 99 -a -g -- sleep 10 # 全局的CPU栈函数跟踪,采样保持10秒
perf record -F 99 -p PID --call-graph dwarf -- sleep 10 # 对指定pid进程进行函数栈追踪,以dwarf模式记录10秒,采样频率99Hz
perf record -e sched:sched_process_exec -a # 使用exec产生的新进程事件记录
perf record -e sched:sched_switch -a -g -- sleep 10 # 记录上下文切换事件10秒,全局范围内all cpu, -g模式使用 fp mode

选项--call-graph表示调用图/调用链的集合,即样本的函数堆栈。

默认的fp使用框架指针。这非常有效,但可能不可靠,尤其是对于优化的代码。通过显式使用-fno-omit-frame-pointer,可以确保该代码可用于您的代码。但是,库的结果可能会有所不同。

使用dwarfperf实际上收集并存储堆栈内存本身的一部分,并通过后处理对其进行展开。这可能非常消耗资源,并且堆栈深度可能有限。默认堆栈内存块为8 kiB,但可以配置。
lbr代表最后一个分支记录。这是Intel CPU支持的硬件机制。这可能会以可移植性为代价提供最佳性能。 lbr也仅限于用户空间功能。

perf record -e migrations -a -- sleep 10 # 采样cpu迁移事件10秒
perf record -e migrations -a -c 1 -- sleep 10 # 每隔1秒进行cpu迁移事件采样,共10秒

读取:

perf report -n --stdio # 读取perf.data并显示百分比等
perf script --header # 显示perf.data的所有事件的数据头
#### 显示5秒之内全局范围内的PMC统计数据
# perf stat -a -- sleep 5

 Performance counter stats for 'system wide':

         10,003.37 msec cpu-clock                 #    2.000 CPUs utilized          
             1,368      context-switches          #    0.137 K/sec                  
                71      cpu-migrations            #    0.007 K/sec                  
             1,630      page-faults               #    0.163 K/sec                  
   <not supported>      cycles                                                      
   <not supported>      instructions                                                
   <not supported>      branches                                                    
   <not supported>      branch-misses                                               

       5.001731126 seconds time elapsed
### 报告执行指定command时,CPU的最后一级缓存统计数据
# perf stat -e LLC-loads,LLC-load-misses,LLC-stores,LLC-prefetches ls > /dev/null

 Performance counter stats for 'ls':

            14,161      LLC-loads                                                     (39.48%)
             4,918      LLC-load-misses           #   34.73% of all LL-cache hits
             1,283      LLC-stores                                                    (60.52%)
   <not supported>      LLC-prefetches

       0.001654001 seconds time elapsed

       0.000000000 seconds user
       0.001696000 seconds sys
perf stat -e sched:sched_switch -a -I 1000 # 每1秒显示上下文切换的数量
perf stat -e sched:sched_switch --filter 'prev_state == 0' -a -I 1000 # 显示被迫上下文切换的数量/s
perf stat -e cpu_clk_unhalted.ring0_trans,cs -a -I 1000 # 每秒的用户态切换到内核态、上下文切换
root@ubuntu:test# perf stat -e cpu_clk_unhalted.ring0_trans,cs -a -I 1000
#           time             counts unit events
     1.000184371         98,833,364      cpu_clk_unhalted.ring0_trans                                   
     1.000184371                347      cs                                                          
     2.001406221         70,411,999      cpu_clk_unhalted.ring0_trans                                   
     2.001406221                347      cs                                                          
     3.002688296        135,797,048      cpu_clk_unhalted.ring0_trans                                   
     3.002688296                658      cs
     [...]
perf sched record -- sleep 10  # 采样10秒有关调度器的数据样本分析文件
perf sched latency # 分析上面记录文件中的每个处理器的调度延时
perf sched timehist # 分析上面记录文件中的每个事件调度延时

image-20210105153525772

CPU火焰图

root@ubuntu:test# perf record -F 99 -a --call-graph dwarf ./t1 
^C[ perf record: Woken up 12 times to write data ]
[ perf record: Captured and wrote 7.490 MB perf.data (735 samples) ]

root@ubuntu:test# perf script --header -i perf.data > out.stacks
root@ubuntu:test# stackcollapse-perf.pl < out.stacks | flamegraph.pl --color=java --hash --title="CPU Flame Graph, $(hostname), $(date -I)" > out.svg

其中,stackcoolapse-perf.pl等工具源码路劲:https://github.com/brendangregg/FlameGraph

image-20210105162212874

上图中条的宽度表示占用CPU时间的多少,main()函数中调用foo1(),foo2()后是个while(1)死循环。

1.7 profile-bpfcc

profile(8) is a BCC tool that samples stack traces at timed intervals and reports a frequency count.

profile(8) has lower overhead than perf(1) as only the stack trace summary is passed to user space.

profile-bpfcc的开销比perf要小很多

root@ubuntu:test# profile-bpfcc -h
usage: profile-bpfcc [-h] [-p PID | -L TID] [-U | -K] [-F FREQUENCY | -c COUNT] [-d] [-a] [-I] [-f] [--stack-storage-size STACK_STORAGE_SIZE] [-C CPU] [duration]

Profile CPU stack traces at a timed interval

positional arguments:
  duration              duration of trace, in seconds

optional arguments:
  -h, --help            show this help message and exit
  -p PID, --pid PID     profile process with this PID only
  -L TID, --tid TID     profile thread with this TID only
  -U, --user-stacks-only
                        show stacks from user space only (no kernel space stacks)
  -K, --kernel-stacks-only
                        show stacks from kernel space only (no user space stacks)
  -F FREQUENCY, --frequency FREQUENCY
                        sample frequency, Hertz
  -c COUNT, --count COUNT
                        sample period, number of events
  -d, --delimited       insert delimiter between kernel/user stacks
  -a, --annotations     add _[k] annotations to kernel frames
  -I, --include-idle    include CPU idle stacks
  -f, --folded          output folded format, one line per stack (for flame graphs)
  --stack-storage-size STACK_STORAGE_SIZE
                        the number of unique stack traces that can be stored and displayed (default 16384)
  -C CPU, --cpu CPU     cpu number to run profile on

examples:
    ./profile             # profile stack traces at 49 Hertz until Ctrl-C
    ./profile -F 99       # profile stack traces at 99 Hertz
    ./profile -c 1000000  # profile stack traces every 1 in a million events
    ./profile 5           # profile at 49 Hertz for 5 seconds only
    ./profile -f 5        # output in folded format for flame graphs
    ./profile -p 185      # only profile process with PID 185
    ./profile -L 185      # only profile thread with TID 185
    ./profile -U          # only show user space stacks (no kernel)
    ./profile -K          # only show kernel space stacks (no user)

profile-bpfcc工具产生火焰图:

root@ubuntu:test# profile-bpfcc -af 10 > profile.stacks
root@ubuntu:test# flamegraph.pl --color=java --hash --title="CPU Flame Graph, profile-bpfcc, $(date -I)" < profile.stacks > profile.svg

image-20210105164432831

profile-bpfcc显示CPU函数堆栈调用关系:

# 另开一个窗口,跑示例程序 ./t1
root@ubuntu:test# profile-bpfcc 
Sampling at 49 Hertz of all threads by user + kernel stack... Hit Ctrl-C to end.
^C
    b'exit_to_usermode_loop'
    b'exit_to_usermode_loop'
    b'prepare_exit_to_usermode'
    b'swapgs_restore_regs_and_return_to_usermode'
    main
    __libc_start_main
    -                t1 (73307)
        1

    b'__lock_text_start'
    b'__lock_text_start'
    b'__wake_up_common_lock'
    b'__wake_up_sync_key'
    b'sock_def_readable'
    b'unix_stream_sendmsg'
    b'sock_sendmsg'
    b'sock_write_iter'
    b'do_iter_readv_writev'
    b'do_iter_write'
    b'vfs_writev'
    b'do_writev'
    b'__x64_sys_writev'
    b'do_syscall_64'
    b'entry_SYSCALL_64_after_hwframe'
    writev
    -                Xorg (1615)
        1

    b'clear_page_orig'
    b'clear_page_orig'
    b'get_page_from_freelist'
    b'__alloc_pages_nodemask'
    b'alloc_pages_current'
    b'__get_free_pages'
    b'pgd_alloc'
    b'mm_init'
    b'mm_alloc'
    b'__do_execve_file.isra.0'
    b'__x64_sys_execve'
    b'do_syscall_64'
    b'entry_SYSCALL_64_after_hwframe'
    [unknown]
    [unknown]
    [unknown]
    -                bd-qimpanel.wat (73422)
        1

    b'vmw_cmdbuf_header_submit'
    b'vmw_cmdbuf_header_submit'
    b'vmw_cmdbuf_ctx_submit.isra.0'
    b'vmw_cmdbuf_ctx_process'
    b'vmw_cmdbuf_man_process'
    b'__vmw_cmdbuf_cur_flush'
    b'vmw_cmdbuf_commit'
    b'vmw_fifo_commit_flush'
    b'vmw_fifo_send_fence'
    b'vmw_execbuf_fence_commands'
    b'vmw_execbuf_process'
    b'vmw_execbuf_ioctl'
    b'drm_ioctl_kernel'
    b'drm_ioctl'
    b'vmw_generic_ioctl'
    b'vmw_unlocked_ioctl'
    b'do_vfs_ioctl'
    b'ksys_ioctl'
    b'__x64_sys_ioctl'
    b'do_syscall_64'
    b'entry_SYSCALL_64_after_hwframe'
    ioctl
    -                Xorg (1615)
        1

    main
    __libc_start_main
    -                t1 (73307)
        71
1.8 cpudist-bpfcc

cpudist(8)12 is a BCC tool for showing the distribution of on-CPU time for each thread wakeup. This can be used to help characterize CPU workloads, providing details for later tuning and design decisions.

比如:

用cpudist观察进程76200的1秒时间

该图中的表示,./t1进程占用CPU的时间是1次512-1023微秒、1次1024-2047微妙等,大部分是栈8192至524287微秒。

image-20210105170716525

1.9 runqlat-bpfcc

runqlat(8)工具用于测试CPU的run queue latency(虽然现在不使用run queue)。

用法:

root@ubuntu:test# runqlat-bpfcc -h
usage: runqlat-bpfcc [-h] [-T] [-m] [-P] [--pidnss] [-L] [-p PID] [interval] [count]

Summarize run queue (scheduler) latency as a histogram

positional arguments:
  interval            output interval, in seconds
  count               number of outputs

optional arguments:
  -h, --help          show this help message and exit
  -T, --timestamp     include timestamp on output
  -m, --milliseconds  millisecond histogram
  -P, --pids          print a histogram per process ID
  --pidnss            print a histogram per PID namespace
  -L, --tids          print a histogram per thread ID
  -p PID, --pid PID   trace this PID only

examples:
    ./runqlat            # summarize run queue latency as a histogram
    ./runqlat 1 10       # print 1 second summaries, 10 times
    ./runqlat -mT 1      # 1s summaries, milliseconds, and timestamps
    ./runqlat -P         # show each PID separately
    ./runqlat -p 185     # trace PID 185 only
root@ubuntu:test# runqlat-bpfcc 1 1
Tracing run queue latency... Hit Ctrl-C to end.

     usecs               : count     distribution
         0 -> 1          : 3        |*                                       |
         2 -> 3          : 9        |*****                                   |
         4 -> 7          : 20       |***********                             |
         8 -> 15         : 62       |**********************************      |
        16 -> 31         : 20       |***********                             |
        32 -> 63         : 72       |****************************************|
        64 -> 127        : 8        |****                                    |
       128 -> 255        : 2        |*                                       |
       256 -> 511        : 11       |******                                  |
       512 -> 1023       : 4        |**                                      |

runqlat(8) works by instrumenting scheduler wakeup and context switch events to determine the time from wakeup to running. These events can be very frequent on busy production systems, exceeding one million events per second. Even though BPF is optimized, at these rates even adding one microsecond per event can cause noticeable overhead. Use with caution, and consider using runqlen(8) instead.

1.10 runqlen-bpfcc

用于测试CPU的run queue队列长度数据,多个CPU汇总的histogram(直方图)。

root@ubuntu:test# runqlen-bpfcc -h
usage: runqlen-bpfcc [-h] [-T] [-O] [-C] [interval] [count]

Summarize scheduler run queue length as a histogram

positional arguments:
  interval         output interval, in seconds
  count            number of outputs

optional arguments:
  -h, --help       show this help message and exit
  -T, --timestamp  include timestamp on output
  -O, --runqocc    report run queue occupancy
  -C, --cpus       print output for each CPU separately

examples:
    ./runqlen            # summarize run queue length as a histogram
    ./runqlen 1 10       # print 1 second summaries, 10 times
    ./runqlen -T 1       # 1s summaries and timestamps
    ./runqlen -O         # report run queue occupancy
    ./runqlen -C         # show each CPU separately

示例:

### 用了两个终端,每个终端里个运行了一个./t1死循环进程,系统是2个CPU总共
root@ubuntu:test# runqlen-bpfcc 1 1
Sampling run queue length... Hit Ctrl-C to end.

     runqlen       : count     distribution
        0          : 194      |****************************************|
   ### 上表的意思是run queue长度一直为0

root@ubuntu:test# runqlen-bpfcc 1 1
Sampling run queue length... Hit Ctrl-C to end.

     runqlen       : count     distribution
        0          : 191      |****************************************|
        1          : 0        |                                        |
        2          : 2        |                                        |
    ### 意思是:绝大部分时间run queue为0,大约1%的时间run queue队列长度为2
1.11 softirq-bpfcc

softirqs(8)15 is a BCC tool that shows the time spent servicing soft IRQs (soft interrupts). The system-wide time in soft interrupts is readily available from different tools. For example, mpstat(1) shows it as %soft. There is also /proc/softirqs to show counts of soft IRQ events. The BCC softirqs(8) tool differs in that it can show time per soft IRQ rather than an event count.

root@ubuntu:pc# softirqs-bpfcc -h
usage: softirqs-bpfcc [-h] [-T] [-N] [-d] [interval] [count]

Summarize soft irq event time as histograms.

positional arguments:
  interval           output interval, in seconds
  count              number of outputs

optional arguments:
  -h, --help         show this help message and exit
  -T, --timestamp    include timestamp on output
  -N, --nanoseconds  output in nanoseconds
  -d, --dist         show distributions as histograms

examples:
    ./softirqs            # sum soft irq event time
    ./softirqs -d         # show soft irq event time as histograms
    ./softirqs 1 10       # print 1 second summaries, 10 times
    ./softirqs -NT 1      # 1s summaries, nanoseconds, and timestamps
root@ubuntu:pc# softirqs-bpfcc 10 1
Tracing soft irq event time... Hit Ctrl-C to end.

SOFTIRQ          TOTAL_usecs
net_tx                     1
tasklet                  126
block                    560
rcu                     4056
net_rx                  4325
sched                   7397
timer                   8293             ### 花在timer定时器的软中断时间是8.293ms

#####################################################################

root@ubuntu:pc# softirqs-bpfcc -d
Tracing soft irq event time... Hit Ctrl-C to end.
^C

softirq = timer
     usecs               : count     distribution
         0 -> 1          : 28       |****************************            |
         2 -> 3          : 39       |****************************************|
         4 -> 7          : 18       |******************                      |
         8 -> 15         : 13       |*************                           |
        16 -> 31         : 5        |*****                                   |
        32 -> 63         : 2        |**                                      |
        64 -> 127        : 2        |**                                      |

softirq = rcu
     usecs               : count     distribution
         0 -> 1          : 47       |****************************************|
         2 -> 3          : 14       |***********                             |
         4 -> 7          : 10       |********                                |
         8 -> 15         : 6        |*****                                   |
        16 -> 31         : 5        |****                                    |
        32 -> 63         : 0        |                                        |
        64 -> 127        : 1        |                                        |

softirq = tasklet
     usecs               : count     distribution
         0 -> 1          : 8        |*****************************           |
         2 -> 3          : 11       |****************************************|
         4 -> 7          : 4        |**************                          |

softirq = sched
     usecs               : count     distribution
         0 -> 1          : 8        |*********                               |
         2 -> 3          : 23       |***************************             |
         4 -> 7          : 22       |*************************               |
         8 -> 15         : 34       |****************************************|
        16 -> 31         : 18       |*********************                   |

softirq = net_rx
     usecs               : count     distribution
         0 -> 1          : 0        |                                        |
         2 -> 3          : 0        |                                        |
         4 -> 7          : 0        |                                        |
         8 -> 15         : 5        |****************************************|
        16 -> 31         : 4        |********************************        |
        32 -> 63         : 2        |****************                        |
1.12 hardirq-bpfcc

显示花在硬中断上的时间

root@ubuntu:pc# hardirqs-bpfcc -h
usage: hardirqs-bpfcc [-h] [-T] [-N] [-C] [-d] [interval] [outputs]

Summarize hard irq event time as histograms

positional arguments:
  interval           output interval, in seconds
  outputs            number of outputs

optional arguments:
  -h, --help         show this help message and exit
  -T, --timestamp    include timestamp on output
  -N, --nanoseconds  output in nanoseconds
  -C, --count        show event counts instead of timing
  -d, --dist         show distributions as histograms

examples:
    ./hardirqs            # sum hard irq event time
    ./hardirqs -d         # show hard irq event time as histograms
    ./hardirqs 1 10       # print 1 second summaries, 10 times
    ./hardirqs -NT 1      # 1s summaries, nanoseconds, and timestamps
root@ubuntu:pc# hardirqs-bpfcc 2 1
Tracing hard irq event time... Hit Ctrl-C to end.

HARDIRQ                    TOTAL_usecs
vmw_vmci                             5
ahci[0000:02:05.0]                  12
vmwgfx                             259
ens33                              414   ### 花费在ens33网卡上的硬中断时间是414us
1.13 bpftrace

bpftrace is a BPF-based tracer that provides a high-level programming language, allowing the creation of powerful one-liners and short scripts. It is well suited for custom application analysis based on clues from other tools. There are bpftrace versions of the earlier tools runqlat(8) and runqlen(8) in the bpftrace repository [Iovisor 20a].

### bpftrace分析 t1 进程,采样频率49Hz,且只显示前3层调用栈
root@ubuntu:test# bpftrace -e 'profile:hz:49 /comm == "t1"/ { @[ustack(3)] = count(); }'
Attaching 1 probe...
^C

@[
    longa+20
    foo1+31
    main+36
]: 1
@[
    longa+27
    foo2+31
    main+46
]: 2
@[
    longa+23
    foo1+31
    main+36
]: 3
@[
    longa+34
    foo2+31
    main+46
]: 3
@[
    longa+17
    foo1+31
    main+36
]: 8
@[
    longa+27
    foo1+31
    main+36
]: 13
@[
    longa+34
    foo1+31
    main+36
]: 27
[root@localhost test]# bpftrace -l 'tracepoint:sched:*'
tracepoint:sched:sched_kthread_stop
tracepoint:sched:sched_kthread_stop_ret
tracepoint:sched:sched_waking
tracepoint:sched:sched_wakeup
tracepoint:sched:sched_wakeup_new
tracepoint:sched:sched_switch
tracepoint:sched:sched_migrate_task
tracepoint:sched:sched_process_free
tracepoint:sched:sched_process_exit
tracepoint:sched:sched_wait_task
tracepoint:sched:sched_process_wait
tracepoint:sched:sched_process_fork
tracepoint:sched:sched_process_exec
tracepoint:sched:sched_stat_wait
tracepoint:sched:sched_stat_sleep
tracepoint:sched:sched_stat_iowait
tracepoint:sched:sched_stat_blocked
tracepoint:sched:sched_stat_runtime
tracepoint:sched:sched_pi_setprio
tracepoint:sched:sched_process_hang
tracepoint:sched:sched_move_numa
tracepoint:sched:sched_stick_numa
tracepoint:sched:sched_swap_numa
tracepoint:sched:sched_wake_idle_without_ipi



[root@localhost test]# bpftrace -lv "kprobe:sched*"
kprobe:sched_itmt_update_handler
kprobe:sched_set_itmt_support
kprobe:sched_clear_itmt_support
kprobe:sched_set_itmt_core_prio
kprobe:schedule_on_each_cpu
kprobe:sched_copy_attr
kprobe:sched_free_group
kprobe:sched_free_group_rcu
kprobe:sched_read_attr
kprobe:sched_show_task
kprobe:sched_change_group
kprobe:sched_rr_get_interval
kprobe:sched_setscheduler
kprobe:sched_setscheduler_nocheck
kprobe:sched_setattr
kprobe:sched_tick_remote
kprobe:sched_can_stop_tick
kprobe:sched_set_stop_task
kprobe:sched_ttwu_pending
kprobe:scheduler_ipi
kprobe:sched_fork
kprobe:schedule_tail
kprobe:sched_exec
kprobe:scheduler_tick
kprobe:sched_setattr_nocheck
kprobe:sched_setaffinity
kprobe:sched_getaffinity
kprobe:sched_setnuma
kprobe:sched_cpu_activate
kprobe:sched_cpu_deactivate
kprobe:sched_cpu_starting
kprobe:sched_cpu_dying
kprobe:sched_create_group
kprobe:sched_online_group
kprobe:sched_destroy_group
kprobe:sched_offline_group
kprobe:sched_move_task
kprobe:sched_show_task.part.60
kprobe:sched_idle_set_state
kprobe:sched_slice.isra.61
kprobe:sched_init_granularity
kprobe:sched_proc_update_handler
kprobe:sched_cfs_slack_timer
kprobe:sched_cfs_period_timer
kprobe:sched_group_set_shares
kprobe:sched_rt_rq_enqueue
kprobe:sched_rt_period_timer
kprobe:sched_rt_bandwidth_account
kprobe:sched_group_set_rt_runtime
kprobe:sched_group_rt_runtime
kprobe:sched_group_set_rt_period
kprobe:sched_group_rt_period
kprobe:sched_rt_can_attach
kprobe:sched_rt_handler
kprobe:sched_rr_handler
kprobe:sched_dl_global_validate
kprobe:sched_dl_do_global
kprobe:sched_dl_overflow
kprobe:sched_get_rd
kprobe:sched_put_rd
kprobe:sched_init_numa
kprobe:sched_domains_numa_masks_set
kprobe:sched_domains_numa_masks_clear
kprobe:sched_domains_numa_masks_clear
kprobe:sched_init_domains
kprobe:sched_numa_warn.part.8
kprobe:sched_autogroup_create_attach
kprobe:sched_autogroup_detach
kprobe:sched_autogroup_exit_task
kprobe:sched_autogroup_fork
kprobe:sched_autogroup_exit
kprobe:schedstat_stop
kprobe:schedstat_start
kprobe:schedstat_next
kprobe:sched_debug_stop
kprobe:sched_feat_open
kprobe:sched_feat_show
kprobe:sched_feat_write
kprobe:sched_debug_header
kprobe:sched_debug_start
kprobe:sched_debug_next
kprobe:sched_debug_show
kprobe:sched_partition_show
kprobe:sched_partition_write
kprobe:sched_autogroup_open
kprobe:sched_open
kprobe:sched_write
kprobe:sched_autogroup_show
kprobe:sched_show
kprobe:sched_autogroup_write
kprobe:schedule_console_callback
kprobe:sched_send_work
kprobe:schedule
kprobe:schedule_idle
kprobe:schedule_user
kprobe:schedule_preempt_disabled
kprobe:schedule_timeout
kprobe:schedule_timeout_interruptible
kprobe:schedule_timeout_killable
kprobe:schedule_timeout_uninterruptible
kprobe:schedule_timeout_idle
kprobe:schedule_hrtimeout_range_clock
kprobe:schedule_hrtimeout_range
kprobe:schedule_hrtimeout
  • 4
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Linux性能测试工具包括: 1. sysstat:系统性能监控工具,可以监控CPU、内存、磁盘、网络等性能指标。 2. top:实时监控系统进程和资源占用情况,可以查看CPU、内存、IO等指标。 3. iostat:监控磁盘IO性能,可以查看磁盘读写速度、IO等待时间等指标。 4. vmstat:监控系统虚拟内存使用情况,可以查看内存、CPU、IO等指标。 5. netstat:监控网络连接和流量,可以查看网络连接状态、流量等指标。 6. sar:系统性能分析工具,可以生成系统性能报告,包括CPU、内存、磁盘、网络等指标。 7. perf:Linux性能分析工具,可以分析CPU、内存、磁盘、网络等性能指标,支持多种分析方式。 8. strace:系统调用跟踪工具,可以跟踪进程的系统调用,用于分析进程性能问题。 9. tcpdump:网络抓包工具,可以抓取网络数据包,用于分析网络性能问题。 以上是常用的Linux性能测试工具,可以根据具体需求选择合适的工具。 ### 回答2: Linux性能测试工具主要用于对计算机系统进行性能测试,实时监测系统的各种指标,并给出分析结果。在Linux操作系统中,常用的性能测试工具包括Sysstat工具、Sar工具、Top工具和Iostat工具等。 Sysstat工具是一种常用的Linux性能测试工具,它可以监测CPU利用率、内存使用情况、磁盘读写情况、网络负载、IO负载等关键性能指标。同时,Sysstat工具可以生成日志文件、图表和报告,方便用户进行性能分析和调优。 Sar工具是System Activity Reporter的缩写,它用于监测系统的活动情况,包括CPU、内存、磁盘、网络和进程活动情况等。Sar工具可以输出实时数据和历史数据,并支持各种参数设置和分析方法。 Top工具常用于监测系统的进程情况和资源占用率,包括CPU、内存、IO、网络等方面。Top工具可以快速查看系统状况,方便用户进行系统优化和调试。 Iostat工具用于监测系统的IO负载情况,包括硬盘读写速度、IOPS、吞吐量等指标。Iostat工具可以分析IO瓶颈和优化方案,提高系统IO性能。 总之,在Linux操作系统中选择适当的性能测试工具,对于系统性能分析和优化具有重要的作用,可以帮助用户提高计算机系统的稳定性和工作效率。 ### 回答3: Linux性能测试工具是一类专门用于测试和评估Linux系统性能的软件工具。它们可以对Linux系统的CPU、内存、硬盘等各个方面进行测试,从而帮助用户了解系统的性能瓶颈和优化方向。以下是常用的Linux性能测试工具介绍: 1. UnixBench:UnixBench 是一个通用的Unix性能测试工具,可用于测试CPU,I/O,内存等部件的性能。它是一个开源软件,包括了大量的测试用例。 2. Sysbench:Sysbench 是一个多功能的系统基准测试工具,可以测试CPU,内存,磁盘I/O等性能。它支持多线程和多进程测试,并且可以自动检测性能瓶颈。 3. Iometer:Iometer 是一款专门用于测试磁盘I/O性能的工具,支持以多种模式测试磁盘读写性能,如随机读,随机写等。 4. Perf:Perf 是一个Linux性能分析工具,可以收集CPU使用率,磁盘I/O,内存使用率等系统数据,并生成分析报告,帮助用户分析和优化系统的性能。 5. Fio:Fio 是一款用于测试磁盘性能和I/O负载的工具,支持多种测试模式,如随机读写,顺序读写等。它支持多线程和异步I/O测试。 6. Netperf:Netperf 是一款网络性能测试工具,可以用于测试TCP,UDP等网络协议的性能。它支持多线程测试,可以模拟多用户并发访问。 以上是几种常见的Linux性能测试工具,用户可以根据实际需要选择合适的工具进行系统性能测试和优化。在选择工具时,应该考虑到测试的覆盖范围、测试用例的准确性、测试结果的可靠性等方面,以充分评估系统的性能

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值