Sounds easy, doesn’t it? Well it actually is quite simple but the error messages along the way can really trip you up!
My first attempt at profiling a bit of code was to use the full-boat Eclipse stack: Eclipse Test & Performance Tools Platform Project! Well, what they don’t tell you anywhere on the project page is that it’s only supported on Windows and Linux. A Mac port was started sometime around 2004 and never completed. Yeah, it’s been that long!
And so this brings us to Apple’s Shark: an extremely barebones, no-frills profiler, but, what the heck, it’s free. For the basics on using this tool with your Java app, this great post has all the details. There’s just one catch: 64-bit support. There is none. If you’re on a 64-bit stack and you try to run it, you’ll see something like the following:
$ java -agentlib:Shark -cp foo.jar com.foo.Bar
Error occurred during initialization of VM
Could not find agent library: libShark.jnilib (searched /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Libraries:/System/Library/Java/Extensions:/Library/Java/Extensions:.)
Er, what? Now let’s see here…
$ ls -al /System/Library/Java/Extensions/libShark.jnilib
-rwxr-xr-x 1 root wheel 50352 Oct 24 2010 /System/Library/Java/Extensions/libShark.jnilib
Well, that’s odd. But it said it looked there, right?! Well, as it turns out, the Shark JNI library only supports 32-bit JVMs. So finally, we arrive at the following:
I recently compiled Q4M on my Mac and I’m documenting it here now because it proved to be somewhat painful so hopefully you’ll avoid a bit of grief by reading this.
First off, you need MySQL Server. I’ve been using MacPorts for some time now, so this is installed via ports. Unfortunately, it seems to be a pretty barebones config so I had to create a custom variant to add the necessary --with-fast-mutexes option. You can grab my modified Portfile from github. Just clone it into some directory and then add that path into /opt/local/etc/macports/sources.conf before the rsync line. Once you have that, go ahead and reinstall MySQL:
$ sudo port install mysql5 +fast_mutexes
Q4M also requires access to the MySQL sources, so let’s get those unpacked:
So it turns out that Windows Firewall, even in Windows 2008, still can’t accept a range of ports, either in the UI or via command line, most commonly when setting up PASV FTP transfers. The common workaround is to create one entry per port in your range like so:
C:> FOR /L %I IN (60000,1,60200) DO netsh firewall add portopening TCP %I "Passive FTP"%I
While this does work, it’s slightly annoying that you have to create 200 individual entries in your config. My slightly better workaround is to just stick every port into the text entry field using this simple ruby helper:
puts (60000..60200).to_a.join(",")
You can run this either in IRB or directly on the command line using the following command:
$ ruby -e 'puts (60000..60200).to_a.join(",")'
This is great if your workstation has ruby on it, but sucks otherwise. So use this javascript version right here instead!
After suffering through yet another morning of ‘find’ pegging my CPU and grinding my sad little laptop hard drive for a couple of hours, I finally decided to rectify the situation. Most Linux distributions these days ship mlocate by default, and so I decided to give it a go on OS X. Unfortunately, it doesn’t quite support OS X out of the box yet. I’ll spare you all the miserable details (it was an epic struggle getting this compiled), but I finally managed to get it working.
Here’s how:
# first we get the source and patch it
$ hg clone http://hg.fedorahosted.org/hg/mlocate
$ cd mlocate
$ wget'https://fedorahosted.org/mlocate/attachment/ticket/15/mlocate-mountlist-hg.2.diff?format=raw'-O mlocate-mountlist-hg.2.diff
$ hg import mlocate-mountlist-hg.2.diff
# prep
$ cd ..
$ git clone git://git.savannah.gnu.org/gnulib.git
$ cd mlocate
$ ../gnulib/gnulib-tool --import
$ mv gnulib/lib/stat-time.h~ gnulib/lib/stat-time.h
$ cp ../gnulib/lib/canonicalize.h gnulib/lib/
$ autoreconf --install--force# install
$ ./configure
$ make
$ sudomakeinstall
Ok, now we have the binaries in place; we’re almost there! One last thing to do, and that’s create a new user account and group for mlocate. After running updatedb it will try to chown the locate db as the user ‘mlocate’, so we need to make sure this users exists. Unfortunately, there’s no adduser command in OS X and it’s a little bit of a pain, so I wrote this little script to take care of it for you. Grab it here.
Simply run it like so:
$ adduser
adduser!
username: mlocate
home dir[default=/var/empty]:
group id(default=700):
user id(default=700):
real name (default=daemon):
shell: (default=/usr/bin/false):
All done! Now let’s try updating the db -
$ sudo/usr/local/bin/updatedb
And that should be it. I still ran into a couple of problems with permissions so your best bet is to fix them every time you run updatedb (just stick it in cron):
Updated (July 23, 2010): You may need newer versions of automake and autoconf as well. I had problems with 1.5 and 2.63 respectively but upgrading to 1.11 and 2.65 (with fink) worked fine.
tl;dr- Yes, you can add a 2nd GPU; OS X will ignore it; Windows will use it. Make sure to disable the card in the 1st slot to use it for gaming.
Apple makes great hardware, there’s no doubt about it. However, occasionally they make decisions that not only boggle the mind but are completely infuriating. Like putting non-standard ports on a laptop and charging twenty bucks for the proper adapter cable!
A similar problem I ran into recently is the issue of the graphics card in the Mac Pro: only specially branded “Mac-compatible” GPUs will work in OS X. What’s the problem with that you ask? Availability and pricing.