【linux实战2】测试工程师实战课程之三剑实战linux性能统计分析

markdown有代码的格式

  1. 使用三剑客提取指定 pid 的进程的 cpu 数据
ps -ef | grep chrome
top -p 17571 | awk '{print $10}'
  1. 使用三剑客提取指定 pid 的进程的 cpu 数据,打印 20 次,间隔 1s( for 循环来做)
for i in {1..20}
do
    top -p 17571 | awk '{print $10}'
    sleep 1
done

ps -ef | grep chrome pid为32749
image

1.使用三剑客提取指定pid的进程的cpu数据
top -n 1 -p 32749 | grep 32749 | awk ‘{print"%CPU:" $10}’
image
image

2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for i in {1…20};do top -n 1 -p 32749 | grep 32749 | awk ‘{print"%CPU:" $10}’;sleep 1;done

1、 使用三剑客提取指定pid的进程的cpu数据

top -n 1 -p 1 |grep -A 1 PID|awk '{print $10}'|sed ':1;N;s/\n/: /;b 1'

# 其实只有两行,sed不需要tag也是一样的
top -n 1 -p 1 |grep -A 1 PID|awk '{print $10}'|sed 'N;s/\n/: /'

2、for循环打印20次

for i in {1..20}; do
    top -n 1 -p 1 |grep -A 1 PID|awk '{print $10}'|sed ':1;N;s/\n/: /;b 1'
    sleep 1
done

image

1、使用三剑客提取指定pid的进程的cpu数据
top -n 1 -p 1 |awk ‘NR==8{print $10}’
image
2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for ((i=0;i<20;i++));do top -n 1 -p 1 |awk ‘NR==8{print $10}’;sleep 1;done

查询chrome的进程为:2489

  1. 使用三剑客提取指定pid的进程的cpu数据
    top -n 20 -d 1 -p 103 |awk ‘NR==8{print $10}’
    image
  2. 使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
    for i in {1 20};do top -n 1 -p 126 |awk ‘NR==8{print $10}’;sleep 1;done

了解

Thank you !

  1. 使用三剑客提取指定pid的进程的cpu数据
    top -d 2 -n 3 -p 1 | awk ‘NR>5’ | awk ‘$2==1{print $10}’

  2. 使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
    for i in {1…20};do top -d 1 -n 1 -p 1 | awk ‘NR>5’ | awk ‘$2==1{print $10}’;done

1、top -n 1 -p 535 | awk ‘NR==8 {print $11}’
2、for ((i=1; i<=20; i++)); do top -n 1 -p 535 | awk ‘NR==8 {print $11}’;sleep 1 ;done

pidstat | awk '/1113/{ print $9 }'


for i in $(seq 1 20);do pidstat | awk '/1113/{ print $9}';sleep 1;done

1、top -d 1 -n 20 -p 10|awk ‘NR==8{print $10}’
QQ截图20200314002047
2、for i in {1…20}
> do
> top -d 1 -n 20 -p 10|awk ‘NR==8{print $10}’
> sleep 1
> done
QQ截图20200314003747

作业1:
top -n 1 -p 1|grep systemd|awk ‘{print "systemd的%CPU: "$10}’

作业2:
for i in {1..20};do echo $(top -d 1 -n 1 -p 1|grep systemd|awk ‘{print "systemd的%CPU: "$10}’);sleep 1;done

  1. 使用三剑客提取指定pid的进程的cpu数据
    top -p ps -ef|grep dockerd|grep -v grep|awk '{print $2}' -n 1|awk ‘NR==8{print $10}’

  2. 使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
    for cycle in {1…20};do top -p ps -ef|grep dockerd|grep -v grep|awk '{print $2}' -n 1|awk ‘NR==8{print $10}’;sleep 1s;done

1.使用三剑客提取指定pid的进程的cpu数据
top -p20 -n 1 |awk ‘NR==8{print $10,$11}’
image
2、 使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for ((i=0;i<20;i++)) ; do top -p20 -n 1 |awk ‘NR==8{print $10,$11}’;done
image

1.使用三剑客提取指定pid的进程的cpu数据
image
2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
image

1.使用三剑客提取指定pid的进程的cpu数据
top -p 23289 -n 1 | grep 23289 | awk ‘{print $10}’
image
2.使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)
for i in {1…20};do top -p 23289 -n 1 | grep 23289 | awk ‘{print $10}’;sleep 1;done
image

作业1.
使用三剑客提取指定pid的进程的cpu数据:

# 找出systemd的pid
$ ps -ef | grep '\b/systemd/\b' | awk '{print $3}' | uniq

# 提取cpu字段
$ top -n 1 -p 1 | grep systemd | awk '{print $10}'

作业2.
使用三剑客提取指定pid的进程的cpu数据,打印20次,间隔1s(for循环来做)

# 在作业1的基础上增加for循环
$ for i in {1..20};do top -n 1 -p 1 | grep systemd | awk '{print $10}';done

1.使用三剑客提取指定 pid 的进程的 cpu 数据

ps -ef | grep docker
top -p 16430 -n 1 | grep 16430| awk '{print $10}'

2.使用三剑客提取指定 pid 的进程的 cpu 数据,打印 20 次,间隔 1s( for 循环来做)

for i in {1..20}
do
    top -p 16430 -n 1 | grep 16430| awk '{print $10}'
    sleep 1
done

作业1:


作业2: