summaryrefslogtreecommitdiffstats
path: root/src/VBox/Main/testcase/tstCollector.cpp
blob: 4f42ec0151631cf5733abc64af50a24d4191489f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
/* $Id: tstCollector.cpp $ */
/** @file
 * VirtualBox Main - Performance collector classes test cases.
 */

/*
 * Copyright (C) 2008-2022 Oracle and/or its affiliates.
 *
 * This file is part of VirtualBox base platform packages, as
 * available from https://www.virtualbox.org.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation, in version 3 of the
 * License.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, see <https://www.gnu.org/licenses>.
 *
 * SPDX-License-Identifier: GPL-3.0-only
 */

#ifdef RT_OS_DARWIN
# include "../src-server/darwin/PerformanceDarwin.cpp"
#endif
#ifdef RT_OS_FREEBSD
# include "../src-server/freebsd/PerformanceFreeBSD.cpp"
#endif
#ifdef RT_OS_LINUX
# include "../src-server/linux/PerformanceLinux.cpp"
#endif
#ifdef RT_OS_OS2
# include "../src-server/os2/PerformanceOS2.cpp"
#endif
#ifdef RT_OS_SOLARIS
# include "../src-server/solaris/PerformanceSolaris.cpp"
#endif
#ifdef RT_OS_WINDOWS
# define _WIN32_DCOM
# include <iprt/win/objidl.h>
# include <iprt/win/objbase.h>
# include "../src-server/win/PerformanceWin.cpp"
#endif

#include <iprt/initterm.h>
#include <iprt/stream.h>
#include <iprt/env.h>
#include <iprt/err.h>
#include <iprt/process.h>
#include <iprt/thread.h>
#include <iprt/time.h>

#define RUN_TIME_MS        1000

