OpenMPI  0.1.1
vt_unify_hooks_aevents.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_AEVENTS_H_
14 #define _VT_UNIFY_HOOKS_AEVENTS_H_
15 
16 #include "vt_unify.h"
17 #include "vt_unify_hooks_base.h"
18 
19 #include "otf.h"
20 
21 #include <deque>
22 #include <map>
23 #include <set>
24 
25 //
26 // HooksAsyncEventsC class
27 //
29 {
30 public:
31 
32  // constructor
34 
35  // destructor
37 
38  // is this hook enabled?
39  static bool isEnabled() { return true; }
40 
41 private:
42 
43  //
44  // async. event types
45  //
46  typedef enum
47  {
48  ASYNC_EVENT_TYPE_COUNTER,
49  // TODO: further async. event types
50  ASYNC_EVENT_TYPE_UNKNOWN
51 
52  } AsyncEventTypeT;
53 
54  //
55  // async. event base structure
56  //
57  struct AsyncEventBaseS
58  {
59  // constructors
60  //
61  AsyncEventBaseS()
62  : type(ASYNC_EVENT_TYPE_UNKNOWN), time(0), kvs(0) {}
63  AsyncEventBaseS( const AsyncEventTypeT & _type, const uint64_t & _time,
64  OTF_KeyValueList *& _kvs )
65  : type(_type), time(_time), kvs(_kvs) {}
66 
67  // destructor
68  ~AsyncEventBaseS() { OTF_KeyValueList_close( kvs ); }
69 
70  AsyncEventTypeT type; // async. event type
71  uint64_t time; // actual timestamp
72  OTF_KeyValueList * kvs; // key-value list
73 
74  };
75 
76  //
77  // async. counter event structure
78  //
79  struct AsyncEventCounterS : AsyncEventBaseS
80  {
81  // constructor
82  AsyncEventCounterS( const uint64_t & _time, OTF_KeyValueList *& _kvs,
83  const uint32_t & _procgrp, const uint32_t & _counter,
84  const uint64_t & _value )
85  : AsyncEventBaseS(ASYNC_EVENT_TYPE_COUNTER, _time, _kvs),
86  procgrp(_procgrp), counter(_counter), value(_value) {}
87 
88  uint32_t procgrp; // global process group token (if it's a group counter)
89  uint32_t counter; // global counter token
90  uint64_t value; // counter value
91 
92  };
93 
94  // TODO: define further async. event structures here
95 
96  //
97  // async. source manager structure
98  //
99  struct AsyncSourceManagerS
100  {
101  //
102  // async. source structure
103  //
104  struct SourceS
105  {
106  // constructors
107  //
108  SourceS()
109  : key(0), finished_reading(false), file_manager(0), rstream(0),
110  handler_array(0) {}
111  SourceS( const uint32_t & _key )
112  : key(_key), finished_reading(false), file_manager(0), rstream(0),
113  handler_array(0) {}
114 
115  // maximum number of queued async. events
116  static uint32_t MaxQueueSize;
117 
118  uint32_t key; // async. source key
119  bool finished_reading; // flag: reading finished?
120  OTF_FileManager * file_manager; // OTF file manager
121  OTF_RStream * rstream; // OTF reader stream
122  OTF_HandlerArray * handler_array; // OTF handler array
123  std::deque<AsyncEventBaseS*> event_queue; // queue of async. events
124 
125  };
126 
127  // constructor
128  AsyncSourceManagerS()
129  : stream_id(0), opened(false), hooks_suspended(false), wstream(0) {}
130 
131  // maximum number of queued events over all async. sources
132  static const uint32_t MAX_QUEUED_EVENTS = 1000000;
133 
134  uint32_t stream_id; // input stream id
135  std::string stream_prefix; // input stream file prefix
136  bool opened; // flag: async. sources opened?
137  bool hooks_suspended; // flag: write rec. hooks suspended?
138  OTF_WStream * wstream; // output OTF writer stream
139  std::map<uint32_t, SourceS> sources; // map key <-> async. source
140 
141  };
142 
143  // record handlers for async. events
144  //
145 
146  // common leading stuff:
147  // get actual time of async. event from key-value list
148  // return false, if event isn't of interest for given async. source
149  static inline bool HandleAsyncEventPre(
150  AsyncSourceManagerS::SourceS & source,
151  const uint32_t & proc, uint64_t & time,
152  OTF_KeyValueList *& kvs );
153  // common secondary stuff: enqueue new async. event
154  // return false, if failed (time not increasing)
155  static inline bool HandleAsyncEventPost(
156  AsyncSourceManagerS::SourceS & source,
157  AsyncEventBaseS *& newAsyncEvent );
158 
159  static int HandleAsyncCounter( AsyncSourceManagerS::SourceS * source,
160  uint64_t time, uint32_t proc, uint32_t counter, uint64_t value,
161  OTF_KeyValueList * kvs );
162 
163  // TODO: declare further record handlers for async. events here
164 
165  // vvvvvvvvvvvvvvvvvvvv HOOK METHODS vvvvvvvvvvvvvvvvvvvv
166 
167  // initialization/finalization hooks
168  //
169 
170  void initHook();
171  void finalizeHook( const bool & error );
172 
173  // phase hooks
174  //
175 
176  void phaseHook_UnifyEvents_pre();
177 
178  // record hooks
179  //
180 
181  // definition records
182 
183  void writeRecHook_DefKeyValue( HooksC::VaArgsT & args );
184 
185  // event records
186 
187  // common stuff for write event record hooks
188  void writeRecHook_Event( uint64_t * time, uint32_t * streamid,
189  OTF_KeyValueList ** kvs, bool * dowrite );
190 
191  void writeRecHook_EventComment( HooksC::VaArgsT & args )
192  {
193  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
194  (OTF_KeyValueList**)args[4], (bool*)args[5] );
195  }
196 
197  void writeRecHook_Enter( HooksC::VaArgsT & args )
198  {
199  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[3],
200  (OTF_KeyValueList**)args[5], (bool*)args[6] );
201  }
202 
203  void writeRecHook_Leave( HooksC::VaArgsT & args )
204  {
205  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[3],
206  (OTF_KeyValueList**)args[5], (bool*)args[6] );
207  }
208 
209  void writeRecHook_Counter( HooksC::VaArgsT & args )
210  {
211  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
212  (OTF_KeyValueList**)args[6], (bool*)args[7] );
213  }
214 
215  void writeRecHook_BeginFileOp( HooksC::VaArgsT & args )
216  {
217  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
218  (OTF_KeyValueList**)args[5], (bool*)args[6] );
219  }
220 
221  void writeRecHook_EndFileOp( HooksC::VaArgsT & args )
222  {
223  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
224  (OTF_KeyValueList**)args[9], (bool*)args[10] );
225  }
226 
227  void writeRecHook_SendMsg( HooksC::VaArgsT & args )
228  {
229  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
230  (OTF_KeyValueList**)args[8], (bool*)args[9] );
231  }
232 
233  void writeRecHook_RecvMsg( HooksC::VaArgsT & args )
234  {
235  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
236  (OTF_KeyValueList**)args[8], (bool*)args[9] );
237  }
238 
239  void writeRecHook_BeginCollOp( HooksC::VaArgsT & args )
240  {
241  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
242  (OTF_KeyValueList**)args[10], (bool*)args[11] );
243  }
244 
245  void writeRecHook_EndCollOp( HooksC::VaArgsT & args )
246  {
247  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
248  (OTF_KeyValueList**)args[4], (bool*)args[5] );
249  }
250 
251  void writeRecHook_RMAPut( HooksC::VaArgsT & args )
252  {
253  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
254  (OTF_KeyValueList**)args[9], (bool*)args[10] );
255  }
256 
257  void writeRecHook_RMAPutRemoteEnd( HooksC::VaArgsT & args )
258  {
259  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
260  (OTF_KeyValueList**)args[9], (bool*)args[10] );
261  }
262  void writeRecHook_RMAGet( HooksC::VaArgsT & args )
263  {
264  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
265  (OTF_KeyValueList**)args[9], (bool*)args[10] );
266  }
267 
268  void writeRecHook_RMAEnd( HooksC::VaArgsT & args )
269  {
270  writeRecHook_Event( (uint64_t*)args[1], (uint32_t*)args[2],
271  (OTF_KeyValueList**)args[7], (bool*)args[8] );
272  }
273 
274  // generic hook
275  void genericHook( const uint32_t & id, HooksC::VaArgsT & args );
276 
277  // ^^^^^^^^^^^^^^^^^^^^ HOOK METHODS ^^^^^^^^^^^^^^^^^^^^
278 
279  // open reader streams of async. sources
280  bool openSources( AsyncSourceManagerS & manager,
281  const uint32_t & streamId, const std::string & streamPrefix,
282  OTF_WStream *& wstream );
283 
284  // write remaining queued async. events and close reader streams
285  bool closeSources( AsyncSourceManagerS & manager );
286 
287  // read events ahead for certain async. source key
288  // if sourceKey is 0, read events ahead for all async. sources
289  bool readAhead( AsyncSourceManagerS & manager,
290  const uint32_t & sourceKey = 0 );
291 
292  // write queued async. events until certain timestamp is reached
293  // if curTime is (uint64_t)-1, write all queued async. events
294  bool writeAsyncEvents( AsyncSourceManagerS & manager,
295  const uint64_t & curTime = (uint64_t)-1 );
296 
297  // get pointer to async. source manager by stream id
298  inline AsyncSourceManagerS *
299  getSourceManagerByStreamId( const uint32_t & streamId );
300 
301  // check whether an event is asynchronous by searching certain async. source
302  // key in key-value list
303  // if sourceKey is 0, search for all async. source keys
304  inline bool isAsyncEvent( OTF_KeyValueList *& kvs,
305  const uint32_t & sourceKey = 0 ) const;
306 
307 #ifdef VT_MPI
308 
309  // share async. source keys to all ranks
310  bool shareSourceKeys();
311 
312 #endif // VT_MPI
313 
314  // class's instance object to allow access from static member methods
315  static HooksAsyncEventsC * Obj;
316 
317  // map stream id <-> async. source manager
318  std::map<uint32_t, AsyncSourceManagerS> m_stream2SourceManager;
319 
320  // set of async. source keys
321  std::set<uint32_t> m_sourceKeys;
322 
323 };
324 
325 #endif // _VT_UNIFY_HOOKS_AEVENTS_H_
uint8_t OTF_KeyValueList_close(OTF_KeyValueList *list)
Close an OTF_KeyValueList instance.
Definition: OTF_KeyValue.c:61
Main include file for applications using OTF.
Object structure which holds OTF record handlers.
Definition: OTF_HandlerArray.h:52
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_hooks_base.h:23
VampirTrace http://www.tu-dresden.de/zih/vampirtrace.
Definition: vt_unify_hooks_aevents.h:28
Definition: OTF_RStream.h:133
Definition: vt_unify_hooks_aevents.h:104
Definition: OTF_WStream.h:95
struct OTF_KeyValueList_struct OTF_KeyValueList
Object type which holds a key-value list.
Definition: OTF_KeyValue.h:242
file handles management structure
Definition: OTF_FileManager.c:32