ATLAS Offline Software
SemiDetHelper.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 // //
7 // Header file for class SemiDetHelper //
8 // //
9 // Description: Main helper class for inclusion of //
10 // "semi-detailed" monitoring in PerfMon. //
11 // "Semi" because it unlike detailed mode of //
12 // PerfMon, doesn't store per-component and //
13 // per-evt info, but only per-component. //
14 // It also monitors fewer variables than //
15 // PerfMon: cpu+vmem+malloc + a few pieces of //
16 // specialised information for convenience. //
17 // //
18 // It doesn't know anything about the framework //
19 // it sits in, but requires PerfMon to supply //
20 // calls to startAud/stopAud as appropriate. //
21 // //
22 // In the end, data is printed to stdout and to //
23 // text-files. A python module, pmonsd.py, is //
24 // provided for easy parsing into a python //
25 // dictionary. It is the intention to never //
26 // break the ability to parse older versions //
27 // of the output with this module. //
28 // //
29 // Full documentation: //
30 // https://twiki.cern.ch/twiki/bin/viewauth/Atlas/PerfMonSD //
31 // //
32 // Author: Thomas H. Kittelmann (Thomas.Kittelmann@cern.ch) //
33 // Initial version: March 2011 //
34 // //
36 
37 #ifndef SEMIDETHELPER_H
38 #define SEMIDETHELPER_H
39 
40 #include "SemiDetMisc.h"
41 #include <string>
42 #include <iomanip>
43 #include <ostream>
44 #include "LinFitSglPass.h"
45 #include "boost/io/ios_state.hpp"
46 
48 
49 namespace PMonSD {
51  public:
52 
53  //Only constructor/destructor + methods needed in PerfMon:
54  SemiDetHelper(const std::string& jobStartJiffies="");
55  //jobStartJiffies: supply the starttime since boot in jiffies
56  //(from /proc/PID/stat) if you want to know how much time elapsed
57  //before this point (cfg_time)
58 
60 
61  //Call from perfmons start/stop auditor hooks (val_nevts is solely to distinguish 1st event from other events)
62  void startAud(const std::string& stepName,const std::string& compName,
63  unsigned val_nevts);//should be last in perfmons startaud method
64  void stopAud(const std::string& stepName,const std::string& compName,
65  unsigned val_nevts);//should be first in perfmons stopaud method
66  bool report(const std::string& file,
67  const std::string& info_full_output_inside,
68  bool stdout_uncollapsed);
69 
70 
71  private:
72 
74  SemiDetHelper & operator= ( const SemiDetHelper & );
75 
76  void reportToStdout(const std::string& info_full_output_inside,bool showall);
77  bool reportToFile(const std::string& file,
78  const std::string& info_full_output_inside);
79 
80  //Actual start/stop aud methods:
81  void startAudStd(const std::string& compName, int stepidx);
82  void stopAudStd(const std::string& compName, int stepidx,unsigned val_nevts);
83  void startAudOther(const std::string& compName, const std::string& stepName);
84  void stopAudOther(const std::string& compName, const std::string& stepName);
85  void startAudFinishUp(CompDataBasic*);
86  CompDataStdSteps * findStdData(const std::string& compName, int stepidx);
87  //For capturing cpu/mem measurements:
88  Meas m_meas;//per-component monitoring (with dbl-counting and timing overhead exclusion)
95  std::string m_starttime;
101  unsigned m_last_nevts;
102  unsigned m_nevts;
104  double m_vmpeak;
105  unsigned m_nevts_sum;//should be m_nevts-1 in normal jobs, but better be safe.
108 
109  //Data structures for standard steps (evt,1st,ini,fin,cbk)
112  //Data structures for other steps (dso, ...)
116 
117 //Set to 1 to benchmark ourselves:
118 #define DEBUG_SemiDetHelper 0
119 #if DEBUG_SemiDetHelper
120  Meas m_debug_meas;
121  CompDataBasic m_debug_data;
122  mutable unsigned m_debug_nfinds;
123  mutable unsigned m_debug_ninserts;
124 #endif
125 
126  void specialAud(int stepidx,unsigned val_nevts);
127  void finalise();
128 
129  //Helper method for map lookups with automatic growth in case of nonexisting key
130  template<class Tmap>
131  typename Tmap::mapped_type& mapLookup(const typename Tmap::key_type& key,Tmap&m, typename Tmap::iterator& cached_iterator) const
132  {
133  //lookup key, and grow automatically if needed.
134  if (cached_iterator==m.end()||(*cached_iterator).first!=key) {
135  cached_iterator=m.find(key);
136 #if DEBUG_SemiDetHelper
137  ++m_debug_nfinds;
138 #endif
139  if (cached_iterator==m.end()) {
140  std::pair<typename Tmap::iterator,bool> r
141  =m.insert(std::pair<typename Tmap::key_type,typename Tmap::mapped_type>(key,typename Tmap::mapped_type()));
142  assert(r.second);
143  cached_iterator=r.first;
144 #if DEBUG_SemiDetHelper
145  ++m_debug_ninserts;
146 #endif
147  }
148  }
149  return (*cached_iterator).second;
150  }
151 
152  //For the report:
153  const std::string m_prefix;
154  const std::string m_stepprefix;
155  const std::string m_specialstep;
156  const std::string m_malloclibname;
157  std::string m_malloc_status;
158 
159  void actualReport(std::ostream&,bool showall,const std::string& info_full_output_inside);
160  void format(std::ostream&os,const std::string& stepName,const std::string& compName,
161  const CompDataBasic*,bool normal_as_extended=false) const;
162  void format(std::ostream&,const std::string& str, bool center=true) const;
163  void format(std::ostream&,const std::string& stepName, const std::string& infoName, const Meas&) const;
164  void format(std::ostream&,const std::string& stepName, const std::string& infoName,
165  const PerfMon::LinFitSglPass& fit_vmem, const PerfMon::LinFitSglPass& fit_malloc) const;
166  void processStep(std::ostream&os,StepWrapper*,bool showall) const;
167  void field_i(std::ostream&os,unsigned width,int64_t val,bool leftjustify=false) const
168  {
169  //NB: Coverity complains about us modifying the left/right state
170  //of "os". But in ::actualReport we are actually restoring the
171  //state, so it is a false positive.
172  //Just save the state anyway.
173  boost::io::ios_base_all_saver ssave (os);
174  os << (leftjustify?std::left:std::right) << std::setw(width) << val;
175  }
176  void field_f(std::ostream&os,unsigned width,double val,bool leftjustify=false) const
177  {
178  //NB: Coverity complains about us modifying the left/right state
179  //of "os". But in ::actualReport we are actually restoring the
180  //state, so it is a false positive.
181  //always rounded to integers (milliseconds and kilobytes are good enough precision)
182  field_i(os,width,int64_t(val+0.5),leftjustify);
183  }
184  void spaces(std::ostream&os,unsigned n) const { os << std::setw(n) << ""; }
185  void colheader(std::ostream&os,StepWrapper*sw) const;
186 
187  void checkForMallocSlowness(int stepidx);
189 
195  std::string m_tmpstr;//One temporary string to reuse
196  };
197 
198 }
199 #endif
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
PMonSD::SemiDetHelper::m_meas
Meas m_meas
Definition: SemiDetHelper.h:88
PMonSD::SemiDetHelper::m_overhead_cpu_n
unsigned m_overhead_cpu_n
Definition: SemiDetHelper.h:192
beamspotman.r
def r
Definition: beamspotman.py:676
LinFitSglPass.h
PMonSD::SemiDetHelper
Definition: SemiDetHelper.h:50
PMonSD::ATLAS_NOT_THREAD_SAFE
double get_malloc_kb ATLAS_NOT_THREAD_SAFE()
PMonSD::SemiDetHelper::m_overhead_cpu_snapshot_post_1stevt
double m_overhead_cpu_snapshot_post_1stevt
Definition: SemiDetHelper.h:193
AddEmptyComponent.compName
compName
Definition: AddEmptyComponent.py:32
PerfMon::LinFitSglPass
Definition: LinFitSglPass.h:22
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
vtune_athena.format
format
Definition: vtune_athena.py:14
PMonSD::SemiDetHelper::~SemiDetHelper
~SemiDetHelper()
Definition: SemiDetHelper.h:59
PMonSD::SemiDetHelper::m_nevts_sum
unsigned m_nevts_sum
Definition: SemiDetHelper.h:105
PMonSD::SemiDetHelper::m_fit_101plus_vmem
PerfMon::LinFitSglPass m_fit_101plus_vmem
Definition: SemiDetHelper.h:98
PMonSD::MapOtherSteps
std::map< OtherKey, CompDataBasic, FastStrCmp > MapOtherSteps
Definition: SemiDetMisc.h:210
checkTP.report
report
Definition: checkTP.py:127
PMonSD::SemiDetHelper::field_i
void field_i(std::ostream &os, unsigned width, int64_t val, bool leftjustify=false) const
Definition: SemiDetHelper.h:167
PMonSD::SemiDetHelper::m_vmem_sum_evtloop
double m_vmem_sum_evtloop
Definition: SemiDetHelper.h:106
PMonSD::CompDataBasic
Definition: SemiDetMisc.h:109
PMonSD::SemiDetHelper::m_starttime
std::string m_starttime
Definition: SemiDetHelper.h:95
PMonSD::SemiDetHelper::m_last_nevts
unsigned m_last_nevts
Definition: SemiDetHelper.h:101
PMonSD::SemiDetHelper::m_tmpstr
std::string m_tmpstr
Definition: SemiDetHelper.h:195
PMonSD::SemiDetHelper::m_prefix
const std::string m_prefix
Definition: SemiDetHelper.h:153
PMonSD::SemiDetHelper::spaces
void spaces(std::ostream &os, unsigned n) const
Definition: SemiDetHelper.h:184
PMonSD::Meas
Definition: SemiDetMisc.h:55
SemiDetMisc.h
PMonSD::OtherKey
std::pair< std::string, std::string > OtherKey
Definition: SemiDetMisc.h:191
PMonSD::SemiDetHelper::m_rss_sum_evtloop
double m_rss_sum_evtloop
Definition: SemiDetHelper.h:107
PMonSD::SemiDetHelper::m_meas_post_ini
Meas m_meas_post_ini
Definition: SemiDetHelper.h:91
beamspotman.n
n
Definition: beamspotman.py:731
PMonSD::SemiDetHelper::mapLookup
Tmap::mapped_type & mapLookup(const typename Tmap::key_type &key, Tmap &m, typename Tmap::iterator &cached_iterator) const
Definition: SemiDetHelper.h:131
file
TFile * file
Definition: tile_monitor.h:29
PMonSD::CompDataStdSteps
Definition: SemiDetMisc.h:176
PMonSD::SemiDetHelper::m_data_std
MapStdSteps m_data_std
Definition: SemiDetHelper.h:110
PMonSD::SemiDetHelper::m_meas_post_lastevt
Meas m_meas_post_lastevt
Definition: SemiDetHelper.h:93
PMonSD::SemiDetHelper::m_tmp_otherkey
OtherKey m_tmp_otherkey
Definition: SemiDetHelper.h:113
PMonSD::SemiDetHelper::m_vmpeak
double m_vmpeak
Definition: SemiDetHelper.h:104
PMonSD::SemiDetHelper::m_overhead_cpu_snapshot_post_lastevt
double m_overhead_cpu_snapshot_post_lastevt
Definition: SemiDetHelper.h:194
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
PMonSD::SemiDetHelper::m_meas_pre_ini
Meas m_meas_pre_ini
Definition: SemiDetHelper.h:90
PMonSD::SemiDetHelper::m_meas_post_1stevt
Meas m_meas_post_1stevt
Definition: SemiDetHelper.h:92
PMonSD
Definition: PerfMonSvc.h:61
PMonSD::SemiDetHelper::field_f
void field_f(std::ostream &os, unsigned width, double val, bool leftjustify=false) const
Definition: SemiDetHelper.h:176
PMonSD::SemiDetHelper::m_cfg_walltime
double m_cfg_walltime
Definition: SemiDetHelper.h:89
PMonSD::SemiDetHelper::m_stepprefix
const std::string m_stepprefix
Definition: SemiDetHelper.h:154
PMonSD::SemiDetHelper::m_data_other
MapOtherSteps m_data_other
Definition: SemiDetHelper.h:114
PMonSD::StepWrapper
Definition: SemiDetMisc.h:213
Base_Fragment.width
width
Definition: Sherpa_i/share/common/Base_Fragment.py:59
PMonSD::SemiDetHelper::m_specialstep
const std::string m_specialstep
Definition: SemiDetHelper.h:155
PMonSD::SemiDetHelper::m_malloclibname
const std::string m_malloclibname
Definition: SemiDetHelper.h:156
Pythia8_RapidityOrderMPI.val
val
Definition: Pythia8_RapidityOrderMPI.py:14
PMonSD::SemiDetHelper::m_data_std_lastlookup
MapStdSteps::iterator m_data_std_lastlookup
Definition: SemiDetHelper.h:111
PMonSD::SemiDetHelper::m_overhead_cpu_total
double m_overhead_cpu_total
Definition: SemiDetHelper.h:191
PMonSD::SemiDetHelper::SemiDetHelper
SemiDetHelper(const SemiDetHelper &)
PMonSD::SemiDetHelper::m_malloc_status
std::string m_malloc_status
Definition: SemiDetHelper.h:157
PMonSD::SemiDetHelper::m_fit_101plus_malloc
PerfMon::LinFitSglPass m_fit_101plus_malloc
Definition: SemiDetHelper.h:99
str
Definition: BTagTrackIpAccessor.cxx:11
PMonSD::SemiDetHelper::m_nevts
unsigned m_nevts
Definition: SemiDetHelper.h:102
PMonSD::SemiDetHelper::m_meas_post_fin
Meas m_meas_post_fin
Definition: SemiDetHelper.h:94
PMonSD::MapStdSteps
std::map< std::string, CompDataStdSteps, FastStrCmp > MapStdSteps
Definition: SemiDetMisc.h:208
PMonSD::SemiDetHelper::m_fit_11to100_vmem
PerfMon::LinFitSglPass m_fit_11to100_vmem
Definition: SemiDetHelper.h:96
checker_macros.h
Define macros for attributes used to control the static checker.
PMonSD::SemiDetHelper::m_last_stepidx
int m_last_stepidx
Definition: SemiDetHelper.h:100
PMonSD::SemiDetHelper::m_data_other_lastlookup
MapOtherSteps::iterator m_data_other_lastlookup
Definition: SemiDetHelper.h:115
PMonSD::SemiDetHelper::m_malloc_might_get_slow
bool m_malloc_might_get_slow
Definition: SemiDetHelper.h:188
PMonSD::SemiDetHelper::m_need_finalise
bool m_need_finalise
Definition: SemiDetHelper.h:103
PMonSD::SemiDetHelper::m_fit_11to100_malloc
PerfMon::LinFitSglPass m_fit_11to100_malloc
Definition: SemiDetHelper.h:97
mapkey::key
key
Definition: TElectronEfficiencyCorrectionTool.cxx:37
PMonSD::SemiDetHelper::m_overhead_cpu_tmp
double m_overhead_cpu_tmp
Definition: SemiDetHelper.h:190