iotop/0011-Use-monotonic-time-to-calculate-durations.patch

62 lines
2.2 KiB
Diff
Raw Normal View History

From a535dc4f25f65379bf81f947307d92eee1618e54 Mon Sep 17 00:00:00 2001
From: Paul Wise <pabs3@bonedaddy.net>
Date: Thu, 4 May 2017 21:23:22 +0800
Subject: [PATCH 11/11] Use monotonic time to calculate durations
Prevents incorrect calculations when the system time is set backwards.
Reported-by: Andrei Costin <zveriu@gmail.com>
Fixes: https://bugs.launchpad.net/bugs/1685512
---
iotop/data.py | 6 +++---
iotop/ui.py | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/iotop/data.py b/iotop/data.py
index 8378e51..befa9c7 100644
--- a/iotop/data.py
+++ b/iotop/data.py
@@ -248,7 +248,7 @@ class ProcessInfo(DumpableObject):
self.threads = {} # {tid: ThreadInfo}
self.stats_delta = Stats.build_all_zero()
self.stats_accum = Stats.build_all_zero()
- self.stats_accum_timestamp = time.time()
+ self.stats_accum_timestamp = time.monotonic()
def is_monitored(self, options):
if (options.pids and not options.processes and
@@ -373,7 +373,7 @@ class ProcessList(DumpableObject):
self.processes = {}
self.taskstats_connection = taskstats_connection
self.options = options
- self.timestamp = time.time()
+ self.timestamp = time.monotonic()
self.vmstat = vmstat.VmStat()
# A first time as we are interested in the delta
@@ -423,7 +423,7 @@ class ProcessList(DumpableObject):
return tids
def update_process_counts(self):
- new_timestamp = time.time()
+ new_timestamp = time.monotonic()
self.duration = new_timestamp - self.timestamp
self.timestamp = new_timestamp
diff --git a/iotop/ui.py b/iotop/ui.py
index 40e9a40..abd6b79 100644
--- a/iotop/ui.py
+++ b/iotop/ui.py
@@ -70,7 +70,7 @@ def format_stats(options, process, duration):
if options.accumulated:
stats = process.stats_accum
display_format = lambda size, duration: format_size(options, size)
- duration = time.time() - process.stats_accum_timestamp
+ duration = time.monotonic() - process.stats_accum_timestamp
else:
stats = process.stats_delta
display_format = lambda size, duration: format_bandwidth(
--
1.8.3.1