Main index > About new desklets > Detailed CPU Monitor Teaser [Now w/ SourceCode!]

By taqueso (User), on Sun Mar 27 08:26:36 2005, last edited on Mon Mar 28 00:55:47 2005: Detailed CPU Monitor Teaser [Now w/ SourceCode!].

I discovered adesklets yesterday, and found that it was exactly what I had in mind for a desklet system. I was not impressed with gdesklets or karamba. I have also been looking for an excuse to learn some python. So I had a late-night hacking session and came up with the cpu monitor desklet I have never been able to find:

[URL=http://www.imageshack.us]http://img122.exs.cx/img122/4743/screenshot4bd.png[/URL]

This is a screenshot from a prototype CPU monitor that shows the full set of cpu counter - user, system, nice, idle, iowait, irq, and irqsoft. The load average is drawn over top. The screenshot is showing a simple color scheme, so you can't really make out the irq and iowait portions.

I still have a few things in mind before the first release, but stay tuned. Suggestions and idle speculations on directions that could be taken with a cpu-monitor of this type are welcomed.

By jeepston (Desklet Author), on Sun Mar 27 12:13:38 2005.

Wow! That is exactly the desklet that I was thinking to write. System monitors with the history. The only thing that is missing on your desklet (IMHO) is the percentage of CPU load.

Good start! Next you can create memory and network monitors in the same style.

By syfou (Core Developer & Desklet Author), on Sun Mar 27 12:27:47 2005.

Just curious - what is the typical load generated by your monitor?

By taqueso (User), on Sun Mar 27 15:44:22 2005, last edited on Sun Mar 27 16:38:29 2005.

This computer is a Barton Mobile 2500+ at 2.0GHz.

With the monitor running with size 400x100, 1 sec updates:

Code:

top - 12:33:31 up 1 day, 15:29, 17 users,  load average: 0.08, 0.16, 0.17
Tasks: 102 total,   1 running, 100 sleeping,   0 stopped,   1 zombie
Cpu(s):  3.0% us,  1.3% sy,  0.0% ni, 95.7% id,  0.0% wa,  0.0% hi,  0.0% si
Mem:    903804k total,   886148k used,    17656k free,      552k buffers
Swap:  1084376k total,   186876k used,   897500k free,   738084k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
27244 root      15   0  198m  22m 4200 S  1.7  2.6  39:45.31 X
15303 taqueso   16   0  7724 5644 1960 S  1.3  0.6   0:01.37 python
15304 taqueso   15   0  6640 4360 2100 S  1.3  0.5   0:01.13 adesklets
 5196 taqueso   15   0 46928  11m 4236 S  0.3  1.3   3:43.10 gnome-terminal
12142 taqueso   17   0  2072  836  632 S  0.3  0.1   1:32.43 top
15300 taqueso   16   0  2072 1080  828 R  0.3  0.1   0:00.32 top
    1 root      16   0  1464   84   60 S  0.0  0.0   0:00.56 init


[edit]whoops, I don't have a 2000GHz processor[/edit]

By syfou (Core Developer & Desklet Author), on Sun Mar 27 15:54:56 2005.

Ouch! :headbash:

Well, I guess this was to be expected. This is something we already experienced many times with cpu monitors (you might want to look around in the forum or to the adesklets-devel mailing list)... Feel free to send us links to you code whenever you feel like it. :-)

If you are already pretty confident yor code is ready for inclusion on adesklets' page, you can as well submit it right away, at your convenience (see documentation on how to proceed).

By taqueso (User), on Sun Mar 27 16:15:15 2005.

I think speed can still be improved.

Lowering the update speed to 2sec cuts usage in half (duh?). Maybe 400x100 is too large a size for this kind of monitor, but it looks pretty good on my 1680x1050 desktop.

Right now I open, read, and close /proc/stat and /proc/loadavg every update. Is there a better (read lighter-weight/faster) way to get this information? I don't like having to open and close the files each update. Is pystatgrab optimized?

