tstCollector.cpp revision 986eb022f9ed91353388b58ff989774debca29ac
/* $Id$ */
/** @file
*
* Collector classes test cases.
*/
/*
* Copyright (C) 2008 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("\ntstCollector: TESTING - Network load, sleeping for 5 sec...\n");
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
return 0;
}
{
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
if (RT_FAILURE(rc))
{
return 1;
}
{
/* We have spawned ourselves as a child process -- scratch the leg */
RTThreadSleep(1000000);
return 1;
}
#ifdef RT_OS_WINDOWS
/*
* Need to initialize security to access performance enumerators.
*/
NULL,
-1,
NULL,
NULL,
#endif
if (!collector)
{
return 1;
}
#if 1
RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 sec\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;
}
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;
}
/*printf("tstCollector: host cpu user = %f sec\n", (hostUserStop - hostUserStart) / 10000000.);
printf("tstCollector: host cpu kernel = %f sec\n", (hostKernelStop - hostKernelStart) / 10000000.);
printf("tstCollector: host cpu idle = %f sec\n", (hostIdleStop - hostIdleStart) / 10000000.);
printf("tstCollector: host cpu total = %f sec\n", hostTotal / 10000000.);*/
RTPrintf("tstCollector: host cpu user = %llu %%\n", (hostUserStop - hostUserStart) * 100 / hostTotal);
RTPrintf("tstCollector: host cpu kernel = %llu %%\n", (hostKernelStop - hostKernelStart) * 100 / hostTotal);
RTPrintf("tstCollector: host cpu idle = %llu %%\n", (hostIdleStop - hostIdleStart) * 100 / hostTotal);
RTPrintf("tstCollector: process cpu user = %llu %%\n", (processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart));
RTPrintf("tstCollector: process cpu kernel = %llu %%\n\n", (processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart));
RTPrintf("tstCollector: TESTING - CPU load, looping for 5 sec\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 = %llu %%\n", (hostUserStop - hostUserStart) * 100 / hostTotal);
RTPrintf("tstCollector: host cpu kernel = %llu %%\n", (hostKernelStop - hostKernelStart) * 100 / hostTotal);
RTPrintf("tstCollector: host cpu idle = %llu %%\n", (hostIdleStop - hostIdleStart) * 100 / hostTotal);
RTPrintf("tstCollector: process cpu user = %llu %%\n", (processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart));
RTPrintf("tstCollector: process cpu kernel = %llu %%\n\n", (processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart));
RTPrintf("tstCollector: TESTING - Memory usage\n");
if (RT_FAILURE(rc))
{
return 1;
}
if (RT_FAILURE(rc))
{
return 1;
}
#endif
#if 1
#endif
#if 0
RTPrintf("\ntstCollector: TESTING - Performance\n\n");
#endif
delete collector;
printf ("\ntstCollector FINISHED.\n");
return rc;
}