forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprogress-display.hpp
More file actions
91 lines (73 loc) · 2.07 KB
/
Copy pathprogress-display.hpp
File metadata and controls
91 lines (73 loc) · 2.07 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
#ifndef OSM2PGSQL_PROGRESS_DISPLAY_HPP
#define OSM2PGSQL_PROGRESS_DISPLAY_HPP
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2021 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
/**
* \file
*
* This file is part of osm2pgsql (https://github.com/openstreetmap/osm2pgsql).
*
* It contains the progress_display_t class.
*/
#include <cstddef>
#include <ctime>
#include <osmium/handler.hpp>
/**
* The progress_display_t class is used to display how far the processing of
* the input data has progressed.
*/
class progress_display_t : public osmium::handler::Handler
{
struct Counter
{
std::size_t count = 0;
std::time_t start = 0;
std::size_t count_k() const noexcept { return count / 1000; }
};
public:
explicit progress_display_t(bool enabled = false) noexcept
: m_enabled(enabled)
{
m_node.start = std::time(nullptr);
}
void node(osmium::Node const &)
{
if (++m_node.count % 10000 == 0) {
possibly_print_status();
}
}
void way(osmium::Way const &)
{
if (++m_way.count % 1000 == 0) {
possibly_print_status();
}
}
void relation(osmium::Relation const &)
{
if (++m_rel.count % 10 == 0) {
possibly_print_status();
}
}
void start_way_counter() { m_way.start = std::time(nullptr); }
void start_relation_counter() { m_rel.start = std::time(nullptr); }
void print_summary() const;
private:
void print_status(std::time_t now) const;
void possibly_print_status();
uint64_t nodes_time(std::time_t now) const noexcept;
uint64_t ways_time(std::time_t now) const noexcept;
uint64_t rels_time(std::time_t now) const noexcept;
uint64_t overall_time(std::time_t now) const noexcept;
Counter m_node{};
Counter m_way{};
Counter m_rel{};
std::time_t m_last_print_time{std::time(nullptr)};
bool m_enabled;
};
#endif // OSM2PGSQL_PROGRESS_DISPLAY_HPP