From 7bc9b2b62d9f140081cee4290912abdf611cf8cf Mon Sep 17 00:00:00 2001 From: Jonas Jelten Date: Tue, 13 Jul 2021 19:02:53 +0200 Subject: [PATCH] osd: fix op event duration calculation Each event is recorded with the timestamp when it's done. Thus the time the event took is `event_timestamp - prev_event_timestamp`, and not `next_event_timestamp - event_timestamp`, since that would be the next event's duration. This off-by-one is fixed by the patch. Signed-off-by: Jonas Jelten --- src/osd/OpRequest.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/osd/OpRequest.cc b/src/osd/OpRequest.cc index 0eb92c23a6a3e..cd62c922d6d45 100644 --- a/src/osd/OpRequest.cc +++ b/src/osd/OpRequest.cc @@ -74,14 +74,14 @@ void OpRequest::_dump(Formatter *f) const f->dump_string("event", i->str); f->dump_stream("time") << i->stamp; - auto i_next = i + 1; + double duration = 0; - if (i_next < events.end()) { - f->dump_float("duration", i_next->stamp - i->stamp); - } else { - f->dump_float("duration", events.rbegin()->stamp - get_initiated()); + if (i != events.begin()) { + auto i_prev = i - 1; + duration = i->stamp - i_prev->stamp; } + f->dump_float("duration", duration); f->close_section(); } f->close_section(); -- 2.39.5