当我在linux shell中运行fio时, fio将在运行时显示进程状态。
fio_common: (g=0): rw=write, bs=4K-4K/4K-4K/4K-4K, ioengine=libaio, iodepth=32
fio-2.2.10
Starting 1 process
Jobs: 1 (f=1): [W(1)] [4.9% done] [0KB/197.9MB/0KB /s] [0/50.7K/0 iops] [eta 00m
Jobs: 1 (f=1): [W(1)] [6.6% done] [0KB/209.8MB/0KB /s] [0/53.6K/0 iops] [eta 00m
Jobs: 1 (f=1): [W(1)] [8.2% done] [0KB/50696KB/0KB /s] [0/12.7K/0 iops] [eta 00m
Jobs: 1 (f=1): [W(1)] [9.8% done] [0KB/209.1MB/0KB /s] [0/53.6K/0 iops] [eta 00m
Jobs: 1 (f=1): [W(1)] [11.5% done] [0KB/208.1MB/0KB /s] [0/53.5K/0 iops] [eta 00
Jobs: 1 (f=1): [W(1)] [13.1% done] [0KB/51556KB/0KB /s] [0/12.9K/0 iops] [eta 00
....
测试后显示结果
fio_common: (groupid=0, jobs=1): err= 0: pid=17635: Thu Oct 8 16:04:10 2015
write: io=3194.8MB, bw=327040KB/s, iops=81760, runt= 10001msec
slat (usec): min=2, max=3371, avg= 4.44, stdev= 5.13
clat (usec): min=40, max=3764, avg=380.23, stdev=57.12
lat (usec): min=45, max=3772, avg=386.59, stdev=57.59
clat percentiles (usec):
| 99.000th=[ 454], 99.900th=[ 1080], 99.990th=[ 2960], 99.999th=[ 3760],
| 100.000th=[ 3760]
bw (KB /s): min=314728, max=361528, per=100.00%, avg=327430.74, stdev=17662.04
lat (usec) : 50=0.01%, 100=0.01%, 250=0.01%, 500=99.52%, 750=0.34%
lat (usec) : 1000=0.02%
lat (msec) : 2=0.10%, 4=0.02%
cpu : usr=10.84%, sys=88.64%, ctx=949, majf=0, minf=13
IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=100.0%, >=64=0.0%
submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.1%, 64=0.0%, >=64=0.0%
issued : total=r=0/w=817682/d=0, short=r=0/w=0/d=0, drop=r=0/w=0/d=0
latency : target=0, window=0, percentile=100.00%, depth=32
Run status group 0 (all jobs):
WRITE: io=3194.8MB, aggrb=327040KB/s, minb=327040KB/s, maxb=327040KB/s, mint=10001msec, maxt=10001msec
Disk stats (read/write):
sdc: ios=91/809830, merge=0/0, ticks=8/33252, in_queue=33080, util=99.09%
现在,我想使用popen()在C ++中执行Flexible IO。
我的方法如下:
#include <iostream>
#include <stdio.h>
#include <unistd.h>
FILE *fioProcess;
char *fioCommand = "sudo fio myJob";
char msgBuf[4096];
int readLength;
fioProcess = popen(fioCommand, "r");
if(fioProcess)
{
while(!feof(fioProcess))
{
readLength = fread(msgBuf, sizeof(char), sizeof(msgBuf), fioProcess);
if(readLength > 0)
{
//parsing msgBuf...
//...
//...
}
sleep(100);
}
}
但我只能在测试后捕获结果。 在fio运行时,fread()或fget()没有任何进程状态信息。 如何在C ++中使用popen捕获fio进程状态消息?