VirtualBox

Changeset 12400 in vbox for trunk/src/VBox/Main/testcase


Ignore:
Timestamp:
Sep 11, 2008 10:34:58 AM (16 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
36452
Message:

PerfAPI: Improved Win collector. More realistic performance test. No factories.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/testcase/tstCollector.cpp

    r12136 r12400  
    2424#include <iprt/runtime.h>
    2525#include <iprt/stream.h>
     26#include <iprt/env.h>
    2627#include <iprt/err.h>
    2728#include <iprt/process.h>
     
    6667}
    6768
    68 #define CALLS_PER_SECOND(n,fn) \
     69#define RUN_TIME_MS        1000
     70
     71#define N_CALLS(n, fn) \
     72    for (int call = 0; call < n; ++call) \
     73        rc = collector->fn; \
     74    if (RT_FAILURE(rc)) \
     75        RTPrintf("tstCollector: "#fn" -> %Vrc\n", rc)
     76
     77#define CALLS_PER_SECOND(fn) \
    6978    nCalls = 0; \
    7079    start = RTTimeMilliTS(); \
     
    7281        rc = collector->fn; \
    7382        ++nCalls; \
    74     } while(RTTimeMilliTS() - start < 1000); \
     83    } while(RTTimeMilliTS() - start < RUN_TIME_MS); \
    7584    if (RT_FAILURE(rc)) \
    7685    { \
     
    7887    } \
    7988    else \
    80         RTPrintf("%50s -- %u calls per second\n", #fn, nCalls); \
    81     totalTime += n * 1000000 / nCalls
     89        RTPrintf("%70s -- %u calls per second\n", #fn, nCalls)
     90
     91void measurePerformance(pm::CollectorHAL *collector, const char *pszName, int cVMs)
     92{
     93
     94    static const char * const args[] = { pszName, "-child", NULL };
     95    pm::CollectorHints hints;
     96    std::vector<RTPROCESS> processes;
     97
     98    hints.collectHostCpuLoad();
     99    hints.collectHostRamUsage();
     100    /* Start fake VMs */
     101    for (int i = 0; i < cVMs; ++i)
     102    {
     103        RTPROCESS pid;
     104        int rc = RTProcCreate(pszName, args, RTENV_DEFAULT, 0, &pid);
     105        if (RT_FAILURE(rc))
     106        {
     107            hints.getProcesses(processes);
     108            std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate));
     109            RTPrintf("tstCollector: RTProcCreate() -> %Vrc\n", rc);
     110            return;
     111        }
     112        hints.collectProcessCpuLoad(pid);
     113        hints.collectProcessRamUsage(pid);
     114    }
     115
     116    hints.getProcesses(processes);
     117    RTThreadSleep(30000); // Let children settle for half a minute
     118
     119    int rc;
     120    ULONG tmp;
     121    uint64_t tmp64;
     122    uint64_t start;
     123    unsigned int nCalls;
     124    uint32_t totalTime = 0;
     125    /* Pre-collect */
     126    CALLS_PER_SECOND(preCollect(hints));
     127    /* Host CPU load */
     128    CALLS_PER_SECOND(getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
     129    /* Process CPU load */
     130    CALLS_PER_SECOND(getRawProcessCpuLoad(processes[nCalls%cVMs], &tmp64, &tmp64, &tmp64));
     131    /* Host CPU speed */
     132    CALLS_PER_SECOND(getHostCpuMHz(&tmp));
     133    /* Host RAM usage */
     134    CALLS_PER_SECOND(getHostMemoryUsage(&tmp, &tmp, &tmp));
     135    /* Process RAM usage */
     136    CALLS_PER_SECOND(getProcessMemoryUsage(processes[nCalls%cVMs], &tmp));
     137
     138    start = RTTimeNanoTS();
     139
     140    for (int times = 0; times < 100; times++)
     141    {
     142        /* Pre-collect */
     143        N_CALLS(1, preCollect(hints));
     144        /* Host CPU load */
     145        N_CALLS(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
     146        /* Host CPU speed */
     147        N_CALLS(1, getHostCpuMHz(&tmp));
     148        /* Host RAM usage */
     149        N_CALLS(1, getHostMemoryUsage(&tmp, &tmp, &tmp));
     150        /* Process CPU load */
     151        N_CALLS(cVMs, getRawProcessCpuLoad(processes[call], &tmp64, &tmp64, &tmp64));
     152        /* Process RAM usage */
     153        N_CALLS(cVMs, getProcessMemoryUsage(processes[call], &tmp));
     154    }
     155    printf("\n%u VMs -- %.2f%% of CPU time\n", cVMs, (RTTimeNanoTS() - start) / 10000000. / times);
     156
     157    /* Shut down fake VMs */
     158    std::for_each(processes.begin(), processes.end(), std::ptr_fun(RTProcTerminate));
     159}
    82160
    83161int main(int argc, char *argv[])
     
    91169    {
    92170        RTPrintf("tstCollector: RTR3Init() -> %d\n", rc);
     171        return 1;
     172    }
     173    if (argc > 1 && !strcmp(argv[1], "-child"))
     174    {
     175        /* We have spawned ourselves as a child process -- scratch the leg */
     176        RTThreadSleep(1000000);
    93177        return 1;
    94178    }
     
    108192#endif
    109193
    110     uint64_t start;
    111 
    112194    pm::CollectorHAL *collector = createCollector();
    113195    if (!collector)
     
    116198        return 1;
    117199    }
    118 #if 1
     200#if 0
     201    uint64_t start;
     202
    119203    uint64_t hostUserStart, hostKernelStart, hostIdleStart;
    120204    uint64_t hostUserStop, hostKernelStop, hostIdleStop, hostTotal;
     
    219303#endif
    220304    RTPrintf("\ntstCollector: TESTING - Performance\n\n");
    221     unsigned nCalls;
    222     ULONG tmp;
    223     uint64_t tmp64;
    224     uint32_t totalTime = 0;
    225     RTPROCESS pid = RTProcSelf();
    226     /* Host CPU load */
    227     CALLS_PER_SECOND(1, getRawHostCpuLoad(&tmp64, &tmp64, &tmp64));
    228     /* Process CPU load */
    229     CALLS_PER_SECOND(100, getRawProcessCpuLoad(pid, &tmp64, &tmp64, &tmp64));
    230     /* Host CPU speed */
    231     CALLS_PER_SECOND(1, getHostCpuMHz(&tmp));
    232     /* Host RAM usage */
    233     CALLS_PER_SECOND(1, getHostMemoryUsage(&tmp, &tmp, &tmp));
    234     /* Process RAM usage */
    235     CALLS_PER_SECOND(100, getProcessMemoryUsage(pid, &tmp));
    236    
    237     printf("%.2f%% of CPU time\n", totalTime / 10000.);
     305
     306    measurePerformance(collector, argv[0], 100);
    238307   
    239308    delete collector;
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette