GeekTool memory monitor
December 15, 2008 at 11:30 AM by Dr. Drang
I stopped using this GeekTool setup for displaying iTunes album art on my Desktop quite a while ago, because I found that GeekTool kept sucking up memory the longer it ran. This only happened with the album art scripts; GeekTool’s memory use seemed pretty stable when running only the weather script, the SuperDuper script, and the text-based iTunes and Pandora scripts.
Two things made start running the album art script again:
- I now keep my Desktop clean. It’s still a convenient place to drop files temporarily, but I now place much more emphasis on the temporarily and clean it off at the end of each day. As such, album art on my Desktop won’t get covered with file icons.
- I saw this Flickr photo of a beautiful Desktop that was using my GeekTool setup for album art. I asked the owner if he was having memory problems with GeekTool and he said he wasn’t, so I figured it was worth trying again.
I hadn’t deleted the album art entries in GeekTool, only disabled them, so it was just a couple of clicks to get them started again. I liked having the album covers back in the lower right corner of my screen again.
Unfortunately, after several days of running, GeekTool’s memory use (as displayed by the Activity Monitor) was up around 100 MB after starting at less than 10 MB. For me, at least, the memory gobbling was still a problem. Toggling the Enable GeekTool checkbox in the Preference Pane off and then back on flushed the memory and restarted GeekTool back at the lower value. Periodically restarting GeekTool is no big deal, but how would I know when to do it?
The Unix ps
command can monitor memory use if you give the right options. After fiddling around in the Terminal to get the options right, I set up a new GeekTool Shell entry with the command
ps axo "rss,ucomm" | awk '/Geek/ {printf "%.2f", $1/1024}'
This tells ps
to get the information on all processes (a
), even those not running in a terminal (x
), and displays the memory use in kilobytes and process name (o "rss,ucomm"
) for each one. This information is piped to awk
, which plucks out the line for GeekTool (/Geek/
) and prints out just the memory use, converted to megabytes and rounded to two decimal places ({printf "%.2f", $1/1024}
).
Update 11/16/09
I’ve changed this to
ps -xo "rss,ucomm" | sort -nr | awk '/GeekTool/ {printf "%.2f MB\n", $1/1024}' | head -n 1
because the ps
command would sometimes return two lines with the string “Geek” or “GeekTool” and create two sets of output. Don’t know why, but the spurious one always had a smaller memory footprint than the real one, so a descending sort on memory (sort -nr
) and grabbing only the first “GeekTool” line (head -n 1
) filters out the unwanted data.
The GeekTool entry looks like this:
It’s placed at the lower right corner of my screen, below the text that identifies the track.
The font is set to 9 point Lucida Grande Bold, right justified, in white with a drop shadow. This is not easy to read, but I didn’t want to distract from the song information, and I only need to know when the number gets big enough to restart GeekTool. Constant monitoring isn’t necessary, so I have GeekTool run the script just once an hour. Even that is probably too often.
I like the idea of using GeekTool to monitor itself. The next logical step will be to see if it can restart itself based on its memory use. That’s a project for another day.