2 * Copyright (c) 2011 The Chromium OS Authors.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 static int get_args(int argc, char * const argv[], char **buff,
26 size_t *buff_ptr, size_t *buff_size)
31 *buff_size = getenv_ulong("profsize", 16, 0);
32 *buff = map_sysmem(getenv_ulong("profbase", 16, 0),
34 *buff_ptr = getenv_ulong("profoffset", 16, 0);
36 *buff_size = simple_strtoul(argv[3], NULL, 16);
37 *buff = map_sysmem(simple_strtoul(argv[2], NULL, 16),
44 static int create_func_list(int argc, char * const argv[])
46 size_t buff_size, avail, buff_ptr, used;
51 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
54 avail = buff_size - buff_ptr;
55 err = trace_list_functions(buff + buff_ptr, avail, &needed);
57 printf("Error: truncated (%#x bytes needed)\n", needed);
58 used = min(avail, needed);
59 printf("Function trace dumped to %08lx, size %#zx\n",
60 (ulong)map_to_sysmem(buff + buff_ptr), used);
61 setenv_hex("profbase", map_to_sysmem(buff));
62 setenv_hex("profsize", buff_size);
63 setenv_hex("profoffset", buff_ptr + used);
68 static int create_call_list(int argc, char * const argv[])
70 size_t buff_size, avail, buff_ptr, used;
75 if (get_args(argc, argv, &buff, &buff_ptr, &buff_size))
78 avail = buff_size - buff_ptr;
79 err = trace_list_calls(buff + buff_ptr, avail, &needed);
81 printf("Error: truncated (%#x bytes needed)\n", needed);
82 used = min(avail, needed);
83 printf("Call list dumped to %08lx, size %#zx\n",
84 (ulong)map_to_sysmem(buff + buff_ptr), used);
86 setenv_hex("profbase", map_to_sysmem(buff));
87 setenv_hex("profsize", buff_size);
88 setenv_hex("profoffset", buff_ptr + used);
93 int do_trace(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
95 const char *cmd = argc < 2 ? NULL : argv[1];
98 return cmd_usage(cmdtp);
101 trace_set_enabled(0);
104 if (create_call_list(argc, argv))
105 return cmd_usage(cmdtp);
108 trace_set_enabled(1);
111 if (create_func_list(argc, argv))
112 return cmd_usage(cmdtp);
118 return CMD_RET_USAGE;
125 trace, 4, 1, do_trace,
126 "trace utility commands",
127 "stats - display tracing statistics\n"
128 "trace pause - pause tracing\n"
129 "trace resume - resume tracing\n"
130 "trace funclist [<addr> <size>] - dump function list into buffer\n"
131 "trace calls [<addr> <size>] "
132 "- dump function call trace into buffer"