tstCollector.cpp revision fc2ea0e4530238466c837e6eb98a3cbc5650bbfe
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Collector classes test cases.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Copyright (C) 2008 Sun Microsystems, Inc.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * This file is part of VirtualBox Open Source Edition (OSE), as
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * available from http://www.virtualbox.org. This file is free software;
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * you can redistribute it and/or modify it under the terms of the GNU
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * General Public License (GPL) as published by the Free Software
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Foundation, in version 2 as it comes in the "COPYING" file of the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Clara, CA 95054 USA or visit http://www.sun.com if you need
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * additional information or have any questions.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("%50s -- %u calls per second\n", #fn, nCalls); \
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Initialize the VBox runtime without loading
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * the support driver.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync * Need to initialize security to access performance enumerators.
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: createMetricFactory() failed\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync uint64_t hostUserStart, hostKernelStart, hostIdleStart;
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync uint64_t hostUserStop, hostKernelStop, hostIdleStop, hostTotal;
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync uint64_t processUserStart, processKernelStart, processTotalStart;
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync uint64_t processUserStop, processKernelStop, processTotalStop;
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: TESTING - CPU load, sleeping for 5 sec\n");
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawHostCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawHostCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: host cpu user = %llu %%\n", (hostUserStop - hostUserStart) * 100 / hostTotal);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: host cpu kernel = %llu %%\n", (hostKernelStop - hostKernelStart) * 100 / hostTotal);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: host cpu idle = %llu %%\n", (hostIdleStop - hostIdleStart) * 100 / hostTotal);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: process cpu user = %llu %%\n", (processUserStop - processUserStart) * 100 / (processTotalStop - processTotalStart));
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: process cpu kernel = %llu %%\n\n", (processKernelStop - processKernelStart) * 100 / (processTotalStop - processTotalStart));
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: TESTING - CPU load, looping for 5 sec\n");
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawHostCpuLoad(&hostUserStart, &hostKernelStart, &hostIdleStart);
689e8c44f580478449d47bd48c9af52e82a028aevboxsync RTPrintf("tstCollector: getRawHostCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStart, &processKernelStart, &processTotalStart);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync while(RTTimeMilliTS() - start < 5000); // Loop for 5 seconds
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawHostCpuLoad(&hostUserStop, &hostKernelStop, &hostIdleStop);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawHostCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync rc = collector->getRawProcessCpuLoad(RTProcSelf(), &processUserStop, &processKernelStop, &processTotalStop);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: getRawProcessCpuLoad() -> %Vrc\n", rc);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: host cpu user = %llu %%\n", (hostUserStop - hostUserStart) * 100 / hostTotal);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync RTPrintf("tstCollector: host cpu kernel = %llu %%\n", (hostKernelStop - hostKernelStart) * 100 / hostTotal);
ba0080e61ec19fbcb656e9652b099912e5cccc1avboxsync 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));
unsigned nCalls;
delete collector;
return rc;