Click here to Skip to main content
15,916,601 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Sleep( ) Pin
8-Oct-01 14:01
suss8-Oct-01 14:01 
GeneralRe: Sleep( ) Pin
Erik G. Poel8-Oct-01 14:06
Erik G. Poel8-Oct-01 14:06 
GeneralRe: Sleep( ) Pin
Tim Smith8-Oct-01 15:06
Tim Smith8-Oct-01 15:06 
GeneralRe: Sleep( ) Pin
ColinDavies8-Oct-01 17:49
ColinDavies8-Oct-01 17:49 
GeneralXP UI Registry settings Pin
Tim Smith8-Oct-01 12:26
Tim Smith8-Oct-01 12:26 
GeneralRe: XP UI Registry settings Pin
Tomasz Sowinski8-Oct-01 23:34
Tomasz Sowinski8-Oct-01 23:34 
GeneralRe: XP UI Registry settings Pin
Tim Smith9-Oct-01 2:01
Tim Smith9-Oct-01 2:01 
GeneralWMI problem, Query too slow Pin
Bill Wilson8-Oct-01 11:48
Bill Wilson8-Oct-01 11:48 
Forum Index | FAQ | Edit Profile | Send Private | Check Private | Search | Logout
Preview your post

The following is a preview of your post. If everything looks ok then you can click 'Continue' and your post will be entered. If not then use your back button to go back and edit some more.

Subject: WBEM Query too slow

Category:

I have an application that must find out the current load on the system on a regular basis. I'm using WMI/WBEM to do this. The problem is that one of the WMI calls takes about 1/2 second to return...

This is a BIG problem.

The call that takes so long is the ExecQuery call that only happens once per calculation. The loop gets the LoadPercentage for each proecssor on the system. (I think). I need the enumerator in anycase.

Here's my code:


long CSysLoad::GetLoadPercentage()
{



// Perform the query
IEnumWbemClassObject *pEnum = 0;

try
{
// ***********************The next line takes 1/2 second
hres = pSvc->ExecQuery( language,query,/*BEM_FLAG_FORWARD_ONLY*/ 0x20,NULL,&pEnum);
}
catch (CException *e)
{
}
if(FAILED(hres))
{

CErrorInfo err;
GET_ERROR_MSG(lpMsg, hres);
err.SetError(hres,CString((LPCSTR) lpMsg ));
throw err;
return 0;
}

long lReturnValue = 0;
// Define the object interface (AND initialize it to NULL)
IWbemClassObject *pObj = 0;
ULONG uReturned = 0; // Used to check the number of objects returned

long lTotalLoad = 0;
int iProcessorCount = 0;

while(true)
{

// Check each processor, average result

hres = pEnum->Next( 0,1,&pObj,&uReturned);

if(uReturned == 0) // If no more to process, uReturned is set to 0 so we're done
break;

// Since we're not done, extract the LoadPercentage from the query result


BSTR strClassProp = SysAllocString(L"LoadPercentage");
VARIANT v;

hres = pObj->Get(strClassProp, 0, &v, 0, 0);
SysFreeString(strClassProp);


// If the property is found, convert our variant to a number.

if(!FAILED(hres))
{
/* bstr_t temp(v);
TCHAR buf[128];

_tcscpy(buf, (LPTSTR)temp);

long lResult = atoi(buf);
*/ if (v.vt = VT_I4)
{
lTotalLoad += v.iVal;
iProcessorCount++;
}

} else {

CErrorInfo err;
GET_ERROR_MSG(lpMsg, hres);
err.SetError(hres,CString((LPCSTR) lpMsg ));
throw err;
return 0;

}

VariantClear(&v);

pObj->Release();

}
// Calculate the answer


return (iProcessorCount > 0) ? lTotalLoad / iProcessorCount : 0;
// If this doesn't work, we will be running WIDE OPEN!!!


}





Thanks for the help,
Bill
GeneralQuestion: Registering a new Document Template Pin
8-Oct-01 11:42
suss8-Oct-01 11:42 
GeneralDrawing question Pin
8-Oct-01 11:24
suss8-Oct-01 11:24 
QuestionWhat is this ':'? Pin
Sam C8-Oct-01 10:58
Sam C8-Oct-01 10:58 
AnswerRe: What is this ':'? Pin
Chris Losinger8-Oct-01 11:09
professionalChris Losinger8-Oct-01 11:09 
GeneralRe: What is this ':'? Pin
Sam C8-Oct-01 12:14
Sam C8-Oct-01 12:14 
GeneralRe: What is this ':'? Pin
Chris Losinger8-Oct-01 12:32
professionalChris Losinger8-Oct-01 12:32 
GeneralRe: What is this ':'? Pin
Sam C8-Oct-01 13:09
Sam C8-Oct-01 13:09 
GeneralRe: What is this ':'? Pin
Chris Losinger8-Oct-01 15:29
professionalChris Losinger8-Oct-01 15:29 
GeneralRe: What is this ':'? Pin
Sam C8-Oct-01 16:23
Sam C8-Oct-01 16:23 
GeneralRe: What is this ':'? Pin
Chris Losinger9-Oct-01 1:31
professionalChris Losinger9-Oct-01 1:31 
GeneralRe: What is this ':'? Pin
Sam C9-Oct-01 3:51
Sam C9-Oct-01 3:51 
GeneralOLE drag and drop using MFC Pin
vgandhi8-Oct-01 10:45
vgandhi8-Oct-01 10:45 
GeneralSuperClass CListViewCtrl Pin
8-Oct-01 8:43
suss8-Oct-01 8:43 
GeneralRe: SuperClass CListViewCtrl Pin
Tomasz Sowinski8-Oct-01 8:53
Tomasz Sowinski8-Oct-01 8:53 
GeneralRe: SuperClass CListViewCtrl Pin
8-Oct-01 9:07
suss8-Oct-01 9:07 
GeneralRe: SuperClass CListViewCtrl Pin
Tomasz Sowinski8-Oct-01 9:17
Tomasz Sowinski8-Oct-01 9:17 
GeneralRe: SuperClass CListViewCtrl Pin
8-Oct-01 9:45
suss8-Oct-01 9:45 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.