Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932681AbbGGRdP (ORCPT ); Tue, 7 Jul 2015 13:33:15 -0400 Received: from mga02.intel.com ([134.134.136.20]:28710 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932440AbbGGRdF (ORCPT ); Tue, 7 Jul 2015 13:33:05 -0400 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,425,1432623600"; d="scan'208";a="724459522" From: kan.liang@intel.com To: acme@kernel.org, jolsa@kernel.org Cc: namhyung@kernel.org, ak@linux.intel.com, linux-kernel@vger.kernel.org, Kan Liang Subject: [PATCH RFC V2 1/5] perf,tools: introduce OPT_CALLBACK_SET/OPT_CALLBACK_NOOPT_SET Date: Tue, 7 Jul 2015 06:19:01 -0400 Message-Id: <1436264345-12085-2-git-send-email-kan.liang@intel.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1436264345-12085-1-git-send-email-kan.liang@intel.com> References: <1436264345-12085-1-git-send-email-kan.liang@intel.com> Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4448 Lines: 93 From: Kan Liang This patch extends the OPT_CALLBACK/OPT_CALLBACK_NOOPT to support 'set' item of struct option. So the perf knows whether an option was set by user. The new macros are used by call-graph and timestamp options. Signed-off-by: Kan Liang --- tools/perf/builtin-record.c | 7 ++++--- tools/perf/perf.h | 2 ++ tools/perf/util/parse-options.c | 2 ++ tools/perf/util/parse-options.h | 4 ++++ 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c index de165a1..c270993 100644 --- a/tools/perf/builtin-record.c +++ b/tools/perf/builtin-record.c @@ -1018,10 +1018,10 @@ struct option __record_options[] = { record__parse_mmap_pages), OPT_BOOLEAN(0, "group", &record.opts.group, "put the counters into a counter group"), - OPT_CALLBACK_NOOPT('g', NULL, &record.opts, + OPT_CALLBACK_NOOPT_SET('g', NULL, &record.opts, &record.opts.callgraph_set, NULL, "enables call-graph recording" , &record_callchain_opt), - OPT_CALLBACK(0, "call-graph", &record.opts, + OPT_CALLBACK_SET(0, "call-graph", &record.opts, &record.opts.callgraph_set, "mode[,dump_size]", record_callchain_help, &record_parse_callchain_opt), OPT_INCR('v', "verbose", &verbose, @@ -1030,7 +1030,8 @@ struct option __record_options[] = { OPT_BOOLEAN('s', "stat", &record.opts.inherit_stat, "per thread counts"), OPT_BOOLEAN('d', "data", &record.opts.sample_address, "Record the sample addresses"), - OPT_BOOLEAN('T', "timestamp", &record.opts.sample_time, "Record the sample timestamps"), + OPT_BOOLEAN_SET('T', "timestamp", &record.opts.sample_time, + &record.opts.sample_time_set, "Sample timestamps"), OPT_BOOLEAN('P', "period", &record.opts.period, "Record the sample period"), OPT_BOOLEAN('n', "no-samples", &record.opts.no_samples, "don't sample"), diff --git a/tools/perf/perf.h b/tools/perf/perf.h index 4a5827ff..9ba02e0 100644 --- a/tools/perf/perf.h +++ b/tools/perf/perf.h @@ -51,6 +51,8 @@ struct record_opts { bool sample_address; bool sample_weight; bool sample_time; + bool sample_time_set; + bool callgraph_set; bool period; bool sample_intr_regs; bool running_time; diff --git a/tools/perf/util/parse-options.c b/tools/perf/util/parse-options.c index 01626be..064385f 100644 --- a/tools/perf/util/parse-options.c +++ b/tools/perf/util/parse-options.c @@ -140,6 +140,8 @@ static int get_value(struct parse_opt_ctx_t *p, return err; case OPTION_CALLBACK: + if (opt->set) + *(bool *)opt->set = true; if (unset) return (*opt->callback)(opt, NULL, 1) ? (-1) : 0; if (opt->flags & PARSE_OPT_NOARG) diff --git a/tools/perf/util/parse-options.h b/tools/perf/util/parse-options.h index 367d8b8..2bec32e 100644 --- a/tools/perf/util/parse-options.h +++ b/tools/perf/util/parse-options.h @@ -132,8 +132,12 @@ struct option { { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), .argh = "time", .help = (h), .callback = parse_opt_approxidate_cb } #define OPT_CALLBACK(s, l, v, a, h, f) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f) } +#define OPT_CALLBACK_SET(s, l, v, os, a, h, f) \ + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .set = check_vtype(os, bool *) } #define OPT_CALLBACK_NOOPT(s, l, v, a, h, f) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG } +#define OPT_CALLBACK_NOOPT_SET(s, l, v, os, a, h, f) \ + { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .flags = PARSE_OPT_NOARG, .set = check_vtype(os, bool *) } #define OPT_CALLBACK_DEFAULT(s, l, v, a, h, f, d) \ { .type = OPTION_CALLBACK, .short_name = (s), .long_name = (l), .value = (v), (a), .help = (h), .callback = (f), .defval = (intptr_t)d, .flags = PARSE_OPT_LASTARG_DEFAULT } #define OPT_CALLBACK_DEFAULT_NOOPT(s, l, v, a, h, f, d) \ -- 1.8.3.1 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/