Ejemplo n.º 1
0
	pdh_error ThreadedSafePDH::PdhOpenQuery(LPCWSTR szDataSource, DWORD_PTR dwUserData, PDH::PDH_HQUERY * phQuery) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhOpenQuery");
		if (pPdhOpenQuery == NULL)
			throw pdh_exception("Failed to initialize PdhOpenQuery :(");
		return pdh_error(pPdhOpenQuery(szDataSource, dwUserData, phQuery));
	}
Ejemplo n.º 2
0
	pdh_error ThreadedSafePDH::PdhAddCounter(PDH::PDH_HQUERY hQuery, LPCWSTR szFullCounterPath, DWORD_PTR dwUserData, PDH::PDH_HCOUNTER * phCounter) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhAddCounter");
		if (pPdhAddCounter == NULL)
			throw pdh_exception("Failed to initialize PdhAddCounter :(");
		return pdh_error(pPdhAddCounter(hQuery,szFullCounterPath,dwUserData,phCounter));
	}
Ejemplo n.º 3
0
	pdh_error ThreadedSafePDH::PdhEnumObjectItems(LPCWSTR szDataSource, LPCWSTR szMachineName, LPCWSTR szObjectName, LPWSTR mszCounterList, LPDWORD pcchCounterListLength, LPWSTR mszInstanceList, LPDWORD pcchInstanceListLength, DWORD dwDetailLevel, DWORD dwFlags) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhEnumObjectItems");
		if (pPdhEnumObjectItems == NULL)
			throw pdh_exception("Failed to initialize PdhEnumObjectItems :(");
		return pdh_error(pPdhEnumObjectItems(szDataSource, szMachineName, szObjectName, mszCounterList, pcchCounterListLength, mszInstanceList, pcchInstanceListLength, dwDetailLevel, dwFlags));
	}
Ejemplo n.º 4
0
	pdh_error ThreadedSafePDH::PdhExpandCounterPath(LPCTSTR szWildCardPath, LPTSTR mszExpandedPathList, LPDWORD pcchPathListLength) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhExpandCounterPath");
		if (pPdhExpandCounterPath == NULL)
			throw pdh_exception("Failed to initialize PdhLookupPerfNameByIndex :(");
		return pdh_error(pPdhExpandCounterPath(szWildCardPath,mszExpandedPathList,pcchPathListLength));
	}
Ejemplo n.º 5
0
	pdh_error ThreadedSafePDH::PdhEnumObjects(LPCWSTR szDataSource, LPCWSTR szMachineName, LPWSTR mszObjectList, LPDWORD pcchBufferSize, DWORD dwDetailLevel, BOOL bRefresh) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhEnumObjects");
		if (pPdhEnumObjects == NULL)
			throw pdh_exception("Failed to initialize PdhEnumObjects :(");
		return pdh_error(pPdhEnumObjects(szDataSource, szMachineName, mszObjectList, pcchBufferSize, dwDetailLevel, bRefresh));
	}
Ejemplo n.º 6
0
	pdh_error ThreadedSafePDH::PdhLookupPerfNameByIndex(LPCTSTR szMachineName,DWORD dwNameIndex,LPTSTR szNameBuffer,LPDWORD pcchNameBufferSize) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhLookupPerfNameByIndex");
		if (pPdhLookupPerfNameByIndex == NULL)
			throw pdh_exception("Failed to initialize PdhLookupPerfNameByIndex :(");
		return pdh_error(pPdhLookupPerfNameByIndex(szMachineName,dwNameIndex,szNameBuffer,pcchNameBufferSize));
	}
Ejemplo n.º 7
0
	pdh_error ThreadedSafePDH::PdhRemoveCounter(PDH::PDH_HCOUNTER hCounter) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhRemoveCounter");
		if (pPdhRemoveCounter == NULL)
			throw pdh_exception("Failed to initialize PdhRemoveCounter :(");
		return pdh_error(pPdhRemoveCounter(hCounter));
	}
