2011-11-24 Ramon Novoa <rnovoa@artica.es>
* windows/pandora_wmi.cc: Use double instead of long for intermediate result to avoid overflows. Fixes bug #3422900. * modules/pandora_module_perfcounter.cc: Print PDH errors in a more descriptive format. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5167 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
d4a8ae4249
commit
d4b510c89c
|
@ -1,3 +1,11 @@
|
||||||
|
2011-11-24 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* windows/pandora_wmi.cc: Use double instead of long for intermediate
|
||||||
|
result to avoid overflows. Fixes bug #3422900.
|
||||||
|
|
||||||
|
* modules/pandora_module_perfcounter.cc: Print PDH errors in a more
|
||||||
|
descriptive format.
|
||||||
|
|
||||||
2011-11-22 Ramon Novoa <rnovoa@artica.es>
|
2011-11-22 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* pandora_windows_service.cc: Fixed a bug that resulted in a buffer
|
* pandora_windows_service.cc: Fixed a bug that resulted in a buffer
|
||||||
|
|
|
@ -129,14 +129,14 @@ Pandora_Module_Perfcounter::run () {
|
||||||
// Open a query object
|
// Open a query object
|
||||||
status = PdhOpenQuery (NULL, 0, &query);
|
status = PdhOpenQuery (NULL, 0, &query);
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
pandoraLog ("PdhOpenQuery failed with error %d", status);
|
pandoraLog ("PdhOpenQuery failed with error %lX", status);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the counter that will provide the data
|
// Add the counter that will provide the data
|
||||||
status = PdhAddCounter (query, this->source.c_str (), 0, &counter);
|
status = PdhAddCounter (query, this->source.c_str (), 0, &counter);
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
pandoraLog ("PdhAddCounter failed with error %d", status);
|
pandoraLog ("PdhAddCounter failed with error %lX", status);
|
||||||
PdhCloseQuery (query);
|
PdhCloseQuery (query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -321,7 +321,7 @@ long
|
||||||
Pandora_Wmi::getFreememoryPercent () {
|
Pandora_Wmi::getFreememoryPercent () {
|
||||||
CDhInitialize init;
|
CDhInitialize init;
|
||||||
CDispPtr wmi_svc, quickfixes;
|
CDispPtr wmi_svc, quickfixes;
|
||||||
long free_memory, total_memory;
|
double free_memory, total_memory;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
dhCheck (dhGetObject (getWmiStr (L"."), NULL, &wmi_svc));
|
||||||
|
@ -330,17 +330,17 @@ Pandora_Wmi::getFreememoryPercent () {
|
||||||
L"SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem "));
|
L"SELECT FreePhysicalMemory, TotalVisibleMemorySize FROM Win32_OperatingSystem "));
|
||||||
|
|
||||||
FOR_EACH (quickfix, quickfixes, NULL) {
|
FOR_EACH (quickfix, quickfixes, NULL) {
|
||||||
dhGetValue (L"%d", &free_memory, quickfix,
|
dhGetValue (L"%e", &free_memory, quickfix,
|
||||||
L".FreePhysicalMemory");
|
L".FreePhysicalMemory");
|
||||||
|
|
||||||
dhGetValue (L"%d", &total_memory, quickfix,
|
dhGetValue (L"%e", &total_memory, quickfix,
|
||||||
L".TotalVisibleMemorySize");
|
L".TotalVisibleMemorySize");
|
||||||
|
|
||||||
if (total_memory == 0) {
|
if (total_memory == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return free_memory * 100 / total_memory;
|
return (long) (free_memory * 100.0 / total_memory);
|
||||||
} NEXT_THROW (quickfix);
|
} NEXT_THROW (quickfix);
|
||||||
} catch (string errstr) {
|
} catch (string errstr) {
|
||||||
pandoraLog ("getFreememory error. %s", errstr.c_str ());
|
pandoraLog ("getFreememory error. %s", errstr.c_str ());
|
||||||
|
|
Loading…
Reference in New Issue