Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp557711ybp; Fri, 4 Oct 2019 00:59:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqzBWJV1IJWH1mcEnJwMRHN+KvTZ70IEerE/vwuWv25TlmSpb8il1aGnY9WJRWddyGsHvQC+ X-Received: by 2002:a05:6402:13c2:: with SMTP id a2mr13628175edx.21.1570175985052; Fri, 04 Oct 2019 00:59:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570175985; cv=none; d=google.com; s=arc-20160816; b=XeRWD4hWH5cb6jXWMysLZVE0yeovnl1h3XKkUsIuF6CXfaj9nYv1JX02mus0Apvy+/ 8QdiL7NtZMrvAXckGlUdJcuhEjca5b5fcG6MSYL51OOTHw1aX7hEEg21Z6FPVwjBbVdL MJd6hpVxzcaBxMLwR7goEb+8z3sMQMPJ2dnMFMHam9YxP/RVkUv1ZJRiHDljuFWQCF9/ Sr5mLWi5wVkta0lelyLFCaicknvpgJPLMBrX26H6EaFrGrN7WXI6qHwwNAvt08u/WmBa Ml4Xa1lv90orbEFNYmep3htUKE3pF0dMy2c6ywK441n+07gHrCBeWm6zbt/r0h9tZ3IS Hszg== 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=IFqp3FYVQxAZCJNtTZgC4FqFytGhefEpuCZKb+wIGoY=; b=HJrhncoJyzXfLOoaYTBLvUUFm7A/FVgvgDO0pOzaxZhYWaQuKbFhaE+UGzx/kfQ/1N G8bdZ+yEzGvtWOPcuSR4yQluhzJMxlfrTAdcuT2rgJLXbq3j43uZJYRoe6QzqaPgjzmq gx4LAk8ar4co4ruOpEl5XdsD7vcoMZE4TQhefilr/2bBBDt7stthnPpXTb9Uw6MI/HWf egZlYkd7Fez7qg6aQ2vX6JbrkOuwnU0e4PWyJH9drSMUiu/bixKJ1qAUNZjFp2sZoRUb OP2WLhQW5kGcwA/vbNBuiV7DQJvTiee0sRZ1FEPtLQ3glicmLWiPSIbxAoc71tIfzohC GL3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=JE50Zo2E; 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 e23si2926322edq.344.2019.10.04.00.59.20; Fri, 04 Oct 2019 00:59:45 -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=JE50Zo2E; 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 S1732092AbfJDCkR (ORCPT + 99 others); Thu, 3 Oct 2019 22:40:17 -0400 Received: from mail-wr1-f44.google.com ([209.85.221.44]:37199 "EHLO mail-wr1-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728360AbfJDCkR (ORCPT ); Thu, 3 Oct 2019 22:40:17 -0400 Received: by mail-wr1-f44.google.com with SMTP id p14so4168043wro.4 for ; Thu, 03 Oct 2019 19:40:15 -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=IFqp3FYVQxAZCJNtTZgC4FqFytGhefEpuCZKb+wIGoY=; b=JE50Zo2EfbrPVM+f2F4BiXLxT4hCFfawY+GKQ2rkA5upuPyck20fc+DerrY/EZVW+2 6v92Ru/e/o65MMiGS+BH7snP10snnOV+gm0Og5anh7XH1W7MRS9g6GogRblBXSrSrr6P BpxWy5a+UZhDvDQfwJHsSY2IfClvj3dxBZ6QOdHQwycFmARkNCz/hbelABTbxcAVwO7D +mp0TnZqfTuYjQLYxnAWHxxg3cgBfgJNvZEZ+SE8x3ItbdK7ldPYdFIr4GDA22h9uBIe OY46nd33aJ0pNlekEBRscvWRzbp39TEaVn11cdy/KuqWydPal4IsoS1depSuO2IX0eWb QeQA== 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=IFqp3FYVQxAZCJNtTZgC4FqFytGhefEpuCZKb+wIGoY=; b=n8UcbW7/HRlSru1VIWADN0R+f2IDChbiasxoB4G2Nj+elKIr6K5w8xhwZ6KeCL9gPp kE1nPh+oemUcsSxdFqw0DkDUdiIB+L8/1eJewIVnh8Lx8LOdwioPUbF8c9dWhHuSQuGe lEMOwUzGmPwitcm4xH+lwCKDBMOP1IHrCQYt5SPn064l2mJf0nC2VCxdzyzA/ZLn/z/o /iR9X6c6WfjoW4AZr4Kx/YwYouO8yKzZMH/nluffTQjdbMeVfYur1kND9MrGgumlcFgN OFmD+1FOD13mUonCPp1hcOHAFob2LQLKERJNHVTwjF+p7rnLdxhwkINADPb2BWhCCPww I5Rg== X-Gm-Message-State: APjAAAXA8Qkgj+13ifk6Q/e2SH5p7Jp+FClHIIeQjcE8DAfRsiRL9ag2 quQGulc2zxHihpgDoH43Yko= X-Received: by 2002:a5d:4102:: with SMTP id l2mr9897968wrp.348.1570156814624; Thu, 03 Oct 2019 19:40:14 -0700 (PDT) Received: from localhost.localdomain ([104.238.174.53]) by smtp.gmail.com with ESMTPSA id o19sm7447776wmh.27.2019.10.03.19.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2019 19:40:14 -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 v3 1/2] perf: support multiple debug options separated by ',' Date: Fri, 4 Oct 2019 10:39:53 +0800 Message-Id: <20191004023954.1116-2-changbin.du@gmail.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191004023954.1116-1-changbin.du@gmail.com> References: <20191004023954.1116-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 e55114f0336f..df82ad9cd16d 100644 --- a/tools/perf/util/debug.c +++ b/tools/perf/util/debug.c @@ -26,7 +26,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) @@ -172,41 +172,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. @@ -217,20 +194,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