00001
00002 #ifndef __TRACE_CORE_H__
00003 #define __TRACE_CORE_H__
00004
00005 #include <stdio.h>
00006 #include <stdlib.h>
00007 #include <string.h>
00008
00009 #include "converse.h"
00010
00011 #define MAX_NUM_LANGUAGES 32 //NOTE: fixed temporarily
00012
00013
00014
00015
00016 class TraceCore;
00017 class TraceLogger;
00018 class TraceEntry;
00019
00020 CpvExtern(int, _traceCoreOn);
00021
00022
00023 struct TraceCoreEvent {
00024 int eID;
00025 struct TraceCoreEvent *next;
00026 };
00027
00028
00029 class TraceCore
00030 {
00031 private:
00032 TraceLogger* traceLogger;
00033 void startPtc();
00034 void closePtc();
00035 FILE *fpPtc;
00036 struct TraceCoreEvent *eventLists[MAX_NUM_LANGUAGES];
00037 int maxlID;
00038 int maxeID[MAX_NUM_LANGUAGES];
00039 int numLangs;
00040 int numEvents[MAX_NUM_LANGUAGES];
00041 int lIDList[MAX_NUM_LANGUAGES];
00042 char *lNames[MAX_NUM_LANGUAGES];
00043 int traceCoreOn;
00044 public:
00045 TraceCore(char** argv);
00046 ~TraceCore();
00047
00048
00049 void RegisterLanguage(int lID);
00050 void RegisterLanguage(int lID, const char* lName);
00051 void RegisterEvent(int lID, int eID);
00052 void LogEvent(int lID, int eID);
00053 void LogEvent(int lID, int eID, int iLen, const int* iData);
00054 void LogEvent(int lID, int eID, int iLen, const int* iData,double t);
00055 void LogEvent(int lID, int eID, int sLen, const char* sData);
00056 void LogEvent(int lID, int eID, int iLen, const int* iData, int sLen, const char* sData);
00057
00058 };
00059
00060 class TraceEntry
00061 {
00062 public:
00063 int languageID;
00064 int eventID;
00065 double timestamp;
00066 int eLen;
00067 int* entity;
00068 int iLen;
00069 int* iData;
00070 int sLen;
00071 char* sData;
00072
00073 TraceEntry() {}
00074 TraceEntry(int lID, int eID, double ts, int el, int* e,
00075 int il, int* i, int sl, char* s):
00076 languageID(lID), eventID(eID), timestamp(ts),
00077 eLen(el), entity(e), iLen(il), iData(i), sLen(sl), sData(s) {}
00078 TraceEntry(int lID, int eID, double ts,
00079 int il, int* i, int sl, char* s):
00080 languageID(lID), eventID(eID), timestamp(ts),
00081 eLen(0), entity(NULL), iLen(il), iData(i), sLen(sl), sData(s) {}
00082 TraceEntry(TraceEntry& te);
00083 ~TraceEntry();
00084
00085 void *operator new(size_t s) {void*ret=malloc(s);_MEMCHECK(ret);return ret;}
00086 void *operator new(size_t, void *ptr) { return ptr; }
00087 void operator delete(void *ptr) { free(ptr); }
00088 #if defined(_WIN32) || CMK_MULTIPLE_DELETE
00089 void operator delete(void *, void *) { }
00090 #endif
00091
00092 void write(FILE* fp, int prevLID, int prevSeek, int nextLID, int nextSeek);
00093 };
00094
00095 class TraceLogger
00096 {
00097 private:
00098 int poolSize;
00099 int numEntries;
00100 TraceEntry *pool;
00101 TraceEntry *buffer;
00102
00103 int numLangs;
00104 char *lName[MAX_NUM_LANGUAGES];
00105 char *fName[MAX_NUM_LANGUAGES];
00106 FILE *fptrs[MAX_NUM_LANGUAGES];
00107
00108 int binary;
00109
00110 bool lastWriteFlag;
00111 int prevLID, prevSeek;
00112 bool isWriting;
00113
00114 public:
00115 TraceLogger(char* program, int b);
00116 ~TraceLogger();
00117
00118 void RegisterLanguage(int lID, const char* ln);
00119
00120 void write(void);
00121 void writeBinary(void);
00122 void writeSts(void);
00123
00124 void add(int lID, int eID, double timestamp, int iLen, int* iData, int sLen, char* sData);
00125 void initlogfiles();
00126
00127
00128 private:
00129 void openLogFiles();
00130 void closeLogFiles();
00131 void verifyFptrs();
00132 void flushLogFiles();
00133
00134 char* pgm;
00135 };
00136
00137 #endif