diff mbox series

[5/8] kernel-shark: Make the time labels of the marker more readable

Message ID 20190213161216.14438-6-ykaradzhov@vmware.com (mailing list archive)
State Accepted
Headers show
Series Various modifications toward KS 1.0 | expand

Commit Message

Yordan Karadzhov Feb. 13, 2019, 4:12 p.m. UTC
The precision of the displayed time of the two markers is set to
1 microsecond (as in the table). In the same time the precision of
the time difference (Delta) is now 1 nanosecond, because we expect
that the user do not care that much about the absolute time of the
event, but may want to measure the interval between two events with
the highest possible precision. The displayed time is formatted
(spaces added) in a way that aims to make it easy to read the
milliseconds and the microseconds.

Signed-off-by: Yordan Karadzhov <ykaradzhov@vmware.com>
---
 kernel-shark/src/KsDualMarker.cpp | 42 +++++++++++++++++++------------
 1 file changed, 26 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/kernel-shark/src/KsDualMarker.cpp b/kernel-shark/src/KsDualMarker.cpp
index 43bc177..5dcbaae 100644
--- a/kernel-shark/src/KsDualMarker.cpp
+++ b/kernel-shark/src/KsDualMarker.cpp
@@ -329,29 +329,39 @@  void KsDualMarkerSM::updateMarkers(const KsDataStore &data,
  */
 void KsDualMarkerSM::updateLabels()
 {
-	QString mark, delta;
+	char separator(' ');
+	int precision(6); // 1 microsecond precision.
+
+	auto lamSetTimeLabel = [&precision, &separator] (QLabel &l, int64_t t) {
+		QString time = KsUtils::Ts2String(t, precision);
+		int i = time.indexOf('.') + 4;
+
+		/* Insert separators for milliseconds amd microseconds. */
+		while (i < time.size()) {
+			time.insert(i, separator);
+			i = i + 4;
+		}
+
+		l.setText(time);
+	};
 
 	// Marker A
-	if (_markA._isSet) {
-		mark = KsUtils::Ts2String(_markA._ts, 7);
-		_labelMA.setText(mark);
-	} else {
-		_labelMA.setText("");
-	}
+	if (_markA._isSet)
+		lamSetTimeLabel(_labelMA, _markA._ts);
+	else
+		_labelMA.clear();
 
 	// Marker B
-	if (_markB._isSet) {
-		mark = KsUtils::Ts2String(_markB._ts, 7);
-		_labelMB.setText(mark);
-	} else {
-		_labelMB.setText("");
-	}
+	if (_markB._isSet)
+		lamSetTimeLabel(_labelMB, _markB._ts);
+	else
+		_labelMB.clear();
 
 	// Delta
 	if (_markA._isSet && _markB._isSet) {
-		delta = KsUtils::Ts2String(_markB._ts - _markA._ts, 7);
-		_labelDelta.setText(delta);
+		precision = 9; // 1 nanoseconds precision.
+		lamSetTimeLabel(_labelDelta, _markB._ts - _markA._ts);
 	} else {
-		_labelDelta.setText("");
+		_labelDelta.clear();
 	}
 }