ATLAS Offline Software
Classes | Functions
RootSpy Namespace Reference

Classes

struct  logitem
 

Functions

const std::pair< std::string, std::string > & getSymbol (const void *address)
 
bool endsWith (const std::string &s, const char *pat, size_t npat)
 
bool ignoreLib (const std::string &libname)
 
const char * getROOTName (void *tobject)
 
const char * getROOTClass (void *tobject)
 
void logcall (const void *cthisptr, void *&realaddr, bool indirect=false)
 
void logcall (const void *cthisptr, const void *&realaddr)
 
const std::pair< std::string, std::string > & getUserSymbol (const logitem &item)
 
void reportcall (const logitem &item, unsigned ncalls)
 
void reporthist (const logitem &item, unsigned thesize)
 
void producereport ()
 

Function Documentation

◆ endsWith()

bool RootSpy::endsWith ( const std::string &  s,
const char *  pat,
size_t  npat 
)

Definition at line 73 of file rootspy.cxx.

73  {
74  return s.size()>=npat && strncmp(&(s[s.size()-npat]),pat,npat)==0;
75  }

◆ getROOTClass()

const char* RootSpy::getROOTClass ( void *  tobject)

Definition at line 95 of file rootspy.cxx.

95  {
96  // cppcheck-suppress nullPointerRedundantCheck; false positive
97  static const char* (*real)(void*) = 0;
98  if (!real) {
99  real = (const char* (*)(void*))dlsym(RTLD_NEXT, "_ZNK7TObject9ClassNameEv");//Fixme: avoid this symbol hardcoding.
100  if (!real) {
101  std::cout<<"ROOTSPY ERROR: Could not find symbol for TObject::GetName() through hardcoded mangling."<<std::endl;
102  return nullptr;
103  }
104  }
105  return real(tobject);
106  }

◆ getROOTName()

const char* RootSpy::getROOTName ( void *  tobject)

Definition at line 82 of file rootspy.cxx.

82  {
83  // cppcheck-suppress nullPointerRedundantCheck; false positive
84  static const char* (*real)(void*) = 0;
85  if (!real) {
86  real = (const char* (*)(void*))dlsym(RTLD_NEXT, "_ZNK6TNamed7GetNameEv");//Fixme: avoid this symbol hardcoding.
87  if (!real) {
88  std::cout<<"ROOTSPY ERROR: Could not find symbol for TNamed::GetName() through hardcoded mangling."<<std::endl;
89  return nullptr;
90  }
91  }
92  return real(tobject);
93  }

◆ getSymbol()

const std::pair<std::string,std::string>& RootSpy::getSymbol ( const void *  address)

Definition at line 48 of file rootspy.cxx.

49  {
50  if (!address) {
51  static std::pair<std::string,std::string> np("/libnothing.so","nullptr");
52  return np;
53  }
54  std::map<const void*,std::pair<std::string,std::string> >::const_iterator it=s_getsymbol_cache.find(address);
55  if (it!=s_getsymbol_cache.end())
56  return it->second;
57 
58  void *array[1];
59  array[0]=const_cast<void*>(address);
60  char **strings = backtrace_symbols (array,1);
61  std::string s(strings[0]);
62  size_t n = s.find('+');
63  if (n!=std::string::npos) s.resize(n);
64  n=s.find('(');
65  std::string cleansymb = &(s.c_str()[(n==std::string::npos?0:n+1)]);
66  std::string libname(s);
67  if (n!=std::string::npos)
68  libname.resize(n);
69  s_getsymbol_cache[address]=std::pair<std::string,std::string>(libname,cleansymb);
70  return s_getsymbol_cache[address];
71  }

◆ getUserSymbol()

const std::pair<std::string,std::string>& RootSpy::getUserSymbol ( const logitem item)

Definition at line 190 of file rootspy.cxx.

190  {
191  unsigned depth=2+item.traceoffset;
192  for (;depth<item.ntrace;++depth) {
193  const std::pair<std::string,std::string>& s=getSymbol(item.trace[depth]);
194  if (!ignoreLib(s.first)) {
195  return s;
196  }
197  }
198  std::cout<<"ROOTSPY WARNING: Could not find user symbol in trace"<<std::endl;
199  return getSymbol(item.trace[item.ntrace-1]);
200  }

◆ ignoreLib()

bool RootSpy::ignoreLib ( const std::string &  libname)

Definition at line 76 of file rootspy.cxx.

77  {
78  return endsWith(libname,"libHist.so",10)||endsWith(libname,"libAthenaMonitoringLib.so",25);
79  }

◆ logcall() [1/2]

void RootSpy::logcall ( const void *  cthisptr,
const void *&  realaddr 
)

Definition at line 183 of file rootspy.cxx.

184  {
185  void* ra = const_cast<void*>(realaddr);
186  logcall(cthisptr,ra,true);
187  realaddr=ra;
188  };

◆ logcall() [2/2]

void RootSpy::logcall ( const void *  cthisptr,
void *&  realaddr,
bool  indirect = false 
)

Definition at line 143 of file rootspy.cxx.

