OpenMPI  0.1.1
State.h
1 /*
2  This is part of the OTF library. Copyright by ZIH, TU Dresden 2005-2012.
3  Authors: Andreas Knuepfer, Holger Brunst, Ronny Brendel, Thomas Kriebitzsch
4 */
5 
6 #ifndef STATE_H
7 #define STATE_H
8 
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12 
13 
14 #include <vector>
15 #include <deque>
16 #include <map>
17 #include <list>
18 
19 #include "OTF_inttypes.h"
20 
21 #include "otf.h"
22 
23 
24 /* *** function stuff *** ********************************* */
25 
26 struct FunctionCall {
27 
28 
29 public:
30 
31  uint64_t time;
32  uint32_t token;
33  OTF_KeyValueList *kvlist;
34 
35 
36 public:
37 
38  /** constructor */
39  FunctionCall( uint64_t _time, uint32_t _token, OTF_KeyValueList *_kvlist );
40 
41  /** copy constructor */
42  FunctionCall( const FunctionCall& fc );
43 
44  /** destructor */
45  ~FunctionCall();
46 
47  /** assignment operator */
48  FunctionCall operator=( const FunctionCall& fc );
49 };
50 
51 
53 
54 
55 public:
56 
57  int64_t occurrences;
58  int64_t exclusiveTime;
59  int64_t inclusiveTime;
60 
61 
62 public:
63 
64  /** constructor */
65  FunctionStatistics( int64_t o= 0, int64_t ex= 0, int64_t in= 0 ) :
66  occurrences( o ), exclusiveTime( ex ), inclusiveTime( in ) {};
67 
68  /** copy constructor */
70  occurrences( other.occurrences ), exclusiveTime( other.exclusiveTime ),
71  inclusiveTime( other.inclusiveTime ) {};
72 };
73 
74 
75 /* *** send stuff ************************************** */
76 struct Send {
77 
78 
79 public:
80 
81  uint64_t originaltime;
82  uint32_t receiver;
83  uint32_t procGroup;
84  uint32_t tag;
85  uint32_t length;
86  uint32_t source;
87  OTF_KeyValueList *kvlist;
88 
89 public:
90 
91  /** constructor */
92  Send( uint64_t _originaltime, uint32_t _receiver, uint32_t _procGroup, uint32_t _tag,
93  uint32_t _length, uint32_t _source, OTF_KeyValueList *_kvlist );
94 
95  /** copy constructor */
96  Send( const Send& s );
97 
98  /** destructor */
99  ~Send();
100 
101  /** assignment operator */
102  Send operator=( const Send& s );
103 };
104 
105 
107 
108 public:
109 
110  uint64_t number_sent;
111  uint64_t number_recvd;
112  uint64_t bytes_sent;
113  uint64_t bytes_recvd;
114 
115 public:
116 
117  SendStatistics( uint64_t ns= 0, uint64_t nr= 0, uint64_t bs= 0, uint64_t br= 0 ) :
118  number_sent( ns ), number_recvd( nr ), bytes_sent( bs ),
119  bytes_recvd( br ) {};
120 
121  SendStatistics( const SendStatistics& other ) :
122  number_sent( other.number_sent ), number_recvd( other.number_recvd ),
123  bytes_sent( other.bytes_sent ), bytes_recvd( other.bytes_recvd ) {};
124 };
125 
126 
128 
129 public:
130 
131  mutable std::map<uint32_t,uint64_t> numSent;
132  mutable std::map<uint32_t,uint64_t> numRecv;
133  mutable std::map<uint32_t,uint64_t> bytesSent;
134  mutable std::map<uint32_t,uint64_t> bytesRecv;
135  mutable std::map<uint32_t,uint32_t> Type2Col;
136 };
137 
138 
140 
141 public:
142 
143  uint64_t time;
144  uint32_t root;
145  uint32_t procGroup;
146  uint32_t col;
147  uint32_t type;
148  uint64_t invoc_sent;
149  uint64_t invoc_recv;
150  uint64_t bytesSent;
151  uint64_t bytesRecv;
152  uint32_t scltoken;
153  OTF_KeyValueList *kvlist;
154 
155 public:
156 
157  /** constructor */
158  BeginCollOperation( uint64_t _time, uint32_t _root, uint32_t _procGroup,
159  uint32_t _col, uint32_t _type, uint64_t _invoc_sent, uint64_t _invoc_recv,
160  uint64_t _bytesSent, uint64_t _bytesRecv, uint32_t _scltoken, OTF_KeyValueList *_kvlist );
161 
162  /** copy constructor */
164 
165  /** destructor */
167 
168  /** assignment operator */
170 
171 };
172 
174 
175 public:
176 
177  uint64_t time;
178  uint32_t scltoken;
179  OTF_KeyValueList *kvlist;
180 
181 
182 public:
183 
184  /** constructor */
185  BeginFileOperation( uint64_t _time, uint32_t _scltoken, OTF_KeyValueList *_kvlist );
186 
187  /** copy constructor */
189 
190  /** destructor */
192 
193  /** assignment operator */
195 
196 };
197 
198 /* *** file operation stuff ******************************** */
199 struct FileOpen {
200 
201 public:
202 
203  uint64_t time;
204  uint32_t fileid;
205  uint32_t source;
206  OTF_KeyValueList *kvlist;
207 
208 public:
209 
210  /** constructor */
211  FileOpen( uint64_t _time, uint32_t _fileid, uint32_t _source, OTF_KeyValueList *_kvlist );
212 
213  /** copy constructor */
214  FileOpen( const FileOpen& fo );
215 
216  /** destructor */
217  ~FileOpen();
218 
219  /** assignment operator */
220  FileOpen operator=( const FileOpen& fo );
221 };
222 
223 
225 
226 public:
227 
228  uint64_t nopen;
229  uint64_t nclose;
230  uint64_t nread;
231  uint64_t nwrite;
232  uint64_t nseek;
233  uint64_t bytesread;
234  uint64_t byteswrite;
235 
236 public:
237 
238  FileOperationStatistics( uint64_t no= 0, uint64_t nc= 0, uint64_t nr= 0,
239  uint64_t nw= 0, uint64_t ns= 0, uint64_t br= 0, uint64_t bw= 0 ) :
240  nopen( no ), nclose( nc ), nread( nr ), nwrite( nw ), nseek( ns ),
241  bytesread( br ), byteswrite( bw ) {};
242 
244  nopen( other.nopen ), nclose( other.nclose ), nread( other.nread ),
245  nwrite( other.nwrite ), nseek( other.nseek ),
246  bytesread( other.bytesread ), byteswrite( other.byteswrite ) {};
247 };
248 
249 
250 /* *** ProcessState *** ********************************* */
251 
252 
253 /** class containing the state of a process trace at a given */
255 
256 
257 public:
258 
259  /* function stack */
260  std::deque<FunctionCall> fstack;
261 
262  /* list of pending messages */
263  std::deque<Send> sstack;
264 
265  /* map of open files */
266  std::map<uint64_t/*handleid*/, FileOpen> openfiles;
267 
268  /* map of begun collective operations */
269  std::map<uint64_t/*matchingId*/, BeginCollOperation> beginCollOps;
270 
271  /* map of unfinished file operations */
272  std::map<uint64_t/*handleid*/, BeginFileOperation> beginFileOps;
273 
274  /* statistic per function since the beginning of the trace */
275  std::map<uint32_t,FunctionStatistics> fstatistics;
276 
277  /* statistics for messages */
278  SendStatistics sstatistics;
279 
280  /* statistics for collective operations */
281  CollectiveOperations CollOps;
282 
283  /* statistic per file since the beginning of the trace */
284  std::map<uint32_t,FileOperationStatistics> fostatistics;
285 
286 
287 public:
288 
289  /** constructor */
291 
292 
293  void enterFunction( uint64_t time, uint32_t token, OTF_KeyValueList *kvlist );
294 
295  void leaveFunction( uint64_t time, uint32_t token );
296 
297  void sendMessage( uint64_t time, uint32_t receiver, uint32_t procGroup,
298  uint32_t tag, uint32_t msglength, uint32_t source, OTF_KeyValueList *kvlist );
299 
300  void collOperation( uint64_t time, uint32_t col, uint32_t type, uint32_t numSent, uint32_t numRecv,
301  uint32_t bytesSent, uint32_t bytesRecv );
302 
303  void recvMessage( uint32_t msglength );
304 
305  void matchMessage( uint32_t receiver, uint32_t procGroup, uint32_t tag );
306 
307  int openFile( uint64_t time, uint32_t fileid, uint64_t handleid,
308  uint32_t source, OTF_KeyValueList *kvlist );
309  int closeFile( uint64_t handleid );
310  int writeFile( uint32_t fileid, uint64_t bytes );
311  int readFile( uint32_t fileid, uint64_t bytes );
312  int seekFile( uint32_t fileid, uint64_t bytes );
313 
314 
315  int beginCollOperation( uint64_t time, uint32_t root, uint32_t procGroup,
316  uint32_t col, uint32_t type, uint64_t matchingId, uint64_t invoc_sent,
317  uint64_t invoc_recv, uint64_t bytesSent, uint64_t bytesRecv,
318  uint32_t scltoken, OTF_KeyValueList *kvlist );
319 
320  int endCollOperation( uint64_t time, uint32_t matchingId );
321 
322  int beginFileOperation( uint64_t time, uint64_t matchingId, uint32_t scltoken,
323  OTF_KeyValueList *kvlist );
324 
325  int endFileOperation( uint64_t matchingId );
326 
327 
328  void printStack( uint32_t processid ) const;
329  void printStatistics( uint32_t processid, uint64_t time,
330  std::map< uint32_t, uint32_t> *functiongroups,
331  std::map< uint32_t, uint32_t> *filegroups ) const;
332  void printSends( uint32_t processid ) const;
333  void printOpenFiles( uint32_t processid ) const;
334 
335  void writeStack( OTF_Writer* writer, uint64_t time, uint32_t processid ) const;
336  void writeStatistics( OTF_Writer* writer, uint64_t time,
337  uint32_t processid,
338  std::map< uint32_t, uint32_t> *functiongroups,
339  std::map< uint32_t, uint32_t> *filegroups ) const;
340  void writeSends( OTF_Writer* writer, uint64_t time, uint32_t processid ) const;
341  void writeOpenFiles( OTF_Writer* writer, uint64_t time, uint32_t processid ) const;
342  void writeCollOps( OTF_Writer* writer, uint64_t time, uint32_t processid ) const;
343  void writeFileOps( OTF_Writer* writer, uint64_t time, uint32_t processid ) const;
344 };
345 
346 /* *** State *** **************************************** */
347 
348 /** state of a whole trace */
349 class State {
350 
351 
352  std::map<uint32_t,ProcessState> processes;
353 
354  /* maps the collective operation to its type */
355  std::map<uint32_t,uint32_t> Col2Type;
356 
357  /* maps the function to its funtiongroupid */
358  std::map< uint32_t, uint32_t> functiongroups;
359 
360  /* maps the files to its filegroupid */
361  std::map< uint32_t, uint32_t> filegroups;
362 
363  bool usefunctiongroups;
364  bool usefilegroups;
365  bool doSnapshots;
366  bool doStatistics;
367 
368 public:
369 
370  /** constructor */
371  State( bool _usefunctiongroups= false, bool _usefilegroups= false,
372  bool _doSnapshots= true, bool _doStatistics= true ) :
373  usefunctiongroups( _usefunctiongroups ), usefilegroups( _usefilegroups ),
374  doSnapshots( _doSnapshots ), doStatistics( _doStatistics ) {};
375 
376 
377  void defProcess( uint32_t processid );
378 
379  void defFunction( uint32_t function, uint32_t group );
380 
381  void defFile( uint32_t fileid, uint32_t group );
382 
383  void defCollOp( uint32_t col, uint32_t type );
384 
385  void enterFunction( uint64_t time, uint32_t processid, uint32_t token, OTF_KeyValueList *kvlist );
386 
387  void leaveFunction( uint64_t time, uint32_t processid, uint32_t token );
388 
389  void sendMessage( uint64_t time, uint32_t sender, uint32_t receiver,
390  uint32_t procGroup, uint32_t tag, uint32_t length, uint32_t source,
391  OTF_KeyValueList *kvlist );
392 
393  void collOperation( uint64_t time, uint32_t proc, uint32_t root, uint32_t col,
394  uint32_t bytesSent, uint32_t bytesRecv );
395 
396  void recvMessage( uint32_t sender, uint32_t receiver, uint32_t procGroup,
397  uint32_t tag, uint32_t msglength );
398 
399  int fileOperation( uint64_t time, uint32_t fileid, uint32_t process,
400  uint64_t handleid, uint32_t operation, uint64_t bytes,
401  uint64_t duration, uint32_t source, OTF_KeyValueList *kvlist );
402 
403  int beginCollOperation( uint64_t time, uint32_t proc, uint32_t root, uint32_t procGroup,
404  uint32_t col, uint64_t matchingId, uint64_t bytesSent, uint64_t bytesRecv,
405  uint32_t scltoken, OTF_KeyValueList *kvlist );
406 
407  int endCollOperation( uint64_t time, uint32_t proc, uint64_t matchingId );
408 
409  int beginFileOperation( uint64_t time, uint32_t process, uint64_t matchingId,
410  uint32_t scltoken, OTF_KeyValueList *kvlist );
411 
412  int endFileOperation( uint64_t time, uint32_t process, uint32_t fileid, uint64_t matchingId,
413  uint64_t handleId, uint32_t operation, uint64_t bytes, uint32_t scltoken, OTF_KeyValueList *kvlist );
414 
415 
416  void printStack() const;
417  void printStatistics( uint64_t time );
418  void printSends() const;
419  void printOpenFiles() const;
420 
421 
422  void writeSnapshot( OTF_Writer* writer, uint64_t time );
423  void writeStatistics( OTF_Writer* writer, uint64_t time );
424 };
425 
426 #endif /* STATE_H */
427 
FunctionCall(uint64_t _time, uint32_t _token, OTF_KeyValueList *_kvlist)
constructor
Definition: State.h:26
~Send()
destructor
BeginFileOperation operator=(const BeginFileOperation &fop)
assignment operator
Main include file for applications using OTF.
Definition: State.h:139
Send(uint64_t _originaltime, uint32_t _receiver, uint32_t _procGroup, uint32_t _tag, uint32_t _length, uint32_t _source, OTF_KeyValueList *_kvlist)
constructor
Send operator=(const Send &s)
assignment operator
BeginCollOperation(uint64_t _time, uint32_t _root, uint32_t _procGroup, uint32_t _col, uint32_t _type, uint64_t _invoc_sent, uint64_t _invoc_recv, uint64_t _bytesSent, uint64_t _bytesRecv, uint32_t _scltoken, OTF_KeyValueList *_kvlist)
constructor
Definition: State.h:76
Definition: State.h:52
FunctionStatistics(const FunctionStatistics &other)
copy constructor
Definition: State.h:69
ProcessState()
constructor
Definition: State.h:290
State(bool _usefunctiongroups=false, bool _usefilegroups=false, bool _doSnapshots=true, bool _doStatistics=true)
constructor
Definition: State.h:371
~FunctionCall()
destructor
state of a whole trace
Definition: State.h:349
~BeginCollOperation()
destructor
BeginFileOperation(uint64_t _time, uint32_t _scltoken, OTF_KeyValueList *_kvlist)
constructor
~FileOpen()
destructor
Definition: State.h:127
FileOpen(uint64_t _time, uint32_t _fileid, uint32_t _source, OTF_KeyValueList *_kvlist)
constructor
FileOpen operator=(const FileOpen &fo)
assignment operator
FunctionCall operator=(const FunctionCall &fc)
assignment operator
BeginCollOperation operator=(const BeginCollOperation &cop)
assignment operator
Definition: State.h:106
~BeginFileOperation()
destructor
FunctionStatistics(int64_t o=0, int64_t ex=0, int64_t in=0)
constructor
Definition: State.h:65
Definition: State.h:224
struct OTF_KeyValueList_struct OTF_KeyValueList
Object type which holds a key-value list.
Definition: OTF_KeyValue.h:242
Holds the data objects needed for global trace creation.
Definition: OTF_Writer.c:21
Definition: State.h:173
class containing the state of a process trace at a given
Definition: State.h:254
Deals with all data type related issues.
Definition: State.h:199