lxn / win

A Windows API wrapper package for the Go Programming Language
Other
1.19k stars 312 forks source link

Add PDH counter wildcard and localization support #126

Open cbwest3 opened 1 year ago

cbwest3 commented 1 year ago

Problem

Microsoft specifies the following method for expanding wildcards and using language-neutral counters (from https://learn.microsoft.com/en-us/windows/win32/api/pdh/nf-pdh-pdhaddenglishcounterw#remarks):

  1. Make a query
  2. Use PdhAddEnglishCounter with the string containing wildcards
  3. Use PdhGetCounterInfo on the counter handle returned by PdhAddEnglishCounter to get a localized full path (szFullPath.) This string still contains wildcards, but the non-wildcard parts are now localized.
  4. Use PdhExpandWildCardPath to expand the wildcards.
  5. Use PdhAddCounter on each of the resulting paths

Solution

The PdhAddCounter and PdhAddEnglishCounter functions already exist. This PR adds the missing PdhGetCounterInfo and PdhExpandWildCardPath functions needed to localize counter names.

These functions allow me to expand \physicaldisk(*)\avg. disk bytes/read to:

cbwest3 commented 1 year ago

@krpors: With your PDH experience, do you mind taking a look? tia

krpors commented 1 year ago

@cbwest Wow this has been 10 years ago already :) Anyway, I have no Windows installation anywhere to actually test the PDH stuff. I'm afraid I can't be of much help. Also, seeing my own PDH code still baffles me. I can't even remember how I got all this to work in the first place 😄

cbwest3 commented 1 year ago

Thanks @krpors, I appreciate the timely response. Best of luck in your current endeavors!