Thursday, February 11, 2010
These two graphs both display cpu usage over time. The blue graph came first and then I modified the Lua script to generate the dot chart. I had been thinking of tackling an animated bar chart for a while and decided that I should just give it a go. But it wasn't easy!
Just to conceptualize how it was going to work in the beginning took a while...
I had to think of a way to capture cpu usage information at one particular time, store that information and display it somehow while capturing new information every cycle and linking that all together to get the illusion of a moving chart.
I had (with the help of the crunchbanglinux forum) found a way to implement a timer in lua:
local timer=(update_num % 4)+1
Parse conky to get the updates number then using the line above, every time the updates number is divisible cleanly by 4 (ie no remainder) then timer =1 (without the +1 it would equal 0)
The result is that the timer counts 1,2,3,4,1,2,3,4,1,2,3,4 etc etc. This was the basis for the animation.
I started with trying a 4 bar graph and after a little figuring out I got to the point where i could get the bars set and moving across, but when the timer reset so did the bars. The problem was that I could pass information down the script by referencing strings:
But to get the table working i needed this:
So that I get a full cycle, so that the next step I can reset back top the beginning. But going from dABC which existed at the bottom of the script back to the top for ABCD, I had to take the information for ABC (from dABC) and move it up the script so that ABC in ABCD is the same ABC from dABC. That makes sense right?
So I needed a function. Functions are how you move information from the bottom of the script to the top!
Anyway. Look here at the code on the crunchbang forum and you will see what I ended up with. The script is pretty long. The reason for this is that, as you can see from the above example, for a 4 step animation you actually need 8 steps, each step containing 4 bits of information. So for 4 steps you need 32 bits of information.
I ended up with a 10 step graph which needed 200 bits of information. If i wanted a 20 step graph then that is 20x2x20=800 bits of info.
If anyone has an easier way then I would be only too glad to hear it!
The other drawback with the graph drawing function, as I have written it, is that you can only feed it one set of information. Unlike other functions where you can feed it say cpu info and settings and also feed it memperc information and settings and get 2 outputs. This function you cant do that...something just doesn't work. It would be easy enough to copy the function, and change its name, then call the newly named function with different information in the conky display function. However, it is also the case that there arent many other conky outputs that are suited to a graph.
Downspeed and upspeed graphs can be generated by conky, and could be generated from my graph drawing script... but extra steps would need to be taken to adjust for the changing units... B to KiB to MiB.
Maybe I'll find a more compact way of doing this... although running this script, total "resting" cpu usage on my system is around the 2's or 3's so it is hardly intensive even for it's size.
Subscribe to: Post Comments (Atom)
Post a Comment