tstCollector.cpp revision 22fa628aeeaca1776f2b5f6998d2699158b0a942
/* $Id$ */
/** @file
*
* Collector classes test cases.
*/
/*
* Copyright (C) 2008 Sun Microsystems, Inc.
*
* 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.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
* Clara, CA 95054 USA or visit http://www.sun.com if you need
* additional information or have any questions.
*/
#ifdef RT_OS_SOLARIS
#include "../solaris/PerformanceSolaris.cpp"
#endif
#ifdef RT_OS_LINUX
#include "../linux/PerformanceLinux.cpp"
#endif
#ifdef RT_OS_WINDOWS
#define _WIN32_DCOM
#include <objidl.h>
#include <objbase.h>
#include "../win/PerformanceWin.cpp"
#endif
#ifdef RT_OS_OS2
#include "../os2/PerformanceOS2.cpp"
#endif
#ifdef RT_OS_DARWIN
#include "../darwin/PerformanceDarwin.cpp"
#endif
{
#ifdef RT_OS_SOLARIS
return new pm::CollectorSolaris();
#endif
#ifdef RT_OS_LINUX
return new pm::CollectorLinux();
#endif
#ifdef RT_OS_WINDOWS
return new pm::CollectorWin();
#endif
#ifdef RT_OS_OS2
return new pm::CollectorOS2();
#endif
#ifdef RT_OS_DARWIN
return new pm::CollectorDarwin();
#endif
return 0;
}
#define RUN_TIME_MS 1000
if (RT_FAILURE(rc)) \
#define CALLS_PER_SECOND(fn) \
nCalls = 0; \
start = RTTimeMilliTS(); \
do { \
++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 */
}
{
/*
* 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 0
RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 sec\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;
}
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 - CPU load, looping for 5 sec\n");
if (RT_FAILURE(rc))
{
return 1;
}
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
if (RT_FAILURE(rc))
{
return 1;
}
start = RTTimeMilliTS();
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
RTPrintf("\ntstCollector: TESTING - Performance\n\n");
delete collector;
printf ("\ntstCollector FINISHED.\n");
return rc;
}