@@ -17,6 +17,11 @@ const std::string OptionSortTypeThenID = "Sort.Type_then_ID";
17
17
const std::string OptionLocationsOnWays = " LocationsOnWays" ;
18
18
std::atomic<uint64_t > blocksProcessed (0 ), blocksToProcess(0 );
19
19
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
+
20
25
// Thread-local so that we can re-use buffers during parsing.
21
26
thread_local PbfReader::PbfReader reader;
22
27
@@ -56,7 +61,7 @@ bool PbfProcessor::ReadNodes(OsmLuaProcessing& output, PbfReader::PrimitiveGroup
56
61
}
57
62
58
63
bool emitted = false ;
59
- if (!tags.empty () && nodeKeys.filter (tags)) {
64
+ if (output. canWriteNodes () && !tags.empty () && nodeKeys.filter (tags)) {
60
65
emitted = output.setNode (static_cast <NodeID>(nodeId), latplon, tags);
61
66
}
62
67
@@ -142,7 +147,7 @@ bool PbfProcessor::ReadWays(
142
147
if (llVec.empty ()) continue ;
143
148
144
149
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);
146
151
147
152
// If we need it for later, store the way's coordinates in the global way store
148
153
if (emitted || osmStore.way_is_used (wayId)) {
@@ -370,16 +375,27 @@ bool PbfProcessor::ReadBlock(
370
375
auto output_progress = [&]()
371
376
{
372
377
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
+ }
383
399
ioMutex.unlock ();
384
400
}
385
401
};
@@ -397,8 +413,13 @@ bool PbfProcessor::ReadBlock(
397
413
bool done = ScanWays (output, pg, pb, wayKeys);
398
414
if (done) {
399
415
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
+ }
402
423
ioMutex.unlock ();
403
424
}
404
425
continue ;
@@ -410,8 +431,13 @@ bool PbfProcessor::ReadBlock(
410
431
bool done = ScanRelations (output, pg, pb, wayKeys);
411
432
if (done) {
412
433
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
+ }
415
441
ioMutex.unlock ();
416
442
}
417
443
continue ;
@@ -591,6 +617,7 @@ int PbfProcessor::ReadPbfFile(
591
617
all_phases.push_back (ReadPhase::Relations);
592
618
593
619
for (auto phase: all_phases) {
620
+ phaseProgress = 0 ;
594
621
uint effectiveShards = 1 ;
595
622
596
623
// On memory-constrained machines, we might read ways/relations
0 commit comments