2011-12-14 Ramon Novoa <rnovoa@artica.es>
* modules/pandora_module_perfcounter.cc, modules/pandora_module_perfcounter.h: Use MinrGW's pdh.h instead of our own definitions. * modules/pandora_module.cc: Fixed a bug in pre-conditions that led to an infinite loop. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@5257 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
parent
899dc9a49b
commit
7f46470d32
|
@ -1,3 +1,12 @@
|
||||||
|
2011-12-14 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
|
* modules/pandora_module_perfcounter.cc,
|
||||||
|
modules/pandora_module_perfcounter.h: Use MinrGW's pdh.h
|
||||||
|
instead of our own definitions.
|
||||||
|
|
||||||
|
* modules/pandora_module.cc: Fixed a bug in pre-conditions that led to an
|
||||||
|
infinite loop.
|
||||||
|
|
||||||
2011-12-12 Ramon Novoa <rnovoa@artica.es>
|
2011-12-12 Ramon Novoa <rnovoa@artica.es>
|
||||||
|
|
||||||
* windows/pandora_wmi.cc: Removed some debugging messages.
|
* windows/pandora_wmi.cc: Removed some debugging messages.
|
||||||
|
|
|
@ -82,7 +82,7 @@ Pandora_Module::~Pandora_Module () {
|
||||||
iter_pre = this->precondition_list->begin ();
|
iter_pre = this->precondition_list->begin ();
|
||||||
for (iter_pre = this->precondition_list->begin ();
|
for (iter_pre = this->precondition_list->begin ();
|
||||||
iter_pre != this->precondition_list->end ();
|
iter_pre != this->precondition_list->end ();
|
||||||
iter++) {
|
iter_pre++) {
|
||||||
/* Free regular expressions */
|
/* Free regular expressions */
|
||||||
precond = *iter_pre;
|
precond = *iter_pre;
|
||||||
if (precond->string_value != "") {
|
if (precond->string_value != "") {
|
||||||
|
@ -91,6 +91,7 @@ Pandora_Module::~Pandora_Module () {
|
||||||
delete (*iter_pre);
|
delete (*iter_pre);
|
||||||
}
|
}
|
||||||
delete (this->precondition_list);
|
delete (this->precondition_list);
|
||||||
|
this->precondition_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean condition list */
|
/* Clean condition list */
|
||||||
|
@ -107,11 +108,13 @@ Pandora_Module::~Pandora_Module () {
|
||||||
delete (*iter);
|
delete (*iter);
|
||||||
}
|
}
|
||||||
delete (this->condition_list);
|
delete (this->condition_list);
|
||||||
|
this->condition_list = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clean the module cron */
|
/* Clean the module cron */
|
||||||
if (this->cron != NULL) {
|
if (this->cron != NULL) {
|
||||||
delete (this->cron);
|
delete (this->cron);
|
||||||
|
this->cron = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,12 +30,12 @@ using namespace Pandora_Modules;
|
||||||
|
|
||||||
// Pointers to pdh.dll functions
|
// Pointers to pdh.dll functions
|
||||||
static HINSTANCE PDH = NULL;
|
static HINSTANCE PDH = NULL;
|
||||||
static PdhOpenQueryT PdhOpenQuery = NULL;
|
static PdhOpenQueryT PdhOpenQueryF = NULL;
|
||||||
static PdhAddCounterT PdhAddCounter = NULL;
|
static PdhAddCounterT PdhAddCounterF = NULL;
|
||||||
static PdhCollectQueryDataT PdhCollectQueryData = NULL;
|
static PdhCollectQueryDataT PdhCollectQueryDataF = NULL;
|
||||||
static PdhGetRawCounterValueT PdhGetRawCounterValue = NULL;
|
static PdhGetRawCounterValueT PdhGetRawCounterValueF = NULL;
|
||||||
static PdhGetFormattedCounterValueT PdhGetFormattedCounterValue = NULL;
|
static PdhGetFormattedCounterValueT PdhGetFormattedCounterValueF = NULL;
|
||||||
static PdhCloseQueryT PdhCloseQuery = NULL;
|
static PdhCloseQueryT PdhCloseQueryF = NULL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a Pandora_Module_Perfcounter object.
|
* Creates a Pandora_Module_Perfcounter object.
|
||||||
|
@ -57,48 +57,48 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdhOpenQuery = (PdhOpenQueryT) GetProcAddress (PDH, "PdhOpenQueryA");
|
PdhOpenQueryF = (PdhOpenQueryT) GetProcAddress (PDH, "PdhOpenQueryA");
|
||||||
if (PdhOpenQuery == NULL) {
|
if (PdhOpenQueryF == NULL) {
|
||||||
pandoraLog ("Error loading function PdhOpenQueryA");
|
pandoraLog ("Error loading function PdhOpenQueryA");
|
||||||
FreeLibrary (PDH);
|
FreeLibrary (PDH);
|
||||||
PDH = NULL;
|
PDH = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdhAddCounter = (PdhAddCounterT) GetProcAddress (PDH, "PdhAddCounterA");
|
PdhAddCounterF = (PdhAddCounterT) GetProcAddress (PDH, "PdhAddCounterA");
|
||||||
if (PdhAddCounter == NULL) {
|
if (PdhAddCounterF == NULL) {
|
||||||
pandoraLog ("Error loading function PdhAddCounterA");
|
pandoraLog ("Error loading function PdhAddCounterA");
|
||||||
FreeLibrary (PDH);
|
FreeLibrary (PDH);
|
||||||
PDH = NULL;
|
PDH = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdhCollectQueryData = (PdhCollectQueryDataT) GetProcAddress (PDH, "PdhCollectQueryData");
|
PdhCollectQueryDataF = (PdhCollectQueryDataT) GetProcAddress (PDH, "PdhCollectQueryData");
|
||||||
if (PdhCollectQueryData == NULL) {
|
if (PdhCollectQueryDataF == NULL) {
|
||||||
pandoraLog ("Error loading function PdhCollectQueryData");
|
pandoraLog ("Error loading function PdhCollectQueryData");
|
||||||
FreeLibrary (PDH);
|
FreeLibrary (PDH);
|
||||||
PDH = NULL;
|
PDH = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdhGetRawCounterValue = (PdhGetRawCounterValueT) GetProcAddress (PDH, "PdhGetRawCounterValue");
|
PdhGetRawCounterValueF = (PdhGetRawCounterValueT) GetProcAddress (PDH, "PdhGetRawCounterValue");
|
||||||
if (PdhGetRawCounterValue == NULL) {
|
if (PdhGetRawCounterValueF == NULL) {
|
||||||
pandoraLog ("Error loading function PdhGetRawCounterValue");
|
pandoraLog ("Error loading function PdhGetRawCounterValue");
|
||||||
FreeLibrary (PDH);
|
FreeLibrary (PDH);
|
||||||
PDH = NULL;
|
PDH = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdhGetFormattedCounterValue = (PdhGetFormattedCounterValueT) GetProcAddress (PDH, "PdhGetFormattedCounterValue");
|
PdhGetFormattedCounterValueF = (PdhGetFormattedCounterValueT) GetProcAddress (PDH, "PdhGetFormattedCounterValue");
|
||||||
if (PdhGetFormattedCounterValue == NULL) {
|
if (PdhGetFormattedCounterValueF == NULL) {
|
||||||
pandoraLog ("Error loading function PdhGetFormattedCounterValue");
|
pandoraLog ("Error loading function PdhGetFormattedCounterValue");
|
||||||
FreeLibrary (PDH);
|
FreeLibrary (PDH);
|
||||||
PDH = NULL;
|
PDH = NULL;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
PdhCloseQuery = (PdhCloseQueryT) GetProcAddress (PDH, "PdhCloseQuery");
|
PdhCloseQueryF = (PdhCloseQueryT) GetProcAddress (PDH, "PdhCloseQuery");
|
||||||
if (PdhCloseQuery == NULL) {
|
if (PdhCloseQueryF == NULL) {
|
||||||
pandoraLog ("Error loading function PdhCloseQuery");
|
pandoraLog ("Error loading function PdhCloseQuery");
|
||||||
FreeLibrary (PDH);
|
FreeLibrary (PDH);
|
||||||
PDH = NULL;
|
PDH = NULL;
|
||||||
|
@ -106,7 +106,7 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (cooked == "1") {
|
if (cooked[0] == '1') {
|
||||||
this->cooked = 1;
|
this->cooked = 1;
|
||||||
} else {
|
} else {
|
||||||
this->cooked = 0;
|
this->cooked = 0;
|
||||||
|
@ -117,7 +117,7 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
|
||||||
* Pandora_Module_Perfcounter destructor.
|
* Pandora_Module_Perfcounter destructor.
|
||||||
*/
|
*/
|
||||||
Pandora_Module_Perfcounter::~Pandora_Module_Perfcounter () {
|
Pandora_Module_Perfcounter::~Pandora_Module_Perfcounter () {
|
||||||
FreeLibrary (PDH);
|
//FreeLibrary (PDH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -127,7 +127,7 @@ Pandora_Module_Perfcounter::run () {
|
||||||
PDH_STATUS status;
|
PDH_STATUS status;
|
||||||
HCOUNTER counter;
|
HCOUNTER counter;
|
||||||
PDH_RAW_COUNTER raw_value;
|
PDH_RAW_COUNTER raw_value;
|
||||||
PDH_FMT_COUNTER fmt_value;
|
PDH_FMT_COUNTERVALUE fmt_value;
|
||||||
ostringstream string_value;
|
ostringstream string_value;
|
||||||
|
|
||||||
// Run
|
// Run
|
||||||
|
@ -143,25 +143,25 @@ Pandora_Module_Perfcounter::run () {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Open a query object
|
// Open a query object
|
||||||
status = PdhOpenQuery (NULL, 0, &query);
|
status = PdhOpenQueryF (NULL, 0, &query);
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
pandoraLog ("PdhOpenQuery failed with error %lX", 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 = PdhAddCounterF (query, this->source.c_str (), 0, &counter);
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
pandoraLog ("PdhAddCounter failed with error %lX", status);
|
pandoraLog ("PdhAddCounter failed with error %lX", status);
|
||||||
PdhCloseQuery (query);
|
PdhCloseQueryF (query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Collect the data
|
// Collect the data
|
||||||
status = PdhCollectQueryData (query);
|
status = PdhCollectQueryDataF (query);
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
// No data
|
// No data
|
||||||
PdhCloseQuery (query);
|
PdhCloseQueryF (query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,20 +170,20 @@ Pandora_Module_Perfcounter::run () {
|
||||||
|
|
||||||
// Some counters require to samples
|
// Some counters require to samples
|
||||||
Sleep (100);
|
Sleep (100);
|
||||||
status = PdhCollectQueryData (query);
|
status = PdhCollectQueryDataF (query);
|
||||||
if (status != ERROR_SUCCESS) {
|
if (status != ERROR_SUCCESS) {
|
||||||
// No data
|
// No data
|
||||||
PdhCloseQuery (query);
|
PdhCloseQueryF (query);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
status = PdhGetFormattedCounterValue(counter, PDH_FMT_LONG, NULL, &fmt_value);
|
status = PdhGetFormattedCounterValueF(counter, PDH_FMT_LONG, NULL, &fmt_value);
|
||||||
} else {
|
} else {
|
||||||
status = PdhGetRawCounterValue(counter, NULL, &raw_value);
|
status = PdhGetRawCounterValueF(counter, NULL, &raw_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close the query object
|
// Close the query object
|
||||||
PdhCloseQuery (query);
|
PdhCloseQueryF (query);
|
||||||
|
|
||||||
if (cooked == 1) {
|
if (cooked == 1) {
|
||||||
string_value << fmt_value.longValue;
|
string_value << fmt_value.longValue;
|
||||||
|
|
|
@ -22,43 +22,17 @@
|
||||||
#ifndef __PANDORA_MODULE_PERFCOUNTER_H__
|
#ifndef __PANDORA_MODULE_PERFCOUNTER_H__
|
||||||
#define __PANDORA_MODULE_PERFCOUNTER_H__
|
#define __PANDORA_MODULE_PERFCOUNTER_H__
|
||||||
|
|
||||||
|
#include <pdh.h>
|
||||||
#include "pandora_module.h"
|
#include "pandora_module.h"
|
||||||
|
|
||||||
#define BUFFER_SIZE 1024
|
#define BUFFER_SIZE 1024
|
||||||
|
|
||||||
// Some definitions to use pdh.dll
|
typedef PDH_FUNCTION (*PdhOpenQueryT) (LPCSTR szDataSource,DWORD_PTR dwUserData,PDH_HQUERY *phQuery);
|
||||||
typedef LONG PDH_STATUS;
|
typedef PDH_FUNCTION (*PdhAddCounterT) (PDH_HQUERY hQuery,LPCSTR szFullCounterPath,DWORD_PTR dwUserData,PDH_HCOUNTER *phCounter);
|
||||||
typedef HANDLE HCOUNTER;
|
typedef PDH_FUNCTION (*PdhCollectQueryDataT) (PDH_HQUERY hQuery);
|
||||||
typedef HANDLE HQUERY;
|
typedef PDH_FUNCTION (*PdhGetRawCounterValueT) (PDH_HCOUNTER hCounter,LPDWORD lpdwType,PPDH_RAW_COUNTER pValue);
|
||||||
typedef struct _PDH_RAW_COUNTER {
|
typedef PDH_FUNCTION (*PdhGetFormattedCounterValueT) (PDH_HCOUNTER hCounter,DWORD dwFormat,LPDWORD lpdwType,PPDH_FMT_COUNTERVALUE pValue);
|
||||||
DWORD CStatus;
|
typedef PDH_FUNCTION (*PdhCloseQueryT) (PDH_HQUERY hQuery);
|
||||||
FILETIME TimeStamp;
|
|
||||||
LONGLONG FirstValue;
|
|
||||||
LONGLONG SecondValue;
|
|
||||||
DWORD MultiCount;
|
|
||||||
} PDH_RAW_COUNTER, *PPDH_RAW_COUNTER;
|
|
||||||
|
|
||||||
typedef struct _PDH_FMT_COUNTER {
|
|
||||||
DWORD CStatus;
|
|
||||||
union {
|
|
||||||
LONG longValue;
|
|
||||||
double doubleValue;
|
|
||||||
LONGLONG largeValue;
|
|
||||||
LPCSTR AnsiStringValue;
|
|
||||||
LPCWSTR WideStringValue;
|
|
||||||
};
|
|
||||||
} PDH_FMT_COUNTER, *PPDH_FMT_COUNTER;
|
|
||||||
|
|
||||||
#define PDH_FMT_LONG 0x00000100
|
|
||||||
#define PDH_FMT_DOUBLE 0x00000200
|
|
||||||
#define PDH_FUNCTION PDH_STATUS __stdcall
|
|
||||||
|
|
||||||
typedef PDH_FUNCTION (*PdhOpenQueryT) (IN LPCSTR szDataSource, IN DWORD_PTR dwUserData, IN HQUERY *phQuery);
|
|
||||||
typedef PDH_FUNCTION (*PdhAddCounterT) (IN HQUERY hQuery, IN LPCSTR szFullCounterPath, IN DWORD_PTR dwUserData, IN HCOUNTER *phCounter);
|
|
||||||
typedef PDH_FUNCTION (*PdhCollectQueryDataT) (IN HQUERY hQuery);
|
|
||||||
typedef PDH_FUNCTION (*PdhGetRawCounterValueT) (IN HCOUNTER, IN LPDWORD lpdwType, IN PPDH_RAW_COUNTER pValue);
|
|
||||||
typedef PDH_FUNCTION (*PdhGetFormattedCounterValueT) (IN HCOUNTER, IN DWORD dwFormat, IN LPDWORD lpdwType, IN PPDH_FMT_COUNTER pValue);
|
|
||||||
typedef PDH_FUNCTION (*PdhCloseQueryT) (IN HQUERY hQuery);
|
|
||||||
|
|
||||||
namespace Pandora_Modules {
|
namespace Pandora_Modules {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue