[PATCH 4/4] common: common_console: Rework log_print

Jules Maselbas jmaselbas at kalray.eu
Thu Mar 25 13:38:37 GMT 2021


Since time_beginning has been removed there is no reason to use a
variables called `diff` or `diff_ul`, there are respectively renamed
to `time_ns` and `time`.
Also remove the test for null timestamp.

Signed-off-by: Jules Maselbas <jmaselbas at kalray.eu>
---
 common/console_common.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/common/console_common.c b/common/console_common.c
index 7e9973ed8..1e4bf87b1 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -188,8 +188,8 @@ void log_print(unsigned flags, unsigned levels)
 	unsigned long last = 0;
 
 	list_for_each_entry(log, &barebox_logbuf, list) {
-		uint64_t diff = log->timestamp;
-		unsigned long difful;
+		uint64_t time_ns = log->timestamp;
+		unsigned long time;
 
 		if (levels && !(levels & (1 << log->level)))
 			continue;
@@ -201,21 +201,19 @@ void log_print(unsigned flags, unsigned levels)
 		if (flags & BAREBOX_LOG_PRINT_RAW)
 			printf("<%i>", log->level);
 
-		do_div(diff, 1000);
-		difful = diff;
-
-		if (!log->timestamp)
-			difful = 0;
+		/* convert ns to us */
+		do_div(time_ns, 1000);
+		time = time_ns;
 
 		if (flags & (BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))
 			printf("[");
 
 		if (flags & BAREBOX_LOG_PRINT_TIME)
-			printf("%10luus", difful);
+			printf("%10luus", time);
 
 		if (flags & BAREBOX_LOG_DIFF_TIME) {
-			printf(" < %10luus", difful - last);
-			last = difful;
+			printf(" < %10luus", time - last);
+			last = time;
 		}
 
 		if (flags & (BAREBOX_LOG_PRINT_TIME | BAREBOX_LOG_DIFF_TIME))
-- 
2.17.1





More information about the barebox mailing list