forked from osm2pgsql-dev/osm2pgsql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathosm2pgsql.cpp
More file actions
104 lines (82 loc) · 2.66 KB
/
Copy pathosm2pgsql.cpp
File metadata and controls
104 lines (82 loc) · 2.66 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
/**
* 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.
*/
#include "db-check.hpp"
#include "dependency-manager.hpp"
#include "input.hpp"
#include "logging.hpp"
#include "middle.hpp"
#include "options.hpp"
#include "osmdata.hpp"
#include "output.hpp"
#include "util.hpp"
#include "version.hpp"
#include <osmium/util/memory.hpp>
#include <exception>
#include <memory>
#include <utility>
/**
* Output overall memory usage as debug message.
*
* This only works on Linux.
*/
static void show_memory_usage()
{
osmium::MemoryUsage mem;
if (mem.peak() != 0) {
log_debug("Overall memory usage: peak={}MByte current={}MByte",
mem.peak(), mem.current());
}
}
static void run(options_t const &options)
{
auto const files = prepare_input_files(
options.input_files, options.input_format, options.append);
auto thread_pool = std::make_shared<thread_pool_t>(
options.parallel_indexing ? options.num_procs : 1U);
log_debug("Started pool with {} threads.", thread_pool->num_threads());
auto middle = create_middle(thread_pool, options);
middle->start();
auto output = output_t::create_output(middle->get_query_instance(),
thread_pool, options);
middle->set_requirements(output->get_requirements());
auto dependency_manager =
options.with_forward_dependencies
? std::make_unique<full_dependency_manager_t>(middle)
: std::make_unique<dependency_manager_t>();
osmdata_t osmdata{std::move(dependency_manager), middle, output, options};
osmdata.start();
// Processing: In this phase the input file(s) are read and parsed,
// populating some of the tables.
process_files(files, &osmdata, options.append,
get_logger().show_progress());
show_memory_usage();
// Process pending ways and relations. Cluster database tables and
// create indexes.
osmdata.stop();
}
int main(int argc, char *argv[])
{
try {
log_info("osm2pgsql version {}", get_osm2pgsql_version());
options_t const options{argc, argv};
if (options.early_return()) {
return 0;
}
util::timer_t timer_overall;
check_db(options);
run(options);
show_memory_usage();
log_info("osm2pgsql took {} overall.",
util::human_readable_duration(timer_overall.stop()));
} catch (std::exception const &e) {
log_error("{}", e.what());
return 1;
}
return 0;
}