Don't create the text collection during parsing but afterwards.
[SXSI/XMLTree.git] / timings.h
1 #ifndef TIMINGS_H_
2 #define TIMINGS_H_
3 //Timing Macro's
4 #include <sys/time.h>
5 #include <time.h>
6 #include <sys/types.h>
7 #include <sys/stat.h> 
8 #include <unistd.h>
9
10 static double tParsing = 0;
11 static unsigned int cParsing = 0;
12
13 static double tLoading = 0;
14 static unsigned int cLoading = 0;
15 static double tBuilding = 0;
16 static unsigned int cBuilding = 0;
17
18 static struct timeval tmpv1;
19 static struct timeval tmpv2;
20 static std::string mem1;
21 static std::string mem2;
22
23 static void read_procmem(std::string& memstr) {
24   std::string buf;
25   pid_t pid = getpid();
26   std::stringstream path;
27   path <<  "/proc/" << pid << "/status";
28   std::ifstream infile;
29   infile.open (path.str().c_str(), std::ifstream::in);
30   while (infile.good()){
31     getline(infile,buf);
32     if (infile.eof()) {
33       memstr = "Could not read memory";
34       return;
35     };
36     int idx = buf.find("VmRSS");
37     if (idx == 0){
38       memstr = buf;
39       return;
40     };
41   };
42   memstr = "Could not read memory";
43   return;
44
45 }
46
47 #define STARTTIMER()   do {                                             \
48   read_procmem(mem1);                                                   \
49   gettimeofday(&tmpv1,NULL);                                            \
50   } while (0)                                                           \
51
52 #define STOPTIMER(x)   do {                                             \
53   gettimeofday(&tmpv2,NULL);                                            \
54   read_procmem(mem2);                                                   \
55   (t##x) = ((tmpv2.tv_sec  - tmpv1.tv_sec) * 1000000.0 +                \
56             (tmpv2.tv_usec  - tmpv1.tv_usec))/1000.0;                   \
57   (c##x)= (c##x)+1;                                                     \
58   } while (0)
59
60 #define PRINTTIME(s,x) do {                                             \
61     std::cerr << (s) << " : " << (t##x) << "ms" << std::endl;           \
62     std::cerr << "Mem use before: " << mem1 << std::endl;               \
63     std::cerr << "Mem use after: " << mem2 << std::endl;                \
64   } while (0)                                                           \
65
66
67
68
69
70
71
72
73 #endif