[U-Boot] [PATCH v2 3/7] Add timing information to printf's for use with bootgraph.pl

Andrew Murray amurray at theiet.org
Sat Sep 10 14:37:03 CEST 2011


From: Andrew Murray <amurray at mpcdata.com>

This patch adds timings information to printfs.
---
Changes for v2:
	- Add dedicated function to printf with timestamps
	- Fix compiler warnings
	- Remove code duplication within printf

Signed-off-by: Andrew Murray <amurray at theiet.org>
---
 common/console.c |   27 ++++++++++++++++++++++++---
 include/common.h |    2 ++
 2 files changed, 26 insertions(+), 3 deletions(-)

diff --git a/common/console.c b/common/console.c
index 8c650e0..63b84ba 100644
--- a/common/console.c
+++ b/common/console.c
@@ -365,24 +365,45 @@ void puts(const char *s)
 	}
 }
 
-int printf(const char *fmt, ...)
+#if defined(CONFIG_BOOT_TRACE)
+int printf_boot_trace(const char *fmt, ...)
 {
 	va_list args;
-	uint i;
+	uint i = 0;
 	char printbuffer[CONFIG_SYS_PBSIZE];
+	char *buf = printbuffer;
 
+	unsigned long long ticks = get_ticks();
+	uint secs = ticks / get_tbclk();
+	uint msec = ((ticks * 1000000) / get_tbclk()) - (secs * 1000000);
+
+	i += sprintf(buf, "[%5u.%06u] ", secs, msec);
+	buf += i;
 	va_start(args, fmt);
 
 	/* For this to work, printbuffer must be larger than
 	 * anything we ever want to print.
 	 */
-	i = vsprintf(printbuffer, fmt, args);
+	i += vsprintf(buf, fmt, args);
 	va_end(args);
 
 	/* Print the string */
 	puts(printbuffer);
 	return i;
 }
+#endif
+
+int printf(const char *fmt, ...)
+{
+	va_list args;
+	uint i = 0;
+
+	va_start(args, fmt);
+	i = vprintf(fmt, args);
+	va_end(args);
+
+	return i;
+}
 
 int vprintf(const char *fmt, va_list args)
 {
diff --git a/include/common.h b/include/common.h
index a926430..16175b4 100644
--- a/include/common.h
+++ b/include/common.h
@@ -712,6 +712,8 @@ void	puts(const char *s);
 int	printf(const char *fmt, ...)
 		__attribute__ ((format (__printf__, 1, 2)));
 int	vprintf(const char *fmt, va_list args);
+int	printf_boot_trace(const char *fmt, ...)
+		__attribute__ ((format (__printf__, 1, 2)));
 
 /* stderr */
 #define eputc(c)		fputc(stderr, c)
-- 
1.7.4.1



More information about the U-Boot mailing list