Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
periodic-counter-updater.h
Go to the documentation of this file.
1 // Copyright 2012 Cloudera Inc.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 
16 #ifndef IMPALA_UTIL_PERIODIC_COUNTER_UPDATER_H
17 #define IMPALA_UTIL_PERIODIC_COUNTER_UPDATER_H
18 
19 #include <boost/function.hpp>
20 #include <boost/scoped_ptr.hpp>
21 #include <boost/thread/mutex.hpp>
22 #include <boost/thread/thread.hpp>
23 #include <boost/unordered_map.hpp>
24 #include <boost/unordered_set.hpp>
25 
26 #include "util/runtime-profile.h"
27 
28 namespace impala {
29 
38  public:
42  };
43 
46 
52  static void RegisterPeriodicCounter(RuntimeProfile::Counter* src_counter,
54  RuntimeProfile::Counter* dst_counter, PeriodicCounterType type);
55 
57  static void RegisterBucketingCounters(RuntimeProfile::Counter* src_counter,
58  std::vector<RuntimeProfile::Counter*>* buckets);
59 
62 
64  static void StopRateCounter(RuntimeProfile::Counter* counter);
65 
67  static void StopSamplingCounter(RuntimeProfile::Counter* counter);
68 
73  static void StopBucketingCounters(std::vector<RuntimeProfile::Counter*>* buckets,
74  bool convert);
75 
78 
79  private:
80  struct RateCounterInfo {
83  int64_t elapsed_ms;
84  };
85 
87  RuntimeProfile::Counter* src_counter; // the counter to be sampled
89  int64_t total_sampled_value; // sum of all sampled values;
90  int64_t num_sampled; // number of samples taken
91  };
92 
94  RuntimeProfile::Counter* src_counter; // the counter to be sampled
95  int64_t num_sampled; // number of samples taken
97  };
98 
100 
103  void UpdateLoop();
104 
106  boost::scoped_ptr<boost::thread> update_thread_;
107 
110 
112  typedef boost::unordered_map<RuntimeProfile::Counter*, RateCounterInfo> RateCounterMap;
114 
117 
120  typedef boost::unordered_map<RuntimeProfile::Counter*, SamplingCounterInfo>
123 
126 
128  typedef boost::unordered_map<std::vector<RuntimeProfile::Counter*>*, BucketCountersInfo>
131 
134 
136  typedef boost::unordered_set<RuntimeProfile::TimeSeriesCounter*> TimeSeriesCounters;
138 
141 
145 };
146 
147 }
148 
149 #endif
boost::scoped_ptr< boost::thread > update_thread_
Thread performing asynchronous updates.
static void RegisterTimeSeriesCounter(RuntimeProfile::TimeSeriesCounter *counter)
Adds counter to be sampled and updated at regular intervals.
~PeriodicCounterUpdater()
Tears down the update thread.
AtomicInt< uint32_t > done_
If 1, tear down the update thread.
static void RegisterPeriodicCounter(RuntimeProfile::Counter *src_counter, RuntimeProfile::DerivedCounterFunction sample_fn, RuntimeProfile::Counter *dst_counter, PeriodicCounterType type)
boost::function< int64_t()> DerivedCounterFunction
Lightweight spinlock.
Definition: spinlock.h:24
boost::unordered_map< std::vector< RuntimeProfile::Counter * > *, BucketCountersInfo > BucketCountersMap
Map from a bucket of counters to the src counter.
RuntimeProfile::DerivedCounterFunction sample_fn
SpinLock rate_lock_
Spinlock that protects the map of rate counters.
static void StopBucketingCounters(std::vector< RuntimeProfile::Counter * > *buckets, bool convert)
boost::unordered_map< RuntimeProfile::Counter *, RateCounterInfo > RateCounterMap
A map of the dst (rate) counter to the src counter and elapsed time.
static void StopRateCounter(RuntimeProfile::Counter *counter)
Stops updating the value of 'counter'.
SpinLock sampling_lock_
Spinlock that protects the map of averages over samples of counters.
static void RegisterBucketingCounters(RuntimeProfile::Counter *src_counter, std::vector< RuntimeProfile::Counter * > *buckets)
Adds a bucketing counter to be updated at regular intervals.
SpinLock bucketing_lock_
Spinlock that protects the map of buckets of counters.
static PeriodicCounterUpdater state_
boost::unordered_set< RuntimeProfile::TimeSeriesCounter * > TimeSeriesCounters
Set of time series counters that need to be updated.
static void StopSamplingCounter(RuntimeProfile::Counter *counter)
Stops updating the value of 'counter'.
SpinLock time_series_lock_
Spinlock that protects the map of time series counters.
boost::unordered_map< RuntimeProfile::Counter *, SamplingCounterInfo > SamplingCounterMap
static void StopTimeSeriesCounter(RuntimeProfile::TimeSeriesCounter *counter)
Stops 'counter' from receiving any more samples.