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