#define N_CALLS(n, fn) \
  do {\
    for (int call = 0; call < n; ++call) \
        rc = collector->fn; \
    if (RT_FAILURE(rc)) \
        RTPrintf("tstCollector: "#fn" -> %Rrc\n", rc); \
  } while (0)

#define CALLS_PER_SECOND(fn, args) \
  do { \
    nCalls = 0; \
    start = RTTimeMilliTS(); \
    do { \
        rc = collector->fn args; \
        if (RT_FAILURE(rc)) \
            break; \
        ++nCalls; \
    } while (RTTimeMilliTS() - start < RUN_TIME_MS); \
    if (RT_FAILURE(rc)) \
        RTPrintf("tstCollector: "#fn" -> %Rrc\n", rc); \
    else \
        RTPrintf("%70s -- %u calls per second\n", #fn, nCalls); \
  } while (0)

void shutdownProcessList(std::vector<RTPROCESS> const &rProcesses)
{
    for (size_t i = 0; i < rProcesses.size(); i++)
        RTProcTerminate(rProcesses[i]);
}

void measurePerformance(pm::CollectorHAL *collector, const char *pszName, int cVMs)
{

    const char * const args[] = { pszName, "-child", NULL };
    pm::CollectorHints hints;
    std::vector<RTPROCESS> processes;

    hints.collectHostCpuLoad();
    hints.collectHostRamUsage();
    /* Start fake VMs */
    for (int i = 0; i < cVMs; ++i)
    {
        RTPROCESS pid;
        int rc = RTProcCreate(pszName, args, RTENV_DEFAULT, 0, &pid);
        if (RT_FAILURE(rc))
        {
            hints.getProcesses(processes);
            shutdownProcessList(processes);

            RTPrintf("tstCollector: RTProcCreate() -> %Rrc\n", rc);
            return;
        }
        hints.collectProcessCpuLoad(pid);
        hints.collectProcessRamUsage(pid);
    }

    hints.getProcesses(processes);
    RTThreadSleep(30000); // Let children settle for half a minute

    int rc;
    ULONG tmp;
    uint64_t tmp64;
    uint64_t start;
    unsigned int nCalls;
    /* Pre-collect */
    CALLS_PER_SECOND(preCollect, (hints, 0));
    /* Host CPU load */
    CALLS_PER_SECOND(getRawHostCpuLoad, (&tmp64, &tmp64, &tmp64));
    /* Process CPU load */
    CALLS_PER_SECOND(getRawProcessCpuLoad, (processes[nCalls % cVMs], &tmp64, &tmp64, &tmp64));
    /* Host CPU speed */
    CALLS_PER_SECOND(getHostCpuMHz, (&tmp));
    /* Host RAM usage */
    CALLS_PER_SECOND(getHostMemoryUsage, (&tmp, &tmp, &tmp));
    /* Process RAM usage */
    CALLS_PER_SECOND(getProcessMemoryUsage, (processes[nCalls % cVMs], &tmp));

    start = RTTimeNanoTS();

    int times;
    for (times = 0; times < 100; times++)
    {
        /* Pre-collect */
        N_CALLS(1, preCollect(hints, 0));
        /* Host CPU load */
        N_CALLS(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
        /* Host CPU speed */
        N_CALLS(1, getHostCpuMHz(&tmp));
        /* Host RAM usage */
        N_CALLS(1, getHostMemoryUsage(&tmp, &tmp, &tmp));
        /* Process CPU load */
        N_CALLS(cVMs, getRawProcessCpuLoad(processes[call], &tmp64, &tmp64, &tmp64));
        /* Process RAM usage */
        N_CALLS(cVMs, getProcessMemoryUsage(processes[call], &tmp));
    }
    RTPrintf("\n%d VMs -- %u%% of CPU time\n", cVMs, (unsigned)((double)(RTTimeNanoTS() - start) / 10000000.0 / times));

    /* Shut down fake VMs */
    shutdownProcessList(processes);
}

#ifdef RT_OS_SOLARIS
#define NETIFNAME "net0"
#else
#define NETIFNAME "eth0"
#endif
int testNetwork(pm::CollectorHAL *collector)
{
    pm::CollectorHints hints;
    uint64_t hostRxStart, hostTxStart;
    uint64_t hostRxStop, hostTxStop, speed = 125000000; /* Assume 1Gbit/s */

    RTPrintf("tstCollector: TESTING - Network load, sleeping for 5 s...\n");

    hostRxStart = hostTxStart = 0;
    int rc = collector->preCollect(hints, 0);
    if (RT_FAILURE(rc))
    {
        RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
        return 1;
    }
    rc = collector->getRawHostNetworkLoad(NETIFNAME, &hostRxStart, &hostTxStart);
    if (rc == VERR_NOT_IMPLEMENTED)
        RTPrintf("tstCollector: getRawHostNetworkLoad() not implemented, skipping\n");
    else
    {
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc);
            return 1;
        }

        RTThreadSleep(5000); // Sleep for five seconds

        rc = collector->preCollect(hints, 0);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
            return 1;
        }
        hostRxStop = hostRxStart;
        hostTxStop = hostTxStart;
        rc = collector->getRawHostNetworkLoad(NETIFNAME, &hostRxStop, &hostTxStop);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawHostNetworkLoad() -> %Rrc\n", rc);
            return 1;
        }
        RTPrintf("tstCollector: host network speed = %llu bytes/sec (%llu mbit/sec)\n",
                speed, speed/(1000000/8));
        RTPrintf("tstCollector: host network rx    = %llu bytes/sec (%llu mbit/sec, %u.%u %%)\n",
                (hostRxStop - hostRxStart)/5, (hostRxStop - hostRxStart)/(5000000/8),
                (hostRxStop - hostRxStart) * 100 / (speed * 5),
                (hostRxStop - hostRxStart) * 10000 / (speed * 5) % 100);
        RTPrintf("tstCollector: host network tx    = %llu bytes/sec (%llu mbit/sec, %u.%u %%)\n\n",
                (hostTxStop - hostTxStart)/5, (hostTxStop - hostTxStart)/(5000000/8),
                (hostTxStop - hostTxStart) * 100 / (speed * 5),
                (hostTxStop - hostTxStart) * 10000 / (speed * 5) % 100);
    }

    return 0;
}

#define FSNAME "/"
int testFsUsage(pm::CollectorHAL *collector)
{
    RTPrintf("tstCollector: TESTING - File system usage\n");

    ULONG total, used, available;

    int rc = collector->getHostFilesystemUsage(FSNAME, &total, &used, &available);
    if (rc == VERR_NOT_IMPLEMENTED)
        RTPrintf("tstCollector: getHostFilesystemUsage() not implemented, skipping\n");
    else
    {
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getHostFilesystemUsage() -> %Rrc\n", rc);
            return 1;
        }
        RTPrintf("tstCollector: host root fs total     = %lu MB\n", total);
        RTPrintf("tstCollector: host root fs used      = %lu MB\n", used);
        RTPrintf("tstCollector: host root fs available = %lu MB\n\n", available);
    }
    return 0;
}

