1 | /* $Id: tstCollector.cpp 51965 2014-07-10 10:37:15Z vboxsync $ */
|
---|
2 |
|
---|
3 | /** @file
|
---|
4 | *
|
---|
5 | * Collector classes test cases.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /*
|
---|
9 | * Copyright (C) 2008-2012 Oracle Corporation
|
---|
10 | *
|
---|
11 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
12 | * available from http://www.virtualbox.org. This file is free software;
|
---|
13 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
14 | * General Public License (GPL) as published by the Free Software
|
---|
15 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
16 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
17 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #ifdef RT_OS_DARWIN
|
---|
21 | # include "../src-server/darwin/PerformanceDarwin.cpp"
|
---|
22 | #endif
|
---|
23 | #ifdef RT_OS_FREEBSD
|
---|
24 | # include "../src-server/freebsd/PerformanceFreeBSD.cpp"
|
---|
25 | #endif
|
---|
26 | #ifdef RT_OS_LINUX
|
---|
27 | # include "../src-server/linux/PerformanceLinux.cpp"
|
---|
28 | #endif
|
---|
29 | #ifdef RT_OS_OS2
|
---|
30 | # include "../src-server/os2/PerformanceOS2.cpp"
|
---|
31 | #endif
|
---|
32 | #ifdef RT_OS_SOLARIS
|
---|
33 | # include "../src-server/solaris/PerformanceSolaris.cpp"
|
---|
34 | #endif
|
---|
35 | #ifdef RT_OS_WINDOWS
|
---|
36 | # define _WIN32_DCOM
|
---|
37 | # include <objidl.h>
|
---|
38 | # include <objbase.h>
|
---|
39 | # include "../src-server/win/PerformanceWin.cpp"
|
---|
40 | #endif
|
---|
41 |
|
---|
42 | #include <iprt/initterm.h>
|
---|
43 | #include <iprt/stream.h>
|
---|
44 | #include <iprt/env.h>
|
---|
45 | #include <iprt/err.h>
|
---|
46 | #include <iprt/process.h>
|
---|
47 | #include <iprt/thread.h>
|
---|
48 | #include <iprt/time.h>
|
---|
49 |
|
---|
50 | #define RUN_TIME_MS 1000
|
---|
51 |
|
---|
52 | #define N_CALLS(n, fn) \
|
---|
53 | for (int call = 0; call < n; ++call) \
|
---|
54 | rc = collector->fn; \
|
---|
55 | if (RT_FAILURE(rc)) \
|
---|
56 | RTPrintf("tstCollector: "#fn" -> %Rrc\n", rc)
|
---|
57 |
|
---|
58 | #define CALLS_PER_SECOND(fn) \
|
---|
59 | nCalls = 0; \
|
---|
60 | start = RTTimeMilliTS(); \
|
---|
61 | do { \
|
---|
62 | rc = collector->fn; \
|
---|
63 | if (RT_FAILURE(rc)) \
|
---|
64 | break; \
|
---|
65 | ++nCalls; \
|
---|
66 | } while (RTTimeMilliTS() - start < RUN_TIME_MS); \
|
---|
67 | if (RT_FAILURE(rc)) \
|
---|
68 | { \
|
---|
69 | RTPrintf("tstCollector: "#fn" -> %Rrc\n", rc); \
|
---|
70 | } \
|
---|
71 | else \
|
---|
72 | RTPrintf("%70s -- %u calls per second\n", #fn, nCalls)
|
---|
73 |
|
---|
74 | void measurePerformance(pm::CollectorHAL *collector, const char *pszName, int cVMs)
|
---|
75 | {
|
---|
76 |
|
---|
77 | static const char * const args[] = { pszName, "-child", NULL };
|
---|
78 | pm::CollectorHints hints;
|
---|
79 | std::vector<RTPROCESS> processes;
|
---|
80 |
|
---|
81 | hints.collectHostCpuLoad();
|
---|
82 | hints.collectHostRamUsage();
|
---|
83 | /* Start fake VMs */
|
---|
84 | for (int i = 0; i < cVMs; ++i)
|
---|
85 | {
|
---|
86 | RTPROCESS pid;
|
---|
87 | int rc = RTProcCreate(pszName, args, RTENV_DEFAULT, 0, &pid);
|
---|
88 | if (RT_FAILURE(rc))
|
---|
89 | {
|
---|
90 | hints.getProcesses(processes);
|
---|
91 | std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate));
|
---|
92 | RTPrintf("tstCollector: RTProcCreate() -> %Rrc\n", rc);
|
---|
93 | return;
|
---|
94 | }
|
---|
95 | hints.collectProcessCpuLoad(pid);
|
---|
96 | hints.collectProcessRamUsage(pid);
|
---|
97 | }
|
---|
98 |
|
---|
99 | hints.getProcesses(processes);
|
---|
100 | RTThreadSleep(30000); // Let children settle for half a minute
|
---|
101 |
|
---|
102 | int rc;
|
---|
103 | ULONG tmp;
|
---|
104 | uint64_t tmp64;
|
---|
105 | uint64_t start;
|
---|
106 | unsigned int nCalls;
|
---|
107 | /* Pre-collect */
|
---|
108 | CALLS_PER_SECOND(preCollect(hints, 0));
|
---|
109 | /* Host CPU load */
|
---|
110 | CALLS_PER_SECOND(getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
|
---|
111 | /* Process CPU load */
|
---|
112 | CALLS_PER_SECOND(getRawProcessCpuLoad(processes[nCalls%cVMs], &tmp64, &tmp64, &tmp64));
|
---|
113 | /* Host CPU speed */
|
---|
114 | CALLS_PER_SECOND(getHostCpuMHz(&tmp));
|
---|
115 | /* Host RAM usage */
|
---|
116 | CALLS_PER_SECOND(getHostMemoryUsage(&tmp, &tmp, &tmp));
|
---|
117 | /* Process RAM usage */
|
---|
118 | CALLS_PER_SECOND(getProcessMemoryUsage(processes[nCalls%cVMs], &tmp));
|
---|
119 |
|
---|
120 | start = RTTimeNanoTS();
|
---|
121 |
|
---|
122 | int times;
|
---|
123 | for (times = 0; times < 100; times++)
|
---|
124 | {
|
---|
125 | /* Pre-collect */
|
---|
126 | N_CALLS(1, preCollect(hints, 0));
|
---|
127 | /* Host CPU load */
|
---|
128 | N_CALLS(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
|
---|
129 | /* Host CPU speed */
|
---|
130 | N_CALLS(1, getHostCpuMHz(&tmp));
|
---|
131 | /* Host RAM usage */
|
---|
132 | N_CALLS(1, getHostMemoryUsage(&tmp, &tmp, &tmp));
|
---|
133 | /* Process CPU load */
|
---|
134 | N_CALLS(cVMs, getRawProcessCpuLoad(processes[call], &tmp64, &tmp64, &tmp64));
|
---|
135 | /* Process RAM usage */
|
---|
136 | N_CALLS(cVMs, getProcessMemoryUsage(processes[call], &tmp));
|
---|
137 | }
|
---|
138 | printf("\n%u VMs -- %.2f%% of CPU time\n", cVMs, (RTTimeNanoTS() - start) / 10000000. / times);
|
---|
139 |
|
---|
140 | /* Shut down fake VMs */
|
---|
141 | std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate));
|
---|
142 | }
|
---|
143 |
|
---|
144 | #ifdef RT_OS_SOLARIS
|
---|
145 | #define NETIFNAME "net0"
|
---|
146 | #else
|
---|
147 | #define NETIFNAME "eth0"
|
---|
148 | #endif
|
---|
149 | int testNetwork(pm::CollectorHAL *collector)
|
---|
150 | {
|
---|
151 | pm::CollectorHints hints;
|
---|
152 | uint64_t hostRxStart, hostTxStart;
|
---|
153 | uint64_t hostRxStop, hostTxStop, speed = 125000000; /* Assume 1Gbit/s */
|
---|
154 |
|
---|
155 | RTPrintf("tstCollector: TESTING - Network load, sleeping for 5 s...\n");
|
---|
156 |
|
---|
157 | hostRxStart = hostTxStart = 0;
|
---|
158 | int rc = collector->preCollect(hints, 0);
|
---|
159 | if (RT_FAILURE(rc))
|
---|
160 | {
|
---|
161 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
162 | return 1;
|
---|
163 | }
|
---|
164 | rc = collector->getRawHostNetworkLoad(NETIFNAME, &hostRxStart, &hostTxStart);
|
---|
165 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
166 | RTPrintf("tstCollector: getRawHostNetworkLoad() not implemented, skipping\n");
|
---|
167 | else
|
---|
168 | {
|
---|
169 | if (RT_FAILURE(rc))
|
---|
170 | {
|
---|
171 | RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc);
|
---|
172 | return 1;
|
---|
173 | }
|
---|
174 |
|
---|
175 | RTThreadSleep(5000); // Sleep for five seconds
|
---|
176 |
|
---|
177 | rc = collector->preCollect(hints, 0);
|
---|
178 | if (RT_FAILURE(rc))
|
---|
179 | {
|
---|
180 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
181 | return 1;
|
---|
182 | }
|
---|
183 | hostRxStop = hostRxStart;
|
---|
184 | hostTxStop = hostTxStart;
|
---|
185 | rc = collector->getRawHostNetworkLoad(NETIFNAME, &hostRxStop, &hostTxStop);
|
---|
186 | if (RT_FAILURE(rc))
|
---|
187 | {
|
---|
188 | RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc);
|
---|
189 | return 1;
|
---|
190 | }
|
---|
191 | RTPrintf("tstCollector: host network speed = %llu bytes/sec (%llu mbit/sec)\n",
|
---|
192 | speed, speed/(1000000/8));
|
---|
193 | RTPrintf("tstCollector: host network rx = %llu bytes/sec (%llu mbit/sec, %u.%u %%)\n",
|
---|
194 | (hostRxStop - hostRxStart)/5, (hostRxStop - hostRxStart)/(5000000/8),
|
---|
195 | (hostRxStop - hostRxStart) * 100 / (speed * 5),
|
---|
196 | (hostRxStop - hostRxStart) * 10000 / (speed * 5) % 100);
|
---|
197 | RTPrintf("tstCollector: host network tx = %llu bytes/sec (%llu mbit/sec, %u.%u %%)\n\n",
|
---|
198 | (hostTxStop - hostTxStart)/5, (hostTxStop - hostTxStart)/(5000000/8),
|
---|
199 | (hostTxStop - hostTxStart) * 100 / (speed * 5),
|
---|
200 | (hostTxStop - hostTxStart) * 10000 / (speed * 5) % 100);
|
---|
201 | }
|
---|
202 |
|
---|
203 | return 0;
|
---|
204 | }
|
---|
205 |
|
---|
206 | #define FSNAME "/"
|
---|
207 | int testFsUsage(pm::CollectorHAL *collector)
|
---|
208 | {
|
---|
209 | RTPrintf("tstCollector: TESTING - File system usage\n");
|
---|
210 |
|
---|
211 | ULONG total, used, available;
|
---|
212 |
|
---|
213 | int rc = collector->getHostFilesystemUsage(FSNAME, &total, &used, &available);
|
---|
214 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
215 | RTPrintf("tstCollector: getHostFilesystemUsage() not implemented, skipping\n");
|
---|
216 | else
|
---|
217 | {
|
---|
218 | if (RT_FAILURE(rc))
|
---|
219 | {
|
---|
220 | RTPrintf("tstCollector: getHostFilesystemUsage() -> %Rrc\n", rc);
|
---|
221 | return 1;
|
---|
222 | }
|
---|
223 | RTPrintf("tstCollector: host root fs total = %lu mB\n", total);
|
---|
224 | RTPrintf("tstCollector: host root fs used = %lu mB\n", used);
|
---|
225 | RTPrintf("tstCollector: host root fs available = %lu mB\n\n", available);
|
---|
226 | }
|
---|
227 | return 0;
|
---|
228 | }
|
---|
229 |
|
---|
230 | int testDisk(pm::CollectorHAL *collector)
|
---|
231 | {
|
---|
232 | pm::CollectorHints hints;
|
---|
233 | uint64_t diskMsStart, totalMsStart;
|
---|
234 | uint64_t diskMsStop, totalMsStop;
|
---|
235 |
|
---|
236 | pm::DiskList disksUsage, disksLoad;
|
---|
237 | int rc = collector->getDiskListByFs(FSNAME, disksUsage, disksLoad);
|
---|
238 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
239 | RTPrintf("tstCollector: getDiskListByFs() not implemented, skipping\n");
|
---|
240 | else
|
---|
241 | {
|
---|
242 | if (RT_FAILURE(rc))
|
---|
243 | {
|
---|
244 | RTPrintf("tstCollector: getDiskListByFs(%s) -> %Rrc\n", FSNAME, rc);
|
---|
245 | return 1;
|
---|
246 | }
|
---|
247 | if (disksUsage.empty())
|
---|
248 | {
|
---|
249 | RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME);
|
---|
250 | return 0;
|
---|
251 | }
|
---|
252 | if (disksLoad.empty())
|
---|
253 | {
|
---|
254 | RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME);
|
---|
255 | return 0;
|
---|
256 | }
|
---|
257 |
|
---|
258 | pm::DiskList::iterator it;
|
---|
259 | for (it = disksUsage.begin(); it != disksUsage.end(); ++it)
|
---|
260 | {
|
---|
261 | uint64_t diskSize = 0;
|
---|
262 | rc = collector->getHostDiskSize(it->c_str(), &diskSize);
|
---|
263 | RTPrintf("tstCollector: TESTING - Disk size (%s) = %llu\n", it->c_str(), diskSize);
|
---|
264 | if (rc == VERR_FILE_NOT_FOUND)
|
---|
265 | RTPrintf("tstCollector: getHostDiskSize(%s) returned VERR_FILE_NOT_FOUND\n", it->c_str());
|
---|
266 | else if (RT_FAILURE(rc))
|
---|
267 | {
|
---|
268 | RTPrintf("tstCollector: getHostDiskSize() -> %Rrc\n", rc);
|
---|
269 | return 1;
|
---|
270 | }
|
---|
271 | }
|
---|
272 |
|
---|
273 | for (it = disksLoad.begin(); it != disksLoad.end(); ++it)
|
---|
274 | {
|
---|
275 | RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 s...\n", it->c_str());
|
---|
276 |
|
---|
277 | hints.collectHostCpuLoad();
|
---|
278 | rc = collector->preCollect(hints, 0);
|
---|
279 | if (RT_FAILURE(rc))
|
---|
280 | {
|
---|
281 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
282 | return 1;
|
---|
283 | }
|
---|
284 | rc = collector->getRawHostDiskLoad(it->c_str(), &diskMsStart, &totalMsStart);
|
---|
285 | if (RT_FAILURE(rc))
|
---|
286 | {
|
---|
287 | RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc);
|
---|
288 | return 1;
|
---|
289 | }
|
---|
290 |
|
---|
291 | RTThreadSleep(5000); // Sleep for five seconds
|
---|
292 |
|
---|
293 | rc = collector->preCollect(hints, 0);
|
---|
294 | if (RT_FAILURE(rc))
|
---|
295 | {
|
---|
296 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
297 | return 1;
|
---|
298 | }
|
---|
299 | rc = collector->getRawHostDiskLoad(it->c_str(), &diskMsStop, &totalMsStop);
|
---|
300 | if (RT_FAILURE(rc))
|
---|
301 | {
|
---|
302 | RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc);
|
---|
303 | return 1;
|
---|
304 | }
|
---|
305 | RTPrintf("tstCollector: host disk util = %llu msec (%u.%u %%), total = %llu msec\n\n",
|
---|
306 | (diskMsStop - diskMsStart),
|
---|
307 | (unsigned)((diskMsStop - diskMsStart) * 100 / (totalMsStop - totalMsStart)),
|
---|
308 | (unsigned)((diskMsStop - diskMsStart) * 10000 / (totalMsStop - totalMsStart) % 100),
|
---|
309 | totalMsStop - totalMsStart);
|
---|
310 | }
|
---|
311 | }
|
---|
312 |
|
---|
313 | return 0;
|
---|
314 | }
|
---|
315 |
|
---|
316 |
|
---|
317 |
|
---|
318 | int main(int argc, char *argv[])
|
---|
319 | {
|
---|
320 | bool cpuTest, ramTest, netTest, diskTest, fsTest, perfTest;
|
---|
321 | cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = false;
|
---|
322 | /*
|
---|
323 | * Initialize the VBox runtime without loading
|
---|
324 | * the support driver.
|
---|
325 | */
|
---|
326 | int rc = RTR3InitExe(argc, &argv, 0);
|
---|
327 | if (RT_FAILURE(rc))
|
---|
328 | {
|
---|
329 | RTPrintf("tstCollector: RTR3InitExe() -> %d\n", rc);
|
---|
330 | return 1;
|
---|
331 | }
|
---|
332 | if (argc > 1)
|
---|
333 | {
|
---|
334 | if (!strcmp(argv[1], "-child"))
|
---|
335 | {
|
---|
336 | /* We have spawned ourselves as a child process -- scratch the leg */
|
---|
337 | RTThreadSleep(1000000);
|
---|
338 | return 1;
|
---|
339 | }
|
---|
340 | for (int i = 1; i < argc; i++)
|
---|
341 | {
|
---|
342 | if (!strcmp(argv[i], "-cpu"))
|
---|
343 | cpuTest = true;
|
---|
344 | else if (!strcmp(argv[i], "-ram"))
|
---|
345 | ramTest = true;
|
---|
346 | else if (!strcmp(argv[i], "-net"))
|
---|
347 | netTest = true;
|
---|
348 | else if (!strcmp(argv[i], "-disk"))
|
---|
349 | diskTest = true;
|
---|
350 | else if (!strcmp(argv[i], "-fs"))
|
---|
351 | fsTest = true;
|
---|
352 | else if (!strcmp(argv[i], "-perf"))
|
---|
353 | perfTest = true;
|
---|
354 | else
|
---|
355 | {
|
---|
356 | RTPrintf("tstCollector: Unknown option: %s\n", argv[i]);
|
---|
357 | return 2;
|
---|
358 | }
|
---|
359 | }
|
---|
360 | }
|
---|
361 | else
|
---|
362 | cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = true;
|
---|
363 |
|
---|
364 | #ifdef RT_OS_WINDOWS
|
---|
365 | HRESULT hRes = CoInitialize(NULL);
|
---|
366 | /*
|
---|
367 | * Need to initialize security to access performance enumerators.
|
---|
368 | */
|
---|
369 | hRes = CoInitializeSecurity(
|
---|
370 | NULL,
|
---|
371 | -1,
|
---|
372 | NULL,
|
---|
373 | NULL,
|
---|
374 | RPC_C_AUTHN_LEVEL_NONE,
|
---|
375 | RPC_C_IMP_LEVEL_IMPERSONATE,
|
---|
376 | NULL, EOAC_NONE, 0);
|
---|
377 | #endif
|
---|
378 |
|
---|
379 | pm::CollectorHAL *collector = pm::createHAL();
|
---|
380 | if (!collector)
|
---|
381 | {
|
---|
382 | RTPrintf("tstCollector: createMetricFactory() failed\n");
|
---|
383 | return 1;
|
---|
384 | }
|
---|
385 |
|
---|
386 | pm::CollectorHints hints;
|
---|
387 | if (cpuTest)
|
---|
388 | {
|
---|
389 | hints.collectHostCpuLoad();
|
---|
390 | hints.collectProcessCpuLoad(RTProcSelf());
|
---|
391 | }
|
---|
392 | if (ramTest)
|
---|
393 | {
|
---|
394 | hints.collectHostRamUsage();
|
---|
395 | hints.collectProcessRamUsage(RTProcSelf());
|
---|
396 | }
|
---|
397 |
|
---|
398 | uint64_t start;
|
---|
399 |
|
---|
400 | uint64_t hostUserStart, hostKernelStart, hostIdleStart;
|
---|
401 | uint64_t hostUserStop, hostKernelStop, hostIdleStop, hostTotal;
|
---|
402 |
|
---|
403 | uint64_t processUserStart, processKernelStart, processTotalStart;
|
---|
404 | uint64_t processUserStop, processKernelStop, processTotalStop;
|
---|
405 |
|
---|
406 | rc = collector->preCollect(hints, 0);
|
---|
407 | if (RT_FAILURE(rc))
|
---|
408 | {
|
---|
409 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
410 | return 1;
|
---|
411 | }
|
---|
412 | if (cpuTest)
|
---|
413 | {
|
---|
414 | RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 s...\n");
|
---|
415 |
|
---|
416 | rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart);
|
---|
417 | if (RT_FAILURE(rc))
|
---|
418 | {
|
---|
419 | RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
|
---|
420 | return 1;
|
---|
421 | }
|
---|
422 | rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
|
---|
423 | if (RT_FAILURE(rc))
|
---|
424 | {
|
---|
425 | RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
|
---|
426 | return 1;
|
---|
427 | }
|
---|
428 |
|
---|
429 | RTThreadSleep(5000); // Sleep for 5 seconds
|
---|
430 |
|
---|
431 | rc = collector->preCollect(hints, 0);
|
---|
432 | if (RT_FAILURE(rc))
|
---|
433 | {
|
---|
434 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
435 | return 1;
|
---|
436 | }
|
---|
437 | rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop);
|
---|
438 | if (RT_FAILURE(rc))
|
---|
439 | {
|
---|
440 | RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
|
---|
441 | return 1;
|
---|
442 | }
|
---|
443 | rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
|
---|
444 | if (RT_FAILURE(rc))
|
---|
445 | {
|
---|
446 | RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
|
---|
447 | return 1;
|
---|
448 | }
|
---|
449 | hostTotal = hostUserStop - hostUserStart
|
---|
450 | + hostKernelStop - hostKernelStart
|
---|
451 | + hostIdleStop - hostIdleStart;
|
---|
452 | RTPrintf("tstCollector: host cpu user = %u.%u %%\n",
|
---|
453 | (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal),
|
---|
454 | (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100));
|
---|
455 | RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n",
|
---|
456 | (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal),
|
---|
457 | (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100));
|
---|
458 | RTPrintf("tstCollector: host cpu idle = %u.%u %%\n",
|
---|
459 | (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal),
|
---|
460 | (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100));
|
---|
461 | RTPrintf("tstCollector: process cpu user = %u.%u %%\n",
|
---|
462 | (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)),
|
---|
463 | (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100));
|
---|
464 | RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n",
|
---|
465 | (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)),
|
---|
466 | (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100));
|
---|
467 |
|
---|
468 | RTPrintf("tstCollector: TESTING - CPU load, looping for 5 s...\n");
|
---|
469 | rc = collector->preCollect(hints, 0);
|
---|
470 | if (RT_FAILURE(rc))
|
---|
471 | {
|
---|
472 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
473 | return 1;
|
---|
474 | }
|
---|
475 | rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart);
|
---|
476 | if (RT_FAILURE(rc))
|
---|
477 | {
|
---|
478 | RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
|
---|
479 | return 1;
|
---|
480 | }
|
---|
481 | rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
|
---|
482 | if (RT_FAILURE(rc))
|
---|
483 | {
|
---|
484 | RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
|
---|
485 | return 1;
|
---|
486 | }
|
---|
487 | start = RTTimeMilliTS();
|
---|
488 | while (RTTimeMilliTS() - start < 5000)
|
---|
489 | ; // Loop for 5 seconds
|
---|
490 | rc = collector->preCollect(hints, 0);
|
---|
491 | if (RT_FAILURE(rc))
|
---|
492 | {
|
---|
493 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
494 | return 1;
|
---|
495 | }
|
---|
496 | rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop);
|
---|
497 | if (RT_FAILURE(rc))
|
---|
498 | {
|
---|
499 | RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
|
---|
500 | return 1;
|
---|
501 | }
|
---|
502 | rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
|
---|
503 | if (RT_FAILURE(rc))
|
---|
504 | {
|
---|
505 | RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
|
---|
506 | return 1;
|
---|
507 | }
|
---|
508 | hostTotal = hostUserStop - hostUserStart
|
---|
509 | + hostKernelStop - hostKernelStart
|
---|
510 | + hostIdleStop - hostIdleStart;
|
---|
511 | RTPrintf("tstCollector: host cpu user = %u.%u %%\n",
|
---|
512 | (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal),
|
---|
513 | (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100));
|
---|
514 | RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n",
|
---|
515 | (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal),
|
---|
516 | (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100));
|
---|
517 | RTPrintf("tstCollector: host cpu idle = %u.%u %%\n",
|
---|
518 | (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal),
|
---|
519 | (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100));
|
---|
520 | RTPrintf("tstCollector: process cpu user = %u.%u %%\n",
|
---|
521 | (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)),
|
---|
522 | (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100));
|
---|
523 | RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n",
|
---|
524 | (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)),
|
---|
525 | (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100));
|
---|
526 | }
|
---|
527 |
|
---|
528 | if (ramTest)
|
---|
529 | {
|
---|
530 | RTPrintf("tstCollector: TESTING - Memory usage\n");
|
---|
531 |
|
---|
532 | ULONG total, used, available, processUsed;
|
---|
533 |
|
---|
534 | rc = collector->getHostMemoryUsage(&total, &used, &available);
|
---|
535 | if (RT_FAILURE(rc))
|
---|
536 | {
|
---|
537 | RTPrintf("tstCollector: getHostMemoryUsage() -> %Rrc\n", rc);
|
---|
538 | return 1;
|
---|
539 | }
|
---|
540 | rc = collector->getProcessMemoryUsage(RTProcSelf(), &processUsed);
|
---|
541 | if (RT_FAILURE(rc))
|
---|
542 | {
|
---|
543 | RTPrintf("tstCollector: getProcessMemoryUsage() -> %Rrc\n", rc);
|
---|
544 | return 1;
|
---|
545 | }
|
---|
546 | RTPrintf("tstCollector: host mem total = %lu kB\n", total);
|
---|
547 | RTPrintf("tstCollector: host mem used = %lu kB\n", used);
|
---|
548 | RTPrintf("tstCollector: host mem available = %lu kB\n", available);
|
---|
549 | RTPrintf("tstCollector: process mem used = %lu kB\n\n", processUsed);
|
---|
550 | }
|
---|
551 |
|
---|
552 | if (netTest)
|
---|
553 | rc = testNetwork(collector);
|
---|
554 | if (fsTest)
|
---|
555 | rc = testFsUsage(collector);
|
---|
556 | if (diskTest)
|
---|
557 | rc = testDisk(collector);
|
---|
558 | if (perfTest)
|
---|
559 | {
|
---|
560 | RTPrintf("tstCollector: TESTING - Performance\n\n");
|
---|
561 |
|
---|
562 | measurePerformance(collector, argv[0], 100);
|
---|
563 | }
|
---|
564 |
|
---|
565 | delete collector;
|
---|
566 |
|
---|
567 | printf ("\ntstCollector FINISHED.\n");
|
---|
568 |
|
---|
569 | return rc;
|
---|
570 | }
|
---|
571 |
|
---|