-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbenchmark.cc
140 lines (115 loc) · 4.16 KB
/
benchmark.cc
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
#include <cstdlib>
#include <algorithm>
#include <iostream>
#include <random>
#include "conf/configuration.h"
#include "conf/options_parser.h"
#include "fmt/core.h"
#include "fmt/ostream.h"
#include "tiles/db/tile_database.h"
#include "tiles/get_tile.h"
#include "tiles/perf_counter.h"
namespace tiles {
struct benchmark_settings : public conf::configuration {
benchmark_settings() : configuration("tiles-benchmark options", "") {
param(db_fname_, "db_fname", "/path/to/tiles.mdb");
param(tile_, "tile",
"xyz coords of a single tile, z for all tiles on a certain zoom "
"level, if not present random smaple");
param(compress_, "compress", "compress the tiles");
}
std::string db_fname_{"tiles.mdb"};
std::vector<uint32_t> tile_;
bool compress_{true};
};
int run_tiles_benchmark(int argc, char const** argv) {
benchmark_settings opt;
try {
conf::options_parser parser({&opt});
parser.read_command_line_args(argc, argv, false);
if (parser.help() || parser.version()) {
std::cout << "tiles-benchmark\n\n";
parser.print_help(std::cout);
return 0;
}
parser.read_configuration_file(false);
parser.print_used(std::cout);
} catch (std::exception const& e) {
std::cout << "options error: " << e.what() << "\n";
return 1;
}
lmdb::env db_env = make_tile_database(opt.db_fname_.c_str(), kDefaultSize);
tile_db_handle db_handle{db_env};
pack_handle const pack_handle{opt.db_fname_.c_str()};
auto render_ctx = make_render_ctx(db_handle);
render_ctx.ignore_prepared_ = true;
render_ctx.compress_result_ = opt.compress_;
if (opt.tile_.empty()) {
geo::latlng const p1{49.83, 8.55};
geo::latlng const p2{50.13, 8.74};
for (auto z = 9; z < 18; z += 2) {
std::vector<geo::tile> tiles;
for (auto const& tile : geo::make_tile_range(p1, p2, z)) {
tiles.push_back(tile);
}
std::mt19937 g(31337);
std::shuffle(begin(tiles), end(tiles), g);
fmt::print(std::cout, "=== process z {} ({} tiles)\n", z, tiles.size());
auto txn = db_handle.make_txn();
auto features_dbi = db_handle.features_dbi(txn);
auto features_cursor = lmdb::cursor{txn, features_dbi};
perf_counter pc;
for (auto const& tile : geo::make_tile_range(p1, p2, z)) {
auto rendered_tile = get_tile(db_handle, txn, features_cursor,
pack_handle, render_ctx, tile, pc);
// break;
}
perf_report_get_tile(pc);
}
} else if (opt.tile_.size() == 1) {
auto const z = opt.tile_.front();
t_log("render entire zoom level: {}", z);
auto txn = db_handle.make_txn();
auto features_dbi = db_handle.features_dbi(txn);
auto features_cursor = lmdb::cursor{txn, features_dbi};
perf_counter pc;
for (auto const& tile : geo::make_tile_range(z)) {
try {
auto const rendered_tile = get_tile(db_handle, txn, features_cursor,
pack_handle, render_ctx, tile, pc);
} catch (...) {
t_log("problem in tile: {}", fmt::streamed(tile));
throw;
}
}
perf_report_get_tile(pc);
} else {
utl::verify(opt.tile_.size() == 3, "need exactly three coordinats: x y z");
geo::tile const tile{opt.tile_[0], opt.tile_[1], opt.tile_[2]};
t_log("render tile: {}", fmt::streamed(tile));
auto txn = db_handle.make_txn();
auto features_dbi = db_handle.features_dbi(txn);
auto features_cursor = lmdb::cursor{txn, features_dbi};
render_ctx.tb_aggregate_lines_ = true;
render_ctx.tb_aggregate_polygons_ = true;
render_ctx.tb_drop_subpixel_polygons_ = true;
render_ctx.tb_print_stats_ = true;
perf_counter pc;
auto const rendered_tile = get_tile(db_handle, txn, features_cursor,
pack_handle, render_ctx, tile, pc);
perf_report_get_tile(pc);
}
return 0;
}
} // namespace tiles
int main(int argc, char const** argv) {
try {
return tiles::run_tiles_benchmark(argc, argv);
} catch (std::exception const& e) {
tiles::t_log("exception caught: {}", e.what());
return 1;
} catch (...) {
tiles::t_log("unknown exception caught");
return 1;
}
}