tstCollector.cpp revision 0ff7152ccdcc57edca12c5f17b9699c66eeff975
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Collector classes test cases.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * available from http://www.virtualbox.org. This file is free software;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * you can redistribute it and/or modify it under the terms of the GNU
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * General Public License (GPL) as published by the Free Software
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
6e9aa255e3376b2da5824c09c4c62bc233463bfevboxsync * additional information or have any questions.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync RTPrintf("%70s -- %u calls per second\n", #fn, nCalls)
a180a41bba1d50822df23fff0099e90b86638b89vboxsyncvoid measurePerformance(pm::CollectorHAL *collector, const char *pszName, int cVMs)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync static const char * const args[] = { pszName, "-child", NULL };
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Start fake VMs */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync for (int i = 0; i < cVMs; ++i)
a180a41bba1d50822df23fff0099e90b86638b89vboxsync int rc = RTProcCreate(pszName, args, RTENV_DEFAULT, 0, &pid);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync RTPrintf("tstCollector: RTProcCreate() -> %Rrc\n", rc);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync RTThreadSleep(30000); // Let children settle for half a minute
a180a41bba1d50822df23fff0099e90b86638b89vboxsync unsigned int nCalls;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Pre-collect */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Host CPU load */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync CALLS_PER_SECOND(getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Process CPU load */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync CALLS_PER_SECOND(getRawProcessCpuLoad(processes[nCalls%cVMs], &tmp64, &tmp64, &tmp64));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Host CPU speed */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Host RAM usage */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync CALLS_PER_SECOND(getHostMemoryUsage(&tmp, &tmp, &tmp));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Process RAM usage */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync CALLS_PER_SECOND(getProcessMemoryUsage(processes[nCalls%cVMs], &tmp));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Pre-collect */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Host CPU load */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync N_CALLS(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Host CPU speed */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Host RAM usage */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Process CPU load */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync N_CALLS(cVMs, getRawProcessCpuLoad(processes[call], &tmp64, &tmp64, &tmp64));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Process RAM usage */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync N_CALLS(cVMs, getProcessMemoryUsage(processes[call], &tmp));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync printf("\n%u VMs -- %.2f%% of CPU time\n", cVMs, (RTTimeNanoTS() - start) / 10000000. / times);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* Shut down fake VMs */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate));
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Initialize the VBox runtime without loading
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * the support driver.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync /* We have spawned ourselves as a child process -- scratch the leg */
a180a41bba1d50822df23fff0099e90b86638b89vboxsync * Need to initialize security to access performance enumerators.
a180a41bba1d50822df23fff0099e90b86638b89vboxsync RTPrintf("tstCollector: createMetricFactory() failed\n", rc);
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint64_t hostUserStart, hostKernelStart, hostIdleStart;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint64_t hostUserStop, hostKernelStop, hostIdleStop, hostTotal;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint64_t processUserStart, processKernelStart, processTotalStart;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync uint64_t processUserStop, processKernelStop, processTotalStop;
a180a41bba1d50822df23fff0099e90b86638b89vboxsync RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 sec\n");
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
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));
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
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));
delete collector;
return rc;