1 11 package org.eclipse.test.internal.performance; 12 13 import java.util.Map ; 14 15 19 class PerformanceMonitorMac extends PerformanceMonitor { 20 21 private static boolean fgHasElapsedTime= true; 22 private static long fgStartupTime; 23 24 27 private static final String NATIVE_LIBRARY_NAME= "perf_3_1_0"; 29 32 private static int fgIsLoaded= 0; 33 34 39 public static boolean isLoaded() { 40 if (fgIsLoaded == 0) { 41 try { 42 System.loadLibrary(NATIVE_LIBRARY_NAME); 43 fgIsLoaded= 2; 44 } catch (Throwable e) { 45 fgIsLoaded= 1; 48 } 49 } 50 return fgIsLoaded == 2; 51 } 52 53 54 58 protected void collectOperatingSystemCounters(Map scalars) { 59 synchronized(this) { 60 if (isLoaded()) { 61 int[] counters= new int[18]; 62 if (getrusage(0, counters) == 0) { 63 64 int user_time= counters[0]*1000 + counters[1]/1000; 65 int kernel_time= counters[2]*1000 + counters[3]/1000; 66 67 addScalar(scalars, InternalDimensions.KERNEL_TIME, kernel_time); 68 addScalar(scalars, InternalDimensions.CPU_TIME, user_time + kernel_time); 69 } 70 } 71 72 long currentTime= System.currentTimeMillis(); 73 if (!PerformanceTestPlugin.isOldDB()) 74 addScalar(scalars, InternalDimensions.SYSTEM_TIME, currentTime); 75 76 if (fgHasElapsedTime) { 77 if (fgStartupTime == 0) { 78 String t= System.getProperty("eclipse.startTime"); if (t != null) { 80 try { 81 fgStartupTime= Long.parseLong(t); 82 } catch (NumberFormatException e) { 83 fgHasElapsedTime= false; 84 } 85 } else 86 fgHasElapsedTime= false; 87 } 88 if (fgHasElapsedTime) 89 addScalar(scalars, InternalDimensions.ELAPSED_PROCESS, currentTime-fgStartupTime); 90 } 91 92 super.collectOperatingSystemCounters(scalars); 93 } 94 } 95 96 private static native int getrusage(int who, int[] counters); 115 } 116 | Popular Tags |