Commit edf7b62e authored by Utkarsh Ayachit's avatar Utkarsh Ayachit

Added support to track VmHWM.

parent ecad2cf2
......@@ -2,9 +2,11 @@
#include "TimerC.h"
#include <sys/time.h>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <stdint.h>
#include <map>
#include <list>
......@@ -23,6 +25,27 @@ namespace impl
return tv.tv_sec + tv.tv_usec/1.0e6;
}
static uint64_t get_vmhwm()
{
std::ifstream in("/proc/self/status");
if (!in)
{
return 0;
}
std::string line;
while (std::getline(in, line))
{
if (strncmp(line.c_str(), "VmHWM:", 6) == 0)
{
std::istringstream iss(line.substr(6));
uint64_t val;
iss >> val;
return val;
}
}
return 0;
}
struct Indent
{
int Count;
......@@ -42,13 +65,15 @@ namespace impl
{
std::string Name;
double Duration;
Event() : Duration(-1.0) {}
uint64_t VmHWM;
Event() : Duration(-1.0), VmHWM(0) {}
bool IsValid() const
{ return this->Duration > -1.0; }
void PrintLog(std::ostream& stream, Indent indent) const
{
stream << indent << this->Name.c_str() << " = " << this->Duration << endl;
stream << indent << this->Name.c_str() << " = "
<< this->Duration << " s, " << this->VmHWM << " kB" << endl;
for (std::list<Event>::const_iterator iter = this->SubEvents.begin();
iter != this->SubEvents.end(); ++iter)
{
......@@ -114,6 +139,7 @@ void MarkEndEvent(const char* eventname)
}
evt.Duration = impl::get_mark() - evt.Duration;
evt.VmHWM = impl::get_vmhwm();
impl::Mark.pop_back();
if (impl::Mark.empty())
......@@ -140,7 +166,15 @@ void MarkEndTimeStep()
//-----------------------------------------------------------------------------
void PrintLog(std::ostream& stream)
{
stream
<< "=================================================================\n"
<< " Time/Memory log :\n"
<< " -----------------\n"
<< " Prints duration and VmHWM at the end of each step.\n"
<< "-----------------------------------------------------------------\n";
impl::PrintLog(stream, impl::Indent());
stream
<< "=================================================================\n";
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment