[10938] | 1 | /* $Id: tstCollector.cpp 99775 2023-05-12 12:21:58Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[86441] | 3 | * VirtualBox Main - Performance collector classes test cases.
|
---|
[10938] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[98103] | 7 | * Copyright (C) 2008-2023 Oracle and/or its affiliates.
|
---|
[10938] | 8 | *
|
---|
[96407] | 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
|
---|
[10938] | 26 | */
|
---|
| 27 |
|
---|
[16018] | 28 | #ifdef RT_OS_DARWIN
|
---|
[35368] | 29 | # include "../src-server/darwin/PerformanceDarwin.cpp"
|
---|
[10938] | 30 | #endif
|
---|
[16018] | 31 | #ifdef RT_OS_FREEBSD
|
---|
[35368] | 32 | # include "../src-server/freebsd/PerformanceFreeBSD.cpp"
|
---|
[16018] | 33 | #endif
|
---|
[10938] | 34 | #ifdef RT_OS_LINUX
|
---|
[35368] | 35 | # include "../src-server/linux/PerformanceLinux.cpp"
|
---|
[10938] | 36 | #endif
|
---|
[16018] | 37 | #ifdef RT_OS_OS2
|
---|
[35368] | 38 | # include "../src-server/os2/PerformanceOS2.cpp"
|
---|
[16018] | 39 | #endif
|
---|
| 40 | #ifdef RT_OS_SOLARIS
|
---|
[35368] | 41 | # include "../src-server/solaris/PerformanceSolaris.cpp"
|
---|
[16018] | 42 | #endif
|
---|
[10938] | 43 | #ifdef RT_OS_WINDOWS
|
---|
[35368] | 44 | # define _WIN32_DCOM
|
---|
[62780] | 45 | # include <iprt/win/objidl.h>
|
---|
| 46 | # include <iprt/win/objbase.h>
|
---|
[35368] | 47 | # include "../src-server/win/PerformanceWin.cpp"
|
---|
[10938] | 48 | #endif
|
---|
| 49 |
|
---|
[14831] | 50 | #include <iprt/initterm.h>
|
---|
[13908] | 51 | #include <iprt/stream.h>
|
---|
| 52 | #include <iprt/env.h>
|
---|
| 53 | #include <iprt/err.h>
|
---|
| 54 | #include <iprt/process.h>
|
---|
[14831] | 55 | #include <iprt/thread.h>
|
---|
| 56 | #include <iprt/time.h>
|
---|
[13908] | 57 |
|
---|
[12400] | 58 | #define RUN_TIME_MS 1000
|
---|
| 59 |
|
---|
| 60 | #define N_CALLS(n, fn) \
|
---|
[56994] | 61 | do {\
|
---|
[12400] | 62 | for (int call = 0; call < n; ++call) \
|
---|
| 63 | rc = collector->fn; \
|
---|
| 64 | if (RT_FAILURE(rc)) \
|
---|
[56994] | 65 | RTPrintf("tstCollector: "#fn" -> %Rrc\n", rc); \
|
---|
| 66 | } while (0)
|
---|
[12400] | 67 |
|
---|
[56994] | 68 | #define CALLS_PER_SECOND(fn, args) \
|
---|
| 69 | do { \
|
---|
[12085] | 70 | nCalls = 0; \
|
---|
| 71 | start = RTTimeMilliTS(); \
|
---|
| 72 | do { \
|
---|
[56994] | 73 | rc = collector->fn args; \
|
---|
[12513] | 74 | if (RT_FAILURE(rc)) \
|
---|
| 75 | break; \
|
---|
[12085] | 76 | ++nCalls; \
|
---|
[45367] | 77 | } while (RTTimeMilliTS() - start < RUN_TIME_MS); \
|
---|
[12085] | 78 | if (RT_FAILURE(rc)) \
|
---|
[13837] | 79 | RTPrintf("tstCollector: "#fn" -> %Rrc\n", rc); \
|
---|
[12133] | 80 | else \
|
---|
[56994] | 81 | RTPrintf("%70s -- %u calls per second\n", #fn, nCalls); \
|
---|
| 82 | } while (0)
|
---|
[12085] | 83 |
|
---|
[99775] | 84 | static void shutdownProcessList(std::vector<RTPROCESS> const &rProcesses)
|
---|
[57413] | 85 | {
|
---|
| 86 | for (size_t i = 0; i < rProcesses.size(); i++)
|
---|
| 87 | RTProcTerminate(rProcesses[i]);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
[99775] | 90 | static void measurePerformance(pm::CollectorHAL *collector, const char *pszName, int cVMs)
|
---|
[12400] | 91 | {
|
---|
| 92 |
|
---|
[63177] | 93 | const char * const args[] = { pszName, "-child", NULL };
|
---|
[12400] | 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);
|
---|
[57413] | 107 | shutdownProcessList(processes);
|
---|
| 108 |
|
---|
[13837] | 109 | RTPrintf("tstCollector: RTProcCreate() -> %Rrc\n", rc);
|
---|
[12400] | 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 */
|
---|
[56994] | 125 | CALLS_PER_SECOND(preCollect, (hints, 0));
|
---|
[12400] | 126 | /* Host CPU load */
|
---|
[56994] | 127 | CALLS_PER_SECOND(getRawHostCpuLoad, (&tmp64, &tmp64, &tmp64));
|
---|
[12400] | 128 | /* Process CPU load */
|
---|
[56994] | 129 | CALLS_PER_SECOND(getRawProcessCpuLoad, (processes[nCalls % cVMs], &tmp64, &tmp64, &tmp64));
|
---|
[12400] | 130 | /* Host CPU speed */
|
---|
[56994] | 131 | CALLS_PER_SECOND(getHostCpuMHz, (&tmp));
|
---|
[12400] | 132 | /* Host RAM usage */
|
---|
[56994] | 133 | CALLS_PER_SECOND(getHostMemoryUsage, (&tmp, &tmp, &tmp));
|
---|
[12400] | 134 | /* Process RAM usage */
|
---|
[56994] | 135 | CALLS_PER_SECOND(getProcessMemoryUsage, (processes[nCalls % cVMs], &tmp));
|
---|
[12400] | 136 |
|
---|
| 137 | start = RTTimeNanoTS();
|
---|
| 138 |
|
---|
[12401] | 139 | int times;
|
---|
| 140 | for (times = 0; times < 100; times++)
|
---|
[12400] | 141 | {
|
---|
| 142 | /* Pre-collect */
|
---|
[27930] | 143 | N_CALLS(1, preCollect(hints, 0));
|
---|
[12400] | 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 | }
|
---|
[93310] | 155 | RTPrintf("\n%d VMs -- %u%% of CPU time\n", cVMs, (unsigned)((double)(RTTimeNanoTS() - start) / 10000000.0 / times));
|
---|
[12400] | 156 |
|
---|
| 157 | /* Shut down fake VMs */
|
---|
[57413] | 158 | shutdownProcessList(processes);
|
---|
[12400] | 159 | }
|
---|
| 160 |
|
---|
[43538] | 161 | #ifdef RT_OS_SOLARIS
|
---|
| 162 | #define NETIFNAME "net0"
|
---|
| 163 | #else
|
---|
| 164 | #define NETIFNAME "eth0"
|
---|
| 165 | #endif
|
---|
[99775] | 166 | static int testNetwork(pm::CollectorHAL *collector)
|
---|
[43445] | 167 | {
|
---|
| 168 | pm::CollectorHints hints;
|
---|
[43507] | 169 | uint64_t hostRxStart, hostTxStart;
|
---|
| 170 | uint64_t hostRxStop, hostTxStop, speed = 125000000; /* Assume 1Gbit/s */
|
---|
[43445] | 171 |
|
---|
[48011] | 172 | RTPrintf("tstCollector: TESTING - Network load, sleeping for 5 s...\n");
|
---|
[43445] | 173 |
|
---|
[44031] | 174 | hostRxStart = hostTxStart = 0;
|
---|
[43445] | 175 | int rc = collector->preCollect(hints, 0);
|
---|
| 176 | if (RT_FAILURE(rc))
|
---|
| 177 | {
|
---|
| 178 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
| 179 | return 1;
|
---|
| 180 | }
|
---|
[43538] | 181 | rc = collector->getRawHostNetworkLoad(NETIFNAME, &hostRxStart, &hostTxStart);
|
---|
[48008] | 182 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
| 183 | RTPrintf("tstCollector: getRawHostNetworkLoad() not implemented, skipping\n");
|
---|
| 184 | else
|
---|
[43445] | 185 | {
|
---|
[48008] | 186 | if (RT_FAILURE(rc))
|
---|
| 187 | {
|
---|
| 188 | RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc);
|
---|
| 189 | return 1;
|
---|
| 190 | }
|
---|
[43445] | 191 |
|
---|
[48008] | 192 | RTThreadSleep(5000); // Sleep for five seconds
|
---|
[43445] | 193 |
|
---|
[48008] | 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);
|
---|
[43445] | 218 | }
|
---|
| 219 |
|
---|
| 220 | return 0;
|
---|
| 221 | }
|
---|
| 222 |
|
---|
[43629] | 223 | #define FSNAME "/"
|
---|
[99775] | 224 | static int testFsUsage(pm::CollectorHAL *collector)
|
---|
[43629] | 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);
|
---|
[48011] | 231 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
| 232 | RTPrintf("tstCollector: getHostFilesystemUsage() not implemented, skipping\n");
|
---|
| 233 | else
|
---|
[43629] | 234 | {
|
---|
[48011] | 235 | if (RT_FAILURE(rc))
|
---|
| 236 | {
|
---|
| 237 | RTPrintf("tstCollector: getHostFilesystemUsage() -> %Rrc\n", rc);
|
---|
| 238 | return 1;
|
---|
| 239 | }
|
---|
[80668] | 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);
|
---|
[43629] | 243 | }
|
---|
| 244 | return 0;
|
---|
| 245 | }
|
---|
| 246 |
|
---|
[99775] | 247 | static int testDisk(pm::CollectorHAL *collector)
|
---|
[43629] | 248 | {
|
---|
| 249 | pm::CollectorHints hints;
|
---|
| 250 | uint64_t diskMsStart, totalMsStart;
|
---|
| 251 | uint64_t diskMsStop, totalMsStop;
|
---|
| 252 |
|
---|
[45051] | 253 | pm::DiskList disksUsage, disksLoad;
|
---|
| 254 | int rc = collector->getDiskListByFs(FSNAME, disksUsage, disksLoad);
|
---|
[48008] | 255 | if (rc == VERR_NOT_IMPLEMENTED)
|
---|
| 256 | RTPrintf("tstCollector: getDiskListByFs() not implemented, skipping\n");
|
---|
| 257 | else
|
---|
[43629] | 258 | {
|
---|
[45012] | 259 | if (RT_FAILURE(rc))
|
---|
| 260 | {
|
---|
[48008] | 261 | RTPrintf("tstCollector: getDiskListByFs(%s) -> %Rrc\n", FSNAME, rc);
|
---|
[45012] | 262 | return 1;
|
---|
| 263 | }
|
---|
[48008] | 264 | if (disksUsage.empty())
|
---|
[45012] | 265 | {
|
---|
[48008] | 266 | RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME);
|
---|
[51965] | 267 | return 0;
|
---|
[45012] | 268 | }
|
---|
[48008] | 269 | if (disksLoad.empty())
|
---|
[45012] | 270 | {
|
---|
[48008] | 271 | RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME);
|
---|
[51965] | 272 | return 0;
|
---|
[45012] | 273 | }
|
---|
[43629] | 274 |
|
---|
[48008] | 275 | pm::DiskList::iterator it;
|
---|
| 276 | for (it = disksUsage.begin(); it != disksUsage.end(); ++it)
|
---|
[45012] | 277 | {
|
---|
[48008] | 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);
|
---|
[48011] | 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))
|
---|
[48008] | 284 | {
|
---|
| 285 | RTPrintf("tstCollector: getHostDiskSize() -> %Rrc\n", rc);
|
---|
| 286 | return 1;
|
---|
| 287 | }
|
---|
[45012] | 288 | }
|
---|
[48008] | 289 |
|
---|
| 290 | for (it = disksLoad.begin(); it != disksLoad.end(); ++it)
|
---|
[45012] | 291 | {
|
---|
[48011] | 292 | RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 s...\n", it->c_str());
|
---|
[48008] | 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);
|
---|
[45012] | 327 | }
|
---|
[43629] | 328 | }
|
---|
| 329 |
|
---|
| 330 | return 0;
|
---|
| 331 | }
|
---|
| 332 |
|
---|
| 333 |
|
---|
| 334 |
|
---|
[10938] | 335 | int main(int argc, char *argv[])
|
---|
| 336 | {
|
---|
[45012] | 337 | bool cpuTest, ramTest, netTest, diskTest, fsTest, perfTest;
|
---|
| 338 | cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = false;
|
---|
[10938] | 339 | /*
|
---|
| 340 | * Initialize the VBox runtime without loading
|
---|
| 341 | * the support driver.
|
---|
| 342 | */
|
---|
[38636] | 343 | int rc = RTR3InitExe(argc, &argv, 0);
|
---|
[10938] | 344 | if (RT_FAILURE(rc))
|
---|
| 345 | {
|
---|
[38636] | 346 | RTPrintf("tstCollector: RTR3InitExe() -> %d\n", rc);
|
---|
[10938] | 347 | return 1;
|
---|
| 348 | }
|
---|
[45012] | 349 | if (argc > 1)
|
---|
[12400] | 350 | {
|
---|
[45012] | 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 | }
|
---|
[12400] | 377 | }
|
---|
[45012] | 378 | else
|
---|
| 379 | cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = true;
|
---|
| 380 |
|
---|
[12085] | 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
|
---|
[10938] | 395 |
|
---|
[12546] | 396 | pm::CollectorHAL *collector = pm::createHAL();
|
---|
[10938] | 397 | if (!collector)
|
---|
| 398 | {
|
---|
[50865] | 399 | RTPrintf("tstCollector: createMetricFactory() failed\n");
|
---|
[10938] | 400 | return 1;
|
---|
| 401 | }
|
---|
[45012] | 402 |
|
---|
[12513] | 403 | pm::CollectorHints hints;
|
---|
[45012] | 404 | if (cpuTest)
|
---|
| 405 | {
|
---|
| 406 | hints.collectHostCpuLoad();
|
---|
| 407 | hints.collectProcessCpuLoad(RTProcSelf());
|
---|
| 408 | }
|
---|
| 409 | if (ramTest)
|
---|
| 410 | {
|
---|
| 411 | hints.collectHostRamUsage();
|
---|
| 412 | hints.collectProcessRamUsage(RTProcSelf());
|
---|
| 413 | }
|
---|
[12513] | 414 |
|
---|
[12400] | 415 | uint64_t start;
|
---|
| 416 |
|
---|
[10938] | 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 |
|
---|
[27930] | 423 | rc = collector->preCollect(hints, 0);
|
---|
[12513] | 424 | if (RT_FAILURE(rc))
|
---|
| 425 | {
|
---|
[13837] | 426 | RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
|
---|
[12513] | 427 | return 1;
|
---|
| 428 | }
|
---|
[45012] | 429 | if (cpuTest)
|
---|
[10938] | 430 | {
|
---|
[48011] | 431 | RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 s...\n");
|
---|
[10938] | 432 |
|
---|
[45012] | 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 | }
|
---|
[10938] | 445 |
|
---|
[45012] | 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 |
|
---|
[48011] | 485 | RTPrintf("tstCollector: TESTING - CPU load, looping for 5 s...\n");
|
---|
[45012] | 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();
|
---|
[45367] | 505 | while (RTTimeMilliTS() - start < 5000)
|
---|
[45012] | 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));
|
---|
[12513] | 543 | }
|
---|
[10938] | 544 |
|
---|
[45012] | 545 | if (ramTest)
|
---|
[12513] | 546 | {
|
---|
[45012] | 547 | RTPrintf("tstCollector: TESTING - Memory usage\n");
|
---|
[10938] | 548 |
|
---|
[45012] | 549 | ULONG total, used, available, processUsed;
|
---|
[10938] | 550 |
|
---|
[45012] | 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 | }
|
---|
[10938] | 568 |
|
---|
[45012] | 569 | if (netTest)
|
---|
| 570 | rc = testNetwork(collector);
|
---|
| 571 | if (fsTest)
|
---|
| 572 | rc = testFsUsage(collector);
|
---|
| 573 | if (diskTest)
|
---|
| 574 | rc = testDisk(collector);
|
---|
| 575 | if (perfTest)
|
---|
[10938] | 576 | {
|
---|
[45012] | 577 | RTPrintf("tstCollector: TESTING - Performance\n\n");
|
---|
| 578 |
|
---|
| 579 | measurePerformance(collector, argv[0], 100);
|
---|
[10938] | 580 | }
|
---|
[12400] | 581 |
|
---|
[10938] | 582 | delete collector;
|
---|
| 583 |
|
---|
[77102] | 584 | RTPrintf("\ntstCollector FINISHED.\n");
|
---|
[10938] | 585 |
|
---|
[66796] | 586 | return RTEXITCODE_SUCCESS;
|
---|
[10938] | 587 | }
|
---|
| 588 |
|
---|