Impala
Impalaistheopensource,nativeanalyticdatabaseforApacheHadoop.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
instruction-counter.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 #ifndef IMPALA_CODEGEN_INSTRUCTION_COUNTER_H_
15 #define IMPALA_CODEGEN_INSTRUCTION_COUNTER_H_
16 
17 #include <map>
18 #include <string>
19 #include <sstream>
20 #include <iomanip>
21 #include <algorithm>
22 
23 #include "common/logging.h"
24 #include "base/logging.h"
25 #include "llvm/IR/Instruction.h"
26 #include "llvm/IR/Module.h"
27 #include "llvm/IR/Function.h"
28 
29 namespace impala {
30 
35  public:
37  static const char* TOTAL_INSTS;
38  static const char* TOTAL_BLOCKS;
39  static const char* TOTAL_FUNCTIONS;
40  static const char* TERMINATOR_INSTS;
41  static const char* BINARY_INSTS;
42  static const char* MEMORY_INSTS;
43  static const char* CAST_INSTS;
44  static const char* OTHER_INSTS;
45 
47 
49  void visit(const llvm::Module& M);
50 
52  void visit(const llvm::Function &F);
53 
55  void visit(const llvm::BasicBlock &BB);
56 
59  void visit(const llvm::Instruction &I);
60 
62  void PrintCounter(const char* name, int count, int max_count_len,
63  std::stringstream* stream) const;
64 
66  std::string PrintCounters() const;
67 
69  int GetCount(const char* name);
70 
72  void ResetCount();
73 
74  private:
75  typedef std::map<std::string, int> CounterMap;
76 
78  template<class Iterator>
79  void visit(Iterator start, Iterator end) {
80  while (start != end) {
81  visit(*start++);
82  }
83  }
84 
86  void IncrementCount(const char* name);
87 
90 };
91 
92 } // namespace impala
93 
94 #endif // IMPALA_CODEGEN_INSTRUCTION_COUNTER_H_
static const char * TOTAL_INSTS
String constants for instruction count names.
void visit(Iterator start, Iterator end)
Allows for easy visitation of iterators.
int GetCount(const char *name)
Return count of counter described by name.
void ResetCount()
Set all counts to 0.
static const char * OTHER_INSTS
static const char * CAST_INSTS
static const char * TOTAL_BLOCKS
std::map< std::string, int > CounterMap
void PrintCounter(const char *name, int count, int max_count_len, std::stringstream *stream) const
Prints a single counter described by name and count.
static const char * TERMINATOR_INSTS
std::string PrintCounters() const
Prints all counters.
uint64_t count
void visit(const llvm::Module &M)
Visits each Function in Module M.
static const char * TOTAL_FUNCTIONS
CounterMap counters_
This maps instruction names to their respective count.
string name
Definition: cpu-info.cc:50
static const char * BINARY_INSTS
void IncrementCount(const char *name)
Increment InstructionCount with name_ equal to name argument.
static const char * MEMORY_INSTS