3 // $Id: Metrics_Cache_T.inl 80826 2008-03-04 14:51:23Z wotte $
5 #ifndef ACE_METRICS_CACHE_T_INL
6 #define ACE_METRICS_CACHE_T_INL
8 ACE_BEGIN_VERSIONED_NAMESPACE_DECL
10 /////////////////////////////
11 // Class ACE_Metrics_Cache //
12 /////////////////////////////
15 template <class ACE_LOCK, class ALLOCATOR>
17 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_enqueue_start (u_long i)
19 if (i < this->probe_set_size_)
22 this->enqueue_count_ [this->supplier_index_] [i];
25 if (! this->interval_initialized_)
27 this->interval_initialized_ = 1;
28 ACE_hrtime_t hrtime_now = ACE_OS::gethrtime ();
29 ACE_High_Res_Timer::hrtime_to_tv (this->interval_start_,
31 this->interval_end_.set (this->interval_start_.sec(),
32 this->interval_start_.usec());
35 // Take the metrics timeprobe last, to avoid measuring the above
36 // metrics processing.
37 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
38 this->enqueue_probes_ [this->supplier_index_][i];
40 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_START);
45 template <class ACE_LOCK, class ALLOCATOR>
47 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_enqueue_stop (u_long i)
49 if (i < this->probe_set_size_)
51 // Take the metrics timeprobe first, to avoid measuring the below
52 // metrics processing.
53 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
54 this->enqueue_probes_ [this->supplier_index_][i];
56 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_STOP);
58 ACE_hrtime_t hrtime_now = ACE_OS::gethrtime ();
59 ACE_High_Res_Timer::hrtime_to_tv (this->interval_end_,
62 u_long & count = enqueue_count_ [this->supplier_index_][i];
69 template <class ACE_LOCK, class ALLOCATOR>
71 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_enqueue_suspend (u_long i)
73 if (i < this->probe_set_size_)
75 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
76 this->enqueue_probes_ [this->supplier_index_][i];
78 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_SUSPEND);
80 this->enqueue_count_ [this->supplier_index_] [i];
86 template <class ACE_LOCK, class ALLOCATOR>
88 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_enqueue_resume (u_long i)
90 if (i < this->probe_set_size_)
93 this->enqueue_count_ [this->supplier_index_] [i];
95 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
96 this->enqueue_probes_ [this->supplier_index_][i];
98 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_RESUME);
103 template <class ACE_LOCK, class ALLOCATOR>
105 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_dequeue_start (u_long i)
107 if (i < this->probe_set_size_)
110 this->dequeue_count_ [this->supplier_index_] [i];
113 if (! this->interval_initialized_)
115 this->interval_initialized_ = 1;
116 ACE_hrtime_t hrtime_now = ACE_OS::gethrtime ();
117 ACE_High_Res_Timer::hrtime_to_tv (this->interval_start_,
119 this->interval_end_.set (this->interval_start_.sec(),
120 this->interval_start_.usec());
123 // Take the metrics timeprobe last, to avoid measuring the above
124 // metrics processing.
125 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
126 this->dequeue_probes_ [this->supplier_index_][i];
128 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_START);
133 template <class ACE_LOCK, class ALLOCATOR>
135 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_dequeue_stop (u_long i)
137 if (i < this->probe_set_size_)
139 // Take the metrics timeprobe first, to avoid measuring the
140 // metrics processing below.
141 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
142 this->dequeue_probes_ [this->supplier_index_][i];
144 probe->timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_STOP);
146 ACE_hrtime_t hrtime_now = ACE_OS::gethrtime ();
147 ACE_High_Res_Timer::hrtime_to_tv (this->interval_end_,
150 u_long & count = dequeue_count_ [this->supplier_index_] [i];
156 template <class ACE_LOCK, class ALLOCATOR>
158 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_dequeue_suspend (u_long i)
160 if (i < this->probe_set_size_)
163 this->dequeue_count_ [this->supplier_index_] [i];
165 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
166 this->dequeue_probes_ [this->supplier_index_][i];
168 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_SUSPEND);
173 template <class ACE_LOCK, class ALLOCATOR>
175 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::report_dequeue_resume (u_long i)
177 if (i < this->probe_set_size_)
180 this->dequeue_count_ [this->supplier_index_] [i];
182 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
183 this->dequeue_probes_ [this->supplier_index_][i];
185 timeprobe (ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR>::WORK_RESUME);
190 template <class ACE_LOCK, class ALLOCATOR>
192 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::reset_base_statistics ()
194 this->interval_initialized_ = 0;
195 this->interval_start_.set (0, 0);
196 this->interval_end_.set (0, 0);
198 for (u_int i = 0; i < this->probe_set_size_; ++i)
200 this->enqueue_count_ [this->consumer_index_] [i] = 0;
201 this->dequeue_count_ [this->consumer_index_] [i] = 0;
203 ACE_Metrics_Timeprobe<ACE_LOCK, ALLOCATOR> * probe =
204 this->enqueue_probes_ [this->consumer_index_][i];
207 this->dequeue_probes_ [this->consumer_index_][i];
213 // Flips the supplier and consumer positions.
215 template <class ACE_LOCK, class ALLOCATOR>
217 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::flip_supplier_and_consumer ()
219 int temp = consumer_index_;
220 consumer_index_ = supplier_index_;
221 supplier_index_ = temp;
224 template <class ACE_LOCK, class ALLOCATOR>
226 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::metrics_enabled(int enabled)
228 metrics_enabled_ = enabled;
231 template <class ACE_LOCK, class ALLOCATOR>
233 ACE_Metrics_Cache<ACE_LOCK, ALLOCATOR>::metrics_enabled(void) const
235 return metrics_enabled_;
238 ACE_END_VERSIONED_NAMESPACE_DECL
240 #endif /* ACE_METRICS_CACHE_T_INL */