Ejemplo n.º 8
0
	pdh_error ThreadedSafePDH::PdhGetFormattedCounterValue(PDH_HCOUNTER hCounter, DWORD dwFormat, LPDWORD lpdwType, PPDH_FMT_COUNTERVALUE pValue) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhGetFormattedCounterValue");
		if (pPdhGetFormattedCounterValue == NULL)
			throw pdh_exception("Failed to initialize PdhGetFormattedCounterValue :(");
		return pdh_error(pPdhGetFormattedCounterValue(hCounter, dwFormat, lpdwType, pValue));
	}
Ejemplo n.º 9
0
	pdh_error ThreadedSafePDH::PdhGetCounterInfo(PDH::PDH_HCOUNTER hCounter, BOOLEAN bRetrieveExplainText, LPDWORD pdwBufferSize, PDH_COUNTER_INFO *lpBuffer) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhGetCounterInfo");
		if (pPdhGetCounterInfo == NULL)
			throw pdh_exception("Failed to initialize PdhGetCounterInfo :(");
		return pdh_error(pPdhGetCounterInfo(hCounter,bRetrieveExplainText,pdwBufferSize,lpBuffer));
	}
Ejemplo n.º 10
0
		virtual PDHError PdhCloseQuery(PDH_HQUERY hQuery) {
			boost::unique_lock<boost::shared_mutex> lock(mutex_);
			if (!lock.owns_lock())
				throw pdh_exception("Failed to get mutex for PdhCloseQuery");
			if (pPdhCloseQuery == NULL)
				throw pdh_exception("Failed to initialize PdhCloseQuery :(");
			return PDH::PDHError(pPdhCloseQuery(hQuery));
		}
Ejemplo n.º 11
0
	pdh_error ThreadedSafePDH::PdhLookupPerfIndexByName(LPCTSTR szMachineName,LPCTSTR szName,DWORD *dwIndex) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhLookupPerfIndexByName");
		if (pPdhLookupPerfIndexByName == NULL)
			throw pdh_exception("Failed to initialize PdhLookupPerfIndexByName");
		return pdh_error(pPdhLookupPerfIndexByName(szMachineName,szName,dwIndex));
	}
Ejemplo n.º 12
0
	pdh_error ThreadedSafePDH::PdhCollectQueryData(PDH_HQUERY hQuery) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhCollectQueryData");
		if (pPdhCollectQueryData == NULL)
			throw pdh_exception("Failed to initialize PdhCollectQueryData :(");
		return pdh_error(pPdhCollectQueryData(hQuery));
	}
Ejemplo n.º 13
0
counter_info PDHCounter::getCounterInfo(BOOL bExplainText) {
    if (hCounter_ == NULL)
        throw pdh_exception("Counter is null!");
    BYTE *lpBuffer = new BYTE[1025];
    DWORD bufSize = 1024;
    pdh_error status = factory::get_impl()->PdhGetCounterInfo(hCounter_, bExplainText, &bufSize, (PDH_COUNTER_INFO*)lpBuffer);
    if (status.is_error())
        throw pdh_exception(getName() + " getCounterInfo failed (no query)", status);
    return counter_info(lpBuffer, bufSize, TRUE);
}
Ejemplo n.º 14
0
	pdh_error ThreadedSafePDH::PdhValidatePath(LPCWSTR szFullPathBuffer, bool force_reload) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for PdhValidatePath");
		if (pPdhValidatePath == NULL)
			throw pdh_exception("Failed to initialize PdhValidatePath :(");
		pdh_error status = pdh_error(pPdhValidatePath(szFullPathBuffer));
		if (status.is_error() && force_reload) {
			reload_unsafe();
			status = pdh_error(pPdhValidatePath(szFullPathBuffer));
		}
		return status;
	}
Ejemplo n.º 15
0
		void close() {
			if (hQuery_ == NULL)
				throw pdh_exception("query is null!");
			PDH::PDHFactory::get_impl()->remove_listener(this);
			on_unload();
			counters_.clear();
		}
