00001 #ifndef _INSTRUMENTATION_H_ 00002 #define _INSTRUMENTATION_H_ 00003 00004 #include <sys/time.h> 00005 #include <stack/stack.h> 00006 #include "../constants.h" 00007 00008 /** The program can be in either of these states 00009 * proc means processing 00010 * read means entered a receive function 00011 * write means entered a write function 00012 * init means is initializing(initFilter) 00013 * finalizing mean is in finalize(finalizeFilter) 00014 * void means time void used for its own 00015 * end is used to end timing results 00016 * process is the sum of proc, read and write 00017 */ 00018 typedef enum { 00019 TIMER_INIT=0, TIMER_PROC, TIMER_READ, 00020 TIMER_WRITE, TIMER_WRITE_BLOCKED, TIMER_LS, 00021 TIMER_FINALIZE, TIMER_VOID, TIMER_END 00022 } TimerState; 00023 /** WARNING: if you change the number of states above, change here also! */ 00024 #define TIMER_NUM_VOID_STATES 9 00025 00026 #ifdef _INSTRUMENTATION_C_ 00027 char *timerStateNames[TIMER_NUM_VOID_STATES]={ 00028 "timer_init", "timer_proc", "timer_read", "timer_write", "timer_w_bkd", 00029 "timer_ls", "timer_finalize", "timer_void", "timer_end_not_used"}; 00030 #endif 00031 00032 #define INST_DIR "instrumentation" 00033 00034 /** this is a state */ 00035 typedef struct _InstState_ { 00036 struct timeval timing; //< the timing for this state 00037 char *stateName; //< a name to the state, used to print it 00038 int isUserState; //< indicates this is a user state 00039 } InstState; 00040 00041 /** this holds the instrumentation data */ 00042 typedef struct _InstrumentationData { 00043 char instDir[MAX_IDIR_LENGTH+1]; //< the instrumentation directory, we write results to this 00044 00045 InstState voidStates[TIMER_NUM_VOID_STATES]; //< void states 00046 InstState *userStates; //< user states 00047 int numUserStates; //< number of user states 00048 00049 /** current timer */ 00050 struct timeval tv; //< time val used to calculate the above timings 00051 struct timezone tz; //< not used 00052 00053 InstState *currentState; //< the state we are 00054 Stack *stackedStates; //< stack of states, so we can have recursive calls 00055 } InstData; 00056 00057 /** Starts the instrumentation data, zeroing everything 00058 * @return the instrumentation data created 00059 */ 00060 InstData *instCreate(); 00061 00062 00063 /** Destroys the Instrumentation data, NULLing the pointer. 00064 * 00065 *@param InstDataPointerAddress the address of the Instrumentation data pointer, which will be NULL after this call 00066 */ 00067 void instDestroy(InstData **InstDataPointerAddress); 00068 00069 /** Sets instrumentation directory, where we write instrumentation data. Its usually instrumentation/#-#-#... where # is the number 00070 * of instances each filter has in the pipeline 00071 * 00072 * @param dir the directory 00073 */ 00074 void instSetDir(InstData *inst, char *dir); 00075 00076 00077 /** enter a state, which can be a void state or am user state. The current state timings are computed and 00078 * is stacked, so we can return to it later 00079 *@param state the state we are changing to 00080 *@param isUserState is this state a user state? 00081 */ 00082 void instEnterState(InstData *inst, InstState *state); 00083 00084 /** switches the state, which means the current one is computed but not stacked, and current is set to the new one */ 00085 void instSwitchState(InstData *inst, InstState *state); 00086 00087 /** leaves the current state, computing times for it. The current state is set to the Top of the stack, which is poped 00088 * @param inst the instrumentation data 00089 */ 00090 void instLeaveState(InstData *inst); 00091 00092 00093 00094 /** Saves all instrumentation data to a file, appending time there 00095 *@param filename the name of the file to save 00096 *@param label a label to write with the timing results 00097 */ 00098 void instSaveTimings(InstData *inst, char *filename, char *label); 00099 00100 /** Adds user states to the instrumentation. 00101 * User can give us his own states 00102 * 00103 * @param userStatesArray an array of user states names, NULL if not used 00104 * @param numStates the number of states in the user array 00105 */ 00106 void instSetUserStates(InstData *inst, char **userStatesArray, int numStates); 00107 00108 #endif
1.4.6