Supporting perf.py on Mac OS

This patch was checked on Mac OS and Linux.