szaydel
2/29/2016 - 3:30 PM

Convert `mpstat -a` output from space separated to CSV format.

Convert mpstat -a output from space separated to CSV format.

We want to make sure that system("") call is used after each line, which will cause awk to do line buffering and flush with each line. If we don't do this we run into a problem where awk buffers a lot of data and then dumps all to stdout in big chunks.

mpstat -aq 1 | awk 'BEGIN {printf("SET,minf,mjf,xcal,intr,ithr,csw,icsw,migr,smtx,srw,syscl,usr,sys,wt,idl,sze\n");} !/SET/ {FS = " "; printf("%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d\n", $1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17); system("");}'