CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
ProfilingTools.cc
Go to the documentation of this file.
1 #include "../interface/ProfilingTools.h"
2 
3 // we try to stick to pure C within the signal handlers
4 #include <stdio.h>
5 #include <dlfcn.h>
6 #include <signal.h>
7 #include <sys/types.h>
8 #include <unistd.h>
9 
10 #include <boost/unordered_map.hpp>
11 
12 void (*igProfRequestDump_)(const char *);
14 
15 void igProfDumpNow(int) {
16  char buff[50];
18  sprintf(buff,"dump.%d.%d.out.gz", getpid(), igProfDumpNumber_);
19  igProfRequestDump_(buff);
20  fprintf(stderr, "Dumped to %s\n", buff); fflush(stderr);
21 }
22 
24  if (void *sym = dlsym(0, "igprof_dump_now")) {
25  igProfRequestDump_ = __extension__ (void(*)(const char *)) sym;
26  fprintf(stderr, "IgProf dump hook enabled. Do kill -USR2 %d to request a dump.\n", int(getpid())); fflush(stderr);
27  } else {
28  fprintf(stderr, "Not being profiled by IgProf. The command you should use to profile this is:\n");
29  fprintf(stderr, " igprof -mp -z -t combine combine datacard [options]\n\n");
30  fflush(stderr);
31  return false;
32  }
33  signal(SIGUSR2,igProfDumpNow);
34  return true;
35 }
36 
37 
38 boost::unordered_map<const char *, PerfCounter> perfCounters_;
39 
41 {
42  return perfCounters_[name];
43 }
44 
46 {
47  for (boost::unordered_map<const char *, PerfCounter>::const_iterator it = perfCounters_.begin(), ed = perfCounters_.end(); it != ed; ++it) {
48  fprintf(stderr, "%-40s: %g\n", it->first, it->second.get());
49  }
50 }
51 
52 // we define them by string value, but we lookup them by const char *
53 namespace runtimedef {
54  boost::unordered_map<const char *, std::pair<int,int> > defines_;
55  boost::unordered_map<std::string, int> definesByString_;
56  int get(const char *name) {
57  std::pair<int,int> & ret = defines_[name];
58  if (ret.second == 0) {
59  ret.first = definesByString_[name];
60  ret.second = 1;
61  }
62  return ret.first;
63  }
64  int get(const std::string & name) {
65  return definesByString_[name];
66  }
67  void set(const std::string & name, int value) {
69  }
70 }
71 
int igProfDumpNumber_
static void printAll()
boost::unordered_map< const char *, PerfCounter > perfCounters_
boost::unordered_map< const char *, std::pair< int, int > > defines_
void igProfDumpNow(int)
boost::unordered_map< std::string, int > definesByString_
bool setupIgProfDumpHook()
void(* igProfRequestDump_)(const char *)
double get() const
void set(const std::string &name, int value)
set the flag, with a run-time name