summaryrefslogtreecommitdiff
path: root/ace/Metrics_Cache_T.cpp
blob: 3868df80269a805619a7c59c1decdfd03278caac (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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
// $Id$

#ifndef ACE_METRICS_CACHE_CPP
#define ACE_METRICS_CACHE_CPP

//#define ACE_BUILD_DLL

#include "ace/Metrics_Cache_T.h"

#if defined (ACE_COMPILE_TIMEPROBES)

#include "ace/Metrics_Cache.h"

#if !defined (__ACE_INLINE__)
#include "ace/Metrics_Cache_T.inl"
#endif /* __ACE_INLINE__ */

// Const strings for timeprobe event type descriptions.

static const char * event_description_strings [] =
{
  "start",
  "stop",
  "suspend",
  "resume"
};

ACE_BEGIN_VERSIONED_NAMESPACE_DECL

/////////////////////////////////
// class ACE_Metrics_Timeprobe //
/////////////////////////////////

template <class ACE_LOCK, class ALLOCATOR>
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::ACE_Metrics_Timeprobe (u_int id,
                                                                   const char *name,
                                                                   u_long size)
  :
    ACE_Timeprobe<ACE_LOCK> (size),
    id_ (id),
    name_ (0)
{
  if (name == 0)
    {
      name = "";
    }

  char * name_tmp;
  ACE_NEW_MALLOC_ARRAY (name_tmp,
                        (char *) this->allocator ()->malloc (strlen(name)+1),
                        char,
                        strlen(name)+1);
  ACE_OS::memcpy (name_tmp, name, strlen (name)+1);
  name_ = name_tmp;

  this->event_descriptions (event_description_strings,
                            sizeof(event_description_strings)/sizeof(const char *));
}

template <class ACE_LOCK, class ALLOCATOR>
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
ACE_Metrics_Timeprobe (ALLOCATOR *alloc,
                       u_int id,
                       const char *name,
                       u_long size)
  :
        ACE_Timeprobe_Ex<ACE_LOCK, ALLOCATOR> (size),
                id_ (id),
    name_ (0)
{
  if (name == 0)
    {
      name = "";
    }

  char * name_tmp;
  ACE_NEW_MALLOC_ARRAY (name_tmp,
//                        (char *) this->allocator ()->malloc (strlen(name)+1),
                        (char *) alloc->malloc(strlen(name)+1),
                        char,
                        strlen(name)+1);
  ACE_OS::memcpy (name_tmp, name, strlen (name)+1);
  name_ = name_tmp;

  this->event_descriptions (event_description_strings,
                            sizeof(event_description_strings)/sizeof(const char *));
}

template <class ACE_LOCK, class ALLOCATOR>
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Timeprobe ()
{
   if (name_)
    {
         this->allocator ()->free ((void*) name_);
    }
}


// Returns true if a timeprobe matches the passed id.

template <class ACE_LOCK, class ALLOCATOR>
int
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::is_event (const ACE_Metrics_Timeprobe<ACE_LOCK,
                                                                                                                                      ALLOCATOR>::
                                                                                                            ACE_METRICS_TIMEPROBE_DATA_TYPE &t,
                                                      ACE_Metrics_Timeprobe<ACE_LOCK,
                                                                                                                                ALLOCATOR>::
                                                                                                            event_id id)
{
  return (t.event_.event_number_ ==  (u_long) id) ? 1 : 0;
}

template <class ACE_LOCK, class ALLOCATOR>
const char *
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (void)
{
   return name_;
}

template <class ACE_LOCK, class ALLOCATOR>
void
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_name (char * name)
{
  char * name_tmp;
  ACE_NEW_MALLOC_ARRAY (name_tmp,
                        (char *) this->allocator ()->malloc (strlen(name)+1),
                        char,
                        strlen(name)+1);
  ACE_OS::memcpy (name_tmp, name, strlen (name)+1);

  if (name_)
  {
     this->allocator ()->free (name_);
  }

  name_ = name_tmp;
}

template <class ACE_LOCK, class ALLOCATOR>
u_int
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (void)
{
  return id_;
}


template <class ACE_LOCK, class ALLOCATOR>
void
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::probe_id (u_int id)
{
  id_ = id;
}


// Flush the ACE metrics timeprobe into shared memory.

template <class ACE_LOCK, class ALLOCATOR> void
ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::
flush_ACE_Metrics_Timeprobe ()
{
}


/////////////////////////////
// Class ACE_Metrics_Cache //
/////////////////////////////


// Constructor.

template <class ACE_LOCK, class ALLOCATOR>
ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
ACE_Metrics_Cache (u_long table_size,
                   u_long number_of_probes,
                   ALLOCATOR *alloc)
  : probe_set_size_ (0),
    enqueue_names_ (0),
    dequeue_names_ (0),
    consumer_index_ (0),
    supplier_index_ (1),
    table_size_ (table_size),
    interval_start_ (ACE_Time_Value::zero),
    interval_end_ (ACE_Time_Value::zero),
    interval_initialized_ (0),
    metrics_enabled_(1),
    allocator_ (alloc)
{
  ACE_UNUSED_ARG(number_of_probes);
  // Initialize probe and count arrays.

  // Ensure that the high res timer global scale factor
  // is set before any of its static methods are used
  ACE_High_Res_Timer::global_scale_factor ();

  enqueue_count_ [0] = 0;
  enqueue_count_ [1] = 0;
  dequeue_count_ [0] = 0;
  dequeue_count_ [1] = 0;
  enqueue_probes_ [0] = 0;
  enqueue_probes_ [1] = 0;
  dequeue_probes_ [0] = 0;
  dequeue_probes_ [1] = 0;
}

// Destructor.

template <class ACE_LOCK, class ALLOCATOR>
ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::~ACE_Metrics_Cache ()
{
}


// Obtain an allocator pointer correctly thunked for the current
// address space.  If there is no allocator stored in the instance,
// the singleton allocator in the current process is used.

template <class ACE_LOCK, class ALLOCATOR> ALLOCATOR *
ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::allocator (void)
{
  ALLOCATOR * alloc = allocator_;
  return alloc
         ? alloc
         : ACE_Singleton<ALLOCATOR, ACE_LOCK>::instance ();
}


// Flush the ACE metrics cache into shared memory.

template <class ACE_LOCK, class ALLOCATOR> void
ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::
flush_ACE_Metrics_Cache ()
{
}

ACE_END_VERSIONED_NAMESPACE_DECL

#endif /* defined (ACE_COMPILE_TIMEPROBES) */

#endif /* ACE_METRICS_CACHE_CPP */