VirtualBox

Changeset 10878 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Jul 25, 2008 7:48:31 AM (17 years ago)
Author:
vboxsync
Message:

PerfAPI: Linux implementation ready

Location:
trunk/src/VBox/Main
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/linux/PerformanceLinux.cpp

    r10872 r10878  
    3939    virtual int getRawHostCpuLoad(uint64_t *user, uint64_t *kernel, uint64_t *idle);
    4040    virtual int getRawProcessCpuLoad(RTPROCESS process, uint64_t *user, uint64_t *kernel, uint64_t *total);
     41private:
     42    int getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, unsigned long *memPagesUsed);
    4143};
    4244
     
    7880{
    7981    int rc = VINF_SUCCESS;
    80     char *pszName;
    81     pid_t pid2;
    82     char c;
    83     int iTmp;
    84     unsigned uTmp;
    85     unsigned long ulTmp, u32user, u32kernel;
    86     char buf[80]; /* @todo: this should be tied to max allowed proc name. */
     82    uint64_t uHostUser, uHostKernel, uHostIdle;
    8783
    88     uint64_t uHostUser, uHostKernel, uHostIdle;
    8984    rc = getRawHostCpuLoad(&uHostUser, &uHostKernel, &uHostIdle);
    90     if (RT_FAILURE(rc))
    91         return rc;
    92     *total = (uint64_t)uHostUser + uHostKernel + uHostIdle;
    93 
    94     RTStrAPrintf(&pszName, "/proc/%d/stat", process);
    95     //printf("Opening %s...\n", pszName);
    96     FILE *f = fopen(pszName, "r");
    97     RTMemFree(pszName);
    98 
    99     if (f)
     85    if (RT_SUCCESS(rc))
    10086    {
    101         if (fscanf(f, "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu",
    102                    &pid2, buf, &c, &iTmp, &iTmp, &iTmp, &iTmp, &iTmp, &uTmp,
    103                    &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u32user, &u32kernel) == 15)
    104         {
    105             Assert((pid_t)process == pid2);
    106             *user = u32user;
    107             *kernel = u32kernel;
    108         }
    109         else
    110             rc = VERR_FILE_IO_ERROR;
    111         fclose(f);
     87        unsigned long ulTmp;
     88        *total = (uint64_t)uHostUser + uHostKernel + uHostIdle;
     89        rc = getRawProcessStats(process, user, kernel, &ulTmp);
    11290    }
    113     else
    114         rc = VERR_ACCESS_DENIED;
    11591
    11692    return rc;
     
    145121    return rc;
    146122}
     123
    147124int CollectorLinux::getProcessMemoryUsage(RTPROCESS process, unsigned long *used)
    148125{
    149     return E_NOTIMPL;
     126    uint64_t u64Tmp;
     127    unsigned long nPagesUsed;
     128    int rc = getRawProcessStats(process, &u64Tmp, &u64Tmp, &nPagesUsed);
     129    if (RT_SUCCESS(rc))
     130    {
     131        Assert(getpagesize() >= 1024);
     132        *used = nPagesUsed * (getpagesize() / 1024);
     133    }
     134    return rc;
     135}
     136
     137int CollectorLinux::getRawProcessStats(RTPROCESS process, uint64_t *cpuUser, uint64_t *cpuKernel, unsigned long *memPagesUsed)
     138{
     139    int rc = VINF_SUCCESS;
     140    char *pszName;
     141    pid_t pid2;
     142    char c;
     143    int iTmp;
     144    uint64_t u64Tmp;
     145    unsigned uTmp;
     146    unsigned long ulTmp, u32user, u32kernel;
     147    char buf[80]; /* @todo: this should be tied to max allowed proc name. */
     148
     149    RTStrAPrintf(&pszName, "/proc/%d/stat", process);
     150    //printf("Opening %s...\n", pszName);
     151    FILE *f = fopen(pszName, "r");
     152    RTMemFree(pszName);
     153
     154    if (f)
     155    {
     156        if (fscanf(f, "%d %s %c %d %d %d %d %d %u %lu %lu %lu %lu %lu %lu "
     157                      "%ld %ld %ld %ld %ld %ld %llu %lu %ld",
     158                   &pid2, buf, &c, &iTmp, &iTmp, &iTmp, &iTmp, &iTmp, &uTmp,
     159                   &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u32user, &u32kernel,
     160                   &ulTmp, &ulTmp, &ulTmp, &ulTmp, &ulTmp, &ulTmp, &u64Tmp,
     161                   &ulTmp, memPagesUsed) == 24)
     162        {
     163            Assert((pid_t)process == pid2);
     164            *cpuUser   = u32user;
     165            *cpuKernel = u32kernel;
     166        }
     167        else
     168            rc = VERR_FILE_IO_ERROR;
     169        fclose(f);
     170    }
     171    else
     172        rc = VERR_ACCESS_DENIED;
     173
     174    return rc;
    150175}
    151176
    152177}
     178
  • trunk/src/VBox/Main/testcase/tstAPI.cpp

    r10870 r10878  
    975975        CHECK_RC_BREAK (session->COMGETTER(Console) (console.asOutParam()));
    976976
    977         RTThreadSleep(3000); // Sleep for 10 seconds
     977        RTThreadSleep(5000); // Sleep for 5 seconds
    978978
    979979        printf("Metrics collected with DSL machine running: --------------------\n");
     
    981981
    982982        // Pause
    983         printf ("Press enter to pause the VM execution in the remote session...");
    984         getchar();
     983        //printf ("Press enter to pause the VM execution in the remote session...");
     984        //getchar();
    985985        CHECK_RC (console->Pause());
    986986
    987         RTThreadSleep(10000); // Sleep for 10 seconds
     987        RTThreadSleep(5000); // Sleep for 5 seconds
    988988
    989989        printf("Metrics collected with DSL machine paused: ---------------------\n");
Note: See TracChangeset for help on using the changeset viewer.

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