From 998fe781977bc84232acb9211af37d64342c4383 Mon Sep 17 00:00:00 2001 From: Jianpeng Ma Date: Wed, 8 Jul 2015 08:31:22 +0800 Subject: [PATCH] common/TrackedOp: Make get_duration get correctly value. For get_duration(), it should return the duration of Op. For ops which in flight, the duration is the time current time subtrace the initiated_time. For the completed Ops, it used the last event(done) subtrace the initiated_time. Signed-off-by: Jianpeng Ma --- src/common/TrackedOp.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/common/TrackedOp.h b/src/common/TrackedOp.h index b2015b88f960..2f656cacb97e 100644 --- a/src/common/TrackedOp.h +++ b/src/common/TrackedOp.h @@ -180,11 +180,12 @@ public: const utime_t& get_initiated() const { return initiated_at; } - // This function maybe needs some work; assumes last event is completion time + double get_duration() const { - return events.empty() ? - 0.0 : - (events.rbegin()->first - get_initiated()); + if (!events.empty() && events.rbegin()->second.compare("done") == 0) + return events.rbegin()->first - get_initiated(); + else + return ceph_clock_now(NULL) - get_initiated(); } void mark_event(const string &event); -- 2.47.3