diff mbox

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

Message ID 1315658227-4388-3-git-send-email-amurray@theiet.org
State Changes Requested
Headers show

Commit Message

Andrew Murray Sept. 10, 2011, 12:37 p.m. UTC
From: Andrew Murray <amurray@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@theiet.org>
---
 common/console.c |   27 ++++++++++++++++++++++++---
 include/common.h |    2 ++
 2 files changed, 26 insertions(+), 3 deletions(-)

Comments

Mike Frysinger Sept. 18, 2011, 2:10 a.m. UTC | #1
On Saturday, September 10, 2011 08:37:03 Andrew Murray wrote:
> +int printf(const char *fmt, ...)
> +{
> +	va_list args;
> +	uint i = 0;
> +
> +	va_start(args, fmt);
> +	i = vprintf(fmt, args);
> +	va_end(args);
> +
> +	return i;
> +}

could you split this change out by itself ?  this reduces code duplication 
between the printf/vprintf funcs.
-mike
diff mbox

Patch

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)