Changeset 9937 in vbox
- Timestamp:
- Jun 25, 2008 6:18:13 PM (17 years ago)
- svn:sync-xref-src-repo-rev:
- 32360
- Location:
- trunk/src/VBox/Main
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/HostImpl.cpp
r9904 r9937 169 169 170 170 #ifdef VBOX_WITH_RESOURCE_USAGE_API 171 /* 172 * Start resource usage sampler. 173 */ 174 //printf("Creating sampling timer with Host::staticSamplerCallback, this=%p\n", this); 175 int rc = RTTimerCreate(&m_pUsageSampler, VBOX_USAGE_SAMPLER_INTERVAL, Host::staticSamplerCallback, this); 176 if (RT_FAILURE(rc)) 177 { 178 AssertMsgFailed(("Failed to create resource usage sampling timer, rc=%d!\n", rc)); 179 return E_FAIL; 171 /* Start resource usage sampler */ 172 { 173 int vrc = RTTimerCreate (&mUsageSampler, VBOX_USAGE_SAMPLER_INTERVAL, 174 UsageSamplerCallback, this); 175 AssertMsgRC (vrc, ("Failed to create resource usage sampling " 176 "timer (%Rra)\n", vrc)); 177 if (RT_FAILURE (vrc)) 178 return E_FAIL; 180 179 } 181 180 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ … … 184 183 return S_OK; 185 184 } 186 187 #ifdef VBOX_WITH_RESOURCE_USAGE_API188 void Host::staticSamplerCallback(PRTTIMER pTimer, void *pvUser, uint64_t iTick)189 {190 ((Host*)pvUser)->usageSamplerCallback();191 }192 193 void Host::usageSamplerCallback()194 {195 int rc = RTSystemProcessorGetUsageStats(&m_CpuStats);196 if (RT_FAILURE(rc))197 {198 AssertMsgFailed(("Failed to get CPU stats, rc=%d!\n", rc));199 }200 //printf("Host::usageSamplerCallback: user=%u%% system=%u%% &m_CpuStats=%p this=%p\n",201 // m_CpuStats.u32User / 10000000, m_CpuStats.u32System / 10000000, &m_CpuStats, this);202 //printf("user=%.2f system=%.2f idle=%.2f\n", m_CpuStats.u32User/10000000., m_CpuStats.u32System/10000000., m_CpuStats.u32Idle/10000000.);203 }204 #endif /* VBOX_WITH_RESOURCE_USAGE_API */205 185 206 186 /** … … 231 211 232 212 #ifdef VBOX_WITH_RESOURCE_USAGE_API 233 /* 234 * Destroy resource usage sampler. 235 */ 236 int rc = RTTimerDestroy(m_pUsageSampler); 237 if (RT_FAILURE(rc)) 238 { 239 AssertMsgFailed(("Failed to destroy resource usage sampling timer, rc=%d!\n", rc)); 213 /* Destroy resource usage sampler */ 214 { 215 int vrc = RTTimerDestroy (mUsageSampler); 216 AssertMsgRC (vrc, ("Failed to destroy resource usage " 217 "sampling timer (%Rra)\n", vrc)); 240 218 } 241 219 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ … … 1128 1106 } 1129 1107 1130 /** 1131 * Obtains the results of the latest measurement of overall CPU 1132 * usage on this host. 1133 * 1134 * @returns error code. 1135 * 1136 * @param user out % of CPU time spent in user mode. 1137 * @param system out % of CPU time spent in kernel mode. 1138 * @param idle out % of idle CPU time. 1139 * 1140 */ 1141 STDMETHODIMP Host::GetProcessorUsage(ULONG *user, ULONG *system, ULONG *idle) 1108 STDMETHODIMP Host::GetProcessorUsage (ULONG *aUser, ULONG *aSystem, ULONG *aIdle) 1142 1109 { 1143 1110 #ifdef VBOX_WITH_RESOURCE_USAGE_API 1144 *user = m_CpuStats.u32User; 1145 *system = m_CpuStats.u32System; 1146 *idle = m_CpuStats.u32Idle; 1111 if (aUser == NULL || aSystem == NULL || aIdle == NULL) 1112 return E_POINTER; 1113 1114 *aUser = mCpuStats.u32User; 1115 *aSystem = mCpuStats.u32System; 1116 *aIdle = mCpuStats.u32Idle; 1147 1117 1148 1118 return S_OK; … … 2745 2715 #endif /* RT_OS_WINDOWS */ 2746 2716 2717 #ifdef VBOX_WITH_RESOURCE_USAGE_API 2718 2719 /* static */ 2720 void Host::UsageSamplerCallback (PRTTIMER pTimer, void *pvUser, uint64_t iTick) 2721 { 2722 AssertReturnVoid (pvUser != NULL); 2723 static_cast <Host *> (pvUser)->usageSamplerCallback(); 2724 } 2725 2726 void Host::usageSamplerCallback() 2727 { 2728 int vrc = RTSystemProcessorGetUsageStats (&mCpuStats); 2729 AssertMsgRC (vrc, ("Failed to get CPU stats (%Rra)\n", vrc)); 2730 2731 // LogFlowThisFunc (("user=%u%% system=%u%% &mCpuStats=%p\n", 2732 // mCpuStats.u32User / 10000000, 2733 // mCpuStats.u32System / 10000000, &mCpuStats); 2734 // LogFlowThisFunc (("user=%.2f system=%.2f idle=%.2f\n", mCpuStats.u32User/10000000., 2735 // mCpuStats.u32System/10000000., mCpuStats.u32Idle/10000000.); 2736 } 2737 2738 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 2739 -
trunk/src/VBox/Main/MachineImpl.cpp
r9904 r9937 147 147 mSession.mPid = NIL_RTPROCESS; 148 148 mSession.mState = SessionState_Closed; 149 150 #ifdef VBOX_WITH_RESOURCE_USAGE_API 151 mUsageSampler = NULL; 152 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 149 153 } 150 154 … … 498 502 499 503 #ifdef VBOX_WITH_RESOURCE_USAGE_API 500 /* 501 * Start resource usage sampler. 502 */ 503 printf("Creating sampling timer with Machine::staticSamplerCallback, this=%p\n", this); 504 int result = RTTimerCreate(&m_pUsageSampler, VBOX_USAGE_SAMPLER_INTERVAL, Machine::staticSamplerCallback, this); 505 if (RT_FAILURE(result)) 506 { 507 AssertMsgFailed(("Failed to create resource usage sampling timer, rc=%d!\n", result)); 508 rc = E_FAIL; 504 /* Start resource usage sampler */ 505 { 506 vrc = RTTimerCreate (&mData->mUsageSampler, VBOX_USAGE_SAMPLER_INTERVAL, 507 Machine::UsageSamplerCallback, this); 508 AssertMsgRC (vrc, ("Failed to create resource usage " 509 "sampling timer(%Rra)\n", vrc)); 510 if (RT_FAILURE (vrc)) 511 rc = E_FAIL; 509 512 } 510 513 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ … … 635 638 636 639 #ifdef VBOX_WITH_RESOURCE_USAGE_API 637 /* 638 * Destroy resource usage sampler. 639 */ 640 int rc = RTTimerDestroy(m_pUsageSampler); 641 if (RT_FAILURE(rc)) 642 { 643 AssertMsgFailed(("Failed to destroy resource usage sampling timer, rc=%d!\n", rc)); 640 /* Destroy resource usage sampler */ 641 { 642 int vrc = RTTimerDestroy (mData->mUsageSampler); 643 AssertMsgRC (vrc, ("Failed to destroy resource usage " 644 "sampling timer (%Rra)\n", vrc)); 644 645 } 645 646 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ … … 702 703 LogFlowThisFuncLeave(); 703 704 } 704 705 #ifdef VBOX_WITH_RESOURCE_USAGE_API706 void Machine::staticSamplerCallback(PRTTIMER pTimer, void *pvUser, uint64_t iTick)707 {708 ((Machine*)pvUser)->usageSamplerCallback();709 }710 711 void Machine::usageSamplerCallback()712 {713 //LogFlowThisFunc(("mData->mSession.mPid = %u &m_CpuStats = %p)\n", mData->mSession.mPid, &m_CpuStats));714 if (mData->mSession.mPid != NIL_RTPROCESS) {715 int rc = RTProcessGetProcessorUsageStats(mData->mSession.mPid, &m_CpuStats);716 if (RT_FAILURE(rc))717 {718 AssertMsgFailed(("Failed to get CPU stats, rc=%d!\n", rc));719 }720 }721 else722 {723 m_CpuStats.u32User = 0;724 m_CpuStats.u32System = 0;725 }726 // printf("Machine::usageSamplerCallback: user=%u%% system=%u%% &m_CpuStats=%p this=%p\n",727 // m_CpuStats.u32User / 10000000, m_CpuStats.u32System / 10000000, &m_CpuStats, this);728 //printf("user=%.2f system=%.2f\n", m_CpuStats.u32User/10000000., m_CpuStats.u32System/10000000.);729 }730 #endif /* VBOX_WITH_RESOURCE_USAGE_API */731 732 705 733 706 // IMachine properties … … 2711 2684 * session. Otherwise read the value from machine extra data, where it is 2712 2685 * stored between sessions. 2713 * 2686 * 2714 2687 * @note since the way this method is implemented depends on whether or not 2715 2688 * a session is currently open, we grab a write lock on the object, in 2716 2689 * order to ensure that the session state does not change during the 2717 2690 * call, and to force us to block if it is currently changing (either 2718 * way) between open and closed. 2691 * way) between open and closed. 2719 2692 */ 2720 2693 STDMETHODIMP Machine::GetConfigRegistryValue (INPTR BSTR aKey, BSTR *aValue) … … 2782 2755 * session. Otherwise read the value from machine extra data, where it is 2783 2756 * stored between sessions. 2784 * 2757 * 2785 2758 * @note since the way this method is implemented depends on whether or not 2786 2759 * a session is currently open, we grab a write lock on the object, in 2787 2760 * order to ensure that the session state does not change during the 2788 2761 * call, and to force us to block if it is currently changing (either 2789 * way) between open and closed. 2762 * way) between open and closed. 2790 2763 */ 2791 2764 STDMETHODIMP Machine::SetConfigRegistryValue (INPTR BSTR aKey, INPTR BSTR aValue) … … 2844 2817 } 2845 2818 2846 /** 2847 * Obtains the results of the latest measurement of CPU usage by 2848 * this machine. 2849 * 2850 * @returns error code. 2851 * 2852 * @param user out % of CPU time spent in user mode. 2853 * @param system out % of CPU time spent in kernel mode. 2854 * 2855 */ 2856 STDMETHODIMP Machine::GetProcessorUsage(ULONG *user, ULONG *system) 2819 STDMETHODIMP Machine::GetProcessorUsage (ULONG *aUser, ULONG *aSystem) 2857 2820 { 2858 2821 #ifdef VBOX_WITH_RESOURCE_USAGE_API 2859 *user = m_CpuStats.u32User; 2860 *system = m_CpuStats.u32System; 2861 // printf("Machine::GetProcessorUsage: user=%u%% system=%u%% &m_CpuStats=%p this=%p\n", 2862 // m_CpuStats.u32User / 10000000, m_CpuStats.u32System / 10000000, &m_CpuStats, this); 2822 if (aUser == NULL || aSystem == NULL) 2823 return E_POINTER; 2824 2825 // LogFlowThisFunc (("user=%u%% system=%u%% &mData->mCpuStats=%p\n", 2826 // mData->mCpuStats.u32User / 10000000, 2827 // mData->mCpuStats.u32System / 10000000, &mData->mCpuStats)); 2828 2829 *aUser = mData->mCpuStats.u32User; 2830 *aSystem = mData->mCpuStats.u32System; 2863 2831 return S_OK; 2864 2832 #else /* !VBOX_WITH_RESOURCE_USAGE_API */ … … 7354 7322 } 7355 7323 7324 #ifdef VBOX_WITH_RESOURCE_USAGE_API 7325 7326 /* static */ 7327 void Machine::UsageSamplerCallback (PRTTIMER pTimer, void *pvUser, uint64_t iTick) 7328 { 7329 AssertReturnVoid (pvUser != NULL); 7330 static_cast <Machine *> (pvUser)->usageSamplerCallback(); 7331 } 7332 7333 void Machine::usageSamplerCallback() 7334 { 7335 // LogFlowThisFunc (("mData->mSession.mPid = %u &mData->mCpuStats = %p)\n", 7336 // mData->mSession.mPid, &m_CpuStats)); 7337 if (mData->mSession.mPid != NIL_RTPROCESS) 7338 { 7339 int vrc = RTProcessGetProcessorUsageStats (mData->mSession.mPid, 7340 &mData->mCpuStats); 7341 AssertMsgRC (vrc, ("Failed to get CPU stats (%Rra)\n", vrc)); 7342 } 7343 else 7344 { 7345 mData->mCpuStats.u32User = 0; 7346 mData->mCpuStats.u32System = 0; 7347 } 7348 // LogFlowThisFunc (("user=%u%% system=%u%% &mData->mCpuStats=%p\n", 7349 // mData->mCpuStats.u32User / 10000000, 7350 // mData->mCpuStats.u32System / 10000000, &mData->mCpuStats)); 7351 // LogFlowThisFunc (("user=%.2f system=%.2f\n", 7352 // mData->mCpuStats.u32User/10000000., mData->mCpuStats.u32System/10000000.)); 7353 } 7354 7355 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 7356 7356 7357 ///////////////////////////////////////////////////////////////////////////// 7357 7358 // SessionMachine class … … 8606 8607 } 8607 8608 8608 /**8609 * Obtains the results of the latest measurement of CPU usage by8610 * this machine.8611 *8612 * @returns error code.8613 *8614 * @param user out % of CPU time spent in user mode.8615 * @param system out % of CPU time spent in kernel mode.8616 *8617 */8618 STDMETHODIMP SessionMachine::GetProcessorUsage(ULONG *user, ULONG *system)8619 {8620 return mPeer->GetProcessorUsage(user, system);8621 }8622 8623 8609 // public methods only for internal purposes 8624 8610 ///////////////////////////////////////////////////////////////////////////// -
trunk/src/VBox/Main/idl/VirtualBox.xidl
r9904 r9937 3467 3467 </param> 3468 3468 </method> 3469 3469 3470 3470 <method name="getConfigRegistryValue"> 3471 3471 <desc> … … 3506 3506 <method name="getProcessorUsage"> 3507 3507 <desc> 3508 Returns the current processor usage measured over all cores of all3509 processors in the host system.3510 3511 <note>3512 The maximum value is 1000000000 which means that all cores of all CPUs3513 are completely used.3514 </note>3508 Returns the current processor usage by this virtual machine measured 3509 over all cores of all processors in the host system. 3510 3511 The values returned for each parameter are in range from <tt>0</tt> (the 3512 machine is powered off or does not load the CPUs at all) to 3513 <tt>1 000 000 000</tt> (all cores of all CPUs are fully in use by this 3514 machine). 3515 3515 </desc> 3516 3516 <param name="user" type="unsigned long" dir="out"> 3517 <desc> The pecentage of processor time spent executing in user3518 mode.3517 <desc> 3518 Pecentage of processor time spent executing in user mode. 3519 3519 </desc> 3520 3520 </param> 3521 3521 <param name="system" type="unsigned long" dir="out"> 3522 <desc> The pecentage of processor time spent executing in kernel3523 mode.3522 <desc> 3523 Pecentage of processor time spent executing in kernel mode. 3524 3524 </desc> 3525 3525 </param> … … 5044 5044 <method name="getProcessorUsage"> 5045 5045 <desc> 5046 Returns the current processor usage measured over all cores of all 5047 processors in the host system. 5048 5049 <note> 5050 The maximum value is 1000000000 which means that all cores of all CPUs 5046 Returns the processor usage by the whole host system measured over all 5047 cores of all processors of the host machine. 5048 5049 The values returned for each parameter are in range from <tt>0</tt> (the 5050 machine is powered off or doesn't load the CPUs at all) to 5051 <tt>1 000 000 000</tt> (all cores of all CPUs are fully loaded by this 5052 machine). 5053 5054 <note> 5055 The maximum value is 1000000000 which means that all cores of all CPUs 5051 5056 are completely used. 5052 5057 </note> 5053 5058 </desc> 5054 5059 <param name="user" type="unsigned long" dir="out"> 5055 <desc> The pecentage of processor time spent executing in user5056 mode.5060 <desc> 5061 Pecentage of processor time spent executing in user mode. 5057 5062 </desc> 5058 5063 </param> 5059 5064 <param name="system" type="unsigned long" dir="out"> 5060 <desc> The pecentage of processor time spent executing in kernel5061 mode.5065 <desc> 5066 Pecentage of processor time spent executing in kernel mode. 5062 5067 </desc> 5063 5068 </param> 5064 5069 <param name="idle" type="unsigned long" dir="out"> 5065 <desc>The pecentage of processor time spent doing nothing. 5070 <desc> 5071 Pecentage of processor time spent doing nothing. 5066 5072 </desc> 5067 5073 </param> -
trunk/src/VBox/Main/include/HostImpl.h
r9904 r9937 110 110 STDMETHOD(RemoveUSBDeviceFilter) (ULONG aPosition, IHostUSBDeviceFilter **aFilter); 111 111 112 STDMETHOD(GetProcessorUsage) (ULONG * user, ULONG *system, ULONG *idle);112 STDMETHOD(GetProcessorUsage) (ULONG *aUser, ULONG *aSystem, ULONG *aIdle); 113 113 114 114 // public methods only for internal purposes … … 170 170 #endif 171 171 172 #ifdef VBOX_WITH_RESOURCE_USAGE_API 173 /** Static timer callback. */ 174 static void UsageSamplerCallback (PRTTIMER pTimer, void *pvUser, uint64_t iTick); 175 /** Member timer callback. */ 176 void usageSamplerCallback(); 177 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 178 172 179 ComObjPtr <VirtualBox, ComWeakRef> mParent; 173 180 … … 180 187 181 188 #ifdef VBOX_WITH_RESOURCE_USAGE_API 182 /** Static timer callback. */183 static void staticSamplerCallback(PRTTIMER pTimer, void *pvUser, uint64_t iTick);184 /** Member timer callback. */185 void usageSamplerCallback();186 187 189 /** Pointer to the usage sampling timer. */ 188 PRTTIMER m_pUsageSampler; 189 /** Time stamp of the last taken sample. */ 190 //uint64_t m_tsLastSampleTaken; 190 PRTTIMER mUsageSampler; 191 191 /** Structure to hold processor usage stats. */ 192 RTCPUUSAGESTATS m _CpuStats;192 RTCPUUSAGESTATS mCpuStats; 193 193 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 194 194 }; -
trunk/src/VBox/Main/include/MachineImpl.h
r9904 r9937 168 168 ComObjPtr <Snapshot> mFirstSnapshot; 169 169 ComObjPtr <Snapshot> mCurrentSnapshot; 170 171 #ifdef VBOX_WITH_RESOURCE_USAGE_API 172 /** Pointer to the usage sampling timer. */ 173 PRTTIMER mUsageSampler; 174 /** Structure to hold processor usage stats. */ 175 RTPROCCPUUSAGESTATS mCpuStats; 176 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 170 177 }; 171 178 … … 713 720 void copyFrom (Machine *aThat); 714 721 722 #ifdef VBOX_WITH_RESOURCE_USAGE_API 723 /** Static timer callback. */ 724 static void UsageSamplerCallback (PRTTIMER pTimer, void *pvUser, uint64_t iTick); 725 /** Member timer callback. */ 726 void usageSamplerCallback(); 727 #endif /* VBOX_WITH_RESOURCE_USAGE_API */ 728 715 729 const InstanceType mType; 716 730 … … 745 759 friend class SessionMachine; 746 760 friend class SnapshotMachine; 747 748 #ifdef VBOX_WITH_RESOURCE_USAGE_API749 /** Static timer callback. */750 static void staticSamplerCallback(PRTTIMER pTimer, void *pvUser, uint64_t iTick);751 /** Member timer callback. */752 void usageSamplerCallback();753 /** Pointer to the usage sampling timer. */754 PRTTIMER m_pUsageSampler;755 /** Structure to hold processor usage stats. */756 RTPROCCPUUSAGESTATS m_CpuStats;757 #endif /* VBOX_WITH_RESOURCE_USAGE_API */758 761 }; 759 762 … … 826 829 IConsole *aInitiator, MachineState_T *aMachineState, IProgress **aProgress); 827 830 828 /* We need to override and call real Machine's method. */829 STDMETHOD(GetProcessorUsage) (ULONG *user, ULONG *system);830 831 831 // public methods only for internal purposes 832 832
Note:
See TracChangeset
for help on using the changeset viewer.