aboutsummaryrefslogtreecommitdiffstats
path: root/roms/u-boot/cmd/time.c
diff options
context:
space:
mode:
authorAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
committerAngelos Mouzakitis <a.mouzakitis@virtualopensystems.com>2023-10-10 14:33:42 +0000
commitaf1a266670d040d2f4083ff309d732d648afba2a (patch)
tree2fc46203448ddcc6f81546d379abfaeb323575e9 /roms/u-boot/cmd/time.c
parente02cda008591317b1625707ff8e115a4841aa889 (diff)
Add submodule dependency filesHEADmaster
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'roms/u-boot/cmd/time.c')
-rw-r--r--roms/u-boot/cmd/time.c45
1 files changed, 45 insertions, 0 deletions
diff --git a/roms/u-boot/cmd/time.c b/roms/u-boot/cmd/time.c
new file mode 100644
index 000000000..db8c1892d
--- /dev/null
+++ b/roms/u-boot/cmd/time.c
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ */
+
+#include <common.h>
+#include <command.h>
+
+static void report_time(ulong cycles)
+{
+ ulong minutes, seconds, milliseconds;
+ ulong total_seconds, remainder;
+
+ total_seconds = cycles / CONFIG_SYS_HZ;
+ remainder = cycles % CONFIG_SYS_HZ;
+ minutes = total_seconds / 60;
+ seconds = total_seconds % 60;
+ /* approximate millisecond value */
+ milliseconds = (remainder * 1000 + CONFIG_SYS_HZ / 2) / CONFIG_SYS_HZ;
+
+ printf("\ntime:");
+ if (minutes)
+ printf(" %lu minutes,", minutes);
+ printf(" %lu.%03lu seconds\n", seconds, milliseconds);
+}
+
+static int do_time(struct cmd_tbl *cmdtp, int flag, int argc,
+ char *const argv[])
+{
+ ulong cycles = 0;
+ int retval = 0;
+ int repeatable = 0;
+
+ if (argc == 1)
+ return CMD_RET_USAGE;
+
+ retval = cmd_process(0, argc - 1, argv + 1, &repeatable, &cycles);
+ report_time(cycles);
+
+ return retval;
+}
+
+U_BOOT_CMD(time, CONFIG_SYS_MAXARGS, 0, do_time,
+ "run commands and summarize execution time",
+ "command [args...]\n");