Skip to content

Commit 0d6a29c

Browse files
committed
Base impl: Hint when parsing takes too long
Only file-based so far
1 parent ec449af commit 0d6a29c

2 files changed

Lines changed: 43 additions & 0 deletions

File tree

include/openPMD/Series.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ namespace internal
217217
* True if a user opts into lazy parsing.
218218
*/
219219
bool m_parseLazily = false;
220+
uint64_t m_hintLazyParsingAfterTimeout = 20;
220221

221222
/**
222223
* In variable-based encoding, all backends except ADIOS2 can only write

src/Series.cpp

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848

4949
#include <algorithm>
5050
#include <cctype>
51+
#include <chrono>
5152
#include <exception>
5253
#include <iomanip>
5354
#include <iostream>
@@ -1737,13 +1738,49 @@ void Series::readFileBased(
17371738
{
17381739
bool atLeastOneIterationSuccessful = false;
17391740
std::optional<error::ReadError> forwardFirstError;
1741+
1742+
using Clock = std::chrono::system_clock;
1743+
Clock::time_point start_parsing, time_of_last_warning;
1744+
auto timeout = series.m_hintLazyParsingAfterTimeout;
1745+
bool printed_warning_already = false;
1746+
if (timeout > 0)
1747+
{
1748+
start_parsing = Clock::now();
1749+
time_of_last_warning = start_parsing;
1750+
}
1751+
1752+
size_t read_iterations = 0;
17401753
for (auto &iteration : series.iterations)
17411754
{
17421755
if (read_only_this_single_iteration.has_value() &&
17431756
*read_only_this_single_iteration != iteration.first)
17441757
{
17451758
continue;
17461759
}
1760+
if (timeout > 0 && !read_only_this_single_iteration.has_value())
1761+
{
1762+
auto current = Clock::now();
1763+
auto diff = std::chrono::duration_cast<std::chrono::seconds>(
1764+
current - time_of_last_warning);
1765+
if (uint64_t(diff.count()) >= timeout)
1766+
{
1767+
auto total_diff =
1768+
std::chrono::duration_cast<std::chrono::seconds>(
1769+
current - start_parsing);
1770+
if (!printed_warning_already)
1771+
{
1772+
std::cerr
1773+
<< R"(Warning: Parsing Iterations is taking a long time. Consider setting {"defer_iteration_parsing": true} for lazy opening of the Series and then explicitly opening Iterations with Iteration::open(). Refer also to the documentation at https://openpmd-api.readthedocs.io. Suppress this warning by setting {"hint_lazy_parsing_timeout": 0}.)"
1774+
<< '\n';
1775+
printed_warning_already = true;
1776+
}
1777+
std::cerr << "Elapsed time: " << total_diff.count()
1778+
<< "s, parsed " << read_iterations << " of "
1779+
<< series.iterations.size() << " Iterations."
1780+
<< std::endl;
1781+
time_of_last_warning = current;
1782+
}
1783+
}
17471784
if (auto error = readIterationEagerly(iteration.second); error)
17481785
{
17491786
std::cerr << "Cannot read iteration '" << iteration.first
@@ -1759,6 +1796,7 @@ void Series::readFileBased(
17591796
{
17601797
atLeastOneIterationSuccessful = true;
17611798
}
1799+
++read_iterations;
17621800
}
17631801
if (!atLeastOneIterationSuccessful)
17641802
{
@@ -3008,6 +3046,10 @@ void Series::parseJsonOptions(TracingJSON &options, ParsedInput &input)
30083046
auto &series = get();
30093047
getJsonOption<bool>(
30103048
options, "defer_iteration_parsing", series.m_parseLazily);
3049+
getJsonOption<uint64_t>(
3050+
options,
3051+
"hint_lazy_parsing_timeout",
3052+
series.m_hintLazyParsingAfterTimeout);
30113053
internal::SeriesData::SourceSpecifiedViaJSON rankTableSource;
30123054
if (getJsonOptionLowerCase(options, "rank_table", rankTableSource.value))
30133055
{

0 commit comments

Comments
 (0)