144  {
145  if (realaddr&&loglvl>1)
146  return;
147  logitem item(indirect);
148  item.ntrace=backtrace(item.trace, logitem::ntracemax);
149  if (!realaddr)
150  realaddr=dlsym(RTLD_NEXT, getSymbol(item.trace[1+item.traceoffset]).second.c_str());
151  if (loglvl>1)
152  return;
153  //Add the non-trace info and calc hash:
154  void* thisptr=const_cast<void*>(cthisptr);
155  const char* rc=thisptr?getROOTClass(thisptr):0;
156  const char* rn=thisptr?getROOTName(thisptr):0;
157  if (!rc) rc="NULL";
158  if (!rn) rn="NULL";
159  size_t nrc(strlen(rc));
160  size_t nrn(strlen(rn));
161  item.name.reserve(nrc+nrn+1);
162  item.name.append(rc,nrc);
163  item.name.push_back(':');
164  item.name.append(rn,nrn);
165  item.calchash();
166  //Log this trace and root item:
168  if (it==s_logcalls.end()) {
169  s_logcalls[item]=1;
170  } else {
171  ++(it->second);
172  }
173  //Log this histogram and its size:
174  unsigned thesize = roothiststatGetSize(static_cast<TH1*>(thisptr));//TK: Really update every single time?
175  std::map<void*,std::pair<logitem,unsigned> >::iterator it2=s_loghists.find(thisptr);//histaddress->(first logitem,maxsize).
176  if (it2==s_loghists.end()) {
177  s_loghists.insert(std::pair<void*,std::pair<logitem,unsigned> >(thisptr,std::pair<logitem,unsigned>(item,thesize)));
178  } else {
179  it2->second.second=std::max<unsigned>(it2->second.second,thesize);
180  }
181  }

◆ producereport()

void RootSpy::producereport ( )

Definition at line 210 of file rootspy.cxx.

210  {
211  std::cout<<"============= rootspy: Producing report [begin]"<<std::endl;
212  std::cout<<"============= Calls"<<std::endl;
213  std::map<logitem,unsigned>::iterator it(s_logcalls.begin()),itE(s_logcalls.end());
214  for (;it!=itE;++it)
215  reportcall(it->first,it->second);
216  std::cout<<"============= Sizes"<<std::endl;
217  std::map<void*,std::pair<logitem,unsigned> >::iterator it2(s_loghists.begin()),it2E(s_loghists.end());
218  for (;it2!=it2E;++it2)
219  reporthist(it2->second.first,it2->second.second);
220  std::cout<<"============= rootspy: Producing report [end]"<<std::endl;
221  }

◆ reportcall()

void RootSpy::reportcall ( const logitem item,
unsigned  ncalls 
)

Definition at line 202 of file rootspy.cxx.

202  {
203  const std::pair<std::string,std::string>& s = getUserSymbol(item);
204  std::cout<<ncalls<<" calls to "<<getSymbol(item.trace[1+item.traceoffset]).second
205  <<" by "<<s.second <<" : "<<s.first <<" : "<<item.name<<std::endl;
206  }

◆ reporthist()

void RootSpy::reporthist ( const logitem item,
unsigned  thesize 
)

Definition at line 207 of file rootspy.cxx.

207  {
208  std::cout<<thesize<<" bytes in "<<item.name<<" from "<<getUserSymbol(item).first<<std::endl;
209  }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
egammaParameters::depth
@ depth
pointing depth of the shower as calculated in egammaqgcld
Definition: egammaParamDefs.h:276
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
RootSpy::getROOTName
const char * getROOTName(void *tobject)
Definition: rootspy.cxx:82
skel.it
it
Definition: skel.GENtoEVGEN.py:423
PlotPulseshapeFromCool.np
np
Definition: PlotPulseshapeFromCool.py:64
endsWith
bool endsWith(const std::string &value, const std::string &ending)
Definition: EventViewCreatorAlgorithm.cxx:176
TruthTest.itE
itE
Definition: TruthTest.py:25
RootSpy::getUserSymbol
const std::pair< std::string, std::string > & getUserSymbol(const logitem &item)
Definition: rootspy.cxx:190
getSymbol
std::string getSymbol(Address_t address)
Definition: HephProf.cxx:74
PyPoolBrowser.item
item
Definition: PyPoolBrowser.py:129
RootSpy::getROOTClass
const char * getROOTClass(void *tobject)
Definition: rootspy.cxx:95
beamspotman.n
n
Definition: beamspotman.py:731
roothiststatGetSize
unsigned roothiststatGetSize(TH1 *h)
Definition: rootspy.cxx:225
python.BunchSpacingUtils.rn
rn
Definition: BunchSpacingUtils.py:87
RootSpy::logcall
void logcall(const void *cthisptr, const void *&realaddr)
Definition: rootspy.cxx:183
lumiFormat.array
array
Definition: lumiFormat.py:98
dso-stats.pat
pat
Definition: dso-stats.py:39
RootSpy::reporthist
void reporthist(const logitem &item, unsigned thesize)
Definition: rootspy.cxx:207
item
Definition: ItemListSvc.h:43
RTTAlgmain.address
address
Definition: RTTAlgmain.py:55
TH1
Definition: rootspy.cxx:268
RootSpy::reportcall
void reportcall(const logitem &item, unsigned ncalls)
Definition: rootspy.cxx:202
check_log.backtrace
backtrace
Definition: check_log.py:58
python.trfValidateRootFile.rc
rc
Definition: trfValidateRootFile.py:350
RootSpy::ignoreLib
bool ignoreLib(const std::string &libname)
Definition: rootspy.cxx:76