Merge ~didrocks/ubiquity:master-time-measurement-fix into ubiquity:master

Proposed by Didier Roche-Tolomelli
Status: Merged
Approved by: Jean-Baptiste Lallement
Approved revision: 91465f39a78d9c7748863d8a52a21dfbfc5588dd
Merged at revision: 91465f39a78d9c7748863d8a52a21dfbfc5588dd
Proposed branch: ~didrocks/ubiquity:master-time-measurement-fix
Merge into: ubiquity:master
Diff against target: 62 lines (+24/-3)
2 files modified
debian/changelog (+8/-0)
ubiquity/telemetry.py (+16/-3)
Reviewer Review Type Date Requested Status
Jean-Baptiste Lallement Approve
Review via email: mp+346975@code.launchpad.net

Commit message

Switch to use uptime instead of time.time() which is sensitive to BIOS time reset after NTP sync, leading to negative values. (LP: #1771966)

To post a comment you must log in.
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

Thanks for this patch. Reviewed and tested on Cosmic.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/debian/changelog b/debian/changelog
2index 2e9a915..52dfcc9 100644
3--- a/debian/changelog
4+++ b/debian/changelog
5@@ -1,3 +1,11 @@
6+ubiquity (18.10.3) UNRELEASED; urgency=medium
7+
8+ * Switch to use uptime instead of time.time() which is sensitive to
9+ BIOS time reset after NTP sync, leading to negative values.
10+ (LP: #1771966)
11+
12+ -- Didier Roche <didrocks@ubuntu.com> Mon, 28 May 2018 16:02:33 +0200
13+
14 ubiquity (18.10.2) cosmic; urgency=medium
15
16 * Update Vcs-* for git migration
17diff --git a/ubiquity/telemetry.py b/ubiquity/telemetry.py
18index 7f68eac..e537160 100644
19--- a/ubiquity/telemetry.py
20+++ b/ubiquity/telemetry.py
21@@ -24,7 +24,6 @@ import json
22 import os
23 import stat
24 import syslog
25-import time
26
27 from ubiquity.misc import raise_privileges
28
29@@ -45,7 +44,7 @@ class _Telemetry():
30 def __init__(self):
31 self._metrics = {}
32 self._stages_hist = {}
33- self._start_time = time.time()
34+ self._start_time = self._get_current_uptime()
35 self.add_stage('start')
36 self._dest_path = '/target/var/log/installer/telemetry'
37 try:
38@@ -54,9 +53,23 @@ class _Telemetry():
39 except FileNotFoundError:
40 self._metrics['Media'] = 'unknown'
41
42+ def _get_current_uptime(self):
43+ """Get current uptime info. None if we couldn't fetch it."""
44+ uptime = None
45+ try:
46+ with open('/proc/uptime') as f:
47+ uptime = float(f.read().split()[0])
48+ except (FileNotFoundError, OSError, ValueError) as e:
49+ syslog.syslog(syslog.LOG_ERR,
50+ "Exception while fetching current uptime: " + str(e))
51+ return uptime
52+
53 def add_stage(self, stage_name):
54 """Record installer stage with current time"""
55- self._stages_hist[int(time.time() - self._start_time)] = stage_name
56+ now = self._get_current_uptime()
57+ if self._start_time is None or now is None:
58+ return
59+ self._stages_hist[int(now - self._start_time)] = stage_name
60
61 def set_installer_type(self, installer_type):
62 """Record installer type"""

Subscribers

People subscribed via source and target branches