Skip to content

Commit f88f51f

Browse files
danpatPatrick Niklaus
authored andcommitted
Log some memory usage statistics after preprocessing tasks.
1 parent 98659fb commit f88f51f

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

include/util/meminfo.hpp

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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

src/tools/contract.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#include <new>
1616
#include <ostream>
1717

18+
#include "util/meminfo.hpp"
19+
1820
using namespace osrm;
1921

2022
enum 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
}
171177
catch (const std::bad_alloc &e)
172178
{

src/tools/extract.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
#include <exception>
1414
#include <new>
1515

16+
#include "util/meminfo.hpp"
17+
1618
using namespace osrm;
1719

1820
enum 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
}
158164
catch (const std::bad_alloc &e)
159165
{

0 commit comments

Comments
 (0)