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