Go to the documentation of this file.00001
00002
00003 #include "ace/Monitor_Control/Windows_Monitor.h"
00004
00005 #if defined (ACE_HAS_WIN32_PDH)
00006
00007 #include "ace/Log_Msg.h"
00008
00009 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
00010
00011 namespace ACE
00012 {
00013 namespace Monitor_Control
00014 {
00015 Windows_Monitor::Windows_Monitor (const ACE_TCHAR *path)
00016 : value_ (0.0)
00017 , path_ (path)
00018 , query_ (0)
00019 , counter_ (0)
00020 , status_ (ERROR_SUCCESS)
00021 {
00022 this->init ();
00023 }
00024
00025 void
00026 Windows_Monitor::update_i (void)
00027 {
00028 PdhCollectQueryData (this->query_);
00029 PDH_FMT_COUNTERVALUE pdh_value;
00030
00031 PdhGetFormattedCounterValue (this->counter_,
00032 PDH_FMT_DOUBLE,
00033 0,
00034 &pdh_value);
00035
00036 this->value_ = pdh_value.doubleValue;
00037 }
00038
00039 void
00040 Windows_Monitor::clear_impl (void)
00041 {
00042 this->init ();
00043 }
00044
00045 void
00046 Windows_Monitor::init (void)
00047 {
00048
00049
00050
00051 this->status_ = ACE_TEXT_PdhOpenQuery (0, 0, &this->query_);
00052
00053 if (ERROR_SUCCESS != this->status_)
00054 {
00055 ACE_ERROR ((LM_DEBUG, ACE_TEXT ("PdhOpenQuery failed\n")));
00056 }
00057
00058 this->status_ =
00059 ACE_TEXT_PdhAddCounter (this->query_,
00060 this->path_.c_str (),
00061 0,
00062 &this->counter_);
00063
00064 if (ERROR_SUCCESS != this->status_)
00065 {
00066 ACE_ERROR ((LM_DEBUG,
00067 ACE_TEXT ("PdhAddCounter %s failed\n"),
00068 this->path_.c_str ()));
00069 }
00070 }
00071 }
00072 }
00073
00074 ACE_END_VERSIONED_NAMESPACE_DECL
00075
00076 #endif