VirtualBox

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


Ignore:
Timestamp:
Sep 9, 2019 11:59:30 AM (6 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
133202
Message:

Main/Guest: Don't start the statistics collection thread until needed. Assert and check every timer call.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/src-client/GuestImpl.cpp

    r80654 r80670  
    108108
    109109    mMagic = GUEST_MAGIC;
    110     int vrc = RTTimerLRCreateEx(&mStatTimer, RT_NS_1SEC, 0 /*fFlags*/, &Guest::i_staticUpdateStats, this);
    111     AssertMsgRC(vrc, ("Failed to create guest statistics update timer (%Rrc) - ignored\n", vrc));
     110    mStatTimer = NIL_RTTIMERLR;
    112111
    113112    hr = unconst(mEventSource).createObject();
     
    168167    int vrc = RTTimerLRDestroy(mStatTimer);
    169168    AssertMsgRC(vrc, ("Failed to create guest statistics update timer(%Rra)\n", vrc));
    170     mStatTimer = NULL;
     169    mStatTimer = NIL_RTTIMERLR;
    171170    mMagic     = 0;
    172171
     
    626625    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    627626
    628     if (mStatUpdateInterval)
    629     {
    630         if (aStatisticsUpdateInterval == 0)
    631             RTTimerLRStop(mStatTimer);
    632         else
    633             RTTimerLRChangeInterval(mStatTimer, aStatisticsUpdateInterval * RT_NS_1SEC_64);
    634     }
    635     else if (aStatisticsUpdateInterval != 0)
    636     {
    637         RTTimerLRChangeInterval(mStatTimer, aStatisticsUpdateInterval * RT_NS_1SEC_64);
    638         RTTimerLRStart(mStatTimer, 0);
    639     }
     627    /* Update the timer, creating it the first time we're called with a non-zero value. */
     628    int vrc;
     629    HRESULT hrc = S_OK;
     630    if (aStatisticsUpdateInterval > 0)
     631    {
     632        if (mStatTimer == NIL_RTTIMERLR)
     633        {
     634            vrc = RTTimerLRCreate(&mStatTimer, aStatisticsUpdateInterval * RT_MS_1SEC, &Guest::i_staticUpdateStats, this);
     635            AssertRCStmt(vrc, hrc = setErrorVrc(vrc, "Failed to create guest statistics update timer (%Rrc)", vrc));
     636        }
     637        else if (aStatisticsUpdateInterval != mStatUpdateInterval)
     638        {
     639            vrc = RTTimerLRChangeInterval(mStatTimer, aStatisticsUpdateInterval * RT_NS_1SEC_64);
     640            AssertRCStmt(vrc, hrc = setErrorVrc(vrc, "Failed to change guest statistics update timer interval from %u to %u failed (%Rrc)",
     641                                                mStatUpdateInterval, aStatisticsUpdateInterval, vrc));
     642            if (mStatUpdateInterval == 0)
     643            {
     644                vrc = RTTimerLRStart(mStatTimer, 0);
     645                AssertRCStmt(vrc, hrc = setErrorVrc(vrc, "Failed to start the guest statistics update timer (%Rrc)", vrc));
     646            }
     647        }
     648    }
     649    /* Setting interval to zero - stop the update timer if needed: */
     650    else if (mStatUpdateInterval > 0 && mStatTimer != NIL_RTTIMERLR)
     651    {
     652        vrc = RTTimerLRStop(mStatTimer);
     653        AssertRCStmt(vrc, hrc = setErrorVrc(vrc, "Failed to stop the guest statistics update timer (%Rrc)", vrc));
     654    }
     655
     656    /* Update the interval now that the timer is in sync. */
    640657    mStatUpdateInterval = aStatisticsUpdateInterval;
    641658
     
    652669    }
    653670
    654     return S_OK;
     671    return hrc;
    655672}
    656673
     
    667684    *aCpuKernel  = mCurrentGuestStat[GUESTSTATTYPE_CPUKERNEL];
    668685    *aCpuIdle    = mCurrentGuestStat[GUESTSTATTYPE_CPUIDLE];
    669     *aMemTotal   = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL] * (_4K/_1K);    /* page (4K) -> 1KB units */
    670     *aMemFree    = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE] * (_4K/_1K);      /* page (4K) -> 1KB units */
     686    *aMemTotal   = mCurrentGuestStat[GUESTSTATTYPE_MEMTOTAL]   * (_4K/_1K); /* page (4K) -> 1KB units */
     687    *aMemFree    = mCurrentGuestStat[GUESTSTATTYPE_MEMFREE]    * (_4K/_1K); /* page (4K) -> 1KB units */
    671688    *aMemBalloon = mCurrentGuestStat[GUESTSTATTYPE_MEMBALLOON] * (_4K/_1K); /* page (4K) -> 1KB units */
    672     *aMemCache   = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE] * (_4K/_1K);    /* page (4K) -> 1KB units */
    673     *aPageTotal  = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL] * (_4K/_1K);  /* page (4K) -> 1KB units */
     689    *aMemCache   = mCurrentGuestStat[GUESTSTATTYPE_MEMCACHE]   * (_4K/_1K); /* page (4K) -> 1KB units */
     690    *aPageTotal  = mCurrentGuestStat[GUESTSTATTYPE_PAGETOTAL]  * (_4K/_1K); /* page (4K) -> 1KB units */
    674691
    675692    /* Play safe or smth? */
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