Currently I am "sliding" the graph with:

Code:

        adesklets.context_set_image(self.graph)
        adesklets.context_set_blend(False)
        adesklets.blend_image_onto_image(self.graph, 1, 1, 0, self.size[0]-1, self.size[1], 0, 0, self.size[0]-1, self.size[1])



I don't know jack about imlib2, is there a preferred way to move an image like that? My compositing scheme can also be improved. I will clean the code up and make it presentable and get some source available for you guys.

By syfou (Core Developer & Desklet Author), on Sun Mar 27 17:00:34 2005.

taqueso wrote:


Lowering the update speed to 2sec cuts usage in half (duh?). Maybe 400x100 is too large a size for this kind of monitor, but it looks pretty good on my 1680x1050 desktop.

That would not really be optimizing, but lowering your expectations, isn't it? :-)

taqueso wrote:


Right now I open, read, and close /proc/stat and /proc/loadavg every update. Is there a better (read lighter-weight/faster) way to get this information? I don't like having to open and close the files each update. Is pystatgrab optimized?

Reading /proc is in my mind a bad idea due to the os-specific nature of this pseudo-filesystem, unless you have alternate ways elsewhere, which is precicely why libstatgrab is so nice. As for performance, believe me, it doesn't make a diffence opening/closing /proc/stat once in a while. For what I read from libstatgrab (src/libstatgrab/cpu_stats.c), that's precicely what the library do on linux and cygmin.

taqueso wrote:


Currently I am "sliding" the graph with:

Code:

        adesklets.context_set_image(self.graph)
        adesklets.context_set_blend(False)
        adesklets.blend_image_onto_image(self.graph, 1, 1, 0, self.size[0]-1, self.size[1], 0, 0, self.size[0]-1, self.size[1])



I don't know jack about imlib2, is there a preferred way to move an image like that? My compositing scheme can also be improved.

No, nothing wrong with that. Although, as you probably "cache" this image anyway, I would probably not slide things at all, but use a scrolling buffer, like people did back in 2D platforms games. Normally drawing the graph, and wrap writing to the beginning of it when the plot reaches its right side, doing the final blending on foreground on two steps instead of one.

taqueso wrote:


I will clean the code up and make it presentable and get some source available for you guys.

Excellent.

By taqueso (User), on Sun Mar 27 23:29:02 2005.

400x100, 1sec updates:
[URL=http://img149.exs.cx/my.php?loc=img149&image=acpugraph400x1006lc.png]http://i149.exs.cx/img149/9243/acpugraph400x1006lc.th.png[/URL]
Different colors:
[URL=http://www.imageshack.us]http://i154.exs.cx/img154/1643/acpugraph22ap.png[/URL]

Here it is! I decided to name my cpu monitor acpugraph. There is no config file support yet, so you will have to change the size and colors in the code. The loadavg line is blocky, I believe the system is only updating the avg every 5s. My plan is to draw a smoother line and switch to pystatgrab at the same time. Performance has been improved a bit (see screenshot above). Thanks for the tip on using the image like a ring buffer syfou.

As I said earlier, I am new to python, imlib2, and adesklets so any tips or constructive criticism is appreciated. I'm not quite ready to submit this for the general public, I want to get forum members input and fix and obvious bugs that pop up first.

http://zoop.org/~taqueso/acpugraph-0.0.tar.bz

And an extra (rediculous) screenshot for you:
[URL=http://img130.exs.cx/my.php?loc=img130&image=isthatguyfskingnuts3wa.jpg]http://img130.exs.cx/img130/5012/isthatguyfskingnuts3wa.th.jpg[/URL]
it is full screen in the pic, but hadn't been running long enough to fill the screen yet - who wants to wait 1680 seconds? ;)


adesklets is proud to be hosted on:

SourceForge.net Logo

Back to adesklets.sf.net.