00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "peo_debug.h"
00038
00039 #include <stdio.h>
00040 #include <time.h>
00041 #include <unistd.h>
00042 #include <string.h>
00043 #include <sys/types.h>
00044 #include <sys/stat.h>
00045 #include <vector>
00046
00047 #include "peo_debug.h"
00048
00049 #define MAX_BUFF_SIZE 1000
00050
00051 #define DEBUG_PATH "./log/"
00052
00053 static bool debug = true;
00054
00055 static char host [MAX_BUFF_SIZE];
00056
00057 std :: vector <FILE *> files;
00058
00059 void setDebugMode (bool __dbg) {
00060
00061 debug = __dbg;
00062 gethostname (host, MAX_BUFF_SIZE);
00063 }
00064
00065 extern int getNodeRank ();
00066
00067 void initDebugging () {
00068
00069 mkdir (DEBUG_PATH, S_IRWXU);
00070
00071 char buff [MAX_BUFF_SIZE];
00072 sprintf (buff, "%s/%d", DEBUG_PATH, getNodeRank ());
00073 files.push_back (fopen (buff, "w"));
00074 }
00075
00076 void endDebugging () {
00077
00078 for (unsigned i = 0; i < files.size (); i ++)
00079 if (files [i] != stdout)
00080 fclose (files [i]);
00081 }
00082
00083 void printDebugMessage (const char * __mess) {
00084
00085 if (debug) {
00086
00087 char buff [MAX_BUFF_SIZE];
00088 time_t t = time (0);
00089
00090
00091 sprintf (buff, "[%s][%s: ", host, ctime (& t));
00092 * strchr (buff, '\n') = ']';
00093 for (unsigned i = 0; i < files.size (); i ++)
00094 fprintf (files [i], buff);
00095
00096
00097 sprintf (buff, "%s", __mess);
00098
00099 for (unsigned i = 0; i < files.size (); i ++) {
00100 fputs (buff, files [i]);
00101 fputs ("\n", files [i]);
00102 fflush (files [i]);
00103 }
00104 }
00105 }