I am using awk and gnuplot to extract some running times and their averages that are number of processes-dependent from a series of log files named bt.B.*.log where * can be 1, 4, 9 and 16 (those are the number of processes).
我使用awk和gnuplot来提取一些运行时间和它们的平均值,它们是一系列名为bt.B。*。log的日志文件依赖于进程的数量,其中*可以是1,4,9和16(这些是进程数)。
The code I'm running under gunplot is
我在枪支下运行的代码是
system "awk 'BEGIN { FS = \"[ \\t]*=[ \\t]*\" } /Time in seconds/ { s += $2; c++ } /Total processes/ { if (! CP) CP = $2 } END { print CP, s/c }' bt.B.1.log > tavg.dat"
system "awk 'BEGIN { FS = \"[ \\t]*=[ \\t]*\" } /Time in seconds/ { s += $2; c++ } /Total processes/ { if (! CP) CP = $2 } END { print CP, s/c }' bt.B.4.log >> tavg.dat"
system "awk 'BEGIN { FS = \"[ \\t]*=[ \\t]*\" } /Time in seconds/ { s += $2; c++ } /Total processes/ { if (! CP) CP = $2 } END { print CP, s/c }' bt.B.9.log >> tavg.dat"
system "awk 'BEGIN { FS = \"[ \\t]*=[ \\t]*\" } /Time in seconds/ { s += $2; c++ } /Total processes/ { if (! CP) CP = $2 } END { print CP, s/c }' bt.B.16.log >> tavg.dat"
system "awk 'BEGIN { FS = \"[ \\t]*[=][ \\t]\" } /Time in seconds/ { printf \"%s\", $2 } /Total processes/ { if (CP) { printf \"\\n\" } else { CP = $2; printf \"%s\\n\", $2 } }' bt.B.1.log > t.dat"
system "awk 'BEGIN { FS = \"[ \\t]*[=][ \\t]\" } /Time in seconds/ { printf \"%s\", $2 } /Total processes/ { if (CP) { printf \"\\n\" } else { CP = $2; printf \"%s\\n\", $2 } }' bt.B.4.log >> t.dat"
system "awk 'BEGIN { FS = \"[ \\t]*[=][ \\t]\" } /Time in seconds/ { printf \"%s\", $2 } /Total processes/ { if (CP) { printf \"\\n\" } else { CP = $2; printf \"%s\\n\", $2 } }' bt.B.9.log >> t.dat"
system "awk 'BEGIN { FS = \"[ \\t]*[=][ \\t]\" } /Time in seconds/ { printf \"%s\", $2 } /Total processes/ { if (CP) { printf \"\\n\" } else { CP = $2; printf \"%s\\n\", $2 } }' bt.B.16.log >> t.dat"
#set xrange [0:20]
#set yrange [0:300]
set encoding iso_8859_1
set xlabel "Número de processos"
set ylabel "Tempo médio de execução (s)"
set border 3
set rmargin 10
unset key
set title "bt.B.*.log"
set tics nomirror
set mxtics
set mytics
set arrow from graph 1,0 to graph 1.05,0 filled
set arrow from graph 0,1 to graph 0,1.05 filled
plot "tavg.dat" using 1:2 smooth bezier title "bt.b.*.log", '' using 1:2 with points ps 3 title ""
Note that the way I'm doing it creates the file tavg.dat using > in the first system command, and then appends the other results to the same file using >>. Same organization for creating the t.dat file.
请注意,我这样做的方式是在第一个系统命令中使用>创建文件tavg.dat,然后使用>>将其他结果附加到同一个文件。用于创建t.dat文件的组织相同。
The issue here is how to iterate over the 4 log files in order to avoid repetition in the script.
这里的问题是如何迭代4个日志文件以避免在脚本中重复。
1 个解决方案
#1
Just define two functions, which generate the appropriate strings which you can give to the system
function:
只需定义两个函数,它们可以生成适当的字符串,您可以将其赋予系统函数:
tavg(n) = "awk 'BEGIN { FS = \"[ \\t]*=[ \\t]*\" } /Time in seconds/ { s += $2; c++ } /Total processes/ { if (! CP) CP = $2 } END { print CP, s/c }' bt.B.".n.".log ".(n == 1 ? ">" : ">>")." tavg.dat;"
t(n) = "awk 'BEGIN { FS = \"[ \\t]*[=][ \\t]\" } /Time in seconds/ { printf \"%s\", $2 } /Total processes/ { if (CP) { printf \"\\n\" } else { CP = $2; printf \"%s\\n\", $2 } }' bt.B.".n.".log ".(n == 1 ? ">" : ">>")." t.dat;"
do for [n in "1 4 9 16"] { system(tavg(n).t(n)) }
...
plot "tavg.dat" ...
#1
Just define two functions, which generate the appropriate strings which you can give to the system
function:
只需定义两个函数,它们可以生成适当的字符串,您可以将其赋予系统函数:
tavg(n) = "awk 'BEGIN { FS = \"[ \\t]*=[ \\t]*\" } /Time in seconds/ { s += $2; c++ } /Total processes/ { if (! CP) CP = $2 } END { print CP, s/c }' bt.B.".n.".log ".(n == 1 ? ">" : ">>")." tavg.dat;"
t(n) = "awk 'BEGIN { FS = \"[ \\t]*[=][ \\t]\" } /Time in seconds/ { printf \"%s\", $2 } /Total processes/ { if (CP) { printf \"\\n\" } else { CP = $2; printf \"%s\\n\", $2 } }' bt.B.".n.".log ".(n == 1 ? ">" : ">>")." t.dat;"
do for [n in "1 4 9 16"] { system(tavg(n).t(n)) }
...
plot "tavg.dat" ...