diff --git a/src/middle-pgsql.cpp b/src/middle-pgsql.cpp index 870bb3441..2dafdfa92 100644 --- a/src/middle-pgsql.cpp +++ b/src/middle-pgsql.cpp @@ -1258,6 +1258,8 @@ void middle_pgsql_t::after_nodes() auto const &table = m_tables.nodes(); analyze_table(m_db_connection, table.schema(), table.name()); } + + m_cache->log_stats(); } void middle_pgsql_t::after_ways() diff --git a/src/middle-ram.cpp b/src/middle-ram.cpp index 5a7bd64b3..1f39b58f3 100644 --- a/src/middle-ram.cpp +++ b/src/middle-ram.cpp @@ -190,6 +190,16 @@ void middle_ram_t::relation(osmium::Relation const &relation) } } +void middle_ram_t::after_nodes() +{ + assert(m_middle_state == middle_state::node); +#ifndef NDEBUG + m_middle_state = middle_state::way; +#endif + + m_node_locations.log_stats(); +} + osmium::Location middle_ram_t::get_node_location(osmid_t id) const { return m_node_locations.get(id); diff --git a/src/middle-ram.hpp b/src/middle-ram.hpp index 19c1245ab..1f4509fa9 100644 --- a/src/middle-ram.hpp +++ b/src/middle-ram.hpp @@ -60,6 +60,8 @@ class middle_ram_t : public middle_t, public middle_query_t void way(osmium::Way const &way) override; void relation(osmium::Relation const &) override; + void after_nodes() override; + osmium::Location get_node_location(osmid_t id) const override; std::size_t nodes_get_list(osmium::WayNodeList *nodes) const override; diff --git a/src/node-locations.cpp b/src/node-locations.cpp index b85db687c..c0417df61 100644 --- a/src/node-locations.cpp +++ b/src/node-locations.cpp @@ -9,6 +9,8 @@ #include "node-locations.hpp" +#include "logging.hpp" + // Workaround: This must be included before buffer_string.hpp due to a missing // include in the upstream code. https://github.com/mapbox/protozero/pull/104 #include @@ -79,6 +81,17 @@ osmium::Location node_locations_t::get(osmid_t id) const return osmium::Location{}; } +void node_locations_t::log_stats() +{ + constexpr auto const mbyte = 1024 * 1024; + log_debug("Node locations cache:"); + log_debug(" num locations stored: {}", m_count); + log_debug(" bytes overall: {}MB", used_memory() / mbyte); + log_debug(" data capacity: {}MB", m_data.capacity() / mbyte); + log_debug(" data size: {}MB", m_data.size() / mbyte); + log_debug(" index used memory: {}MB", m_index.used_memory() / mbyte); +} + void node_locations_t::clear() { m_data.clear(); diff --git a/src/node-locations.hpp b/src/node-locations.hpp index 7de861fd4..4e4d9495b 100644 --- a/src/node-locations.hpp +++ b/src/node-locations.hpp @@ -71,6 +71,9 @@ class node_locations_t return m_data.capacity() + m_index.used_memory(); } + /// Dump information about memory usage to debug log + void log_stats(); + /** * Clear the memory used by this object. The object can be reused after * that.