From f88f51fd98331d78da08378204c4182db5e38863 Mon Sep 17 00:00:00 2001 From: Daniel Patterson Date: Fri, 2 Sep 2016 14:03:57 -0700 Subject: [PATCH] Log some memory usage statistics after preprocessing tasks. --- include/util/meminfo.hpp | 43 ++++++++++++++++++++++++++++++++++++++++ src/tools/contract.cpp | 8 +++++++- src/tools/extract.cpp | 8 +++++++- 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 include/util/meminfo.hpp diff --git a/include/util/meminfo.hpp b/include/util/meminfo.hpp new file mode 100644 index 000000000..98290c7d5 --- /dev/null +++ b/include/util/meminfo.hpp @@ -0,0 +1,43 @@ +#ifndef MEMINFO_HPP +#define MEMINFO_HPP + +#include "util/log.hpp" + +#include +#ifndef _WIN32 +#include +#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: "; +#endif // _WIN32 +} +} +} + +#endif \ No newline at end of file diff --git a/src/tools/contract.cpp b/src/tools/contract.cpp index 2521e80d4..0ea179e39 100644 --- a/src/tools/contract.cpp +++ b/src/tools/contract.cpp @@ -15,6 +15,8 @@ #include #include +#include "util/meminfo.hpp" + using namespace osrm; enum class return_code : unsigned @@ -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) { diff --git a/src/tools/extract.cpp b/src/tools/extract.cpp index 3068b0168..bd0b255d1 100644 --- a/src/tools/extract.cpp +++ b/src/tools/extract.cpp @@ -13,6 +13,8 @@ #include #include +#include "util/meminfo.hpp" + using namespace osrm; enum class return_code : unsigned @@ -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) {