From patchwork Sun Apr 28 02:17:41 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 240219 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id E884F2C00B2 for ; Sun, 28 Apr 2013 12:20:22 +1000 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 9F3744A1BE; Sun, 28 Apr 2013 04:19:43 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RQwN3c43RgxF; Sun, 28 Apr 2013 04:19:43 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 817D04A1BF; Sun, 28 Apr 2013 04:18:57 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EB0CB4A1A9 for ; Sun, 28 Apr 2013 04:18:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rAxx-M8kfHWs for ; Sun, 28 Apr 2013 04:18:30 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-qc0-f201.google.com (mail-qc0-f201.google.com [209.85.216.201]) by theia.denx.de (Postfix) with ESMTPS id 395694A184 for ; Sun, 28 Apr 2013 04:18:23 +0200 (CEST) Received: by mail-qc0-f201.google.com with SMTP id o22so555847qcr.2 for ; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=pmUqhIrUK2sgTXxOE9AoN38trWNVreqxRMaq4x6NvpY=; b=OqKulfn0pEAt8weT9BJVCvCQtdAn2k2xzvxpSHvAd18FlSUvGKWUPOVJO2k5X/4yfh hT1DdttA4iI/WOVmSMHVt+NLAaeJwyzXe0tQR2Awxm//4fp0U4686sxqpZvbaBnbiGkB HJQM1xBzz3TcEhXd0EkTy1nuJ4i2XqS3BIRTLO5/MhrCGwJrgz8N3ToZprxP8ID3JaaN AQ2gmoHBgRU7JioEAM944JGfEs1pH/OV2nBOPrGR88X+42fj7tPWIXIhJ5lIWfHjMl8X Lr3A9KCXcI/cR4dB9DdmO9+JVVrnqBN4oGG7GvPPDHfUG2SmrCEmKs+NAC5gkhK0jedT Yzkg== X-Received: by 10.236.91.206 with SMTP id h54mr24940604yhf.27.1367115501838; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) Received: from corp2gmr1-2.hot.corp.google.com (corp2gmr1-2.hot.corp.google.com [172.24.189.93]) by gmr-mx.google.com with ESMTPS id o42si106507yhe.5.2013.04.27.19.18.21 for (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Sat, 27 Apr 2013 19:18:21 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.83.1]) by corp2gmr1-2.hot.corp.google.com (Postfix) with ESMTP id 94A315A402F; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 4B316160C13; Sat, 27 Apr 2013 19:18:21 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Sat, 27 Apr 2013 19:17:41 -0700 Message-Id: <1367115472-29531-5-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1367115472-29531-1-git-send-email-sjg@chromium.org> References: <1367115472-29531-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQlTJndcwozOBXhg2rkSQn0GMjU2uEDfEjJjYlUXkTtkxAa9aIe2B6OI6WMZYPGIJkNdx85D3ZgclQNtlNkuwqtKDMgQ9rtkaL1d+0quK/nzgGEsbdSz5uLOrh2+OmhgPw7y0pr2RObRVxF9Tu8gKPw1gYU9LtJ1Lp2iC4eXHI+D5xXXq+3L/wY72yoP94AFmk834vqX Cc: Tom Rini , u-boot-review@google.com Subject: [U-Boot] [RFC PATCH 04/15] Add a trace command X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de 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 --- common/Makefile | 1 + common/cmd_trace.c | 133 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 common/cmd_trace.c diff --git a/common/Makefile b/common/Makefile index 444d546..03aa026 100644 --- a/common/Makefile +++ b/common/Makefile @@ -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 index 0000000..cf109e3 --- /dev/null +++ b/common/cmd_trace.c @@ -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 +#include +#include +#include + +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", + 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", + 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 [ ] - dump function list into buffer\n" + "trace calls [ ] " + "- dump function call trace into buffer" +);