File tree Expand file tree Collapse file tree 3 files changed +57
-2
lines changed Expand file tree Collapse file tree 3 files changed +57
-2
lines changed Original file line number Diff line number Diff line change 1+ #ifndef MEMINFO_HPP
2+ #define MEMINFO_HPP
3+
4+ #include " util/log.hpp"
5+
6+ #include < stxxl/mng>
7+ #ifndef _WIN32
8+ #include < sys/resource.h>
9+ #endif
10+
11+ namespace osrm
12+ {
13+ namespace util
14+ {
15+ inline void DumpMemoryStats ()
16+ {
17+ #if STXXL_VERSION_MAJOR > 1 || (STXXL_VERSION_MAJOR == 1 && STXXL_VERSION_MINOR >= 4)
18+ auto manager = stxxl::block_manager::get_instance ();
19+ util::Log () << " STXXL: peak bytes used: " << manager->get_maximum_allocation ();
20+ util::Log () << " STXXL: total disk allocated: " << manager->get_total_bytes ();
21+ #else
22+ #warning STXXL 1.4+ recommended - STXXL memory summary will not be available
23+ util::Log () << " STXXL: memory summary not available, needs STXXL 1.4 or higher" ;
24+ #endif
25+
26+ #ifndef _WIN32
27+ rusage usage;
28+ getrusage (RUSAGE_SELF, &usage);
29+ #ifdef __linux__
30+ // Under linux, ru.maxrss is in kb
31+ util::Log () << " RAM: peak bytes used: " << usage.ru_maxrss * 1024 ;
32+ #else // __linux__
33+ // Under BSD systems (OSX), it's in bytes
34+ util::Log () << " RAM: peak bytes used: " << usage.ru_maxrss ;
35+ #endif // __linux__
36+ #else // _WIN32
37+ util::Log () << " RAM: peak bytes used: <not implemented on Windows>" ;
38+ #endif // _WIN32
39+ }
40+ }
41+ }
42+
43+ #endif
Original file line number Diff line number Diff line change 1515#include < new>
1616#include < ostream>
1717
18+ #include " util/meminfo.hpp"
19+
1820using namespace osrm ;
1921
2022enum class return_code : unsigned
@@ -166,7 +168,11 @@ int main(int argc, char *argv[]) try
166168
167169 tbb::task_scheduler_init init (contractor_config.requested_num_threads );
168170
169- return contractor::Contractor (contractor_config).Run ();
171+ auto exitcode = contractor::Contractor (contractor_config).Run ();
172+
173+ util::DumpMemoryStats ();
174+
175+ return exitcode;
170176}
171177catch (const std::bad_alloc &e)
172178{
Original file line number Diff line number Diff line change 1313#include < exception>
1414#include < new>
1515
16+ #include " util/meminfo.hpp"
17+
1618using namespace osrm ;
1719
1820enum class return_code : unsigned
@@ -153,7 +155,11 @@ int main(int argc, char *argv[]) try
153155 // setup scripting environment
154156 extractor::LuaScriptingEnvironment scripting_environment (
155157 extractor_config.profile_path .string ().c_str ());
156- return extractor::Extractor (extractor_config).run (scripting_environment);
158+ auto exitcode = extractor::Extractor (extractor_config).run (scripting_environment);
159+
160+ util::DumpMemoryStats ();
161+
162+ return exitcode;
157163}
158164catch (const std::bad_alloc &e)
159165{
You can’t perform that action at this time.
0 commit comments