Block-Structured AMR Software Framework
AMReX_RegionsProfStats.H
Go to the documentation of this file.
1 // ----------------------------------------------------------------------
2 // RegionsProfStats.H
3 // ----------------------------------------------------------------------
4 #ifndef BL_REGIONSPROFSTATS_H
5 #define BL_REGIONSPROFSTATS_H
6 #include <AMReX_Config.H>
7 
8 #include <AMReX_BLProfStats.H>
9 #include <AMReX_BLProfiler.H>
10 #include <AMReX_REAL.H>
11 #include <AMReX_SPACE.H>
12 #include <AMReX_Array.H>
13 #include <AMReX_Vector.H>
14 #include <AMReX_IntVect.H>
15 #include <AMReX_Box.H>
16 #include <AMReX_FArrayBox.H>
17 #include <cstdio>
18 #include <iostream>
19 #include <fstream>
20 #include <string>
21 #include <map>
22 #include <unordered_map>
23 #include <vector>
24 #include <stack>
25 #include <sstream>
26 #include <stdlib.h>
27 using std::cout;
28 using std::cerr;
29 using std::endl;
30 using std::vector;
31 using std::string;
32 using std::multimap;
33 
34 using amrex::Real;
35 
36 
37 // ----------------------------------------------------------------------
38 class RegionsProfStats : public BLProfStats {
39  public:
40 
41  struct DataBlock {
43  : proc(0), nRSS(0), nTraceStats(0), fileName(""), seekpos(0), readoffset(0),
44  streamIndex(-1)
45  { }
46  DataBlock(int p, long nrss, long nts, const std::string &fn, long sp, int si)
47  : proc(p), nRSS(nrss), nTraceStats(nts), fileName(fn), seekpos(sp),
48  readoffset(0), streamIndex(si)
49  { }
50 
51  int proc;
53  std::string fileName;
54  long seekpos;
55  long readoffset;
57 
58  double timeMin, timeMax;
61  };
62 
63 
64  public:
67 
68  virtual void AddCStatsHeaderFileName(const std::string &hfn);
69 
70  virtual void SetCSVersion(int csv) { csVersion = csv; }
71  int GetCSVersion() const { return csVersion; }
72 
73  void SetMaxFNumber(int n) { maxFNumber = n; }
74  int GetMaxFNumber() const { return maxFNumber; }
75 
76  void AddFunctionName(const std::string &/*fname*/)
77  { amrex::Abort("Wrong AddFunctionName for RegionsProfStats. Use (string, int)."); }
78  virtual void AddFunctionName(const std::string &fname, int fnumber);
79  virtual void AddTimeMinMax(double tmin, double tmax);
80 
81  TimeRange MakeRegionPlt(amrex::FArrayBox &rFab, int noregionnumber,
82  int width, int height,
84  virtual void CollectFuncStats(amrex::Vector<amrex::Vector<FuncStat> > &funcStats);
85  virtual void WriteSummary(std::ostream &os, bool bwriteavg = false, int whichProc = 0,
86  bool graphTopPct = true);
87  bool AllCallTimesFAB(amrex::FArrayBox &actFab, const std::string &whichFuncName);
89  const std::string whichFuncName,
90  int whichFuncNumber, const amrex::Box &procBox);
91  void CheckRegionsData();
92 
93  virtual void InitCStatsDataBlock(int proc, long nrss, long ntracestats,
94  const std::string &filename, long seekpos);
95 
96  static void SetInitDataBlocks(bool b) { bInitDataBlocks = b; }
97  static bool InitDBlocks() { return bInitDataBlocks; }
98  static void InitDataFileNames(const amrex::Vector<std::string> &hfn);
99  bool TraceDataValid() const { return mFNameNumbersPerProc.size() > 0; }
100 
101  void SyncFNamesAndNumbers();
102  bool InitRegionTimeRanges(const amrex::Box &procBox);
103 
104  void WriteHTML(std::ostream &os, bool simpleCombine = true, int whichProc = 0);
105  void PrintCallTreeNode(CallTreeNode &callTree, amrex::Vector<std::string> &fNumberNames);
106  void CreateVCallStats(CallTreeNode &callTree,
108  void WriteHTMLNC(std::ostream &os, int whichProc = 0);
109  void WriteTextTrace(std::ostream &os, bool simpleCombine = true, int whichProc = 0,
110  std::string delimString = "\t");
111 
114 
115  static void OpenAllStreams(const std::string &dirname);
116  static void CloseAllStreams();
117 
118  void FillRegionTimeRanges(amrex::Vector<amrex::Vector<TimeRange>> &rtr, // ---- [region][range]
119  int whichProc);
120 
121  private:
125 
127  amrex::Vector<amrex::Vector<int> > fnameRemap; // [dataNProc][remappedfnumber]
128  std::map<std::string, int> mFNameNumbersLocal; // [fname, fnumber]
132  static std::map<std::string, int> regDataFileNames; // [filename, stream index]
133 
134  static std::map<Real, std::string, std::greater<Real> > mTimersTotalsSorted;
135 
136  bool Include(const FuncStat &fs);
137 
140 
141  void ReadBlock(DataBlock &dBlock, bool readRSS = true,
142  bool readTraces = true); // reads whole block
143  void ReadBlockNoOpen(DataBlock &dBlock, bool readRSS = true,
144  bool readTraces = true); // files must be open already
145  bool ReadBlock(DataBlock &dBlock, const int nmessages); // reads nmessages
146  void ClearBlock(DataBlock &dBlock);
147 
148  friend int yyparse(void *);
149 
150 };
151 
152 #endif
153 // ----------------------------------------------------------------------
154 // ----------------------------------------------------------------------
Definition: AMReX_BLProfStats.H:30
Definition: AMReX_RegionsProfStats.H:38
void ReadBlock(DataBlock &dBlock, bool readRSS=true, bool readTraces=true)
Definition: AMReX_RegionsProfStats.cpp:1507
int currentDataBlock
Definition: AMReX_RegionsProfStats.H:122
void SyncFNamesAndNumbers()
Definition: AMReX_RegionsProfStats.cpp:110
void ClearBlock(DataBlock &dBlock)
Definition: AMReX_RegionsProfStats.cpp:1610
void WriteHTML(std::ostream &os, bool simpleCombine=true, int whichProc=0)
Definition: AMReX_RegionsProfStats.cpp:842
void WriteHTMLNC(std::ostream &os, int whichProc=0)
Definition: AMReX_RegionsProfStats.cpp:1097
void CreateVCallStats(CallTreeNode &callTree, amrex::Vector< amrex::BLProfiler::CallStats > &vCallStatsNC)
Definition: AMReX_RegionsProfStats.cpp:1062
TimeRange MakeRegionPlt(amrex::FArrayBox &rFab, int noregionnumber, int width, int height, amrex::Vector< amrex::Vector< amrex::Box >> &regionBoxes)
Definition: AMReX_RegionsProfStats.cpp:203
friend int yyparse(void *)
int maxFNumber
Definition: AMReX_RegionsProfStats.H:124
RegionsProfStats()
Definition: AMReX_RegionsProfStats.cpp:87
bool TraceDataValid() const
Definition: AMReX_RegionsProfStats.H:99
bool AllCallTimesFAB(amrex::FArrayBox &actFab, const std::string &whichFuncName)
Definition: AMReX_RegionsProfStats.cpp:518
static amrex::Vector< std::string > regHeaderFileNames
Definition: AMReX_RegionsProfStats.H:130
amrex::Vector< std::map< std::string, int > > mFNameNumbersPerProc
Definition: AMReX_RegionsProfStats.H:126
static void CloseAllStreams()
Definition: AMReX_RegionsProfStats.cpp:1489
void PrintCallTreeNode(CallTreeNode &callTree, amrex::Vector< std::string > &fNumberNames)
Definition: AMReX_RegionsProfStats.cpp:1079
void SetMaxFNumber(int n)
Definition: AMReX_RegionsProfStats.H:73
virtual void InitCStatsDataBlock(int proc, long nrss, long ntracestats, const std::string &filename, long seekpos)
Definition: AMReX_RegionsProfStats.cpp:1418
bool Include(const FuncStat &fs)
Definition: AMReX_RegionsProfStats.cpp:510
amrex::Vector< std::string > numbersToFName
Definition: AMReX_RegionsProfStats.H:129
static void OpenAllStreams(const std::string &dirname)
Definition: AMReX_RegionsProfStats.cpp:1438
int GetCSVersion() const
Definition: AMReX_RegionsProfStats.H:71
static bool InitDBlocks()
Definition: AMReX_RegionsProfStats.H:97
virtual void AddTimeMinMax(double tmin, double tmax)
Definition: AMReX_RegionsProfStats.cpp:196
bool InitRegionTimeRanges(const amrex::Box &procBox)
Definition: AMReX_RegionsProfStats.cpp:316
virtual void SetCSVersion(int csv)
Definition: AMReX_RegionsProfStats.H:70
void ReadBlockNoOpen(DataBlock &dBlock, bool readRSS=true, bool readTraces=true)
Definition: AMReX_RegionsProfStats.cpp:1548
static const amrex::Vector< std::string > & GetHeaderFileNames()
Definition: AMReX_RegionsProfStats.H:112
int GetMaxFNumber() const
Definition: AMReX_RegionsProfStats.H:74
static amrex::Vector< std::ifstream * > regDataStreams
Definition: AMReX_RegionsProfStats.H:131
const amrex::Vector< std::string > & NumbersToFName() const
Definition: AMReX_RegionsProfStats.H:113
static bool persistentStreams
Definition: AMReX_RegionsProfStats.H:139
static std::map< std::string, int > regDataFileNames
Definition: AMReX_RegionsProfStats.H:132
static bool bInitDataBlocks
Definition: AMReX_RegionsProfStats.H:139
void FillRegionTimeRanges(amrex::Vector< amrex::Vector< TimeRange >> &rtr, int whichProc)
Definition: AMReX_RegionsProfStats.cpp:280
void FillAllCallTimes(amrex::Vector< amrex::Vector< Real > > &allCallTimes, const std::string whichFuncName, int whichFuncNumber, const amrex::Box &procBox)
Definition: AMReX_RegionsProfStats.cpp:594
amrex::Vector< DataBlock > dataBlocks
Definition: AMReX_RegionsProfStats.H:138
virtual void CollectFuncStats(amrex::Vector< amrex::Vector< FuncStat > > &funcStats)
Definition: AMReX_RegionsProfStats.cpp:637
virtual void AddCStatsHeaderFileName(const std::string &hfn)
Definition: AMReX_RegionsProfStats.cpp:100
static void SetInitDataBlocks(bool b)
Definition: AMReX_RegionsProfStats.H:96
std::map< std::string, int > mFNameNumbersLocal
Definition: AMReX_RegionsProfStats.H:128
virtual void WriteSummary(std::ostream &os, bool bwriteavg=false, int whichProc=0, bool graphTopPct=true)
Definition: AMReX_RegionsProfStats.cpp:665
amrex::Vector< amrex::Vector< int > > fnameRemap
Definition: AMReX_RegionsProfStats.H:127
void WriteTextTrace(std::ostream &os, bool simpleCombine=true, int whichProc=0, std::string delimString="\t")
Definition: AMReX_RegionsProfStats.cpp:1321
int csVersion
Definition: AMReX_RegionsProfStats.H:123
static std::map< Real, std::string, std::greater< Real > > mTimersTotalsSorted
Definition: AMReX_RegionsProfStats.H:134
void AddFunctionName(const std::string &)
Definition: AMReX_RegionsProfStats.H:76
void CheckRegionsData()
Definition: AMReX_RegionsProfStats.cpp:756
static void InitDataFileNames(const amrex::Vector< std::string > &hfn)
Definition: AMReX_RegionsProfStats.cpp:1408
~RegionsProfStats()
Definition: AMReX_RegionsProfStats.cpp:95
A Fortran Array of REALs.
Definition: AMReX_FArrayBox.H:229
Long size() const noexcept
Definition: AMReX_Vector.H:50
void Abort(const std::string &msg)
Print out message to cerr and exit via abort().
Definition: AMReX.cpp:225
Definition: AMReX_BLProfStats.H:55
Definition: AMReX_RegionsProfStats.H:41
amrex::Vector< amrex::BLProfiler::CallStats > vCallStats
Definition: AMReX_RegionsProfStats.H:60
std::string fileName
Definition: AMReX_RegionsProfStats.H:53
amrex::Vector< amrex::BLProfiler::RStartStop > rStartStop
Definition: AMReX_RegionsProfStats.H:59
double timeMax
Definition: AMReX_RegionsProfStats.H:58
DataBlock()
Definition: AMReX_RegionsProfStats.H:42
long readoffset
Definition: AMReX_RegionsProfStats.H:55
long nTraceStats
Definition: AMReX_RegionsProfStats.H:52
int proc
Definition: AMReX_RegionsProfStats.H:51
int streamIndex
Definition: AMReX_RegionsProfStats.H:56
double timeMin
Definition: AMReX_RegionsProfStats.H:58
long seekpos
Definition: AMReX_RegionsProfStats.H:54
long nRSS
Definition: AMReX_RegionsProfStats.H:52
DataBlock(int p, long nrss, long nts, const std::string &fn, long sp, int si)
Definition: AMReX_RegionsProfStats.H:46