sysstat icon indicating copy to clipboard operation
sysstat copied to clipboard

#174: Support CSV output from `pidstat`.

Open tst-ppenev opened this issue 7 years ago • 2 comments

  • Added a --csv <file_path> option to pidstat for enabling CSV output to a file.
  • Added a P_O_CSV flag that can be added to pidflag to indicate CSV should be output.
  • Added csv_write_header and csv_write_stats functions to pidstat.c for outputting CSV.
  • Added helper functions efprintf and csv_efprintf_s to common.c for writing a formatted string to a file stream with error reporting, and for writing a CSV string quoted according to RFC 4180 respectively.

Fixes #174.

tst-ppenev avatar Feb 28 '18 03:02 tst-ppenev

Builds and executes OK

tst-dmendyke avatar Mar 02 '18 04:03 tst-dmendyke

btw it's really easy to transform a pidstat output to csv using https://github.com/shenwei356/csvtk. Execute this script with as first argument the result of pidstat. For example:

pidstat -h -H -p SELF 1 10 > stat.txt bash to-csv.sh stat.txt

With to-csv.sh containing:

#!/bin/bash

temp=${1/txt/temp}
csv=${1/txt/csv}
head -n 3 $1 | tail -n 1 | sed 's/# //' > $temp
sed '1d' $1 >> $temp
csvtk space2tab $temp > $csv
rm $temp

soyuka avatar Aug 14 '20 11:08 soyuka