From: kim Date: Sun, 17 May 2009 07:22:13 +0000 (+0000) Subject: Added debugging messages X-Git-Url: http://git.nguyen.vg/gitweb/?p=SXSI%2FXMLTree.git;a=commitdiff_plain;h=fadbf5f42541aa09769cbe406f5756fa042fe2d9 Added debugging messages git-svn-id: svn+ssh://idea.nguyen.vg/svn/sxsi/trunk/XMLTree@391 3cdefd35-fc62-479d-8e8d-bae585ffb9ca --- diff --git a/XMLTree.cpp b/XMLTree.cpp index f03360e..dfda61a 100644 --- a/XMLTree.cpp +++ b/XMLTree.cpp @@ -1,7 +1,64 @@ - #include "basics.h" #include +#include #include "XMLTree.h" +#include +#include +#include +#include + +static double tLoading = 0; + +static unsigned int cLoading = 0; +static struct timeval tmpv1; +static struct timeval tmpv2; +static string mem1; +static string mem2; + +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 { \ + gettimeofday(&tmpv1,NULL); \ + read_procmem(mem1); \ + } while (0) \ + +#define STOPTIMER(x) do { \ + read_procmem(mem2); \ + gettimeofday(&tmpv2,NULL); \ + (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; \ + std::cerr.flush(); \ + } while (0) \ + // functions to convert tag positions to the corresponding tree node and viceversa. // These are implemented in order to be able to change the tree and Tags representations, @@ -160,11 +217,14 @@ XMLTree *XMLTree::Load(int fd) fp = fdopen(fd, "r"); XML_Tree = new XMLTree(); - + STARTTIMER(); // Load the tree structure XML_Tree->Par = (bp *)umalloc(sizeof(bp)); loadTree(XML_Tree->Par, fp); + STOPTIMER(Loading); + PRINTTIME("Loading parenthesis struct", Loading); + STARTTIMER(); XML_Tree->TagName = new vector(); XML_Tree->tIdMap = new std::unordered_map(); @@ -186,7 +246,9 @@ XMLTree *XMLTree::Load(int fd) XML_Tree->tIdMap->insert(std::make_pair(s,i)); }; - + STOPTIMER(Loading); + PRINTTIME("Loading tag names struct", Loading); + STARTTIMER(); // loads the tag structure XML_Tree->Tags = static_sequence::load(fp); @@ -205,6 +267,9 @@ XMLTree *XMLTree::Load(int fd) delete [] seq; /// End ugly tests + STOPTIMER(Loading); + PRINTTIME("Loading tag struct", Loading); + STARTTIMER(); // loads the flags @@ -212,6 +277,11 @@ XMLTree *XMLTree::Load(int fd) XML_Tree->EBVector = static_bitsequence_rrr02::load(fp); + + STOPTIMER(Loading); + PRINTTIME("Loading text bitvector struct", Loading); + STARTTIMER(); + // Not used int sample_rate_text = 64; // loads the texts @@ -219,7 +289,10 @@ XMLTree *XMLTree::Load(int fd) XML_Tree->Text = TextCollection::Load(fp,sample_rate_text); } else XML_Tree->Text = NULL; - + STOPTIMER(Loading); + PRINTTIME("Loading TextCollection", Loading); + STARTTIMER(); + return XML_Tree; }