Skip to content

Commit

Permalink
Log some memory usage statistics after preprocessing tasks.
Browse files Browse the repository at this point in the history
  • Loading branch information
danpat authored and Patrick Niklaus committed Dec 13, 2016
1 parent 98659fb commit f88f51f
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 2 deletions.
43 changes: 43 additions & 0 deletions include/util/meminfo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#ifndef MEMINFO_HPP
#define MEMINFO_HPP

#include "util/log.hpp"

#include <stxxl/mng>
#ifndef _WIN32
#include <sys/resource.h>
#endif

namespace osrm
{
namespace util
{
inline void DumpMemoryStats()
{
#if STXXL_VERSION_MAJOR > 1 || (STXXL_VERSION_MAJOR == 1 && STXXL_VERSION_MINOR >= 4)
auto manager = stxxl::block_manager::get_instance();
util::Log() << "STXXL: peak bytes used: " << manager->get_maximum_allocation();
util::Log() << "STXXL: total disk allocated: " << manager->get_total_bytes();
#else
#warning STXXL 1.4+ recommended - STXXL memory summary will not be available
util::Log() << "STXXL: memory summary not available, needs STXXL 1.4 or higher";
#endif

#ifndef _WIN32
rusage usage;
getrusage(RUSAGE_SELF, &usage);
#ifdef __linux__
// Under linux, ru.maxrss is in kb
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss * 1024;
#else // __linux__
// Under BSD systems (OSX), it's in bytes
util::Log() << "RAM: peak bytes used: " << usage.ru_maxrss;
#endif // __linux__
#else // _WIN32
util::Log() << "RAM: peak bytes used: <not implemented on Windows>";
#endif // _WIN32
}
}
}

#endif
8 changes: 7 additions & 1 deletion src/tools/contract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include <new>
#include <ostream>

#include "util/meminfo.hpp"

using namespace osrm;

enum class return_code : unsigned
Expand Down Expand Up @@ -166,7 +168,11 @@ int main(int argc, char *argv[]) try

tbb::task_scheduler_init init(contractor_config.requested_num_threads);

return contractor::Contractor(contractor_config).Run();
auto exitcode = contractor::Contractor(contractor_config).Run();

util::DumpMemoryStats();

return exitcode;
}
catch (const std::bad_alloc &e)
{
Expand Down
8 changes: 7 additions & 1 deletion src/tools/extract.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#include <exception>
#include <new>

#include "util/meminfo.hpp"

using namespace osrm;

enum class return_code : unsigned
Expand Down Expand Up @@ -153,7 +155,11 @@ int main(int argc, char *argv[]) try
// setup scripting environment
extractor::LuaScriptingEnvironment scripting_environment(
extractor_config.profile_path.string().c_str());
return extractor::Extractor(extractor_config).run(scripting_environment);
auto exitcode = extractor::Extractor(extractor_config).run(scripting_environment);

util::DumpMemoryStats();

return exitcode;
}
catch (const std::bad_alloc &e)
{
Expand Down

0 comments on commit f88f51f

Please sign in to comment.