Converting to CSV, assuming the output is in:
Command being timed: "sh -c sleep "5""
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 0%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:05.00
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 1920
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 1
Minor (reclaiming a frame) page faults: 176
Voluntary context switches: 7
Involuntary context switches: 1
Swaps: 0
File system inputs: 88
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
format like that of time -v
with the GNU standalone utility (not the time
builtin of the GNU shell) may just be a matter of piping to:
perl -MText::CSV -ne '
if (/^\s*(.*):\s+(.*)/) {
push @header, $1;
push @values, $2;
}
END {
$csv = Text::CSV->new;
$csv->say(*STDOUT, \@header);
$csv->say(*STDOUT, \@values);
}'
Which on the sample above gives me:
"Command being timed","User time (seconds)","System time (seconds)","Percent of CPU this job got","Elapsed (wall clock) time (h:mm:ss or m:ss)","Average shared text size (kbytes)","Average unshared data size (kbytes)","Average stack size (kbytes)","Average total size (kbytes)","Maximum resident set size (kbytes)","Average resident set size (kbytes)","Major (requiring I/O) page faults","Minor (reclaiming a frame) page faults","Voluntary context switches","Involuntary context switches",Swaps,"File system inputs","File system outputs","Socket messages sent","Socket messages received","Signals delivered","Page size (bytes)","Exit status"
"""sh -c sleep ""5""""",0.00,0.00,0%,0:05.00,0,0,0,0,1920,0,1,176,7,1,0,88,0,0,0,0,4096,0
If it's more like the format seen on the macos time(1) man page for /usr/bin/time -l -h -p sleep 5
:
perl -MText::CSV -ne '
if (/^\s*(?|(?<v>\d+)\s+(?<h>.*)|(?<h>\S+)\s+(?<v>\S+))/) {
push @header, $+{h};
push @values, $+{v};
}
END {
$csv = Text::CSV->new;
$csv->say(*STDOUT, \@header);
$csv->say(*STDOUT, \@values);
}'
Which on the sample at that page gives me:
real,user,sys,"maximum resident set size","average shared memory size","average unshared data size","average unshared stack size","page reclaims","page faults",swaps,"block input operations","block output operations","messages sent","messages received","signals received","voluntary context switches","involuntary context switches","instructions retired","cycles elapsed","peak memory footprint"
5.01,0.00,0.00,0,0,0,0,80,0,0,1,0,0,0,0,3,0,2054316,2445544,241664
For the sample now added to your question:
perl -MText::CSV -ne '
if (/^(\S+)\s+(real)\s+(\S+)\s+(user)\s+(\S+)\s+(sys)/) {
push @header, $2,$4,$6;
push @values, $1,$3,$5;
} elsif (/^\s*(\d+)\s+(.*)/) {
push @header, $2;
push @values, $1;
}
END {
$csv = Text::CSV->new;
$csv->say(*STDOUT, \@header);
$csv->say(*STDOUT, \@values);
}'
Which gives:
real,user,sys,"maximum resident set size","average shared memory size","average unshared data size","average unshared stack size","page reclaims","page faults",swaps,"block input operations","block output operations","messages sent","messages received","signals received","voluntary context switches","involuntary context switches","instructions retired","cycles elapsed","peak memory footprint"
57.03,212.49,16.24,88588288,0,0,0,5531,2,0,0,0,0,0,0,1,3337714,2273379580064,693450611012,87999936
time
are you running, with which parameters? Mine (debian 12, GNU time 1.9-0.2) doesn't output things likecontext switches
by default ... please add that info to your question (not in the comments)./usr/bin/time
has a lot of formatting options, have you considered using those? Have you seen/usr/bin/time --help
? Looks like it can mostly do what I think you want itself.time
output?Results
to eitherExpected Output
orOutput I Get
depending on whether that's the output you want or the output you get that you don't want and, if it's the latter, also add the expected output. Also, your code is printing column header line so make sure to include that in your expected output and get rid of the**
s in the output that are making it such that we can't copy/paste it to test with.