2

Through gnuplot I am trying to print an average line on the graph, but it is not working, if I use awk command in the second part or second sub-plot command like this

plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
     "<awk '{sum += $2} END {print sum/NR}' iops.1.log" with lines title "avg iops"

But if I give the value directly that I get if I run the same awk command on the bash command line, the line gets printed like this.

plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
     4590 with lines title "avg iops"

The line above prints the running average line in the graph using just one value(4590) in the second subplot

What is exactly happening and why is must not be working?

3 Answers 3

2

It might be a bug, but luckily you can calculate the average y value within gnuplot without needing awk:

stats "iops.1.log" nooutput
ave=STATS_sum_y/STATS_records
plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
 ave with lines title "avg iops"
Sign up to request clarification or add additional context in comments.

Comments

1

When plotting with plot "<awk ..." and the awk-command returns a single number, you effectively have a data file with a single number. In contrast to this, invoking plot 4560 plots a function, which is then plotted over the full x-range.

If you want to stick with awk, or simply as explanation of an alternative, you can do

avg = system("<awk '{sum += $2} END {print sum/NR}' iops.1.log")
plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
     int(avg) with lines title "avg iops"

Comments

1

The construct "<..." gives a piped file. To calculate and plot the mean, you can use back tics:

plot "iops.1.log" using ($1/1000):2 with lines title "job 1",\
    `awk '{sum += $2} END {print sum/NR}' iops.1.log` with lines title "avg iops"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.