Wednesday, April 3, 2013

awk: Filtering and Calculation

Filter wanted data columns

Here is a list of output from ftrace, filtered by the pid (12798) of sample program, then filtered with grep:

sample-12798 [003] 42655.062100: sched_stat_runtime: comm=bash pid=12798 runtime=258929 [ns] vruntime=143898862 [ns]
sample-12798 [001] 42655.062977: sched_stat_runtime: comm=sample pid=12798 runtime=864136 [ns] vruntime=94618957 [ns]

Print only the column of runtime,

... | awk '{printf"%s\n", substr($7,9,length($7)-8)}'

Calculate the Sum

... | awk 'BEGIN {sum=0}{sum+=$1} END {print sum}'

No comments:

Post a Comment