Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
perf-counters.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_PERF_COUNTER_H
17 #define IMPALA_UTIL_PERF_COUNTER_H
18 
19 #include <iostream>
20 #include <string>
21 #include <vector>
22 
23 #include "util/debug-util.h"
24 
32 //
40 
41 namespace impala {
42 
43 class PerfCounters {
44  public:
45  enum Counter {
50 
58 
62 
67  };
68 
72  bool AddDefaultCounters();
73 
76  bool AddCounter(Counter);
77 
80  void Snapshot(const std::string& name = "");
81 
83  const std::vector<int64_t>* counters(int snapshot) const;
84 
86  const std::vector<std::string>* counter_names() const { return &counter_names_; }
87 
89  void PrettyPrint(std::ostream* out) const;
90 
91  PerfCounters();
92  ~PerfCounters();
93 
94  private:
96  PerfCounters(const PerfCounters&);
98 
99  bool InitSysCounter(Counter counter);
100  bool InitProcSelfIOCounter(Counter counter);
101  bool InitProcSelfStatusCounter(Counter counter);
102 
103  bool GetSysCounters(std::vector<int64_t>& snapshot);
104  bool GetProcSelfIOCounters(std::vector<int64_t>& snapshot);
105  bool GetProcSelfStatusCounters(std::vector<int64_t>& snapshot);
106 
107  enum DataSource {
111  };
112 
113  struct CounterData {
116  TUnit::type unit;
117 
119  union {
121  int fd;
124  };
126  std::string proc_status_field;
127  };
128 
129  std::vector<CounterData> counters_;
130  std::vector<std::string> counter_names_;
131  std::vector<std::string> snapshot_names_;
132  std::vector<std::vector<int64_t> > snapshots_;
136 };
137 
138 }
139 
140 #endif
bool InitSysCounter(Counter counter)
std::string proc_status_field
For PROC_SELF_STATUS. Field name for counter.
bool InitProcSelfIOCounter(Counter counter)
bool GetProcSelfIOCounters(std::vector< int64_t > &snapshot)
std::vector< std::vector< int64_t > > snapshots_
void PrettyPrint(std::ostream *out) const
Prints out the names and results for all snapshots to 'out'.
bool InitProcSelfStatusCounter(Counter counter)
bool GetProcSelfStatusCounters(std::vector< int64_t > &snapshot)
int fd
For SYS_PERF_COUNTER. File descriptor where the counter value is stored.
std::vector< std::string > counter_names_
bool GetSysCounters(std::vector< int64_t > &snapshot)
std::vector< std::string > snapshot_names_
int proc_io_line_number
For PROC_SELF_IO. Line number from /proc/self/io file with this counter's value.
void Snapshot(const std::string &name="")
PerfCounters & operator=(const PerfCounters &)
bool AddCounter(Counter)
const std::vector< std::string > * counter_names() const
Returns readable names for the added counters.
Definition: perf-counters.h:86
std::vector< CounterData > counters_
string name
Definition: cpu-info.cc:50
const std::vector< int64_t > * counters(int snapshot) const
Returns the results of that snapshot.