-
-
Notifications
You must be signed in to change notification settings - Fork 480
Expand file tree
/
Copy pathprogress-display.cpp
More file actions
121 lines (100 loc) · 3.27 KB
/
Copy pathprogress-display.cpp
File metadata and controls
121 lines (100 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2024 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include "format.hpp"
#include "logging.hpp"
#include "progress-display.hpp"
#include "util.hpp"
namespace {
double count_per_second(std::size_t count, uint64_t elapsed) noexcept
{
if (count == 0) {
return 0.0;
}
if (elapsed == 0) {
return static_cast<double>(count);
}
return static_cast<double>(count) / static_cast<double>(elapsed);
}
std::string cps_display(std::size_t count, uint64_t elapsed)
{
double const cps = count_per_second(count, elapsed);
if (cps >= 1000.0) {
return fmt::format("{:.0f}k/s", cps / 1000);
}
return fmt::format("{:.0f}/s", cps);
}
} // anonymous namespace
void progress_display_t::print_summary() const
{
std::time_t const now = std::time(nullptr);
if (m_enabled) {
get_logger().no_leading_return();
fmt::print(stderr, "\r{:90s}\r", "");
}
log_info("Reading input files done in {}.",
util::human_readable_duration(overall_time(now)));
auto const nt = nodes_time(now);
log_info(" Processed {} nodes in {} - {}", m_node.count,
util::human_readable_duration(nt), cps_display(m_node.count, nt));
auto const wt = ways_time(now);
log_info(" Processed {} ways in {} - {}", m_way.count,
util::human_readable_duration(wt), cps_display(m_way.count, wt));
auto const rt = rels_time(now);
log_info(" Processed {} relations in {} - {}", m_rel.count,
util::human_readable_duration(rt), cps_display(m_rel.count, rt));
}
void progress_display_t::print_status(std::time_t now) const
{
if (m_enabled) {
get_logger().needs_leading_return();
fmt::print(stderr,
"\rProcessing: Node({}k {:.1f}k/s) Way({}k {:.2f}k/s)"
" Relation({} {:.1f}/s)",
m_node.count_k(),
count_per_second(m_node.count_k(), nodes_time(now)),
m_way.count_k(),
count_per_second(m_way.count_k(), ways_time(now)),
m_rel.count, count_per_second(m_rel.count, rels_time(now)));
}
}
void progress_display_t::possibly_print_status()
{
std::time_t const now = std::time(nullptr);
if (m_last_print_time < now) {
m_last_print_time = now;
print_status(now);
}
}
uint64_t progress_display_t::nodes_time(std::time_t now) const noexcept
{
if (m_node.count == 0) {
return 0;
}
return static_cast<uint64_t>((m_way.start > 0 ? m_way.start : now) -
m_node.start);
}
uint64_t progress_display_t::ways_time(std::time_t now) const noexcept
{
if (m_way.count == 0) {
return 0;
}
return static_cast<uint64_t>((m_rel.start > 0 ? m_rel.start : now) -
m_way.start);
}
uint64_t progress_display_t::rels_time(std::time_t now) const noexcept
{
if (m_rel.count == 0) {
return 0;
}
return static_cast<uint64_t>(now - m_rel.start);
}
uint64_t progress_display_t::overall_time(std::time_t now) const noexcept
{
return static_cast<uint64_t>(now - m_node.start);
}