OpenMPI  0.1.1
vt_unify_hooks_prof.h
1 /**
2  * VampirTrace
3  * http://www.tu-dresden.de/zih/vampirtrace
4  *
5  * Copyright (c) 2005-2012, ZIH, TU Dresden, Federal Republic of Germany
6  *
7  * Copyright (c) 1998-2005, Forschungszentrum Juelich, Juelich Supercomputing
8  * Centre, Federal Republic of Germany
9  *
10  * See the file COPYING in the package base directory for details
11  **/
12 
13 #ifndef _VT_UNIFY_HOOKS_PROF_H_
14 #define _VT_UNIFY_HOOKS_PROF_H_
15 
16 #include "vt_unify.h"
17 #include "vt_unify_hooks_base.h"
18 
19 #include <algorithm>
20 #include <map>
21 #include <string>
22 #include <vector>
23 
24 //
25 // HooksProfC class
26 //
27 class HooksProfC : public HooksBaseC
28 {
29 public:
30 
31  //
32  // function profile sort flags
33  //
34  enum
35  {
36  FUNC_PROF_SORT_FLAG_DIR_UP = 0x1,
37  FUNC_PROF_SORT_FLAG_DIR_DOWN = 0x2,
38  FUNC_PROF_SORT_FLAG_FUNCNAME = 0x4,
39  FUNC_PROF_SORT_FLAG_COUNT = 0x8,
40  FUNC_PROF_SORT_FLAG_INCL = 0x10,
41  FUNC_PROF_SORT_FLAG_EXCL = 0x20,
42  FUNC_PROF_SORT_FLAG_INCL_CALL = 0x40,
43  FUNC_PROF_SORT_FLAG_EXCL_CALL = 0x80
44 
45  };
46 
47  //
48  // function profile structure
49  //
50  struct FuncProfS
51  {
52  FuncProfS()
53  : funcid( 0 ), count( 0.0 ), incl( 0 ), excl( 0 ) {}
54 
55  FuncProfS( const uint32_t & _funcid )
56  : funcid( _funcid ), count( 0.0 ), incl( 0 ), excl( 0 ) {}
57 
58  FuncProfS( const uint32_t & _funcid, const std::string & _funcname,
59  const double & _count, const uint64_t & _incl,
60  const uint64_t & _excl )
61  : funcid( _funcid ), funcname( _funcname ), count( _count ),
62  incl( _incl ), excl( _excl ) {}
63 
64 #ifdef VT_MPI
65  VT_MPI_INT getPackSize();
66  void pack( char *& buffer, const VT_MPI_INT & bufferSize,
67  VT_MPI_INT & bufferPos );
68  void unpack( char *& buffer, const VT_MPI_INT & bufferSize,
69  VT_MPI_INT & bufferPos );
70 #endif // VT_MPI
71 
72  inline FuncProfS & operator+=( const FuncProfS & a );
73  inline bool operator==( const FuncProfS & a ) const;
74  inline bool operator<( const FuncProfS & a) const;
75 
76  uint32_t funcid; // function identifier
77  std::string funcname; // function name
78  double count; // number of calls
79  uint64_t incl; // inclusive time
80  uint64_t excl; // exclusive time
81 
82  };
83 
84  // constructor
85  HooksProfC();
86 
87  // destructor
88  ~HooksProfC();
89 
90  // is this hook enabled?
91  static bool isEnabled() { return true; }
92 
93 private:
94 
95  // vvvvvvvvvvvvvvvvvvvv HOOK METHODS vvvvvvvvvvvvvvvvvvvv
96 
97  // initialization/finalization hooks
98  //
99 
100  void initHook();
101  void finalizeHook( const bool & error );
102 
103  // phase hooks
104  //
105 
106  void phaseHook_GetUnifyControls_post();
107  void phaseHook_UnifyStatistics_post();
108 
109  // record hooks
110  //
111 
112  void writeRecHook_DefTimerResolution( HooksC::VaArgsT & args );
113  void writeRecHook_DefProcess( HooksC::VaArgsT & args );
114  void writeRecHook_DefFunction( HooksC::VaArgsT & args );
115  void writeRecHook_FunctionSummary( HooksC::VaArgsT & args );
116 
117  // ^^^^^^^^^^^^^^^^^^^^ HOOK METHODS ^^^^^^^^^^^^^^^^^^^^
118 
119  // process function statistics
120  void processFuncStat( const uint32_t & procId, const uint32_t & funcId,
121  const uint64_t & count, const uint64_t & incl,
122  const uint64_t & excl );
123 
124  // get function profile
125  // (procId=0 -> summary over all processes)
126  void getFuncProf( std::vector<FuncProfS> & funcProfs,
127  const uint32_t & procId = 0 );
128 
129  // print/write function profile to stdout/file
130  // (outFile=<empty> -> print to stdout)
131  bool printFuncProf( const std::vector<FuncProfS> & funcProfs,
132  const std::string & outFile = "" );
133 
134  // check for available function profile
135  // (procId=0 -> any process)
136  bool haveFuncProf( const uint32_t & procId = 0 );
137 
138  // get function name by id
139  std::string getFuncNameById( const uint32_t & funcId );
140 
141  // trim function name (only for output on stdout)
142  std::string shortName( const std::string & longName, uint32_t len = 20 );
143 
144  // convert timestamp to a human readable format
145  std::string formatTime( const uint64_t & time );
146 
147 #ifdef VT_MPI
148 
149  // gather function profiles from all ranks
150  void gatherFuncProfs();
151 
152 #endif // VT_MPI
153 
154  // map function id <-> function name
155  // (only significant for rank 0)
156  std::map<uint32_t, std::string> m_funcId2Name;
157 
158  // vector of summary function profiles
159  // (only significant for rank 0)
160  std::vector<FuncProfS> m_sumFuncProfs;
161 
162  // map process id <-> map function id <-> function profile
163  std::map<uint32_t, std::map<uint32_t, FuncProfS> > m_procId2FuncProf;
164 
165  // number of processes
166  uint32_t m_numProcs;
167 
168  // timer resolution
169  uint64_t m_timerRes;
170 
171 };
172 
173 #endif // _VT_UNIFY_HOOKS_PROF_H_
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_hooks_base.h:23
Definition: vt_unify_hooks_prof.h:50
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_hooks_prof.h:27
HooksProfC()
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_hooks_prof.cc:28