+#ifndef TIMINGS_H_
+#define TIMINGS_H_
+//Timing Macro's
+#include <sys/time.h>
+#include <time.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+static double tParsing = 0;
+static unsigned int cParsing = 0;
+
+static double tLoading = 0;
+static unsigned int cLoading = 0;
+static double tBuilding = 0;
+static unsigned int cBuilding = 0;
+
+static struct timeval tmpv1;
+static struct timeval tmpv2;
+static string mem1;
+static string mem2;
+
+static void read_procmem(string& memstr) {
+ std::string buf;
+ pid_t pid = getpid();
+ std::stringstream path;
+ path << "/proc/" << pid << "/status";
+ std::ifstream infile;
+ infile.open (path.str().c_str(), std::ifstream::in);
+ while (infile.good()){
+ getline(infile,buf);
+ if (infile.eof()) {
+ memstr = "Could not read memory";
+ return;
+ };
+ int idx = buf.find("VmRSS");
+ if (idx == 0){
+ memstr = buf;
+ return;
+ };
+ };
+ memstr = "Could not read memory";
+ return;
+
+}
+
+#define STARTTIMER() do { \
+ read_procmem(mem1); \
+ gettimeofday(&tmpv1,NULL); \
+ } while (0) \
+
+#define STOPTIMER(x) do { \
+ gettimeofday(&tmpv2,NULL); \
+ read_procmem(mem2); \
+ (t##x) = ((tmpv2.tv_sec - tmpv1.tv_sec) * 1000000.0 + \
+ (tmpv2.tv_usec - tmpv1.tv_usec))/1000.0; \
+ (c##x)= (c##x)+1; \
+ } while (0)
+
+#define PRINTTIME(s,x) do { \
+ std::cerr << (s) << " : " << (t##x) << "ms" << std::endl; \
+ std::cerr << "Mem use before: " << mem1 << std::endl; \
+ std::cerr << "Mem use after: " << mem2 << std::endl; \
+ } while (0) \
+
+
+
+
+
+
+
+
+#endif