public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/6] bootstage: Add time accumulation feature
Date: Fri, 28 Sep 2012 11:56:36 -0700	[thread overview]
Message-ID: <1348858600-7095-3-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1348858600-7095-1-git-send-email-sjg@chromium.org>

Sometimes we want to add up the amount of time spent in a particular
activity when it is happening in a number of discrete chunks.

Add bootstage_start() to mark the start of an acitivity and
bootstage_accum() to accumulate the time since the last start. Calling
these function in pairs results in the accumulated time being collected.

Signed-off-by: Simon Glass <sjg@chromium.org>
---
 common/bootstage.c  |   36 +++++++++++++++++++++++++++++++++---
 include/bootstage.h |   27 +++++++++++++++++++++++++++
 2 files changed, 60 insertions(+), 3 deletions(-)

diff --git a/common/bootstage.c b/common/bootstage.c
index 3275499..e7c3fa8 100644
--- a/common/bootstage.c
+++ b/common/bootstage.c
@@ -90,6 +90,25 @@ ulong bootstage_mark_name(enum bootstage_id id, const char *name)
 	return bootstage_add_record(id, name, flags, timer_get_boot_us());
 }
 
+uint32_t bootstage_start(enum bootstage_id id, const char *name)
+{
+	struct bootstage_record *rec = &record[id];
+
+	rec->start_us = timer_get_boot_us();
+	rec->name = name;
+	return rec->start_us;
+}
+
+uint32_t bootstage_accum(enum bootstage_id id)
+{
+	struct bootstage_record *rec = &record[id];
+	uint32_t duration;
+
+	duration = (uint32_t)timer_get_boot_us() - rec->start_us;
+	rec->time_us += duration;
+	return duration;
+}
+
 static void print_time(unsigned long us_time)
 {
 	char str[15], *s;
@@ -108,8 +127,13 @@ static void print_time(unsigned long us_time)
 static uint32_t print_time_record(enum bootstage_id id,
 			struct bootstage_record *rec, uint32_t prev)
 {
-	print_time(rec->time_us);
-	print_time(rec->time_us - prev);
+	if (prev == -1U) {
+		printf("%11s", "");
+		print_time(rec->time_us);
+	} else {
+		print_time(rec->time_us);
+		print_time(rec->time_us - prev);
+	}
 	if (rec->name)
 		printf("  %s\n", rec->name);
 	else if (id >= BOOTSTAGE_ID_USER)
@@ -144,13 +168,19 @@ void bootstage_report(void)
 	qsort(record, ARRAY_SIZE(record), sizeof(*rec), h_compare_record);
 
 	for (id = 0; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
-		if (rec->time_us != 0)
+		if (rec->time_us != 0 && !rec->start_us)
 			prev = print_time_record(rec->id, rec, prev);
 	}
 	if (next_id > BOOTSTAGE_ID_COUNT)
 		printf("(Overflowed internal boot id table by %d entries\n"
 			"- please increase CONFIG_BOOTSTAGE_USER_COUNT\n",
 		       next_id - BOOTSTAGE_ID_COUNT);
+
+	puts("\nAccumulated time:\n");
+	for (id = 0, rec = record; id < BOOTSTAGE_ID_COUNT; id++, rec++) {
+		if (rec->start_us)
+			prev = print_time_record(id, rec, -1);
+	}
 }
 
 ulong __timer_get_boot_us(void)
diff --git a/include/bootstage.h b/include/bootstage.h
index 64b2ec6..127c94f 100644
--- a/include/bootstage.h
+++ b/include/bootstage.h
@@ -247,6 +247,33 @@ ulong bootstage_error(enum bootstage_id id);
 
 ulong bootstage_mark_name(enum bootstage_id id, const char *name);
 
+/**
+ * Mark the start of a bootstage activity. The end will be marked later with
+ * bootstage_accum() and at that point we accumulate the time taken. Calling
+ * this function turns the given id into a accumulator rather than and
+ * absolute mark in time. Accumulators record the total amount of time spent
+ * in an activty during boot.
+ *
+ * @param id	Bootstage id to record this timestamp against
+ * @param name	Textual name to display for this id in the report (maybe NULL)
+ * @return start timestamp in microseconds
+ */
+uint32_t bootstage_start(enum bootstage_id id, const char *name);
+
+/**
+ * Mark the end of a bootstage activity
+ *
+ * After previously marking the start of an activity with bootstage_start(),
+ * call this function to mark the end. You can call these functions in pairs
+ * as many times as you like.
+ *
+ * @param id	Bootstage id to record this timestamp against
+ * @return time spent in this iteration of the activity (i.e. the time now
+ *		less the start time recorded in the last bootstage_start() call
+ *		with this id.
+ */
+uint32_t bootstage_accum(enum bootstage_id id);
+
 /* Print a report about boot time */
 void bootstage_report(void);
 
-- 
1.7.7.3

  parent reply	other threads:[~2012-09-28 18:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-28 18:56 [U-Boot] [PATCH 0/6] bootstage: Add a number of new features Simon Glass
2012-09-28 18:56 ` [U-Boot] [PATCH 1/6] bootstage: Export bootstage_add_record() function Simon Glass
2012-09-28 18:56 ` Simon Glass [this message]
2012-09-28 18:56 ` [U-Boot] [PATCH 3/6] bootstage: Store boot timings in device tree Simon Glass
2012-09-28 18:56 ` [U-Boot] [PATCH 4/6] bootstage: Add feature to stash/unstash bootstage info Simon Glass
2012-09-28 18:56 ` [U-Boot] [PATCH 5/6] bootstage: Add bootstage command Simon Glass
2012-09-28 18:56 ` [U-Boot] [PATCH 6/6] bootstage: Add new bootstage IDs for board, LCD Simon Glass
2012-10-02 23:02 ` [U-Boot] [PATCH 0/6] bootstage: Add a number of new features Anatolij Gustschin
2012-10-03  0:07   ` Simon Glass

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=1348858600-7095-3-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox