Skip to content

Commit c7578ac

Browse files
authored
Merge pull request #2156 from joto/debug-log-cache
Dump some stats about memory usage of cache to debug log
2 parents bdd5583 + 978e525 commit c7578ac

5 files changed

+30
-0
lines changed

src/middle-pgsql.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,8 @@ void middle_pgsql_t::after_nodes()
12581258
auto const &table = m_tables.nodes();
12591259
analyze_table(m_db_connection, table.schema(), table.name());
12601260
}
1261+
1262+
m_cache->log_stats();
12611263
}
12621264

12631265
void middle_pgsql_t::after_ways()

src/middle-ram.cpp

+10
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,16 @@ void middle_ram_t::relation(osmium::Relation const &relation)
190190
}
191191
}
192192

193+
void middle_ram_t::after_nodes()
194+
{
195+
assert(m_middle_state == middle_state::node);
196+
#ifndef NDEBUG
197+
m_middle_state = middle_state::way;
198+
#endif
199+
200+
m_node_locations.log_stats();
201+
}
202+
193203
osmium::Location middle_ram_t::get_node_location(osmid_t id) const
194204
{
195205
return m_node_locations.get(id);

src/middle-ram.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class middle_ram_t : public middle_t, public middle_query_t
6060
void way(osmium::Way const &way) override;
6161
void relation(osmium::Relation const &) override;
6262

63+
void after_nodes() override;
64+
6365
osmium::Location get_node_location(osmid_t id) const override;
6466

6567
std::size_t nodes_get_list(osmium::WayNodeList *nodes) const override;

src/node-locations.cpp

+13
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99

1010
#include "node-locations.hpp"
1111

12+
#include "logging.hpp"
13+
1214
// Workaround: This must be included before buffer_string.hpp due to a missing
1315
// include in the upstream code. https://github.com/mapbox/protozero/pull/104
1416
#include <protozero/config.hpp>
@@ -79,6 +81,17 @@ osmium::Location node_locations_t::get(osmid_t id) const
7981
return osmium::Location{};
8082
}
8183

84+
void node_locations_t::log_stats()
85+
{
86+
constexpr auto const mbyte = 1024 * 1024;
87+
log_debug("Node locations cache:");
88+
log_debug(" num locations stored: {}", m_count);
89+
log_debug(" bytes overall: {}MB", used_memory() / mbyte);
90+
log_debug(" data capacity: {}MB", m_data.capacity() / mbyte);
91+
log_debug(" data size: {}MB", m_data.size() / mbyte);
92+
log_debug(" index used memory: {}MB", m_index.used_memory() / mbyte);
93+
}
94+
8295
void node_locations_t::clear()
8396
{
8497
m_data.clear();

src/node-locations.hpp

+3
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,9 @@ class node_locations_t
7171
return m_data.capacity() + m_index.used_memory();
7272
}
7373

74+
/// Dump information about memory usage to debug log
75+
void log_stats();
76+
7477
/**
7578
* Clear the memory used by this object. The object can be reused after
7679
* that.

0 commit comments

Comments
 (0)