From 3c06924a028a0e6bfd52745be93784e9afcf4a2f Mon Sep 17 00:00:00 2001 From: Ilia Filippov Date: Thu, 1 Aug 2013 12:47:37 +0400 Subject: [PATCH] Supporting perf.py on Mac OS --- examples/perf.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/perf.py b/examples/perf.py index 8503bd8c..f96ef9ec 100755 --- a/examples/perf.py +++ b/examples/perf.py @@ -73,10 +73,19 @@ def cpu_get(): #returns cpu_usage def cpu_check(): if is_windows == False: - cpu1 = cpu_get() - time.sleep(1) - cpu2 = cpu_get() - cpu_percent = (float(cpu1[0] - cpu2[0])/float(cpu1[1] - cpu2[1]))*100 + if is_mac == False: + cpu1 = cpu_get() + time.sleep(1) + cpu2 = cpu_get() + cpu_percent = (float(cpu1[0] - cpu2[0])/float(cpu1[1] - cpu2[1]))*100 + else: + os.system("sysctl -n vm.loadavg > cpu_temp") + c = open("cpu_temp", 'r') + c_line = c.readline() + c.close + os.remove("cpu_temp") + R = c_line.split(' ') + cpu_percent = float(R[1]) * 3 else: os.system("wmic cpu get loadpercentage /value > cpu_temp") c = open("cpu_temp", 'r') @@ -143,6 +152,8 @@ parser.add_option('-p', '--path', dest='path', global is_windows is_windows = (platform.system() == 'Windows' or 'CYGWIN_NT' in platform.system()) +global is_mac +is_mac = (platform.system() == 'Darwin') # save corrent path pwd = os.getcwd()