Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add memory measurements to interpreted PyROOT #95

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions include/rootbench/MemoryMeasurement.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
///\file Memory measurement.

#include <string>

//running usr/bin/time to collect measurements in perffile
std::string getMemoryStats(const std::string& dir, const std::string& filename, std::string& rootInvocation, const std::string& rootexe, const std::string& endInvoc);

//getting Maximum resident set size form perffile and storing in peakSize
int getMemoryMeasurement(std::string& perftutorial);

//extracting filename from given path
std::string getFileName(std::string& path);

1 change: 1 addition & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
RB_ADD_LIBRARY(RBSupport
ErrorHandling.cxx
MemoryMeasurement.cxx
)
51 changes: 51 additions & 0 deletions lib/MemoryMeasurement.cxx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
///\file Contains utilities to measure memory usage.
#include <iostream>
#include <cstdlib>
#include <string>
#include <cstdlib>
#include <fstream>
#include <iostream>
#include <unistd.h>
#include <chrono>
#include <stdlib.h>
#include "rootbench/RBConfig.h"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Includes should be in reverse order, that is, less generic to more generic.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I will change the order.

#include "rootbench/MemoryMeasurement.h"

std::string getFileName(std::string path) {
std::string base_fn = path.substr(path.find_last_of("/\\") + 1);
return base_fn.substr(0, base_fn.find_last_of('.'));
}

std::string getMemoryStats(const std::string& dir, const std::string& filename, std::string& rootInvocation, const std::string& rootexe, const std::string& endInvoc) {
std::string perffile="";
if (access("/usr/bin/time", X_OK) == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not hardcode this path /usr/bin/time, we should use a more standard way to resolve a system binary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alright! I will try to change it.

std::string rootsys = RB::GetRootSys();
std::string thisroot = rootsys + "/bin/thisroot.sh";
perffile = getFileName(filename) + "_perfile.txt";
if (!filename.empty()) {
std::string fullpath = rootsys + "/" + dir + filename;
// FIXME: no source in /usr/dash
// We are writing /usr/bin/time -v output in file to get maximum resident memory for the benchmark
rootInvocation = "/usr/bin/time -v -o \"" + perffile + rootexe + fullpath + endInvoc;
std::cout<<"helllloooooooooooooooooooo "<< rootInvocation <<" hellllllloooooooooooooo"<<std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like debug printouts.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes sorry, forgot to remove them.

}
else {
rootInvocation = "/usr/bin/time -v -o \"" + perffile + "\" root.exe -l -q -b "; // for pyroot?
}
}
else {
std::cout << "Cannot find usr/bin/time" << std::endl;
}
return perffile;
}
// rootInvocation = "source \"" + thisroot + "\" && /usr/bin/time -v -o \"" + perffile + "\" root.exe -l -q -b -n -x \"" + fullpath + "\" -e return ";
// rootInvocation = "source \"" + thisroot + "\" && /usr/bin/time -v -o \"" + perffile + "\" root.exe -l -q -b ";

int getMemoryMeasurement(std::string& perftutorial) {
int peakSize=0;
std::string memorytutorial = "cat \"" + perftutorial + "\"| grep 'Maximum resident set size' | awk '{print $6}' > tmp_mem_file";
int res = std::system(memorytutorial.c_str());
(void) res;
std::ifstream("tmp_mem_file") >> peakSize;
return peakSize;
}
2 changes: 1 addition & 1 deletion root/interpreter/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ RB_ADD_GBENCHMARK(InterpreterBenchmarks

RB_ADD_GBENCHMARK(InterpreterBenchmarksNoPCH
RunInterpreterNoPCH.cxx
LABEL short)
LABEL short)
34 changes: 11 additions & 23 deletions root/interpreter/InterpreterTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,27 @@

#include <chrono>

#include "rootbench/RBConfig.h"
//#include "rootbench/RBConfig.h"
#include "rootbench/MemoryMeasurement.h"

