tracer.h

Go to the documentation of this file.
00001 #ifndef _TRACER_H_
00002 #define _TRACER_H_
00003 
00004 #include <sys/time.h>
00005 #include <sys/resource.h>
00006 #include <unistd.h>
00007 #include <stdarg.h>
00008 #include <string.h>
00009 #include <stack/stack.h>
00010 #include <dbLkList/dbLkList.h>
00011 
00012 #define MAXSAVEDSTATES 1000
00013 
00014 #define SEPARATOR " "
00015 
00016 /* Possible atrtibute types:
00017  *
00018  * i : integer
00019  * s : string ( char * )
00020  * a : integer array ( int * ) -> first element must be the size -1 
00021  *                                Use iArrayToTrc( int size, int * array )
00022  * I : Post-informed ( on trcLeaveState ) integer.
00023  * S : Post-informed ( on trcLeaveState ) string.
00024  * A : Post-informed ( on trcLeaveState ) integer array.
00025  */
00026 
00027 
00028 /** This is a state attribute */
00029 typedef struct _TrcAttribute_ {
00030         char type;
00031         void * value;
00032 } TrcAttribute;
00033 
00034 /** This is a state */
00035 typedef struct _TrcState_ {
00036         struct timeval initTime;    // initial time for this state
00037         struct timeval endTime;     // final time for this state
00038         struct rusage initRusage;   // initial rusage statistics for this state 
00039         struct rusage endRusage;    // final rusage statistics for this state 
00040         int numAttributes;
00041         int numPosAttributes;
00042         TrcAttribute * attributes;              // other attributes of the state
00043 } TrcState;
00044 
00045 /** This holds the tracing data */
00046 typedef struct _TrcData_ {
00047         
00048         TrcState *currentState; // the state we are
00049         FILE * tracefile;       // FILE * to the file where tracing data will be written
00050         
00051         struct timeval initTime;
00052         
00053         int numSavedStates;     // number of states in list
00054         DbLkList *savedStates;  // a list of saved states
00055 
00056         Stack *stackedStates;   // stack of states, so we can have recursive calls      
00057         int numStackedStates;
00058 
00059         char firstFlush;
00060         
00061 } TrcData;
00062 
00063 /** Starts the tracing data, zeroing everything
00064   * @return the tracing data created
00065   */
00066 TrcData *trcCreateData( char * filename );
00067 
00068 /** Enters a specific state, setting the values of the attributes
00069  *  @param id = a pointer to an TrcData structure returned by a previous trcCreateData call; 
00070  *  @param types = a null terminated string of length = numAttributes 
00071  *                 specifying the types of the incoming attributes, as above:
00072  *    i = fixed integer
00073  *    s = fixed string
00074  *      
00075  */
00076 void trcEnterState(TrcData *trc, char * types, ...);
00077 
00078 /** Destroys the Tracing data, NULLing the pointer.
00079   *
00080   *@param trcPointer the address of the Tracing data pointer, which will be NULL after this call
00081   */
00082 void trcDestroyData(TrcData **trcPointer);
00083 
00084 /** leaves the current state, computing times for it.
00085  * The current state is set to the Top of the stack, which is poped
00086  * @param trc Pointer to tracing data
00087  */
00088 void trcLeaveState(TrcData *trc, ...);
00089 
00090 /** Saves all tracing data to a file, appending time there
00091   *@param filename the name of the file to save
00092   *@param label a label to write with the timing results
00093   */
00094 void trcFlush(TrcData *trc);
00095 
00096 int * trcIArrayToTrc( int size, int * array );
00097 
00098 /** Reset the initial time of the current state, as if trcEnterState
00099  *  was called again ( but no other state is created ).
00100  *  @param trc Pointer to tracing data
00101  */
00102 void trcResetCurrentState( TrcData * trc );
00103 
00104 #endif

Generated on Tue Jan 17 19:18:39 2006 for Void by  doxygen 1.4.6