Thursday, December 31, 2009

Macbook Memory and Swap files tip

If you are like me, meaning (in this special case):
  • don't like to reboot your Macbook and have it running for weeks,
  • from time to time have some heavy computing sessions with dozens of progs running,
  • realising, that OS X Snow Leopard still does not manage its memory efficiently, by for example releasing the many and huge swap files created for these heavy computing sessions after these programs have been closed, even so your memory monitor shows you, that you have plenty of free RAM left
  • and you still don't want to reboot to remedy this problem (= OSX still using the swap files, even so it has free RAM).
you could try the following in a Terminal (found here: Link, but I save you from reading all that.. ;) )
  • sudo purge
  • sudo killall -HUP dynamic_pager
From the manpage of purge:
Purge can be used to approximate initial boot conditions with a cold disk buffer
cache for performance analysis. It does not affect anonymous memory that has been
allocated through malloc, vm_allocate, etc.

dynamic_pager is the prog responsible for the swap files on the Mac. This command is what you could call a 'friendly' kill, because it asks to 'HangUP' on the program, not just to terminate it.
I have tried it and so far it looks very efficient, and saved me already 1 or 2 reboots after only 1 day (of heavy computing.. ;)

Enjoy and Happy New Year to all my 2.3 readers.. ;)

Wednesday, December 9, 2009

Mac data analysis tip of the day

So, you have a lot of plots/images in a folder, but you now only want to look at some of them.
Fortunately, in a Terminal, you could easily 'grab' the right ones by shell globbing (=a form of pattern matching for you non-geeks out there), meaning:

Let's say you have plots/images ending in *.profile.png and *.histo.png, so you easily 'grab' only the profiles by ls *.profile.png, nothing easier than that, but how do you get Mac's Preview now to show this choice to you?

Well, as so often, Mac OS just does the right thing:
You type: 'open *.profile.png' and you get all plots/images nicely put into one Preview window.

A slight setback, but logical:
So far they are treated as single documents, so if you just hit Cmd-P to get a print of all your analyis work, you only get offered to print the currently-selected one.
Even a Cmd-A to select all does NOT change this completely, but is on the right track: After selecting all images you can use the File->Print Selected Images menu entry (Or Alt-Cmd-P) to do just that.
And of course with that you can now print again into a new PDF file to have your plots nicely saved all together.

So, I would call this 'efficiency-with-a-hickup', but nevertheless a much more workable and faster solution to produce a pdf out of a shell-globbed (you don't wanna mouse select every 2nd or 3rd image in your folder now, would you?) selection than possible under pure *nix or *doze..
(I timed it, took me rougly 20 seconds to get the pdf, and only because I couldn't decide nor type the resulting filename ;)

PS.: The way to combine/edit PDFs has slightly changed in SL, get the details here.