VirtualBox

Changeset 28009 in vbox


Ignore:
Timestamp:
Apr 6, 2010 2:23:05 PM (15 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
59716
Message:

Additions/VBoxService: Solaris VM statistics.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceStats.cpp

    r27972 r28009  
    3737# include <unistd.h>
    3838
     39#elif defined(RT_OS_SOLARIS)
     40# include <kstat.h>
     41# include <sys/sysinfo.h>
     42# include <unistd.h>
    3943#else
    4044/** @todo port me. */
     
    421425        }
    422426        RTStrmClose(pStrm);
     427    }
     428
     429#elif defined(RT_OS_SOLARIS)
     430    VMMDevReportGuestStats req;
     431    RT_ZERO(req);
     432    kstat_ctl_t *pStatKern = kstat_open();
     433    if (pStatKern)
     434    {
     435        /*
     436         * Memory statistics.
     437         */
     438        uint64_t u64Total = 0, u64Free = 0, u64Buffers = 0, u64Cached = 0, u64PagedTotal = 0;
     439        int rc = -1;
     440        kstat_t *pStatPages = kstat_lookup(pStatKern, "unix", 0 /* instance */, "system_pages");
     441        if (pStatPages)
     442        {
     443            rc = kstat_read(pStatKern, pStatPages, NULL /* optional-copy-buf */);
     444            if (rc != -1)
     445            {
     446                kstat_named_t *pStat = NULL;
     447                pStat = (kstat_named_t *)kstat_data_lookup(pStatPages, "pagestotal");
     448                if (pStat)
     449                    u64Total = pStat->value.ul;
     450
     451                pStat = (kstat_named_t *)kstat_data_lookup(pStatPages, "freemem");
     452                if (pStat)
     453                    u64Free = pStat->value.ul;
     454            }
     455        }
     456
     457        kstat_t *pStatZFS = kstat_lookup(pStatKern, "zfs", 0 /* instance */, "arcstats");
     458        if (pStatZFS)
     459        {
     460            rc = kstat_read(pStatKern, pStatZFS, NULL /* optional-copy-buf */);
     461            if (rc != -1)
     462            {
     463                kstat_named_t *pStat = (kstat_named_t *)kstat_data_lookup(pStatZFS, "size");
     464                if (pStat)
     465                    u64Cached = pStat->value.ul;
     466            }
     467        }
     468
     469        /*
     470         * The vminfo are accumulative counters updated every "N" ticks. Let's get the
     471         * number of stat updates so far and use that to divide the swap counter.
     472         */
     473        kstat_t *pStatInfo = kstat_lookup(pStatKern, "unix", 0 /* instance */, "sysinfo");
     474        if (pStatInfo)
     475        {
     476            sysinfo_t SysInfo;
     477            rc = kstat_read(pStatKern, pStatInfo, &SysInfo);
     478            if (rc != -1)
     479            {
     480                kstat_t *pStatVMInfo = kstat_lookup(pStatKern, "unix", 0 /* instance */, "vminfo");
     481                if (pStatVMInfo)
     482                {
     483                    vminfo_t VMInfo;
     484                    rc = kstat_read(pStatKern, pStatVMInfo, &VMInfo);
     485                    if (rc != -1)
     486                    {
     487                        u64PagedTotal = VMInfo.swap_avail / SysInfo.updates;
     488                    }
     489                }
     490            }
     491        }
     492
     493        req.guestStats.u32PhysMemTotal   = u64Total;        /* already in pages */
     494        req.guestStats.u32PhysMemAvail   = u64Free;         /* already in pages */
     495        req.guestStats.u32MemSystemCache = u64Cached / _4K;
     496        req.guestStats.u32PageFileSize   = u64PagedTotal;   /* already in pages */
     497        /** @todo req.guestStats.u32Threads */
     498        /** @todo req.guestStats.u32Processes */
     499        /** @todo req.guestStats.u32Handles -- ??? */
     500        /** @todo req.guestStats.u32MemoryLoad */
     501        /** @todo req.guestStats.u32MemCommitTotal */
     502        /** @todo req.guestStats.u32MemKernelTotal */
     503        /** @todo req.guestStats.u32MemKernelPaged */
     504        /** @todo req.guestStats.u32MemKernelNonPaged */
     505        req.guestStats.u32PageSize = getpagesize();
     506        req.guestStats.u32PhysMemBalloon = VBoxServiceBalloonQueryPages(_4K);
     507        req.guestStats.u32StatCaps = VBOX_GUEST_STAT_PHYS_MEM_TOTAL \
     508                                   | VBOX_GUEST_STAT_PHYS_MEM_AVAIL \
     509                                   | VBOX_GUEST_STAT_PHYS_MEM_BALLOON \
     510                                   | VBOX_GUEST_STAT_PAGE_FILE_SIZE;
     511
     512        /*
     513         * CPU statistics.
     514         */
     515        cpu_stat_t StatCPU;
     516        RT_ZERO(StatCPU);
     517        kstat_t *pStatNode = NULL;
     518        uint32_t cCPUs = 0;
     519        for (pStatNode = pStatKern->kc_chain; pStatNode != NULL; pStatNode = pStatNode->ks_next)
     520        {
     521            if (!strcmp(pStatNode->ks_module, "cpu_stat"))
     522            {
     523                rc = kstat_read(pStatKern, pStatNode, &StatCPU);
     524                if (rc == -1)
     525                    break;
     526
     527                uint64_t u64Idle   = StatCPU.cpu_sysinfo.cpu[CPU_IDLE];
     528                uint64_t u64User   = StatCPU.cpu_sysinfo.cpu[CPU_USER];
     529                uint64_t u64System = StatCPU.cpu_sysinfo.cpu[CPU_KERNEL];
     530
     531                uint64_t u64DeltaIdle   = u64Idle   - gCtx.au64LastCpuLoad_Idle[cCPUs];
     532                uint64_t u64DeltaSystem = u64System - gCtx.au64LastCpuLoad_Kernel[cCPUs];
     533                uint64_t u64DeltaUser   = u64User   - gCtx.au64LastCpuLoad_User[cCPUs];
     534
     535                uint64_t u64DeltaAll    = u64DeltaIdle + u64DeltaSystem + u64DeltaUser;
     536
     537                gCtx.au64LastCpuLoad_Idle[cCPUs]   = u64Idle;
     538                gCtx.au64LastCpuLoad_Kernel[cCPUs] = u64System;
     539                gCtx.au64LastCpuLoad_User[cCPUs]   = u64User;
     540
     541                req.guestStats.u32CpuId = cCPUs;
     542                req.guestStats.u32CpuLoad_Idle   = (uint32_t)(u64DeltaIdle   * 100 / u64DeltaAll);
     543                req.guestStats.u32CpuLoad_Kernel = (uint32_t)(u64DeltaSystem * 100 / u64DeltaAll);
     544
     545                req.guestStats.u32StatCaps |= VBOX_GUEST_STAT_CPU_LOAD_IDLE \
     546                                           | VBOX_GUEST_STAT_CPU_LOAD_KERNEL \
     547                                           | VBOX_GUEST_STAT_CPU_LOAD_USER;
     548
     549                cCPUs++;
     550            }
     551        }
     552
     553        /*
     554         * Report whatever statistics were collected.
     555         */
     556        rc = VbglR3StatReport(&req);
     557        if (RT_SUCCESS(rc))
     558            VBoxServiceVerbose(3, "VBoxStatsReportStatistics: new statistics reported successfully!\n");
     559        else
     560            VBoxServiceVerbose(3, "VBoxStatsReportStatistics: stats report failed with rc=%Rrc\n", rc);
     561
     562        kstat_close(pStatKern);
    423563    }
    424564
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