From 97222189ad907b6da8ddbd453e9b6783b1377152 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20G=C3=BCndling?= Date: Mon, 4 Nov 2024 11:51:23 +0100 Subject: [PATCH] add more timing information --- src/endpoints/routing.cc | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/endpoints/routing.cc b/src/endpoints/routing.cc index 5e5f4ee5b..8d4ddec0d 100644 --- a/src/endpoints/routing.cc +++ b/src/endpoints/routing.cc @@ -350,7 +350,9 @@ std::pair, n::duration_t> routing::route_direct( return {itineraries, fastest_direct}; } -std::map join(auto&&... maps) { +using stats_map_t = std::map; + +stats_map_t join(auto&&... maps) { auto ret = std::map{}; auto const add = [&](std::map const& x) { ret.insert(begin(x), end(x)); @@ -431,6 +433,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const { auto const [start_time, t] = get_start_time(query); + UTL_START_TIMING(direct); auto const [direct, fastest_direct] = (holds_alternative(from) && holds_alternative(to) && t.has_value()) @@ -438,12 +441,14 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const { query.wheelchair_, std::chrono::seconds{query.maxDirectTime_}) : std::pair{std::vector{}, kInfinityDuration}; + UTL_STOP_TIMING(direct); if (utl::find(modes, api::ModeEnum::TRANSIT) != end(modes) && fastest_direct > 5min) { utl::verify(tt_ != nullptr && tags_ != nullptr, "mode=TRANSIT requires timetable to be loaded"); + UTL_START_TIMING(query_preparation); auto q = n::routing::query{ .start_time_ = start_time.start_time_, .start_match_mode_ = get_match_mode(start), @@ -517,6 +522,7 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const { ? std::nullopt : std::optional{fastest_direct}}; remove_slower_than_fastest_direct(q); + UTL_STOP_TIMING(query_preparation); if (tt_->locations_.footpaths_out_.at(q.prf_idx_).empty()) { q.prf_idx_ = 0U; @@ -535,7 +541,10 @@ api::plan_response routing::operator()(boost::urls::url_view const& url) const { std::nullopt); return { - .debugOutput_ = join(r.search_stats_.to_map(), r.algo_stats_.to_map()), + .debugOutput_ = join(stats_map_t{{"direct", UTL_TIMING_MS(direct)}, + {"query_preparation", + UTL_TIMING_MS(query_preparation)}}, + r.search_stats_.to_map(), r.algo_stats_.to_map()), .from_ = from_p, .to_ = to_p, .direct_ = std::move(direct),