1 11 package org.eclipse.test.internal.performance; 12 13 import java.io.BufferedReader ; 14 import java.io.FileReader ; 15 import java.io.IOException ; 16 import java.io.InputStreamReader ; 17 import java.util.Map ; 18 import java.util.StringTokenizer ; 19 20 class PerformanceMonitorLinux extends PerformanceMonitor { 21 22 private static long PAGESIZE= 4096; 23 private static long JIFFIES= 10L; 24 private static boolean fgHasElapsedTime= true; 25 private static long fgStartupTime; 26 27 31 protected void collectOperatingSystemCounters(Map scalars) { 32 synchronized(this) { 33 37 StringTokenizer st= readTokens("/proc/self/stat", false); if (st != null) { 39 st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); st.nextToken(); long minflt = Long.parseLong(st.nextToken()); st.nextToken(); long majflt = Long.parseLong(st.nextToken()); st.nextToken(); long utime = Long.parseLong(st.nextToken()); long stime = Long.parseLong(st.nextToken()); st.nextToken(); st.nextToken(); 57 addScalar(scalars, InternalDimensions.KERNEL_TIME, stime*JIFFIES); 59 addScalar(scalars, InternalDimensions.CPU_TIME, (utime+stime)*JIFFIES); 60 addScalar(scalars, InternalDimensions.SOFT_PAGE_FAULTS, minflt); 61 addScalar(scalars, InternalDimensions.HARD_PAGE_FAULTS, majflt); 62 } 63 64 68 st= readTokens("/proc/self/statm", false); if (st != null) { 70 st.nextToken(); int resident= Integer.parseInt(st.nextToken()); st.nextToken(); int trs= Integer.parseInt(st.nextToken()); int drs= Integer.parseInt(st.nextToken()); int lrs= Integer.parseInt(st.nextToken()); 78 addScalar(scalars, InternalDimensions.WORKING_SET, resident*PAGESIZE); 79 addScalar(scalars, InternalDimensions.TRS, trs*PAGESIZE); 80 addScalar(scalars, InternalDimensions.DRS, drs*PAGESIZE); 81 addScalar(scalars, InternalDimensions.LRS, lrs*PAGESIZE); 82 } 83 84 long currentTime= System.currentTimeMillis(); 85 if (!PerformanceTestPlugin.isOldDB()) 86 addScalar(scalars, InternalDimensions.SYSTEM_TIME, currentTime); 87 88 if (fgHasElapsedTime) { 89 if (fgStartupTime == 0) { 90 String t= System.getProperty("eclipse.startTime"); if (t != null) { 92 try { 93 fgStartupTime= Long.parseLong(t); 94 } catch (NumberFormatException e) { 95 fgHasElapsedTime= false; 96 } 97 } else 98 fgHasElapsedTime= false; 99 } 100 if (fgHasElapsedTime) 101 addScalar(scalars, InternalDimensions.ELAPSED_PROCESS, currentTime-fgStartupTime); 102 } 103 104 super.collectOperatingSystemCounters(scalars); 105 } 106 } 107 108 112 protected void collectGlobalPerformanceInfo(Map scalars) { 113 synchronized(this) { 114 117 StringTokenizer st= readOutput("free -b", true); if (st != null) { 120 st.nextToken(); long total= Long.parseLong(st.nextToken()); 122 long used= Long.parseLong(st.nextToken()); 123 long free= Long.parseLong(st.nextToken()); 124 st.nextToken(); long buffers= Long.parseLong(st.nextToken()); 126 long cache= Long.parseLong(st.nextToken()); 127 128 addScalar(scalars, InternalDimensions.PHYSICAL_TOTAL, total); 129 addScalar(scalars, InternalDimensions.USED_LINUX_MEM, used); 130 addScalar(scalars, InternalDimensions.FREE_LINUX_MEM, free); 131 addScalar(scalars, InternalDimensions.BUFFERS_LINUX, buffers); 132 addScalar(scalars, InternalDimensions.SYSTEM_CACHE, cache); 133 } 134 super.collectGlobalPerformanceInfo(scalars); 135 } 136 } 137 138 private StringTokenizer readTokens(String procPath, boolean skipFirst) { 139 BufferedReader rdr= null; 140 try { 141 rdr= new BufferedReader (new FileReader (procPath)); 142 if (skipFirst) 143 rdr.readLine(); return new StringTokenizer (rdr.readLine()); 145 } catch (IOException e) { 146 PerformanceTestPlugin.log(e); 147 } finally { 148 try { 149 if (rdr != null) 150 rdr.close(); 151 } catch (IOException e) { 152 } 154 } 155 return null; 156 } 157 158 private StringTokenizer readOutput(String cmd, boolean skipFirst) { 159 BufferedReader rdr= null; 160 try { 161 Process process= Runtime.getRuntime().exec(cmd); 162 rdr= new BufferedReader (new InputStreamReader (process.getInputStream())); 163 if (skipFirst) 164 rdr.readLine(); return new StringTokenizer (rdr.readLine()); 166 } catch (IOException e) { 167 PerformanceTestPlugin.log(e); 168 } finally { 169 try { 170 if (rdr != null) 171 rdr.close(); 172 } catch (IOException e) { 173 } 175 } 176 return null; 177 } 178 } 179 | Popular Tags |