00001
00002
00003 #ifndef TSLog_h
00004 #define TSLog_h
00005
00006 #include <BIEmpi.h>
00007 #include <stdio.h>
00008 #include <iostream>
00009 using namespace std;
00010
00011 namespace BIE {
00012
00014 class TSLog
00015 {
00016 public:
00017
00019
00020
00021 static const int circBufNumEntries=30;
00023 char circBuf[circBufNumEntries][100];
00025 volatile int circBufPos;
00027 double startTime;
00029 bool disabled;
00030
00032 TSLog()
00033 {
00034 circBufPos = 0;
00035 startTime = MPI_Wtime();
00036 disabled = false;
00037 }
00038
00040 TSLog(bool OnorOff)
00041 {
00042 circBufPos = 0;
00043 startTime = MPI_Wtime();
00044 disabled = !OnorOff;
00045 }
00046
00047
00049 void LogIt(const char* buf)
00050 {
00051 if (disabled) return;
00052
00053 double now = MPI_Wtime();
00054 double elapsedTime = now-startTime;
00055
00056 char timeString[100];
00057 sprintf(timeString, "Time:(%f)%f - ", now, elapsedTime);
00058 strcpy(circBuf[circBufPos], timeString);
00059 strcat(circBuf[circBufPos],buf);
00060
00061 circBufPos++;
00062
00063 if (circBufPos >= circBufNumEntries) circBufPos = 0;
00064 }
00065
00068 void LogInt(const char* buf, int i)
00069 {
00070 char intString[100];
00071 sprintf(intString, "%s%d", buf, i);
00072 LogIt(intString);
00073 }
00074
00077 void LogDouble(const char* buf, double d)
00078 {
00079 char doubleString[100];
00080 sprintf(doubleString, "%s%f", buf, d);
00081 LogIt(doubleString);
00082 }
00083
00085 void PrintIt()
00086 {
00087 if (disabled) return;
00088
00089 cout << "Log " << this << "\n";
00090
00091 for (int i=0; i<circBufPos; i++){
00092 cout << " [" << i << "] " << circBuf[i] << "\n";
00093 }
00094 cout << "\n";
00095 }
00096 };
00097
00098 }
00099
00100
00101 #endif //TSLog_h