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:
Ramon Novoa 2011-12-14 10:38:53 +00:00
parent 8a19c14f5d
commit becd47d5fa
4 changed files with 51 additions and 65 deletions

View File

@ -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>
* windows/pandora_wmi.cc: Removed some debugging messages.

View File

@ -82,7 +82,7 @@ Pandora_Module::~Pandora_Module () {
iter_pre = this->precondition_list->begin ();
for (iter_pre = this->precondition_list->begin ();
iter_pre != this->precondition_list->end ();
iter++) {
iter_pre++) {
/* Free regular expressions */
precond = *iter_pre;
if (precond->string_value != "") {
@ -91,6 +91,7 @@ Pandora_Module::~Pandora_Module () {
delete (*iter_pre);
}
delete (this->precondition_list);
this->precondition_list = NULL;
}
/* Clean condition list */
@ -107,11 +108,13 @@ Pandora_Module::~Pandora_Module () {
delete (*iter);
}
delete (this->condition_list);
this->condition_list = NULL;
}
/* Clean the module cron */
if (this->cron != NULL) {
delete (this->cron);
this->cron = NULL;
}
}

View File

@ -30,12 +30,12 @@ using namespace Pandora_Modules;
// Pointers to pdh.dll functions
static HINSTANCE PDH = NULL;
static PdhOpenQueryT PdhOpenQuery = NULL;
static PdhAddCounterT PdhAddCounter = NULL;
static PdhCollectQueryDataT PdhCollectQueryData = NULL;
static PdhGetRawCounterValueT PdhGetRawCounterValue = NULL;
static PdhGetFormattedCounterValueT PdhGetFormattedCounterValue = NULL;
static PdhCloseQueryT PdhCloseQuery = NULL;
static PdhOpenQueryT PdhOpenQueryF = NULL;
static PdhAddCounterT PdhAddCounterF = NULL;
static PdhCollectQueryDataT PdhCollectQueryDataF = NULL;
static PdhGetRawCounterValueT PdhGetRawCounterValueF = NULL;
static PdhGetFormattedCounterValueT PdhGetFormattedCounterValueF = NULL;
static PdhCloseQueryT PdhCloseQueryF = NULL;
/**
* Creates a Pandora_Module_Perfcounter object.
@ -57,48 +57,48 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
return;
}
PdhOpenQuery = (PdhOpenQueryT) GetProcAddress (PDH, "PdhOpenQueryA");
if (PdhOpenQuery == NULL) {
PdhOpenQueryF = (PdhOpenQueryT) GetProcAddress (PDH, "PdhOpenQueryA");
if (PdhOpenQueryF == NULL) {
pandoraLog ("Error loading function PdhOpenQueryA");
FreeLibrary (PDH);
PDH = NULL;
return;
}
PdhAddCounter = (PdhAddCounterT) GetProcAddress (PDH, "PdhAddCounterA");
if (PdhAddCounter == NULL) {
PdhAddCounterF = (PdhAddCounterT) GetProcAddress (PDH, "PdhAddCounterA");
if (PdhAddCounterF == NULL) {
pandoraLog ("Error loading function PdhAddCounterA");
FreeLibrary (PDH);
PDH = NULL;
return;
}
PdhCollectQueryData = (PdhCollectQueryDataT) GetProcAddress (PDH, "PdhCollectQueryData");
if (PdhCollectQueryData == NULL) {
PdhCollectQueryDataF = (PdhCollectQueryDataT) GetProcAddress (PDH, "PdhCollectQueryData");
if (PdhCollectQueryDataF == NULL) {
pandoraLog ("Error loading function PdhCollectQueryData");
FreeLibrary (PDH);
PDH = NULL;
return;
}
PdhGetRawCounterValue = (PdhGetRawCounterValueT) GetProcAddress (PDH, "PdhGetRawCounterValue");
if (PdhGetRawCounterValue == NULL) {
PdhGetRawCounterValueF = (PdhGetRawCounterValueT) GetProcAddress (PDH, "PdhGetRawCounterValue");
if (PdhGetRawCounterValueF == NULL) {
pandoraLog ("Error loading function PdhGetRawCounterValue");
FreeLibrary (PDH);
PDH = NULL;
return;
}
PdhGetFormattedCounterValue = (PdhGetFormattedCounterValueT) GetProcAddress (PDH, "PdhGetFormattedCounterValue");
if (PdhGetFormattedCounterValue == NULL) {
PdhGetFormattedCounterValueF = (PdhGetFormattedCounterValueT) GetProcAddress (PDH, "PdhGetFormattedCounterValue");
if (PdhGetFormattedCounterValueF == NULL) {
pandoraLog ("Error loading function PdhGetFormattedCounterValue");
FreeLibrary (PDH);
PDH = NULL;
return;
}
PdhCloseQuery = (PdhCloseQueryT) GetProcAddress (PDH, "PdhCloseQuery");
if (PdhCloseQuery == NULL) {
PdhCloseQueryF = (PdhCloseQueryT) GetProcAddress (PDH, "PdhCloseQuery");
if (PdhCloseQueryF == NULL) {
pandoraLog ("Error loading function PdhCloseQuery");
FreeLibrary (PDH);
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;
} else {
this->cooked = 0;
@ -117,7 +117,7 @@ Pandora_Module_Perfcounter::Pandora_Module_Perfcounter (string name, string sour
* Pandora_Module_Perfcounter destructor.
*/
Pandora_Module_Perfcounter::~Pandora_Module_Perfcounter () {
FreeLibrary (PDH);
//FreeLibrary (PDH);
}
void
@ -127,7 +127,7 @@ Pandora_Module_Perfcounter::run () {
PDH_STATUS status;
HCOUNTER counter;
PDH_RAW_COUNTER raw_value;
PDH_FMT_COUNTER fmt_value;
PDH_FMT_COUNTERVALUE fmt_value;
ostringstream string_value;
// Run
@ -143,25 +143,25 @@ Pandora_Module_Perfcounter::run () {
}
// Open a query object
status = PdhOpenQuery (NULL, 0, &query);
status = PdhOpenQueryF (NULL, 0, &query);
if (status != ERROR_SUCCESS) {
pandoraLog ("PdhOpenQuery failed with error %lX", status);
return;
}
// 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) {
pandoraLog ("PdhAddCounter failed with error %lX", status);
PdhCloseQuery (query);
PdhCloseQueryF (query);
return;
}
// Collect the data
status = PdhCollectQueryData (query);
status = PdhCollectQueryDataF (query);
if (status != ERROR_SUCCESS) {
// No data
PdhCloseQuery (query);
PdhCloseQueryF (query);
return;
}
@ -170,20 +170,20 @@ Pandora_Module_Perfcounter::run () {
// Some counters require to samples
Sleep (100);
status = PdhCollectQueryData (query);
status = PdhCollectQueryDataF (query);
if (status != ERROR_SUCCESS) {
// No data
PdhCloseQuery (query);
PdhCloseQueryF (query);
return;
}
status = PdhGetFormattedCounterValue(counter, PDH_FMT_LONG, NULL, &fmt_value);
status = PdhGetFormattedCounterValueF(counter, PDH_FMT_LONG, NULL, &fmt_value);
} else {
status = PdhGetRawCounterValue(counter, NULL, &raw_value);
status = PdhGetRawCounterValueF(counter, NULL, &raw_value);
}
// Close the query object
PdhCloseQuery (query);
PdhCloseQueryF (query);
if (cooked == 1) {
string_value << fmt_value.longValue;

View File

@ -22,43 +22,17 @@
#ifndef __PANDORA_MODULE_PERFCOUNTER_H__
#define __PANDORA_MODULE_PERFCOUNTER_H__
#include <pdh.h>
#include "pandora_module.h"
#define BUFFER_SIZE 1024
// Some definitions to use pdh.dll
typedef LONG PDH_STATUS;
typedef HANDLE HCOUNTER;
typedef HANDLE HQUERY;
typedef struct _PDH_RAW_COUNTER {
DWORD CStatus;
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);
typedef PDH_FUNCTION (*PdhOpenQueryT) (LPCSTR szDataSource,DWORD_PTR dwUserData,PDH_HQUERY *phQuery);
typedef PDH_FUNCTION (*PdhAddCounterT) (PDH_HQUERY hQuery,LPCSTR szFullCounterPath,DWORD_PTR dwUserData,PDH_HCOUNTER *phCounter);
typedef PDH_FUNCTION (*PdhCollectQueryDataT) (PDH_HQUERY hQuery);
typedef PDH_FUNCTION (*PdhGetRawCounterValueT) (PDH_HCOUNTER hCounter,LPDWORD lpdwType,PPDH_RAW_COUNTER pValue);
typedef PDH_FUNCTION (*PdhGetFormattedCounterValueT) (PDH_HCOUNTER hCounter,DWORD dwFormat,LPDWORD lpdwType,PPDH_FMT_COUNTERVALUE pValue);
typedef PDH_FUNCTION (*PdhCloseQueryT) (PDH_HQUERY hQuery);
namespace Pandora_Modules {