diff options
author | Paul Wise <pabs3@bonedaddy.net> | 2017-05-04 21:23:22 +0800 |
---|---|---|
committer | Paul Wise <pabs3@bonedaddy.net> | 2017-05-04 21:26:23 +0800 |
commit | e14ecff45ee26203dfef61f9e84fe3555837066b (patch) | |
tree | 36f9dd56bbeed22c8a1fb0844fa6831517460f0c | |
parent | c9acd2932c3b5af9f4a86eaac4b507023642ebc2 (diff) | |
download | iotop-e14ecff45ee26203dfef61f9e84fe3555837066b.tar.gz |
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
-rw-r--r-- | iotop/data.py | 6 | ||||
-rw-r--r-- | iotop/ui.py | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/iotop/data.py b/iotop/data.py index d18ca9d..a7b3278 100644 --- a/iotop/data.py +++ b/iotop/data.py @@ -247,7 +247,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 @@ -424,7 +424,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 f7ef654..d414559 100644 --- a/iotop/ui.py +++ b/iotop/ui.py @@ -76,7 +76,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( |