static int runTutorial(const std::string& dir, const std::string& filename, const std::string& perffile) {
std::string rootsys = RB::GetRootSys();
static int runTutorial(const std::string& dir, const std::string& filename, std::string& perftutorial) {
std::string rootInvocation;
std::string thisroot = rootsys + "/bin/thisroot.sh";
if (!filename.empty()) {
std::string fullpath = rootsys + "/" + dir + "/" + filename;
// FIXME: no source in /usr/dash
// We are writing /usr/bin/time -v output in file to get maximum resident memory for the benchmark
rootInvocation = "source \"" + thisroot + "\" && /usr/bin/time -v -o \"" + perffile + "\" root.exe -l -q -b -n -x \"" + fullpath + "\" -e return ";
} else {
rootInvocation = "source \"" + thisroot + "\" && /usr/bin/time -v -o \"" + perffile + "\" root.exe -l -q -b ";
}

std::string rootexe = "\" root.exe -l -q -b -n -x \"";
std::string endInvoc = "\" -e return ";
perftutorial = getMemoryStats(dir,filename,rootInvocation, rootexe, endInvoc);
return std::system(rootInvocation.c_str());
}

static void TestTutorial(benchmark::State &state, const char *dir, const char *tutorial) {
int peakSize = 0;
std::string perftutorial ("perfile.txt");
for(auto _ : state){
auto start = std::chrono::high_resolution_clock::now();
runTutorial(dir, tutorial,perftutorial);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed_seconds =
std::chrono::duration_cast<std::chrono::duration<double>>(
end - start);
std::string perftutorial="";
runTutorial(dir, tutorial, perftutorial);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
state.SetIterationTime(elapsed_seconds.count());
std::string memorytutorial = "cat \"" + perftutorial + "\"| grep 'Maximum resident set size' | awk '{print $6}' > tmp_mem_file";
int res = std::system(memorytutorial.c_str());
(void) res;
std::ifstream("tmp_mem_file") >> peakSize;
peakSize = getMemoryMeasurement(perftutorial);
}
state.counters.insert({{"RSS", peakSize}});
}
27 changes: 17 additions & 10 deletions root/pyroot/PyROOTTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,32 @@

#include <chrono>

#include "rootbench/RBConfig.h"
//#include "rootbench/RBConfig.h"
#include "rootbench/MemoryMeasurement.h"

static int runTutorial(const std::string& dir, const std::string& filename) {
std::string rootsys = RB::GetRootSys();
std::string fullpath = rootsys + "/" + dir + "/" + filename;
std::string rootInvocation = "root -l -b -q -e 'TPython::Exec(\" exec( open(\"" + fullpath + "\").read())\")'";
static int runTutorial(const std::string& dir, const std::string& filename, std::string& perftutorial) {
std::string rootInvocation;
std::string rootexe = "\" root -l -b -q -e 'TPython::Exec(\" exec( open('";
std::string endInvoc = "').read())\")'";
perftutorial = getMemoryStats(dir,filename,rootInvocation, rootexe, endInvoc);
return std::system(rootInvocation.c_str());

// std::string rootsys = RB::GetRootSys();
// std::string fullpath = rootsys + "/" + dir + "/" + filename;
// std::string rootInvocation = "root -l -b -q -e 'TPython::Exec(\" exec( open(\"" + fullpath + "\").read())\")'";
// return std::system(rootInvocation.c_str());
}

static void TestTutorial(benchmark::State &state, const char *dir, const char *tutorial) {
int peakSize = 0;
for(auto _ : state){
auto start = std::chrono::high_resolution_clock::now();
runTutorial(dir, tutorial);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed_seconds =
std::chrono::duration_cast<std::chrono::duration<double>>(
end - start);
std::string perftutorial="";
runTutorial(dir, tutorial, perftutorial);
auto end = std::chrono::high_resolution_clock::now();
auto elapsed_seconds = std::chrono::duration_cast<std::chrono::duration<double>>(end - start);
state.SetIterationTime(elapsed_seconds.count());
peakSize = getMemoryMeasurement(perftutorial);
}
state.counters.insert({{"RSS", peakSize}});
}