Ejemplo n.º 16
0
void PDHCounter::remove() {
    if (hCounter_ == NULL)
        return;
    pdh_error status = factory::get_impl()->PdhRemoveCounter(hCounter_);
    if (status.is_error())
        throw pdh_exception(getName() + " PdhRemoveCounter failed", status);
    hCounter_ = NULL;
}
Ejemplo n.º 17
0
void PDHCounter::addToQuery(PDH::PDH_HQUERY hQuery) {
    if (hQuery == NULL)
        throw pdh_exception(getName(), "addToQuery failed (no query).");
    if (hCounter_ != NULL)
        throw pdh_exception(getName(), "addToQuery failed (already opened).");
    pdh_error status = factory::get_impl()->PdhAddCounter(hQuery, utf8::cvt<std::wstring>(counter_->get_counter()).c_str(), 0, &hCounter_);
    if (status.is_not_found()) {
        hCounter_ = NULL;
        status = factory::get_impl()->PdhAddEnglishCounter(hQuery, utf8::cvt<std::wstring>(counter_->get_counter()).c_str(), 0, &hCounter_);
    }
    if (status.is_error()) {
        hCounter_ = NULL;
        throw pdh_exception(getName() + " PdhAddCounter failed", status);
    }
    if (hCounter_ == NULL)
        throw pdh_exception("Counter is null!");
}
Ejemplo n.º 18
0
		void gatherData() {
			collect();
			for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) {
				PDH::PDHError status = (*it)->collect();
				if (status.is_negative_denominator()) {
					Sleep(500);
					collect();
					status = (*it)->collect();
				}
				if (status.is_negative_denominator()) {
					if (!hasDisplayedInvalidCOunter_) {
						hasDisplayedInvalidCOunter_ = true;
						throw pdh_exception((*it)->getName(), "Negative denominator issue (check FAQ for ways to solve this): ", status);
					}
				} else if (status.is_error()) {
					throw pdh_exception((*it)->getName(), "Failed to poll counter", status);
				}
			}
		}
Ejemplo n.º 19
0
		virtual void on_reload() {
			if (hQuery_ != NULL)
				return;
			PDH::PDHError status = PDH::PDHFactory::get_impl()->PdhOpenQuery( NULL, 0, &hQuery_ );
			if (status.is_error())
				throw pdh_exception("PdhOpenQuery failed", status);
			for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) {
				(*it)->addToQuery(getQueryHandle());
			}
		}
Ejemplo n.º 20
0
		virtual void on_unload() {
			if (hQuery_ == NULL)
				return;
			for (CounterList::iterator it = counters_.begin(); it != counters_.end(); it++) {
				(*it)->remove();
			}
			PDH::PDHError status = PDH::PDHFactory::get_impl()->PdhCloseQuery(hQuery_);
			if (status.is_error())
				throw pdh_exception("PdhCloseQuery failed", status);
			hQuery_ = NULL;
		}
Ejemplo n.º 21
0
	void ThreadedSafePDH::remove_listener(subscriber* sub) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for reload");
		for(subscriber_list::iterator it = subscribers_.begin(); it != subscribers_.end(); ++it) {
			if ( (*it) == sub)
				it = subscribers_.erase(it);
			if (it == subscribers_.end())
				break;
		}
	}
Ejemplo n.º 22
0
		inline void collect() {
			PDH::PDHError status = PDH::PDHFactory::get_impl()->PdhCollectQueryData(hQuery_);
			if (status.is_error())
				throw pdh_exception("PdhCollectQueryData failed: ", status);
		}
Ejemplo n.º 23
0
		virtual void add_listener(PDHImplSubscriber* sub) {
			boost::unique_lock<boost::shared_mutex> lock(mutex_);
			if (!lock.owns_lock())
				throw pdh_exception("Failed to get mutex for reload");
			subscribers_.push_back(sub);
		}
Ejemplo n.º 24
0
		void open() {
			if (hQuery_ != NULL)
				throw pdh_exception("query is not null!");
			PDH::PDHFactory::get_impl()->add_listener(this);
			on_reload();
		}
Ejemplo n.º 25
0
	bool ThreadedSafePDH::reload() {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for reload");
		return reload_unsafe();
	}
Ejemplo n.º 26
0
	void ThreadedSafePDH::add_listener(subscriber* sub) {
		boost::unique_lock<boost::shared_mutex> lock(mutex_);
		if (!lock.owns_lock())
			throw pdh_exception("Failed to get mutex for reload");
		subscribers_.push_back(sub);
	}