Skip to content
Snippets Groups Projects
Commit 5e3ae911 authored by René Fritze's avatar René Fritze
Browse files

[profiler] fixes and adds test for multiple run issue

parent 070ab8c5
No related branches found
No related tags found
No related merge requests found
......@@ -97,6 +97,10 @@ long Profiler::getTimingIdx(const std::string section_name, const int run_number
const Datamap& data = datamaps_[run_number];
Datamap::const_iterator section = data.find(section_name);
if (section == data.end()) {
// timer might still be running
const auto& timer_it = known_timers_map_.find(section_name);
if (timer_it != known_timers_map_.end())
return timer_it->second.second.delta();
ASSERT_EXCEPTION(false, "no timer found: " + section_name);
return -1;
}
......@@ -120,6 +124,9 @@ void Profiler::addCount(const int num)
void Profiler::nextRun()
{
// set all known timers to "stopped"
for (auto& timer_it : known_timers_map_)
timer_it.second.first = false;
current_run_number_++;
}
......
......@@ -34,13 +34,15 @@ TEST(ProfilerTest, ScopedTiming)
TEST(ProfilerTest, MultiRuns)
{
const auto range = Math::range(1, 3);
DSC_PROFILER.reset(range.size());
// needs to be range.size() + 1 since we're calling nextRun() range.size() times
DSC_PROFILER.reset(range.size() + 1);
for (auto i : range) {
scoped_busywait("ProfilerTest.MultiRuns", i * wait_ms);
DSC_PROFILER.nextRun();
}
for (auto i : range) {
EXPECT_GE(DSC_PROFILER.getTiming("ProfilerTest.MultiRuns", i - 1), i * wait_ms);
// i-1 cause runs have 0-based index
EXPECT_GE(DSC_PROFILER.getTimingIdx("ProfilerTest.MultiRuns", i - 1), i * wait_ms);
}
}
......@@ -63,6 +65,19 @@ TEST(ProfilerTest, ExpectedFailures)
EXPECT_THROW(DSC_PROFILER.stopTiming("This_section_was_never_start"), Dune::RangeError);
}
TEST(ProfilerTest, NestedTiming)
{
auto& prof = DSC_PROFILER;
prof.reset(1);
prof.startTiming("NestedTiming.Outer");
busywait(100);
prof.startTiming("NestedTiming.Inner");
busywait(100);
auto inner = prof.getTiming("NestedTiming.Inner");
auto outer = prof.getTiming("NestedTiming.Outer");
EXPECT_GT(outer, inner);
}
int main(int argc, char** argv)
{
testing::InitGoogleTest(&argc, argv);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment