ProfilerSupport.cxx
Go to the documentation of this file.
1 #include <cstdlib>
2 
3 #include <sys/types.h>
4 #include <sys/stat.h>
5 #include <unistd.h>
6 
7 #include <iostream>
8 #include <vector>
9 
10 namespace ana
11 {
12  /// Support for the --prof commandline option
14  {
15  public:
17  {
18  if(getenv("CPUPROFILE")){
19  char tmp[] = "/tmp/XXXXXX.pdf";
20  mkstemps(tmp, 4);
21 
22  const char* pd = getenv("GPERFTOOLS_DIR");
23  if(!pd){
24  std::cout << "Couldn't find pprof executable" << std::endl;
25  return;
26  }
27  const std::string perfdir = pd;
28 
29  const std::string pprof = perfdir + "/bin/pprof";
30 
31  // pprof needs both of these set
32  setenv("PATH", (perfdir+"/bin/:"+std::string(getenv("PATH"))).c_str(), 1);
33  setenv("LD_LIBRARY_PATH", (perfdir+"/lib/:"+std::string(getenv("LD_LIBRARY_PATH"))).c_str(), 1);
34 
35  std::cout << "Creating profile. This can take some time..." << std::endl;
36  const std::string cmd1 = pprof + " --pdf `which root.exe` " + std::string(getenv("CPUPROFILE")) + " > " + tmp;
37  std::cout << cmd1 << std::endl;
38  const int ret = system(cmd1.c_str());
39  if(ret != 0) return;
40 
41  std::cout << "Displaying profile..." << std::endl;
42  const std::string cmd2 = "evince "+std::string(tmp);
43  std::cout << cmd2 << std::endl;
44  system(cmd2.c_str());
45  }
46  }
47  };
48 
49  namespace{
50  // Run destructor at end of process
51  static ProfilerSupport ps;
52  }
53 }
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
system("rm -rf microbeam.root")
Support for the –prof commandline option.
Float_t tmp
Definition: plot.C:36
std::string getenv(std::string const &name)
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154