tstCollector.cpp revision d2e22219e5f2f49558a3d03abf9ad9301b9e1f3b
/* $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
#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;
}
{
/*
* Initialize the VBox runtime without loading
* the support driver.
*/
if (RT_FAILURE(rc))
{
return 1;
}
if (!collector)
{
return 1;
}
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;
}
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;
}
delete collector;
printf ("tstCollector FINISHED.\n");
return rc;
}