int testDisk(pm::CollectorHAL *collector)
{
    pm::CollectorHints hints;
    uint64_t diskMsStart, totalMsStart;
    uint64_t diskMsStop, totalMsStop;

    pm::DiskList disksUsage, disksLoad;
    int rc = collector->getDiskListByFs(FSNAME, disksUsage, disksLoad);
    if (rc == VERR_NOT_IMPLEMENTED)
        RTPrintf("tstCollector: getDiskListByFs() not implemented, skipping\n");
    else
    {
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getDiskListByFs(%s) -> %Rrc\n", FSNAME, rc);
            return 1;
        }
        if (disksUsage.empty())
        {
            RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME);
            return 0;
        }
        if (disksLoad.empty())
        {
            RTPrintf("tstCollector: getDiskListByFs(%s) returned empty usage list\n", FSNAME);
            return 0;
        }

        pm::DiskList::iterator it;
        for (it = disksUsage.begin(); it != disksUsage.end(); ++it)
        {
            uint64_t diskSize = 0;
            rc = collector->getHostDiskSize(it->c_str(), &diskSize);
            RTPrintf("tstCollector: TESTING - Disk size (%s) = %llu\n", it->c_str(), diskSize);
            if (rc == VERR_FILE_NOT_FOUND)
                RTPrintf("tstCollector: getHostDiskSize(%s) returned VERR_FILE_NOT_FOUND\n", it->c_str());
            else if (RT_FAILURE(rc))
            {
                RTPrintf("tstCollector: getHostDiskSize() -> %Rrc\n", rc);
                return 1;
            }
        }

        for (it = disksLoad.begin(); it != disksLoad.end(); ++it)
        {
            RTPrintf("tstCollector: TESTING - Disk utilization (%s), sleeping for 5 s...\n", it->c_str());

            hints.collectHostCpuLoad();
            rc = collector->preCollect(hints, 0);
            if (RT_FAILURE(rc))
            {
                RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
                return 1;
            }
            rc = collector->getRawHostDiskLoad(it->c_str(), &diskMsStart, &totalMsStart);
            if (RT_FAILURE(rc))
            {
                RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc);
                return 1;
            }

            RTThreadSleep(5000); // Sleep for five seconds

            rc = collector->preCollect(hints, 0);
            if (RT_FAILURE(rc))
            {
                RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
                return 1;
            }
            rc = collector->getRawHostDiskLoad(it->c_str(), &diskMsStop, &totalMsStop);
            if (RT_FAILURE(rc))
            {
                RTPrintf("tstCollector: getRawHostDiskLoad() -> %Rrc\n", rc);
                return 1;
            }
            RTPrintf("tstCollector: host disk util    = %llu msec (%u.%u %%), total = %llu msec\n\n",
                     (diskMsStop - diskMsStart),
                     (unsigned)((diskMsStop - diskMsStart) * 100 / (totalMsStop - totalMsStart)),
                     (unsigned)((diskMsStop - diskMsStart) * 10000 / (totalMsStop - totalMsStart) % 100),
                     totalMsStop - totalMsStart);
        }
    }

    return 0;
}



