CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ConsumerMonitorCollection.cc
Go to the documentation of this file.
1 // $Id: ConsumerMonitorCollection.cc,v 1.12 2011/03/07 15:31:32 mommsen Exp $
3 
7 
8 
9 namespace stor {
10 
12  (
13  const utils::Duration_t& updateInterval,
14  const utils::Duration_t& recentDuration
15  ):
16  MonitorCollection(updateInterval),
17  updateInterval_(updateInterval),
18  recentDuration_(recentDuration),
19  totalQueuedMQ_(updateInterval, recentDuration),
20  totalDroppedMQ_(updateInterval, recentDuration),
21  totalServedMQ_(updateInterval, recentDuration)
22  {}
23 
24 
26  (
27  const QueueID& qid,
28  const unsigned int& data_size
29  )
30  {
31  boost::mutex::scoped_lock l( mutex_ );
32  addEventSampleToMap(qid, data_size, qmap_);
33  totalQueuedMQ_.addSample(data_size);
34  }
35 
36 
38  (
39  const QueueID& qid,
40  const size_t& count
41  )
42  {
43  boost::mutex::scoped_lock l( mutex_ );
44  addEventSampleToMap(qid, count, dmap_);
45  totalDroppedMQ_.addSample(count);
46  }
47 
48 
50  (
51  const QueueID& qid,
52  const unsigned int& data_size
53  )
54  {
55  boost::mutex::scoped_lock l( mutex_ );
56  addEventSampleToMap(qid, data_size, smap_);
57  totalServedMQ_.addSample(data_size);
58  }
59 
60 
62  (
63  const QueueID& qid,
64  const unsigned int& data_size,
66  )
67  {
68  ConsStatMap::iterator pos = map.lower_bound(qid);
69 
70  // 05-Oct-2009, KAB - added a test of whether qid appears before pos->first
71  // in the map sort order. Since lower_bound can return a non-end iterator
72  // even when qid is not in the map, we need to complete the test of whether
73  // qid is in the map. (Another way to look at this is we need to implement
74  // the full test described in the efficientAddOrUpdates pattern suggested
75  // by Item 24 of 'Effective STL' by Scott Meyers.)
76  if (pos == map.end() || (map.key_comp()(qid, pos->first)))
77  {
78  // The key does not exist in the map, add it to the map
79  // Use pos as a hint to insert, so it can avoid another lookup
80  pos = map.insert(pos,
83  new MonitoredQuantity(updateInterval_, recentDuration_)
84  )
85  )
86  );
87  }
88 
89  pos->second->addSample( data_size );
90  }
91 
92 
94  (
95  const QueueID& qid,
97  ) const
98  {
99  boost::mutex::scoped_lock l( mutex_ );
100  return getValueFromMap( qid, result, qmap_ );
101  }
102 
103 
105  (
106  const QueueID& qid,
108  ) const
109  {
110  boost::mutex::scoped_lock l( mutex_ );
111  return getValueFromMap( qid, result, smap_ );
112  }
113 
114 
116  (
117  const QueueID& qid,
119  ) const
120  {
121  boost::mutex::scoped_lock l( mutex_ );
122  return getValueFromMap( qid, result, dmap_ );
123  }
124 
126  (
127  const QueueID& qid,
128  MonitoredQuantity::Stats& result,
129  const ConsStatMap& map
130  ) const
131  {
132  ConsStatMap::const_iterator pos = map.find(qid);
133 
134  if (pos == map.end()) return false;
135 
136  pos->second->getStats( result );
137  return true;
138  }
139 
140 
142  {
143  totalQueuedMQ_.getStats(totalStats.queuedStats);
145  totalServedMQ_.getStats(totalStats.servedStats);
146  }
147 
149  {
150  boost::mutex::scoped_lock l( mutex_ );
151  for( ConsStatMap::iterator i = qmap_.begin(); i != qmap_.end(); ++i )
152  i->second->reset();
153  for( ConsStatMap::iterator i = smap_.begin(); i != smap_.end(); ++i )
154  i->second->reset();
155  for( ConsStatMap::iterator i = dmap_.begin(); i != dmap_.end(); ++i )
156  i->second->reset();
157 
161  }
162 
163 
165  {
166  boost::mutex::scoped_lock l( mutex_ );
167  for( ConsStatMap::iterator i = qmap_.begin(); i != qmap_.end(); ++i )
168  i->second->calculateStatistics();
169  for( ConsStatMap::iterator i = smap_.begin(); i != smap_.end(); ++i )
170  i->second->calculateStatistics();
171  for( ConsStatMap::iterator i = dmap_.begin(); i != dmap_.end(); ++i )
172  i->second->calculateStatistics();
173 
177  }
178 
179 
181  {
182  boost::mutex::scoped_lock l( mutex_ );
183  qmap_.clear();
184  smap_.clear();
185  dmap_.clear();
186 
190  }
191 
192 } // namespace stor
193 
void addQueuedEventSample(const QueueID &, const unsigned int &data_size)
int i
Definition: DBlmapReader.cc:9
bool getServed(const QueueID &qid, MonitoredQuantity::Stats &result) const
boost::shared_ptr< MonitoredQuantity > MonitoredQuantityPtr
bool getDropped(const QueueID &qid, MonitoredQuantity::Stats &result) const
void getStats(Stats &stats) const
void addEventSampleToMap(const QueueID &, const unsigned int &data_size, ConsStatMap &)
void calculateStatistics(const utils::TimePoint_t &currentTime=utils::getCurrentTime())
boost::posix_time::time_duration Duration_t
Definition: Utils.h:41
void addDroppedEvents(const QueueID &, const size_t &count)
std::map< QueueID, MonitoredQuantityPtr > ConsStatMap
tuple result
Definition: query.py:137
ConsumerMonitorCollection(const utils::Duration_t &updateInterval, const utils::Duration_t &recentDuration)
Container::value_type value_type
bool getQueued(const QueueID &qid, MonitoredQuantity::Stats &result) const
void addServedEventSample(const QueueID &, const unsigned int &data_size)
bool getValueFromMap(const QueueID &, MonitoredQuantity::Stats &, const ConsStatMap &) const