tstCollector.cpp revision d701438865f1f95511d4995b6fa05a520b94a2af
/* $Id$ */
/** @file
*
* Collector classes test cases.
*/
/*
* Copyright (C) 2008-2012 Oracle Corporation
*
* This file is part of VirtualBox Open Source Edition (OSE), as
* available from http://www.virtualbox.org. This file is free software;
* General Public License (GPL) as published by the Free Software
* Foundation, in version 2 as it comes in the "COPYING" file of the
* VirtualBox OSE distribution. VirtualBox OSE is distributed in the
* hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
*/
#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 <objidl.h>
# include <objbase.h>
# include "../src-server/win/PerformanceWin.cpp"
#endif
#include <iprt/initterm.h>
#define RUN_TIME_MS 1000
if (RT_FAILURE(rc)) \
#define CALLS_PER_SECOND(fn) \
nCalls = 0; \
start = RTTimeMilliTS(); \
do { \
if (RT_FAILURE(rc)) \
break; \
++nCalls; \
if (RT_FAILURE(rc)) \
{ \
} \
else \
{
/* Start fake VMs */
for (int i = 0; i < cVMs; ++i)
{
if (RT_FAILURE(rc))
{
return;
}
}
int rc;
unsigned int nCalls;
/* Pre-collect */
/* Host CPU load */
/* Process CPU load */
/* Host CPU speed */
/* Host RAM usage */
/* Process RAM usage */
start = RTTimeNanoTS();
int times;
{
/* Pre-collect */
/* Host CPU load */
/* Host CPU speed */
/* Host RAM usage */
/* Process CPU load */
/* Process RAM usage */
}
/* Shut down fake VMs */
}
#ifdef RT_OS_SOLARIS
#define NETIFNAME "net0"
#else
#define NETIFNAME "eth0"
#endif
{
RTPrintf("tstCollector: TESTING - Network load, sleeping for 5 s...\n");
hostRxStart = hostTxStart = 0;
if (RT_FAILURE(rc))
{
return 1;
}
if (rc == VERR_NOT_IMPLEMENTED)
RTPrintf("tstCollector: getRawHostNetworkLoad() not implemented, skipping\n");
else
{
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
}
return 0;
}
#define FSNAME "/"
{
RTPrintf("tstCollector: TESTING - File system usage\n");
if (rc == VERR_NOT_IMPLEMENTED)
RTPrintf("tstCollector: getHostFilesystemUsage() not implemented, skipping\n");
else
{
if (RT_FAILURE(rc))
{
return 1;
}
}
return 0;
}
{
if (rc == VERR_NOT_IMPLEMENTED)
RTPrintf("tstCollector: getDiskListByFs() not implemented, skipping\n");
else
{
if (RT_FAILURE(rc))
{
return 1;
}
if (disksUsage.empty())
{
return 1;
}
{
return 1;
}
{
if (rc == VERR_FILE_NOT_FOUND)
else if (RT_FAILURE(rc))
{
return 1;
}
}
{
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
RTPrintf("tstCollector: host disk util = %llu msec (%u.%u %%), total = %llu msec\n\n",
(diskMsStop - diskMsStart),
}
}
return 0;
}
{
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
if (RT_FAILURE(rc))
{
return 1;
}
if (argc > 1)
{
{
/* We have spawned ourselves as a child process -- scratch the leg */
RTThreadSleep(1000000);
return 1;
}
for (int i = 1; i < argc; i++)
{
cpuTest = true;
ramTest = true;
netTest = true;
diskTest = true;
fsTest = true;
perfTest = true;
else
{
return 2;
}
}
}
else
#ifdef RT_OS_WINDOWS
/*
* Need to initialize security to access performance enumerators.
*/
NULL,
-1,
NULL,
NULL,
#endif
if (!collector)
{
return 1;
}
if (cpuTest)
{
}
if (ramTest)
{
}
if (RT_FAILURE(rc))
{
return 1;
}
if (cpuTest)
{
RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 s...\n");
if (RT_FAILURE(rc))
{
return 1;
}
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
if (RT_FAILURE(rc))
{
return 1;
}
RTPrintf("tstCollector: host cpu user = %u.%u %%\n",
RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n",
RTPrintf("tstCollector: host cpu idle = %u.%u %%\n",
RTPrintf("tstCollector: process cpu user = %u.%u %%\n",
(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");
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
if (RT_FAILURE(rc))
{
return 1;
}
start = RTTimeMilliTS();
; // Loop for 5 seconds
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
if (RT_FAILURE(rc))
{
return 1;
}
RTPrintf("tstCollector: host cpu user = %u.%u %%\n",
RTPrintf("tstCollector: host cpu kernel = %u.%u %%\n",
RTPrintf("tstCollector: host cpu idle = %u.%u %%\n",
RTPrintf("tstCollector: process cpu user = %u.%u %%\n",
(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");
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
}
if (netTest)
if (fsTest)
if (diskTest)
if (perfTest)
{
RTPrintf("tstCollector: TESTING - Performance\n\n");
}
delete collector;
printf ("\ntstCollector FINISHED.\n");
return rc;
}