Received: by 2002:a25:b323:0:0:0:0:0 with SMTP id l35csp2915087ybj; Mon, 23 Sep 2019 11:28:59 -0700 (PDT) X-Google-Smtp-Source: APXvYqw6BcUsl3YLdooO9/VAV97IoO6PwRDeUnsBlMluDDGk1xthJyrVB1Gk8OeI6vISUhFi+wks X-Received: by 2002:a50:f616:: with SMTP id c22mr1477287edn.235.1569263339171; Mon, 23 Sep 2019 11:28:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569263339; cv=none; d=google.com; s=arc-20160816; b=y7/W9GY8EhVaK5qL92wgpwRwmighVKPJDYigsdVoR4apkq88GSiBscOuc6pyDQ/YVs PxJtdf/GntKkz2ACclDYdH6Jnsp+FEwCJdAnLCWWAelP8mMeUAoWxDjK2nBZhioeZma3 YSzTR8jKoMyvjINNjCWj8zxsLu4S/YEufCwvYq5vWuQKM8WgghkW7yWfB0WUbHlrU4x6 konFkZESt52Ak8X/1JUfvqIlv9KOeDnDLJ68SUB7ZBaS+PtyqT8o0PZAVXW5IcsJdQvt sLL0gNOWZ/wN4F5Q9CJyWi4w/XT0qeaNJVNmXwwVXHbJoEHGFinoH+rR9vtYP/VMRfeb A12w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u8q6MNCABMDlM/R1LIFa8oysDHH50DToOChOmjLLVbU=; b=yfwNEFK76Pggw47T61Hhcm8gL0NYHrR/1JDFGak+TAsm2+vR4bipPE9Nv/EGk5+vBS UKxO8/XmJ0vo4YEJvOYFKsrDQCwONtHKK1P0eBzHpXxzm/dbAop1cvnsjMSH4jRfHGoC PJySo9t53m5Bk1ZJD4uZiTB/7LbM9wwqWPUgG4LpuFnLH1KFvQzA5YLaVF3S2zCngU+U TlI8RF5nMrPlEIIFDahATMEXgo1V//hRoWkn4cFOeDMORjw+TCBGRle9tgg7oumdoPwn yHr95b0senSvQFFY/89GwX+VGl065G0V5oT2WKGqgn+q3ey6T6O/BRZtqyQXp4Qf9Shf pHaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iY9lbdia; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z7si7139487edb.160.2019.09.23.11.28.36; Mon, 23 Sep 2019 11:28:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iY9lbdia; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727281AbfIVCil (ORCPT + 99 others); Sat, 21 Sep 2019 22:38:41 -0400 Received: from mail-pl1-f171.google.com ([209.85.214.171]:41926 "EHLO mail-pl1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727262AbfIVCik (ORCPT ); Sat, 21 Sep 2019 22:38:40 -0400 Received: by mail-pl1-f171.google.com with SMTP id t10so4931143plr.8 for ; Sat, 21 Sep 2019 19:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u8q6MNCABMDlM/R1LIFa8oysDHH50DToOChOmjLLVbU=; b=iY9lbdiaKjI60gd9i5XxcIo6DblArB55ty+VPbKRX/kyc9Gy3Gw50rzuxdw27vlObx wpR7GADzfAeh3ONtf/Pi2BBPnYqM5Dra3cVQ89qBgVb95cIOBq8Y3SvmjW45RDKImbAp v9bXenkDNzLliTetGiP/9JHcIo4Z+31qy3G9e6lsvTWfle8/qSP8cjiRGISFY23ZhpNp 6O5pfg1SKFEv3tVqJTiLDeSrGBA15JauDm3HNRMfVzdGxMVWC7U7pNwSKJ78E59OAwpa 22EeuBxgp6OwXzyl60jD84Za8lWZUZbwXdiFgFOt1QYSGggNyOO8gytEfIVqMjRosmad ZDlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u8q6MNCABMDlM/R1LIFa8oysDHH50DToOChOmjLLVbU=; b=uWPYkJO1ecfm/VTTP4IwLeKpQ9vFpV4gTFiVqbKX+P8M6RrSCIrnCWHPUlhDgMIsia lusfw+GMxXLTox2voV+BIf6vN6hs9zQ/dYsrvOooRYBEK1OPkHmI7U8OzwtB46Kzto+G gA1UXQ3y9lYLA5nGQJ3f7SdkrauVfSEjvfr/Pg8m8quFx/1P3/t+sg9a5CGQfSQD4VQu Krr8wmv9XARB5D60nDm6J1l4O3DZUj60dwD16WxB3YMx3FJZo5roy1kUzYKM6yZ9uK7R aZdEfx3VL/8RzMLdwgNFjeooCgkoZu0oXc0Khz56VKxriAJkg+NlBMmuQiJyethES80J xFkA== X-Gm-Message-State: APjAAAW/R0u9k60yskjnuHSTC9QpqslVi8zZz2vNImr0ePZPiTS54DTm oTJNB2zAR7GeaUXXVPVX38geYmy+gzg= X-Received: by 2002:a17:902:aa93:: with SMTP id d19mr321916plr.301.1569119919582; Sat, 21 Sep 2019 19:38:39 -0700 (PDT) Received: from localhost.localdomain ([207.148.65.56]) by smtp.gmail.com with ESMTPSA id p20sm5597047pgj.47.2019.09.21.19.38.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 21 Sep 2019 19:38:39 -0700 (PDT) From: Changbin Du To: Peter Zijlstra , Ingo Molnar , Arnaldo Carvalho de Melo , Jiri Olsa Cc: Alexander Shishkin , Namhyung Kim , linux-kernel@vger.kernel.org, Changbin Du Subject: [PATCH v2 1/2] perf: support multiple debug options separated by ',' Date: Sun, 22 Sep 2019 10:38:22 +0800 Message-Id: <20190922023823.12543-2-changbin.du@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190922023823.12543-1-changbin.du@gmail.com> References: <20190922023823.12543-1-changbin.du@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch adds support for multiple debug options separated by ',' and non-int values. --debug verbose=2,stderr Signed-off-by: Changbin Du --- tools/perf/Documentation/perf.txt | 10 ++-- tools/perf/util/debug.c | 86 ++++++++++++++++--------------- 2 files changed, 50 insertions(+), 46 deletions(-) diff --git a/tools/perf/Documentation/perf.txt b/tools/perf/Documentation/perf.txt index 401f0ed67439..c05a94b2488e 100644 --- a/tools/perf/Documentation/perf.txt +++ b/tools/perf/Documentation/perf.txt @@ -19,11 +19,11 @@ OPTIONS --debug verbose=2 # sets verbose = 2 List of debug variables allowed to set: - verbose - general debug messages - ordered-events - ordered events object debug messages - data-convert - data convert command debug messages - stderr - write debug output (option -v) to stderr - in browser mode + verbose=level - general debug messages + ordered-events=level - ordered events object debug messages + data-convert=level - data convert command debug messages + stderr - write debug output (option -v) to stderr + in browser mode --buildid-dir:: Setup buildid cache directory. It has higher priority than diff --git a/tools/perf/util/debug.c b/tools/perf/util/debug.c index a1b59bd35519..ae6eb6d1c695 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -27,7 +27,7 @@ int verbose; bool dump_trace = false, quiet = false; int debug_ordered_events; -static int redirect_to_stderr; +static bool redirect_to_stderr; int debug_data_convert; int veprintf(int level, int var, const char *fmt, va_list args) @@ -173,41 +173,18 @@ void trace_event(union perf_event *event) trace_event_printer, event); } -static struct debug_variable { - const char *name; - int *ptr; -} debug_variables[] = { - { .name = "verbose", .ptr = &verbose }, - { .name = "ordered-events", .ptr = &debug_ordered_events}, - { .name = "stderr", .ptr = &redirect_to_stderr}, - { .name = "data-convert", .ptr = &debug_data_convert }, - { .name = NULL, } -}; - -int perf_debug_option(const char *str) +static int str2loglevel(const char *vstr) { - struct debug_variable *var = &debug_variables[0]; - char *vstr, *s = strdup(str); int v = 1; - - vstr = strchr(s, '='); - if (vstr) - *vstr++ = 0; - - while (var->name) { - if (!strcmp(s, var->name)) - break; - var++; - } - - if (!var->name) { - pr_err("Unknown debug variable name '%s'\n", s); - free(s); - return -1; - } + char *endptr; if (vstr) { - v = atoi(vstr); + v = strtol(vstr, &endptr,0); + if (vstr == endptr) { + fprintf(stderr, "warning: '%s' is not a digit\n", vstr); + return -1; + } + /* * Allow only values in range (0, 10), * otherwise set 0. @@ -218,20 +195,47 @@ int perf_debug_option(const char *str) if (quiet) v = -1; - *var->ptr = v; - free(s); + return v; +} + +int perf_debug_option(const char *str) +{ + char *sep, *vstr; + char *dstr = strdup(str); + char *opt = dstr; + + do { + if ((sep = strchr(opt, ',')) != NULL) + *sep = '\0'; + + vstr = strchr(opt, '='); + if (vstr) + *vstr++ = 0; + + if (!strcmp(opt, "verbose")) + verbose = str2loglevel(vstr); + else if (!strcmp(opt, "ordered-events")) + debug_ordered_events = str2loglevel(vstr); + else if (!strcmp(opt, "data-convert")) + debug_data_convert = str2loglevel(vstr); + else if (!strcmp(opt, "stderr")) + redirect_to_stderr = true; + else { + fprintf(stderr, "unkown debug option '%s'\n", opt); + free(dstr); + return -1; + } + + opt = sep + 1; + } while (sep && sep[1]); + + free(dstr); return 0; } int perf_quiet_option(void) { - struct debug_variable *var = &debug_variables[0]; - - /* disable all debug messages */ - while (var->name) { - *var->ptr = -1; - var++; - } + verbose = debug_ordered_events = debug_data_convert = -1; return 0; } -- 2.20.1