Skip to contentSkip to conversation

blkparse: split off the timestamp correction code in to a separate function

PATCH Applied Hiroaki Mihara 2 participants 2 messages Sep 24, 2019 – Sep 25, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 blkparse: split off the timestamp correction code in to a separate function

find_genesis() function has code to correct abs_start_time, which is later used to calculate the absolute timestamps of each traced records.

Put this code in a separate function, so that it can be used later by the blkparse code. No functional change.

---
 blkparse.c | 29 +++++++++++++++++------------
 1 file changed, 17 insertions(+), 12 deletions(-)
blkparse.c +17 -12
index 3de2ebe..cf7a87b 100644
@@ -2022,6 +2022,22 @@ static void show_device_and_cpu_stats(void)
 	}
 }
 
+static void correct_abs_start_time(void)
+{
+	long delta = genesis_time - start_timestamp;
+
+	abs_start_time.tv_sec  += SECONDS(delta);
+	abs_start_time.tv_nsec += NANO_SECONDS(delta);
+	if (abs_start_time.tv_nsec < 0) {
+		abs_start_time.tv_nsec += 1000000000;
+		abs_start_time.tv_sec -= 1;
+	} else
+	if (abs_start_time.tv_nsec > 1000000000) {
+		abs_start_time.tv_nsec -= 1000000000;
+		abs_start_time.tv_sec += 1;
+	}
+}
+
 static void find_genesis(void)
 {
 	struct trace *t = trace_list;
@@ -2039,18 +2055,7 @@ static void find_genesis(void)
 	 */
 	if (start_timestamp
 	 && start_timestamp != genesis_time) {
-		long delta = genesis_time - start_timestamp;
-
-		abs_start_time.tv_sec  += SECONDS(delta);
-		abs_start_time.tv_nsec += NANO_SECONDS(delta);
-		if (abs_start_time.tv_nsec < 0) {
-			abs_start_time.tv_nsec += 1000000000;
-			abs_start_time.tv_sec -= 1;
-		} else
-		if (abs_start_time.tv_nsec > 1000000000) {
-			abs_start_time.tv_nsec -= 1000000000;
-			abs_start_time.tv_sec += 1;
-		}
+		correct_abs_start_time();
 	}
 }
 
Signature · 1 line
2.21.0
Applied
#1 lore raw
Quoted 6 lines · Hiroaki Mihara

find_genesis() function has code to correct abs_start_time, which is later used to calculate the absolute timestamps of each traced records.

Put this code in a separate function, so that it can be used later by the blkparse code. No functional change.

Applied this, and the other 2. Thanks.

Signature · 1 line
Jens Axboe