-
April 12th, 2004, 04:44 PM
#16
I'm just speaking theoretical here, because I never used the pdh functions in depth, but ...
Are you working with a localized version of Windows (not English) ?
In that case, what happens to the names of the objects, might they be translated to the lcoalized language too ? I mean "Processor" and "% Processor Time". At least PerfMon shows them to me in my german Windows version with the german names (in the object list ...)
-
April 12th, 2004, 05:00 PM
#17
PerfMon on my Win2k works correctly.
But... I have a rus Windows version... so the name of a counter is russian. But I don't think that problem is in such way...
So the whole name is \\NAME_OF_MY_MACHINE\Ïðîöåññîð(_Total)\% ç*ãðóæå**îñòè ïðîöåññîð*
-
April 12th, 2004, 05:08 PM
#18
At least I don't hope so... as I said, just a theoretical question to be sure since I don't see any other failures in your code ... and I saw perfmon reporting me object names in german on my Windows version.
I asked before and perhaps I missed the answer, but... Do you build your application as Unicode ?
-
April 12th, 2004, 05:10 PM
#19
I don't know but.. may be problem whith szMachineName or dwInstanceIndex..?
-
April 12th, 2004, 05:14 PM
#20
Originally posted by Punga
PerfMon on my Win2k works correctly.
But... I have a rus Windows version... so the name of a counter is russian. But I don't think that problem is in such way...
So the whole name is \\NAME_OF_MY_MACHINE\Ïðîöåññîð(_Total)\% ç*ãðóæå**îñòè ïðîöåññîð*
Actually I do think that is the problem, the lookup is done in the registry, though the below states it also stores the english version also, perhaps it's a trump because of the locale. Convert the counter name to what you posted above and use that. I've only used english for the PdhXXX functions. Here is msdn's link to surf around on.
http://msdn.microsoft.com/library/de...addcounter.asp
Retrieving Counter Names and Explanations
Object type names, counter names, object explanations, and counter explanations are not made directly available in the performance data structures. Instead, the performance data structures contain indexes you can use to locate where the names and explanations for each object and counter can be found. The ObjectNameTitleIndex and ObjectHelpTitleIndex members of the PERF_OBJECT_TYPE structure contain the indexes to the object name and explanation, respectively. The CounterNameTitleIndex and CounterHelpTitleIndex members of the PERF_COUNTER_DEFINITION structure contain the indexes to the counter name and explanation, respectively.
To access the names and explanations, read the Counter and Help values in the following registry key.
HKEY_LOCAL_MACHINE\
SOFTWARE\
Microsoft\
Windows NT\
CurrentVersion\
Perflib\
langid
The langid is the ASCII representation of the 3-digit hexadecimal language identifier. For example, the U.S. English langid is 009. In a non-English version of Windows, counters are stored in both the native language of the system and in English.
Why is it everyone can't just use english and eat at McDonalds
/Promoting the american stereotype...
-
April 12th, 2004, 05:17 PM
#21
Sorry to tell you that (and I can't tell that this is fine), but:
1) I tried your code sniplet and it didn't work for me
2) I changed the names to the german translations and it worked ...
PDH_STATUS pdhResult = 0;
TCHAR szCounterPath[1024];
DWORD dwPathSize = 1024;
PDH_COUNTER_PATH_ELEMENTS pe;
HQUERY hQuery;
HQUERY hCounter;
pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
pe.szMachineName = 0l;
pe.szObjectName = "Prozessor";
pe.szInstanceName = "_Total";
pe.szParentInstance = NULL;
pe.dwInstanceIndex = 0;
pe.szCounterName = "Prozessorzeit (%)";
pdhResult = PdhMakeCounterPath(&pe, szCounterPath, &dwPathSize, 0);
pdhResult = PdhAddCounter(hQuery, szCounterPath, 0, &hCounter);
So you have to try the russian equivalents (sorry, or is there a difference between russian and white-russian / belaruss ? Im not sure, I should know that living here not to far away from you, but I have to admit I don't) and I think you have to use unicode for that.
Last edited by Marco F; April 12th, 2004 at 05:20 PM.
-
April 12th, 2004, 05:19 PM
#22
I need to build my application as Unicode ? Tell me plz how to do this And how should I write names of PDH_COUNTER_PATH_ELEMENTS structure elements, whith _T(...) or not ?
-
April 12th, 2004, 05:20 PM
#23
Originally posted by Marco F
Sorry to tell you that (and I can't tell that this is fine), but:
1) I tried your code sniplet and it didn't work for me
2) I changed the names to the german translations and it worked ...
PDH_STATUS pdhResult = 0;
TCHAR szCounterPath[1024];
DWORD dwPathSize = 1024;
PDH_COUNTER_PATH_ELEMENTS pe;
HQUERY hQuery;
HQUERY hCounter;
pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
pe.szMachineName = 0l;
pe.szObjectName = "Prozessor";
pe.szInstanceName = "_Total";
pe.szParentInstance = NULL;
pe.dwInstanceIndex = 0;
pe.szCounterName = "Prozessorzeit (%)";
pdhResult = PdhMakeCounterPath(&pe, szCounterPath, &dwPathSize, 0);
pdhResult = PdhAddCounter(hQuery, szCounterPath, 0, &hCounter);
So you have to try the russian equivalents (sorry, or is there a difference between russian and white-russian / belaruss ? Im not sure, I should know that living here not to far away from you, but I have to admit I don't) and I think you have to use unicode for that.
That is why on my previous posts I kept asking for him to run perfmon and look at the counter name.
-
April 12th, 2004, 05:21 PM
#24
I think you must use unicode or at least you ave to explizitlly call the UNICODE-version of the pdh-functions. I think your russian characters are not in the "standard-Ansi" range, but you should know that better than me.
-
April 12th, 2004, 05:24 PM
#25
But the program won't work under the eng. version Win2k... Or I mistake?
-
April 12th, 2004, 05:43 PM
#26
Forcing Unicode-PDH-Functions:
=========================
PDH_STATUS pdhResult = 0;
wchar_t szCounterPath[1024];
DWORD dwPathSize = 1024;
PDH_COUNTER_PATH_ELEMENTS_W pe;
HQUERY hQuery;
HQUERY hCounter;
pdhResult = PdhOpenQuery( NULL, 0, &hQuery );
pe.szMachineName = 0l;
pe.szObjectName = L"Prozessor";
pe.szInstanceName = L"_Total";
pe.szParentInstance = NULL;
pe.dwInstanceIndex = 0;
pe.szCounterName = L"Prozessorzeit (%)";
pdhResult = PdhMakeCounterPathW(&pe, szCounterPath, &dwPathSize, 0);
pdhResult = PdhAddCounterW(hQuery, szCounterPath, 0, &hCounter);
===================
yes, the program will not work in ANY W2K version different from russian. Sorry, I don't know a better way. Perhaps there is one, but I don't know.
Only thing you could do is to localize the strings via a string table for your different target locales.
-
April 14th, 2004, 07:14 AM
#27
Use my sample which helps you getting cpu usage for whole system or for a single process:
How to get CPU usage by performance counters (without PDH)
-
April 14th, 2004, 01:00 PM
#28
-->> dudiav
I can't extract the downloaded archive *.zip.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|