Changeset 12400 in vbox for trunk/src/VBox/Main/testcase
- Timestamp:
- Sep 11, 2008 10:34:58 AM (16 years ago)
- svn:sync-xref-src-repo-rev:
- 36452
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/testcase/tstCollector.cpp
r12136 r12400 24 24 #include <iprt/runtime.h> 25 25 #include <iprt/stream.h> 26 #include <iprt/env.h> 26 27 #include <iprt/err.h> 27 28 #include <iprt/process.h> … … 66 67 } 67 68 68 #define CALLS_PER_SECOND(n,fn) \ 69 #define RUN_TIME_MS 1000 70 71 #define N_CALLS(n, fn) \ 72 for (int call = 0; call < n; ++call) \ 73 rc = collector->fn; \ 74 if (RT_FAILURE(rc)) \ 75 RTPrintf("tstCollector: "#fn" -> %Vrc\n", rc) 76 77 #define CALLS_PER_SECOND(fn) \ 69 78 nCalls = 0; \ 70 79 start = RTTimeMilliTS(); \ … … 72 81 rc = collector->fn; \ 73 82 ++nCalls; \ 74 } while(RTTimeMilliTS() - start < 1000); \83 } while(RTTimeMilliTS() - start < RUN_TIME_MS); \ 75 84 if (RT_FAILURE(rc)) \ 76 85 { \ … … 78 87 } \ 79 88 else \ 80 RTPrintf("%50s -- %u calls per second\n", #fn, nCalls); \ 81 totalTime += n * 1000000 / nCalls 89 RTPrintf("%70s -- %u calls per second\n", #fn, nCalls) 90 91 void measurePerformance(pm::CollectorHAL *collector, const char *pszName, int cVMs) 92 { 93 94 static const char * const args[] = { pszName, "-child", NULL }; 95 pm::CollectorHints hints; 96 std::vector<RTPROCESS> processes; 97 98 hints.collectHostCpuLoad(); 99 hints.collectHostRamUsage(); 100 /* Start fake VMs */ 101 for (int i = 0; i < cVMs; ++i) 102 { 103 RTPROCESS pid; 104 int rc = RTProcCreate(pszName, args, RTENV_DEFAULT, 0, &pid); 105 if (RT_FAILURE(rc)) 106 { 107 hints.getProcesses(processes); 108 std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate)); 109 RTPrintf("tstCollector: RTProcCreate() -> %Vrc\n", rc); 110 return; 111 } 112 hints.collectProcessCpuLoad(pid); 113 hints.collectProcessRamUsage(pid); 114 } 115 116 hints.getProcesses(processes); 117 RTThreadSleep(30000); // Let children settle for half a minute 118 119 int rc; 120 ULONG tmp; 121 uint64_t tmp64; 122 uint64_t start; 123 unsigned int nCalls; 124 uint32_t totalTime = 0; 125 /* Pre-collect */ 126 CALLS_PER_SECOND(preCollect(hints)); 127 /* Host CPU load */ 128 CALLS_PER_SECOND(getRawHostCpuLoad(&tmp64, &tmp64, &tmp64)); 129 /* Process CPU load */ 130 CALLS_PER_SECOND(getRawProcessCpuLoad(processes[nCalls%cVMs], &tmp64, &tmp64, &tmp64)); 131 /* Host CPU speed */ 132 CALLS_PER_SECOND(getHostCpuMHz(&tmp)); 133 /* Host RAM usage */ 134 CALLS_PER_SECOND(getHostMemoryUsage(&tmp, &tmp, &tmp)); 135 /* Process RAM usage */ 136 CALLS_PER_SECOND(getProcessMemoryUsage(processes[nCalls%cVMs], &tmp)); 137 138 start = RTTimeNanoTS(); 139 140 for (int times = 0; times < 100; times++) 141 { 142 /* Pre-collect */ 143 N_CALLS(1, preCollect(hints)); 144 /* Host CPU load */ 145 N_CALLS(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64)); 146 /* Host CPU speed */ 147 N_CALLS(1, getHostCpuMHz(&tmp)); 148 /* Host RAM usage */ 149 N_CALLS(1, getHostMemoryUsage(&tmp, &tmp, &tmp)); 150 /* Process CPU load */ 151 N_CALLS(cVMs, getRawProcessCpuLoad(processes[call], &tmp64, &tmp64, &tmp64)); 152 /* Process RAM usage */ 153 N_CALLS(cVMs, getProcessMemoryUsage(processes[call], &tmp)); 154 } 155 printf("\n%u VMs -- %.2f%% of CPU time\n", cVMs, (RTTimeNanoTS() - start) / 10000000. / times); 156 157 /* Shut down fake VMs */ 158 std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate)); 159 } 82 160 83 161 int main(int argc, char *argv[]) … … 91 169 { 92 170 RTPrintf("tstCollector: RTR3Init() -> %d\n", rc); 171 return 1; 172 } 173 if (argc > 1 && !strcmp(argv[1], "-child")) 174 { 175 /* We have spawned ourselves as a child process -- scratch the leg */ 176 RTThreadSleep(1000000); 93 177 return 1; 94 178 } … … 108 192 #endif 109 193 110 uint64_t start;111 112 194 pm::CollectorHAL *collector = createCollector(); 113 195 if (!collector) … … 116 198 return 1; 117 199 } 118 #if 1 200 #if 0 201 uint64_t start; 202 119 203 uint64_t hostUserStart, hostKernelStart, hostIdleStart; 120 204 uint64_t hostUserStop, hostKernelStop, hostIdleStop, hostTotal; … … 219 303 #endif 220 304 RTPrintf("\ntstCollector: TESTING - Performance\n\n"); 221 unsigned nCalls; 222 ULONG tmp; 223 uint64_t tmp64; 224 uint32_t totalTime = 0; 225 RTPROCESS pid = RTProcSelf(); 226 /* Host CPU load */ 227 CALLS_PER_SECOND(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64)); 228 /* Process CPU load */ 229 CALLS_PER_SECOND(100, getRawProcessCpuLoad(pid, &tmp64, &tmp64, &tmp64)); 230 /* Host CPU speed */ 231 CALLS_PER_SECOND(1, getHostCpuMHz(&tmp)); 232 /* Host RAM usage */ 233 CALLS_PER_SECOND(1, getHostMemoryUsage(&tmp, &tmp, &tmp)); 234 /* Process RAM usage */ 235 CALLS_PER_SECOND(100, getProcessMemoryUsage(pid, &tmp)); 236 237 printf("%.2f%% of CPU time\n", totalTime / 10000.); 305 306 measurePerformance(collector, argv[0], 100); 238 307 239 308 delete collector;
Note:
See TracChangeset
for help on using the changeset viewer.