Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perf get time elasped with field separator option

I have a program which parses the output of the linux command perf. It requires the use of option -x, (the field separator option. I want to extract elapsed time (not task-time or cpu-clock) using perf. However when I use the -x option, the elapsed time is not present in the output and I cannot find a corresponding perf event. Here are the sample outputs

perf stat ls
============
 Performance counter stats for 'ls':

          0.934889 task-clock (msec)         #    0.740 CPUs utilized          
                 6 context-switches          #    0.006 M/sec                  
                 0 cpu-migrations            #    0.000 K/sec                  
               261 page-faults               #    0.279 M/sec                  
         1,937,910 cycles                    #    2.073 GHz                    
   <not supported> stalled-cycles-frontend 
   <not supported> stalled-cycles-backend  
         1,616,944 instructions              #    0.83  insns per cycle        
           317,016 branches                  #  339.095 M/sec                  
            12,439 branch-misses             #    3.92% of all branches        

       0.001262625 seconds time elapsed //here we have it

Now with field separator option

perf stat -x, ls
================
2.359807,task-clock
6,context-switches
0,cpu-migrations
261,page-faults
1863028,cycles
<not supported>,stalled-cycles-frontend
<not supported>,stalled-cycles-backend
1670644,instructions
325047,branches
12251,branch-misses

Any help is appreciated

like image 508
knightrider Avatar asked Dec 02 '14 20:12

knightrider


1 Answers

# perf stat ls 2>&1 >/dev/null | tail -n 2 | sed 's/ \+//' | sed 's/ /,/'

0.002272536,seconds time elapsed
like image 75
Breno Leitão Avatar answered Nov 10 '22 22:11

Breno Leitão