int main(int argc, char *argv[])
{
    bool cpuTest, ramTest, netTest, diskTest, fsTest, perfTest;
    cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = false;
    /*
     * Initialize the VBox runtime without loading
     * the support driver.
     */
    int rc = RTR3InitExe(argc, &argv, 0);
    if (RT_FAILURE(rc))
    {
        RTPrintf("tstCollector: RTR3InitExe() -> %d\n", rc);
        return 1;
    }
    if (argc > 1)
    {
        if (!strcmp(argv[1], "-child"))
        {
            /* We have spawned ourselves as a child process -- scratch the leg */
            RTThreadSleep(1000000);
            return 1;
        }
        for (int i = 1; i < argc; i++)
        {
            if (!strcmp(argv[i], "-cpu"))
                cpuTest = true;
            else if (!strcmp(argv[i], "-ram"))
                ramTest = true;
            else if (!strcmp(argv[i], "-net"))
                netTest = true;
            else if (!strcmp(argv[i], "-disk"))
                diskTest = true;
            else if (!strcmp(argv[i], "-fs"))
                fsTest = true;
            else if (!strcmp(argv[i], "-perf"))
                perfTest = true;
            else
            {
                RTPrintf("tstCollector: Unknown option: %s\n", argv[i]);
                return 2;
            }
        }
    }
    else
        cpuTest = ramTest = netTest = diskTest = fsTest = perfTest = true;

#ifdef RT_OS_WINDOWS
    HRESULT hRes = CoInitialize(NULL);
    /*
     * Need to initialize security to access performance enumerators.
     */
    hRes = CoInitializeSecurity(
        NULL,
        -1,
        NULL,
        NULL,
        RPC_C_AUTHN_LEVEL_NONE,
        RPC_C_IMP_LEVEL_IMPERSONATE,
        NULL, EOAC_NONE, 0);
#endif

    pm::CollectorHAL *collector = pm::createHAL();
    if (!collector)
    {
        RTPrintf("tstCollector: createMetricFactory() failed\n");
        return 1;
    }

    pm::CollectorHints hints;
    if (cpuTest)
    {
        hints.collectHostCpuLoad();
        hints.collectProcessCpuLoad(RTProcSelf());
    }
    if (ramTest)
    {
        hints.collectHostRamUsage();
        hints.collectProcessRamUsage(RTProcSelf());
    }

    uint64_t start;

    uint64_t hostUserStart, hostKernelStart, hostIdleStart;
    uint64_t hostUserStop, hostKernelStop, hostIdleStop, hostTotal;

    uint64_t processUserStart, processKernelStart, processTotalStart;
    uint64_t processUserStop, processKernelStop, processTotalStop;

    rc = collector->preCollect(hints, 0);
    if (RT_FAILURE(rc))
    {
        RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
        return 1;
    }
    if (cpuTest)
    {
        RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 s...\n");

        rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
            return 1;
        }

        RTThreadSleep(5000); // Sleep for 5 seconds

        rc = collector->preCollect(hints, 0);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        hostTotal = hostUserStop - hostUserStart
            + hostKernelStop - hostKernelStart
            + hostIdleStop - hostIdleStart;
        RTPrintf("tstCollector: host cpu user      = %u.%u %%\n",
                 (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal),
                 (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100));
        RTPrintf("tstCollector: host cpu kernel    = %u.%u %%\n",
                 (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal),
                 (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100));
        RTPrintf("tstCollector: host cpu idle      = %u.%u %%\n",
                 (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal),
                 (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100));
        RTPrintf("tstCollector: process cpu user   = %u.%u %%\n",
                 (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)),
                 (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100));
        RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n",
                 (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)),
                 (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100));

        RTPrintf("tstCollector: TESTING - CPU load, looping for 5 s...\n");
        rc = collector->preCollect(hints, 0);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        start = RTTimeMilliTS();
        while (RTTimeMilliTS() - start < 5000)
            ; // Loop for 5 seconds
        rc = collector->preCollect(hints, 0);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: preCollect() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawHostCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Rrc\n", rc);
            return 1;
        }
        hostTotal = hostUserStop - hostUserStart
            + hostKernelStop - hostKernelStart
            + hostIdleStop - hostIdleStart;
        RTPrintf("tstCollector: host cpu user      = %u.%u %%\n",
                 (unsigned)((hostUserStop - hostUserStart) * 100 / hostTotal),
                 (unsigned)((hostUserStop - hostUserStart) * 10000 / hostTotal % 100));
        RTPrintf("tstCollector: host cpu kernel    = %u.%u %%\n",
                 (unsigned)((hostKernelStop - hostKernelStart) * 100 / hostTotal),
                 (unsigned)((hostKernelStop - hostKernelStart) * 10000 / hostTotal % 100));
        RTPrintf("tstCollector: host cpu idle      = %u.%u %%\n",
                 (unsigned)((hostIdleStop - hostIdleStart) * 100 / hostTotal),
                 (unsigned)((hostIdleStop - hostIdleStart) * 10000 / hostTotal % 100));
        RTPrintf("tstCollector: process cpu user   = %u.%u %%\n",
                 (unsigned)((processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart)),
                 (unsigned)((processUserStop - processUserStart) * 10000 / (processTotalStop - processTotalStart) % 100));
        RTPrintf("tstCollector: process cpu kernel = %u.%u %%\n\n",
                 (unsigned)((processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart)),
                 (unsigned)((processKernelStop - processKernelStart) * 10000 / (processTotalStop - processTotalStart) % 100));
    }

    if (ramTest)
    {
        RTPrintf("tstCollector: TESTING - Memory usage\n");

        ULONG total, used, available, processUsed;

        rc = collector->getHostMemoryUsage(&total, &used, &available);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getHostMemoryUsage() -> %Rrc\n", rc);
            return 1;
        }
        rc = collector->getProcessMemoryUsage(RTProcSelf(), &processUsed);
        if (RT_FAILURE(rc))
        {
            RTPrintf("tstCollector: getProcessMemoryUsage() -> %Rrc\n", rc);
            return 1;
        }
        RTPrintf("tstCollector: host mem total     = %lu kB\n", total);
        RTPrintf("tstCollector: host mem used      = %lu kB\n", used);
        RTPrintf("tstCollector: host mem available = %lu kB\n", available);
        RTPrintf("tstCollector: process mem used   = %lu kB\n\n", processUsed);
    }

    if (netTest)
        rc = testNetwork(collector);
    if (fsTest)
    rc = testFsUsage(collector);
    if (diskTest)
        rc = testDisk(collector);
    if (perfTest)
    {
        RTPrintf("tstCollector: TESTING - Performance\n\n");

        measurePerformance(collector, argv[0], 100);
    }

    delete collector;

    RTPrintf("\ntstCollector FINISHED.\n");

    return RTEXITCODE_SUCCESS;
}