Tuesday, 22 September 2009

$image size vs. $image resizing, and a Simple Way to Make Conky Monitor Itself

Subbass recently made a comment on the Official Conky Blog that got me thinking: is it more efficient for Conky to resize an image in every iteration or for it to display an image "straight", without resizing it? Okay, seems like an obvious answer, but it raised the more interesting question: can you get Conky to display CPU and memory usage, but just for itself? It would be incredibly useful for us experimental types, to understand how we can make our Conkys more lightweight (given that the whole ethos of Conky to begin with is "a LIGHTWEIGHT system monitor").

With the help of dk75 and mobilediesel, I came up with the following, which uses ps to give the time-averaged CPU and memory usage of your Conky process(es):
${execpi 1 ps ux | grep -w conky | grep -v grep | awk '{print "CPU ",$3,"% MEM ",$4,"%"}'}

The important thing to note is that because it uses ps, the output is time-averaged over the entire life of the process. This is different to top, which shows the information since the last iteration of top. (Check the relevant man pages for more information.) Both programs have their uses; in the case of comparing the relative efficiency of different .conkyrcs, I find the ps method the most suitable. Incidentally, if you want to use top instead, you can use:
${execi 1 top -b -n1 -p $(pidof conky |awk '{gsub(" ", ",", $0); print}') |awk '/conky/ {print "CPU:",$9"%","MEM:",$10"%"}'}

The Test
I created three .conkyrc files, based on this one (my original config that was written for the Conky blog):
TEXT
${image ~/images/bk_semi_trans_sq.png -p 3,5 -s 40x40}${image ~/images/bk_semi_trans_sq.png -p 47,5 -s 40x40}${image ~/images/bk_semi_trans_sq.png -p 91,5 -s 40x40}${image ~/images/bk_semi_trans_sq.png -p 135,5 -s 40x40}
${if_match ${desktop}==1}${image ~/images/wh_sq.png -p 3,5 -s 40x40}${endif}${if_match ${desktop}==2}${image ~/images/wh_sq.png -p 47,5 -s 40x40}${endif}${if_match ${desktop}==3}${image ~/images/wh_sq.png -p 91,5 -s 40x40}${endif}${if_match ${desktop}==4}${image ~/images/wh_sq.png -p 135,5 -s 40x40}${endif}
${execpi 1 ps ux | grep -w conky | grep -v grep | awk '{print "CPU ",$3,"% MEM ",$4,"%"}'}

Versions 2 and 3 were, respectively, using a set of 40x40px images and no resizing, and using a set of 10x10px images with resizing.

I ran each Conky for 10 minutes on its own, and at the end of the 10 minutes, took a screenshot capturing the CPU and memory percents.

Version 1, 50x50px images, scaled down to 40x40px, CPU 13.4% and MEM 1.0%:
From My Little Desktop Photos


Version 2, 40x40px images, no resizing, CPU 9.3% and MEM 1.0%:
From My Little Desktop Photos


Version 3, 10x10px images, scaled up to 40x40px, CPU 11.2% and MEM 1.0%:
From My Little Desktop Photos


In summary, it is most efficient to use the correctly-sized images for your Conky. However, if you must scale your images, best to use smaller images and scale up, rather than bigger ones scaled down.

I should note, that the CPU and memory percentages are obviously dependent on my system, which is just a little netbook, so forgive me if they seem prohibitively high! Also, you can improve the performance of this particular Conky greatly by increasing the update_interval; I was using 0.1s because I wanted my desktop indicator to switch quickly upon desktop change. However, if you're happy with a bit of a lag, you can always change it to 0.5s or 1s.

2 comments:

  1. 4% saving on such small images, certainly means it would be worthwhile keeping an eye on that whenever using any resizing, and even better to avoid it where possible.

    Well done on doing the work to find this out. /bow

    ReplyDelete