All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 06/21] Add function to print a number with grouped digits
Date: Tue, 11 Jun 2013 11:14:38 -0700	[thread overview]
Message-ID: <1370974493-21822-7-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1370974493-21822-1-git-send-email-sjg@chromium.org>

Move bootstage's numbering printing code into a generic place so that it can
be used by tracing also.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
Changes in v2: None

 common/bootstage.c | 22 ++++------------------
 include/vsprintf.h | 11 +++++++++++
 lib/vsprintf.c     | 16 ++++++++++++++++
 3 files changed, 31 insertions(+), 18 deletions(-)

diff --git a/common/bootstage.c b/common/bootstage.c
index f5027ef..94a32a9 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -49,6 +49,7 @@ static int next_id = BOOTSTAGE_ID_USER;
 enum {
 	BOOTSTAGE_VERSION	= 0,
 	BOOTSTAGE_MAGIC		= 0xb00757a3,
+	BOOTSTAGE_DIGITS	= 9,
 };
 
 struct bootstage_hdr {
@@ -165,21 +166,6 @@ uint32_t bootstage_accum(enum bootstage_id id)
 	return duration;
 }
 
-static void print_time(unsigned long us_time)
-{
-	char str[15], *s;
-	int grab = 3;
-
-	/* We don't seem to have %'d in U-Boot */
-	sprintf(str, "%12lu", us_time);
-	for (s = str + 3; *s; s += grab) {
-		if (s != str + 3)
-			putc(s[-1] != ' ' ? ',' : ' ');
-		printf("%.*s", grab, s);
-		grab = 3;
-	}
-}
-
 /**
  * Get a record name as a printable string
  *
@@ -208,10 +194,10 @@ static uint32_t print_time_record(enum bootstage_id id,
 
 	if (prev == -1U) {
 		printf("%11s", "");
-		print_time(rec->time_us);
+		print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS);
 	} else {
-		print_time(rec->time_us);
-		print_time(rec->time_us - prev);
+		print_grouped_ull(rec->time_us, BOOTSTAGE_DIGITS);
+		print_grouped_ull(rec->time_us - prev, BOOTSTAGE_DIGITS);
 	}
 	printf("  %s\n", get_record_name(buf, sizeof(buf), rec));
 
diff --git a/include/vsprintf.h b/include/vsprintf.h
index 651077c..6568854 100644
--- a/include/vsprintf.h
+++ b/include/vsprintf.h
@@ -178,4 +178,15 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args);
 #define vscnprintf(buf, size, fmt, args...) vsprintf(buf, fmt, ##args)
 #endif /* CONFIG_SYS_VSNPRINTF */
 
+/**
+ * print_grouped_ull() - print a value with digits grouped by ','
+ *
+ * This prints a value with grouped digits, like 12,345,678 to make it easier
+ * to read.
+ *
+ * @val:	Value to print
+ * @digits:	Number of digiits to print
+ */
+void print_grouped_ull(unsigned long long int_val, int digits);
+
 #endif
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 533a96b..82e5c13 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -870,3 +870,19 @@ char *simple_itoa(ulong i)
 	} while (i > 0);
 	return p + 1;
 }
+
+/* We don't seem to have %'d in U-Boot */
+void print_grouped_ull(unsigned long long int_val, int digits)
+{
+	char str[21], *s;
+	int grab = 3;
+
+	digits = (digits + 2) / 3;
+	sprintf(str, "%*llu", digits * 3, int_val);
+	for (s = str; *s; s += grab) {
+		if (s != str)
+			putc(s[-1] != ' ' ? ',' : ' ');
+		printf("%.*s", grab, s);
+		grab = 3;
+	}
+}
-- 
1.8.3

  parent reply	other threads:[~2013-06-11 18:14 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-11 18:14 [U-Boot] [PATCH v2 0/21] Add tracing functionality to U-Boot Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 01/21] pci: Convert extern inline functions to static inline Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 02/21] x86: Correct missing local variable in bootm Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 03/21] Fix missing return in do_mem_loop() Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 04/21] Show stdout on error in fit-test Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 05/21] bootstage: Correct printf types Simon Glass
2013-06-11 18:14 ` Simon Glass [this message]
2013-06-11 18:14 ` [U-Boot] [PATCH v2 07/21] Add trace library Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 08/21] Add a trace command Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 09/21] Support tracing in config.mk when enabled Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 10/21] Add trace support to generic board Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 11/21] Add proftool to decode profile data Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 12/21] sandbox: Support trace feature Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 13/21] Add a simple test for sandbox trace Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 14/21] Clarify bootm OS arguments Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 15/21] Refactor the bootm command to reduce code duplication Simon Glass
2013-06-27 13:40   ` Stefan Roese
2013-06-27 14:40     ` Tom Rini
2013-06-27 15:39     ` Simon Glass
2013-06-27 19:51     ` Simon Glass
2013-06-27 20:07       ` Tom Rini
2013-06-28  2:14       ` Simon Glass
2013-06-28  4:12         ` Stefan Roese
2013-06-28  5:44           ` Simon Glass
2013-06-28  6:58           ` Simon Glass
2013-06-28  7:04             ` Stefan Roese
2013-06-28  7:12               ` Simon Glass
2013-06-28  7:57                 ` Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 16/21] Add a 'fake' go command to the bootm command Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 17/21] arm: Implement the 'fake' go command Simon Glass
2013-06-11 19:59   ` Albert ARIBAUD
2013-06-11 20:02     ` Simon Glass
2013-06-11 20:21       ` Albert ARIBAUD
2013-06-11 21:17         ` Simon Glass
2013-06-11 21:36           ` Albert ARIBAUD
2013-06-20  4:16             ` Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 18/21] exynos: Avoid function instrumentation for microsecond timer Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 19/21] exynos: config: Add tracing options Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 20/21] x86: Support tracing function Simon Glass
2013-06-11 18:14 ` [U-Boot] [PATCH v2 21/21] x86: config: Add tracing options Simon Glass
2013-06-26 20:24 ` [U-Boot] [PATCH v2 0/21] Add tracing functionality to U-Boot Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370974493-21822-7-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.