Add a trace command
authorSimon Glass <sjg@chromium.org>
Tue, 11 Jun 2013 18:14:40 +0000 (11:14 -0700)
committerTom Rini <trini@ti.com>
Wed, 26 Jun 2013 14:16:41 +0000 (10:16 -0400)
Add a trace command with sub-commands to start/stop tracing, print out
statistics and dump trace information to memory for later upload to a host.

Signed-off-by: Simon Glass <sjg@chromium.org>
common/Makefile
common/cmd_trace.c [new file with mode: 0644]

index 35816037ecf73ee589fd6d32be3a81f831b325c9..6aa41a4dacdc98f4458ad507ae9d57bfa1d40501 100644 (file)
@@ -169,6 +169,7 @@ COBJS-$(CONFIG_CMD_SPIBOOTLDR) += cmd_spibootldr.o
 COBJS-$(CONFIG_CMD_STRINGS) += cmd_strings.o
 COBJS-$(CONFIG_CMD_TERMINAL) += cmd_terminal.o
 COBJS-$(CONFIG_CMD_TIME) += cmd_time.o
+COBJS-$(CONFIG_CMD_TRACE) += cmd_trace.o
 COBJS-$(CONFIG_SYS_HUSH_PARSER) += cmd_test.o
 COBJS-$(CONFIG_CMD_TPM) += cmd_tpm.o
 COBJS-$(CONFIG_CMD_TSI148) += cmd_tsi148.o
diff --git a/common/cmd_trace.c b/common/cmd_trace.c
new file mode 100644 (file)
index 0000000..ec3137a
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * Copyright (c) 2011 The Chromium OS Authors.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <command.h>
+#include <trace.h>
+#include <asm/io.h>
+
+static int get_args(int argc, char * const argv[], char **buff,
+                   size_t *buff_ptr, size_t *buff_size)
+{
+       if (argc < 2)
+               return -1;
+       if (argc < 4) {
+               *buff_size = getenv_ulong("profsize", 16, 0);
+               *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
+                                  *buff_size);
+               *buff_ptr = getenv_ulong("profoffset", 16, 0);
+       } else {
+               *buff_size = simple_strtoul(argv[3], NULL, 16);
+               *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
+                                  *buff_size);
+               *buff_ptr = 0;
+       };
+       return 0;
+}
+
+static int create_func_list(int argc, char * const argv[])
+{
+       size_t buff_size, avail, buff_ptr, used;
+       unsigned int needed;
+       char *buff;
+       int err;
+
+       if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
+               return -1;
+
+       avail = buff_size - buff_ptr;
+       err = trace_list_functions(buff + buff_ptr, avail, &needed);
+       if (err)
+               printf("Error: truncated (%#x bytes needed)\n", needed);
+       used = min(avail, needed);
+       printf("Function trace dumped to %08lx, size %#zx\n",
+              (ulong)map_to_sysmem(buff + buff_ptr), used);
+       setenv_hex("profbase", map_to_sysmem(buff));
+       setenv_hex("profsize", buff_size);
+       setenv_hex("profoffset", buff_ptr + used);
+
+       return 0;
+}
+
+static int create_call_list(int argc, char * const argv[])
+{
+       size_t buff_size, avail, buff_ptr, used;
+       unsigned int needed;
+       char *buff;
+       int err;
+
+       if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
+               return -1;
+
+       avail = buff_size - buff_ptr;
+       err = trace_list_calls(buff + buff_ptr, avail, &needed);
+       if (err)
+               printf("Error: truncated (%#x bytes needed)\n", needed);
+       used = min(avail, needed);
+       printf("Call list dumped to %08lx, size %#zx\n",
+              (ulong)map_to_sysmem(buff + buff_ptr), used);
+
+       setenv_hex("profbase", map_to_sysmem(buff));
+       setenv_hex("profsize", buff_size);
+       setenv_hex("profoffset", buff_ptr + used);
+
+       return 0;
+}
+
+int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+       const char *cmd = argc < 2 ? NULL : argv[1];
+
+       if (!cmd)
+               return cmd_usage(cmdtp);
+       switch (*cmd) {
+       case 'p':
+               trace_set_enabled(0);
+               break;
+       case 'c':
+               if (create_call_list(argc, argv))
+                       return cmd_usage(cmdtp);
+               break;
+       case 'r':
+               trace_set_enabled(1);
+               break;
+       case 'f':
+               if (create_func_list(argc, argv))
+                       return cmd_usage(cmdtp);
+               break;
+       case 's':
+               trace_print_stats();
+               break;
+       default:
+               return CMD_RET_USAGE;
+       }
+
+       return 0;
+}
+
+U_BOOT_CMD(
+       trace,  4,      1,      do_trace,
+       "trace utility commands",
+       "stats                        - display tracing statistics\n"
+       "trace pause                        - pause tracing\n"
+       "trace resume                       - resume tracing\n"
+       "trace funclist [<addr> <size>]     - dump function list into buffer\n"
+       "trace calls  [<addr> <size>]       "
+               "- dump function call trace into buffer"
+);