Skip to content

Commit 5fa5fa3

Browse files
authored
Merge branch 'master' into libdeflate
2 parents 203731c + 88b8b6f commit 5fa5fa3

File tree

6 files changed

+84
-29
lines changed

6 files changed

+84
-29
lines changed

include/helpers.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@
77

88
#define Z_DEFAULT_COMPRESSION -1
99

10+
#ifdef _MSVC_LANG
11+
#define ISATTY true
12+
#else
13+
#define ISATTY isatty(1)
14+
#endif
15+
1016
// General helper routines
1117

1218
inline void endian_swap(unsigned int& x) {

include/osm_lua_processing.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ class OsmLuaProcessing {
6969
// Do we have Lua routines for non-MP relations?
7070
bool canReadRelations();
7171
bool canPostScanRelations();
72+
bool canWriteNodes();
73+
bool canWriteWays();
7274
bool canWriteRelations();
7375

7476
// Shapefile tag remapping
@@ -264,6 +266,8 @@ class OsmLuaProcessing {
264266
bool supportsRemappingShapefiles;
265267
bool supportsReadingRelations;
266268
bool supportsPostScanRelations;
269+
bool supportsWritingNodes;
270+
bool supportsWritingWays;
267271
bool supportsWritingRelations;
268272
const class ShpMemTiles &shpMemTiles;
269273
class OsmMemTiles &osmMemTiles;

include/tile_data.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ template<typename OO> void finalizeObjects(
6969
int i = -1;
7070
for (auto it = begin; it != end; it++) {
7171
i++;
72-
if (it->size() > 0 || i % 10 == 0 || i == 4095) {
72+
if (it->size() > 0 || i % 50 == 0 || i == 4095) {
7373
std::cout << "\r" << name << ": finalizing z6 tile " << (i + 1) << "/" << CLUSTER_ZOOM_AREA;
7474

7575
#ifdef CLOCK_MONOTONIC

src/osm_lua_processing.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,8 @@ OsmLuaProcessing::OsmLuaProcessing(
235235
supportsRemappingShapefiles = !!luaState["attribute_function"];
236236
supportsReadingRelations = !!luaState["relation_scan_function"];
237237
supportsPostScanRelations = !!luaState["relation_postscan_function"];
238+
supportsWritingNodes = !!luaState["node_function"];
239+
supportsWritingWays = !!luaState["way_function"];
238240
supportsWritingRelations = !!luaState["relation_function"];
239241

240242
// ---- Call init_function of Lua logic
@@ -272,6 +274,14 @@ bool OsmLuaProcessing::canPostScanRelations() {
272274
return supportsPostScanRelations;
273275
}
274276

277+
bool OsmLuaProcessing::canWriteNodes() {
278+
return supportsWritingNodes;
279+
}
280+
281+
bool OsmLuaProcessing::canWriteWays() {
282+
return supportsWritingWays;
283+
}
284+
275285
bool OsmLuaProcessing::canWriteRelations() {
276286
return supportsWritingRelations;
277287
}
@@ -1064,7 +1074,10 @@ void OsmLuaProcessing::setRelation(
10641074
// Start Lua processing for relation
10651075
if (!isNativeMP && !supportsWritingRelations) return;
10661076
try {
1067-
luaState[isNativeMP ? "way_function" : "relation_function"]();
1077+
if (isNativeMP && supportsWritingWays)
1078+
luaState["way_function"]();
1079+
else if (!isNativeMP && supportsWritingRelations)
1080+
luaState["relation_function"]();
10681081
} catch(luaProcessingException &e) {
10691082
std::cerr << "Lua error on relation " << originalOsmID << std::endl;
10701083
exit(1);

src/pbf_processor.cpp

Lines changed: 43 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ const std::string OptionSortTypeThenID = "Sort.Type_then_ID";
1717
const std::string OptionLocationsOnWays = "LocationsOnWays";
1818
std::atomic<uint64_t> blocksProcessed(0), blocksToProcess(0);
1919

20+
// Access is guarded by ioMutex.
21+
// This counter decreases the chattiness of tilemaker's progress updates,
22+
// especially when run in a non-interactive context.
23+
uint64_t phaseProgress = 0;
24+
2025
// Thread-local so that we can re-use buffers during parsing.
2126
thread_local PbfReader::PbfReader reader;
2227

@@ -56,7 +61,7 @@ bool PbfProcessor::ReadNodes(OsmLuaProcessing& output, PbfReader::PrimitiveGroup
5661
}
5762

5863
bool emitted = false;
59-
if (!tags.empty() && nodeKeys.filter(tags)) {
64+
if (output.canWriteNodes() && !tags.empty() && nodeKeys.filter(tags)) {
6065
emitted = output.setNode(static_cast<NodeID>(nodeId), latplon, tags);
6166
}
6267

@@ -142,7 +147,7 @@ bool PbfProcessor::ReadWays(
142147
if (llVec.empty()) continue;
143148

144149
try {
145-
bool emitted = output.setWay(static_cast<WayID>(pbfWay.id), llVec, tags);
150+
bool emitted = output.canWriteWays() && output.setWay(static_cast<WayID>(pbfWay.id), llVec, tags);
146151

147152
// If we need it for later, store the way's coordinates in the global way store
148153
if (emitted || osmStore.way_is_used(wayId)) {
@@ -370,16 +375,27 @@ bool PbfProcessor::ReadBlock(
370375
auto output_progress = [&]()
371376
{
372377
if (ioMutex.try_lock()) {
373-
std::ostringstream str;
374-
str << "\r";
375-
void_mmap_allocator::reportStoreSize(str);
376-
if (effectiveShards > 1)
377-
str << std::to_string(shard + 1) << "/" << std::to_string(effectiveShards) << " ";
378-
379-
// TODO: revive showing the # of ways/relations?
380-
str << "Block " << blocksProcessed.load() << "/" << blocksToProcess.load() << " ";
381-
std::cout << str.str();
382-
std::cout.flush();
378+
// If we're interactive, show an update for each block.
379+
// If we're not interactive, show an update for each 1% of blocks.
380+
uint64_t blockProgress = blocksProcessed.load();
381+
uint64_t minimumIncrement = blocksToProcess.load() / 100;
382+
if (minimumIncrement < 1 || ISATTY)
383+
minimumIncrement = 1;
384+
385+
if (phaseProgress == 0 || phaseProgress + minimumIncrement <= blockProgress) {
386+
phaseProgress = blockProgress;
387+
388+
std::ostringstream str;
389+
str << "\r";
390+
void_mmap_allocator::reportStoreSize(str);
391+
if (effectiveShards > 1)
392+
str << std::to_string(shard + 1) << "/" << std::to_string(effectiveShards) << " ";
393+
394+
// TODO: revive showing the # of ways/relations?
395+
str << "Block " << blocksProcessed.load() << "/" << blocksToProcess.load() << " ";
396+
std::cout << str.str();
397+
std::cout.flush();
398+
}
383399
ioMutex.unlock();
384400
}
385401
};
@@ -397,8 +413,13 @@ bool PbfProcessor::ReadBlock(
397413
bool done = ScanWays(output, pg, pb, wayKeys);
398414
if(done) {
399415
if (ioMutex.try_lock()) {
400-
std::cout << "\r(Scanning for nodes used in ways: " << (100*blocksProcessed.load()/blocksToProcess.load()) << "%) ";
401-
std::cout.flush();
416+
size_t scanProgress = 100*blocksProcessed.load()/blocksToProcess.load();
417+
418+
if (scanProgress != phaseProgress) {
419+
phaseProgress = scanProgress;
420+
std::cout << "\r(Scanning for nodes used in ways: " << (100*blocksProcessed.load()/blocksToProcess.load()) << "%) ";
421+
std::cout.flush();
422+
}
402423
ioMutex.unlock();
403424
}
404425
continue;
@@ -410,8 +431,13 @@ bool PbfProcessor::ReadBlock(
410431
bool done = ScanRelations(output, pg, pb, wayKeys);
411432
if(done) {
412433
if (ioMutex.try_lock()) {
413-
std::cout << "\r(Scanning for ways used in relations: " << (100*blocksProcessed.load()/blocksToProcess.load()) << "%) ";
414-
std::cout.flush();
434+
size_t scanProgress = 100*blocksProcessed.load()/blocksToProcess.load();
435+
436+
if (scanProgress != phaseProgress) {
437+
phaseProgress = scanProgress;
438+
std::cout << "\r(Scanning for ways used in relations: " << (100*blocksProcessed.load()/blocksToProcess.load()) << "%) ";
439+
std::cout.flush();
440+
}
415441
ioMutex.unlock();
416442
}
417443
continue;
@@ -591,6 +617,7 @@ int PbfProcessor::ReadPbfFile(
591617
all_phases.push_back(ReadPhase::Relations);
592618

593619
for(auto phase: all_phases) {
620+
phaseProgress = 0;
594621
uint effectiveShards = 1;
595622

596623
// On memory-constrained machines, we might read ways/relations

src/tilemaker.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,7 @@ int main(const int argc, const char* argv[]) {
345345
std::mutex io_mutex;
346346

347347
// Loop through tiles
348-
std::atomic<uint64_t> tilesWritten(0);
348+
std::atomic<uint64_t> tilesWritten(0), lastTilesWritten(0);
349349

350350
for (auto source : sources) {
351351
source->finalize(options.threadNum);
@@ -518,7 +518,7 @@ int main(const int argc, const char* argv[]) {
518518
batchSize++;
519519
}
520520

521-
boost::asio::post(pool, [=, &tileCoordinates, &pool, &sharedData, &sources, &attributeStore, &io_mutex, &tilesWritten]() {
521+
boost::asio::post(pool, [=, &tileCoordinates, &pool, &sharedData, &sources, &attributeStore, &io_mutex, &tilesWritten, &lastTilesWritten]() {
522522
std::vector<std::string> tileTimings;
523523
std::size_t endIndex = std::min(tileCoordinates.size(), startIndex + batchSize);
524524
for(std::size_t i = startIndex; i < endIndex; ++i) {
@@ -557,16 +557,21 @@ int main(const int argc, const char* argv[]) {
557557
tilesWritten += (endIndex - startIndex);
558558

559559
if (io_mutex.try_lock()) {
560-
// Show progress grouped by z6 (or lower)
561-
size_t z = tileCoordinates[startIndex].first;
562-
size_t x = tileCoordinates[startIndex].second.x;
563-
size_t y = tileCoordinates[startIndex].second.y;
564-
if (z > CLUSTER_ZOOM) {
565-
x = x / (1 << (z - CLUSTER_ZOOM));
566-
y = y / (1 << (z - CLUSTER_ZOOM));
567-
z = CLUSTER_ZOOM;
560+
uint64_t written = tilesWritten.load();
561+
562+
if (written >= lastTilesWritten + tileCoordinates.size() / 100 || ISATTY) {
563+
lastTilesWritten = written;
564+
// Show progress grouped by z6 (or lower)
565+
size_t z = tileCoordinates[startIndex].first;
566+
size_t x = tileCoordinates[startIndex].second.x;
567+
size_t y = tileCoordinates[startIndex].second.y;
568+
if (z > CLUSTER_ZOOM) {
569+
x = x / (1 << (z - CLUSTER_ZOOM));
570+
y = y / (1 << (z - CLUSTER_ZOOM));
571+
z = CLUSTER_ZOOM;
572+
}
573+
cout << "z" << z << "/" << x << "/" << y << ", writing tile " << written << " of " << tileCoordinates.size() << " \r" << std::flush;
568574
}
569-
cout << "z" << z << "/" << x << "/" << y << ", writing tile " << tilesWritten.load() << " of " << tileCoordinates.size() << " \r" << std::flush;
570575
io_mutex.unlock();
571576
}
572577
});

0 commit comments

Comments
 (0)