Added debugging messages
authorkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Sun, 17 May 2009 07:22:13 +0000 (07:22 +0000)
committerkim <kim@3cdefd35-fc62-479d-8e8d-bae585ffb9ca>
Sun, 17 May 2009 07:22:13 +0000 (07:22 +0000)
git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@391 3cdefd35-fc62-479d-8e8d-bae585ffb9ca

XMLTree.cpp

index f03360e..dfda61a 100644 (file)
@@ -1,7 +1,64 @@
-\r
 #include "basics.h"\r
 #include <cstring>\r
+#include <sstream>\r
 #include "XMLTree.h"\r
+#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
 \r
 // functions to convert tag positions to the corresponding tree node and viceversa. \r
 // These are implemented in order to be able to change the tree and Tags representations, \r
@@ -160,11 +217,14 @@ XMLTree *XMLTree::Load(int fd)
     fp = fdopen(fd, "r");\r
 \r
     XML_Tree = new XMLTree();\r
-\r
+    STARTTIMER();\r
     // Load the tree structure\r
     XML_Tree->Par = (bp *)umalloc(sizeof(bp));\r
 \r
     loadTree(XML_Tree->Par, fp); \r
+    STOPTIMER(Loading);\r
+    PRINTTIME("Loading parenthesis struct", Loading);\r
+    STARTTIMER();\r
 \r
     XML_Tree->TagName = new vector<string>();\r
     XML_Tree->tIdMap = new std::unordered_map<string,int>();\r
@@ -186,7 +246,9 @@ XMLTree *XMLTree::Load(int fd)
        XML_Tree->tIdMap->insert(std::make_pair(s,i));\r
        \r
     };\r
-\r
+    STOPTIMER(Loading);\r
+    PRINTTIME("Loading tag names struct", Loading);\r
+    STARTTIMER();\r
 \r
     // loads the tag structure\r
     XML_Tree->Tags = static_sequence::load(fp);\r
@@ -205,6 +267,9 @@ XMLTree *XMLTree::Load(int fd)
     delete [] seq;\r
     /// End ugly tests\r
     \r
+    STOPTIMER(Loading);\r
+    PRINTTIME("Loading tag struct", Loading);\r
+    STARTTIMER();\r
 \r
     // loads the flags\r
     \r
@@ -212,6 +277,11 @@ XMLTree *XMLTree::Load(int fd)
 \r
     XML_Tree->EBVector = static_bitsequence_rrr02::load(fp);\r
 \r
+\r
+    STOPTIMER(Loading);\r
+    PRINTTIME("Loading text bitvector struct", Loading);\r
+    STARTTIMER();\r
+\r
     // Not used  \r
     int sample_rate_text = 64;\r
     // loads the texts\r
@@ -219,7 +289,10 @@ XMLTree *XMLTree::Load(int fd)
       XML_Tree->Text = TextCollection::Load(fp,sample_rate_text);\r
     }\r
     else XML_Tree->Text = NULL;\r
-    \r
+    STOPTIMER(Loading);\r
+    PRINTTIME("Loading TextCollection", Loading);\r
+    STARTTIMER();\r
+\r
     return XML_Tree;\r
  }\r
 \r