blob: 7d3b68d5c0e031e35b06fb460b00416d14f83128 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
#include "ace/Monitor_Control/Windows_Multi_Instance_Monitor.h"
#if defined (ACE_HAS_WIN32_PDH)
#include "ace/Log_Category.h"
#include "ace/SString.h"
#include "ace/os_include/os_pdhmsg.h"
ACE_BEGIN_VERSIONED_NAMESPACE_DECL
namespace ACE
{
namespace Monitor_Control
{
Windows_Multi_Instance_Monitor::Windows_Multi_Instance_Monitor (
const ACE_TCHAR *wildcard_path)
: value_ (0.0)
, instances_ (0)
, n_instances_ (0)
, status_ (ERROR_SUCCESS)
{
/// Create a string which is a concatentation of the path
/// name of each 'instance' we need to monitor.
DWORD paths_size = 4096;
ACE_LPSTR paths = (ACE_LPSTR) GlobalAlloc (GPTR, paths_size);
this->status_ = ACE_TEXT_PdhExpandCounterPath (wildcard_path,
paths,
&paths_size);
if (PDH_MORE_DATA == static_cast<DWORD> (this->status_))
{
++paths_size;
GlobalFree (paths);
paths = (ACE_LPSTR) GlobalAlloc (GPTR, paths_size);
this->status_ = ACE_TEXT_PdhExpandCounterPath (wildcard_path,
paths,
&paths_size);
}
if (PDH_CSTATUS_VALID_DATA != static_cast<DWORD> (this->status_))
{
ACELIB_ERROR ((LM_ERROR,
ACE_TEXT ("%s: PdhExpandCounterPath failed\n"),
wildcard_path));
}
ACE_LPSTR path = paths;
/// Create a regular Windows monitor for each path name.
while (*path != 0)
{
Windows_Monitor *instance = new Windows_Monitor (path);
this->instances_.enqueue_tail (instance);
path += ACE_OS::strlen (path) + 1;
}
GlobalFree (paths);
}
Windows_Multi_Instance_Monitor::~Windows_Multi_Instance_Monitor (void)
{
Windows_Monitor *instance = 0;
/// Destroy the single instance monitors created in the constructor.
while (this->instances_.dequeue_head (instance) == 0)
{
delete instance;
}
}
void
Windows_Multi_Instance_Monitor::update_i (void)
{
Windows_Monitor **current_instance = 0;
/// Sum the values of each single instance monitor.
for (INSTANCES_ITERATOR i (this->instances_); !i.done (); i.advance ())
{
i.next (current_instance);
(*current_instance)->update_i ();
this->value_ += (*current_instance)->value_;
}
}
void
Windows_Multi_Instance_Monitor::clear_impl (void)
{
Windows_Monitor **current_instance = 0;
/// Sum the values of each single instance monitor.
for (INSTANCES_ITERATOR i (this->instances_); !i.done (); i.advance ())
{
i.next (current_instance);
(*current_instance)->clear_impl ();
}
}
}
}
ACE_END_VERSIONED_NAMESPACE_DECL
#endif /* defined (ACE_HAS_WIN32_PDH) */
|