00001 //////////////////////////////////////////////////////////////////////////////// 00002 /// 00003 /// \file 00004 /// \author Gerald Fahrnholz 00005 /// 00006 /// \defgroup GrpPerformanceDataSet Using PerformanceDataSet 00007 /// @{ 00008 /// \ingroup GrpTestUtils 00009 /// \brief 00010 /// Class PerformanceDataSet allows easy access to performance counter values. 00011 /// 00012 /// \n This file was originally retrieved from MSDN (q194655) 00013 /// as rkLeak.h/cpp and adjusted for test purposes. 00014 /// 00015 /// The code assumes the existence of PDH.DLL on the system. 00016 /// If not available define NO_PDH_DLL to suppress this part of code. 00017 /// 00018 /// <b>Usage:</b>\n 00019 /// \code 00020 /// 00021 ///.// Define counters to check 00022 ///.// (assuming Windows XP with German language pack, and a computer named SIRIUS) 00023 /// std::vector<std::string> counterNames; 00024 /// counterNames.push_back("\\\\SIRIUS\\Prozessor(0)\\Prozessorzeit (%)"); 00025 /// counterNames.push_back("\\\\SIRIUS\\Prozess(notepad)\\Threadanzahl"); 00026 /// counterNames.push_back("\\\\SIRIUS\\Prozess(TestPerformanceDataSet)\\Private Bytes"); 00027 /// 00028 ///.// Prepare access to counter names (may fail in case of invalid names) 00029 /// TTB::PerformanceDataSet perfDataSet; 00030 /// perfDataSet.InitPerfCounters (m_counterNames); 00031 /// 00032 ///.// Access current counter values 00033 /// std::vector<double> counterValues =perfDataSet.GetCurrentCounterValues(); 00034 /// \endcode 00035 /// 00036 /// \sa PerformanceDataSet.h (File documentation) 00037 /// \sa TestToolBox::PerformanceDataSet (class documentation) 00038 /// \sa GrpTestPerformanceDataSet (unit test for class PerformanceDataSet) 00039 /// 00040 //////////////////////////////////////////////////////////////////////////////// 00041 00042 #pragma once 00043 00044 //************************************************************************ 00045 // P r e c o m p i l e r I n c l u d e D i r e c t i v e s 00046 //************************************************************************ 00047 00048 #include <vector> 00049 #include <pdh.h> 00050 00051 // PDH.DLL may not be available for the target system 00052 #ifndef NO_PDH_DLL 00053 00054 // link to library for accessing performance counters 00055 #pragma comment(lib, "pdh.lib") 00056 00057 #endif 00058 00059 #pragma warning(disable: 4511) // copy constructor could not be generated 00060 #pragma warning(disable: 4512) // assignment operator could not be generated 00061 00062 namespace TestToolBox 00063 { 00064 00065 /// vector of counter names to check 00066 typedef std::vector<std::string> PerfCounterNames; 00067 00068 /// vector of returned counter values 00069 typedef std::vector<double> PerfCounterValues; 00070 00071 /// \brief Class wrapping access to performance counters via PDH.DLL. 00072 /// For more info about usage see \ref GrpPerformanceDataSet. 00073 class PerformanceDataSet 00074 { 00075 public: 00076 ///\cond do not document 00077 00078 /// Constructor 00079 explicit PerformanceDataSet(void); 00080 00081 /// Destructor 00082 virtual ~PerformanceDataSet(); 00083 ///\endcond 00084 00085 /// \brief Initialize all counter names and try to register them 00086 /// If something went wrong return false. 00087 bool InitPerfCounters (PerfCounterNames in_counterNames); 00088 00089 /// Get the current values for all counters defined by InitPerfCounters 00090 PerfCounterValues GetCurrentCounterValues (void); 00091 00092 00093 protected: 00094 00095 00096 /// Handle to the query for performance data 00097 HQUERY m_hQuery; 00098 00099 /// Pointer to array of counter handles 00100 HCOUNTER* m_phCounter; 00101 00102 /// Vector of performance counter names 00103 PerfCounterNames m_perfCounterFullNames; 00104 00105 /// Flag indicating if the initialization has failed 00106 bool m_initFailed; 00107 00108 }; // end class PerformanceDataSet 00109 00110 }; // namespace TestUtil 00111 00112 #pragma warning(default: 4511) // copy constructor could not be generated 00113 #pragma warning(default: 4512) // assignment operator could not be generated 00114 00115 ///@} // end group GrpPerformanceDataSet