/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. #ifdef Py_WITH_INSTRUMENTATION
  5. #include "llvm/Support/raw_ostream.h"
  6. using llvm::errs;
  7. // C++ requires template parameters to have external linkage.
  8. // Global const char[] default to static, so we have to force it.
  9. //
  10. // eg.
  11. // extern const char name[], shortname[];
  12. // const char name[] = "SomeName";
  13. // const char shortname = "Name";
  14. //
  15. // OpStats<name, shortname> FooStats;
  16. template<const char* full_name, const char* short_name>
  17. class OpStats {
  18. public:
  19. OpStats()
  20. : total(0), optimized(0), unpredictable(0), omitted(0) {
  21. }
  22. ~OpStats() {
  23. errs() << "\n" << full_name << " inlining:\n";
  24. errs() << "Total " << short_name << ": " << this->total << "\n";
  25. errs() << "Optimized " << short_name << ": " << this->optimized << "\n";
  26. errs() << "Unpredictable types: " << this->unpredictable << "\n";
  27. errs() << short_name << " without inline version: " <<
  28. this->omitted << "\n";
  29. }
  30. // Total number of binary opcodes compiled.
  31. unsigned total;
  32. // Number of opcodes inlined.
  33. unsigned optimized;
  34. // Number of opcodes with unpredictable types.
  35. unsigned unpredictable;
  36. // Number of opcodes without inline-able functions.
  37. unsigned omitted;
  38. };
  39. #endif /* Py_WITH_INSTRUMENTATION */
  40. #endif /* UTIL_INSTRUMENTATION_H_ */