PageRenderTime 591ms CodeModel.GetById 309ms app.highlight 3ms RepoModel.GetById 194ms app.codeStats 0ms

/Util/Instrumentation.h

http://unladen-swallow.googlecode.com/
C++ Header | 48 lines | 26 code | 8 blank | 14 comment | 0 complexity | 17527fe35ae3afadb4343ffabba71a14 MD5 | raw file
 1// -*- C++ -*-
 2#ifndef UTIL_INSTRUMENTATION_H_
 3#define UTIL_INSTRUMENTATION_H_
 4
 5#ifdef Py_WITH_INSTRUMENTATION
 6
 7#include "llvm/Support/raw_ostream.h"
 8
 9using llvm::errs;
10
11// C++ requires template parameters to have external linkage.
12// Global const char[] default to static, so we have to force it.
13//
14// eg.
15// extern const char name[], shortname[];
16// const char name[] = "SomeName";
17// const char shortname = "Name";
18//
19// OpStats<name, shortname> FooStats;
20
21template<const char* full_name, const char* short_name>
22class OpStats {
23public:
24    OpStats()
25        : total(0), optimized(0), unpredictable(0), omitted(0) {
26    }
27
28    ~OpStats() {
29        errs() << "\n" << full_name << " inlining:\n";
30        errs() << "Total " << short_name << ": " << this->total << "\n";
31        errs() << "Optimized " << short_name << ": " << this->optimized << "\n";
32        errs() << "Unpredictable types: " << this->unpredictable << "\n";
33        errs() << short_name << " without inline version: " <<
34            this->omitted << "\n";
35    }
36
37    // Total number of binary opcodes compiled.
38    unsigned total;
39    // Number of opcodes inlined.
40    unsigned optimized;
41    // Number of opcodes with unpredictable types.
42    unsigned unpredictable;
43    // Number of opcodes without inline-able functions.
44    unsigned omitted;
45};
46
47#endif /* Py_WITH_INSTRUMENTATION */
48#endif /* UTIL_INSTRUMENTATION_H_ */