From: Adrian Hunter <adrian.hunter@intel.com>
To: Arnaldo Carvalho de Melo <acme@kernel.org>, Jiri Olsa <jolsa@redhat.com>
Cc: Andi Kleen <ak@linux.intel.com>,
Alexey Budankov <alexey.budankov@linux.intel.com>,
Namhyung Kim <namhyung@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH] perf tools: Consolidate close_control_option()'s into one function
Date: Thu, 3 Sep 2020 15:29:37 +0300 [thread overview]
Message-ID: <20200903122937.25691-1-adrian.hunter@intel.com> (raw)
In-Reply-To: <e4d294a9-9d97-2cb0-c43d-926fbf90b819@intel.com>
Consolidate control option fifo closing into one function.
Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
This patch is on top of patch:
"perf tools: Add FIFO file names as alternative options to --control"
tools/perf/builtin-record.c | 12 +-----------
tools/perf/builtin-stat.c | 12 +-----------
tools/perf/util/evlist.c | 10 ++++++++++
tools/perf/util/evlist.h | 1 +
4 files changed, 13 insertions(+), 22 deletions(-)
diff --git a/tools/perf/builtin-record.c b/tools/perf/builtin-record.c
index 476b34ff3152..9db3901e6561 100644
--- a/tools/perf/builtin-record.c
+++ b/tools/perf/builtin-record.c
@@ -2253,16 +2253,6 @@ static int parse_control_option(const struct option *opt,
return evlist__parse_control(str, &opts->ctl_fd, &opts->ctl_fd_ack, &opts->ctl_fd_close);
}
-static void close_control_option(struct record_opts *opts)
-{
- if (opts->ctl_fd_close) {
- opts->ctl_fd_close = false;
- close(opts->ctl_fd);
- if (opts->ctl_fd_ack >= 0)
- close(opts->ctl_fd_ack);
- }
-}
-
static void switch_output_size_warn(struct record *rec)
{
u64 wakeup_size = evlist__mmap_size(rec->opts.mmap_pages);
@@ -2849,7 +2839,7 @@ int cmd_record(int argc, const char **argv)
symbol__exit();
auxtrace_record__free(rec->itr);
out_opts:
- close_control_option(&rec->opts);
+ evlist__close_control(rec->opts.ctl_fd, rec->opts.ctl_fd_ack, &rec->opts.ctl_fd_close);
return err;
}
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 21424ed0734b..68d4bdf15635 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1051,16 +1051,6 @@ static int parse_control_option(const struct option *opt,
return evlist__parse_control(str, &config->ctl_fd, &config->ctl_fd_ack, &config->ctl_fd_close);
}
-static void close_control_option(struct perf_stat_config *config)
-{
- if (config->ctl_fd_close) {
- config->ctl_fd_close = false;
- close(config->ctl_fd);
- if (config->ctl_fd_ack >= 0)
- close(config->ctl_fd_ack);
- }
-}
-
static struct option stat_options[] = {
OPT_BOOLEAN('T', "transaction", &transaction_run,
"hardware transaction statistics"),
@@ -2408,7 +2398,7 @@ int cmd_stat(int argc, const char **argv)
metricgroup__rblist_exit(&stat_config.metric_events);
runtime_stat_delete(&stat_config);
- close_control_option(&stat_config);
+ evlist__close_control(stat_config.ctl_fd, stat_config.ctl_fd_ack, &stat_config.ctl_fd_close);
return status;
}
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index e72ff7e78dec..ee7b576d3b12 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -1802,6 +1802,16 @@ int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *c
return 0;
}
+void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close)
+{
+ if (*ctl_fd_close) {
+ *ctl_fd_close = false;
+ close(ctl_fd);
+ if (ctl_fd_ack >= 0)
+ close(ctl_fd_ack);
+ }
+}
+
int evlist__initialize_ctlfd(struct evlist *evlist, int fd, int ack)
{
if (fd == -1) {
diff --git a/tools/perf/util/evlist.h b/tools/perf/util/evlist.h
index 91d1da6e1fe3..bc38a53f6a1a 100644
--- a/tools/perf/util/evlist.h
+++ b/tools/perf/util/evlist.h
@@ -376,6 +376,7 @@ enum evlist_ctl_cmd {
};
int evlist__parse_control(const char *str, int *ctl_fd, int *ctl_fd_ack, bool *ctl_fd_close);
+void evlist__close_control(int ctl_fd, int ctl_fd_ack, bool *ctl_fd_close);
int evlist__initialize_ctlfd(struct evlist *evlist, int ctl_fd, int ctl_fd_ack);
int evlist__finalize_ctlfd(struct evlist *evlist);
bool evlist__ctlfd_initialized(struct evlist *evlist);
--
2.17.1
next prev parent reply other threads:[~2020-09-03 12:43 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-01 9:37 [PATCH V2 0/6] perf tools: Enable AUX area tracing snapshots using a FIFO Adrian Hunter
2020-09-01 9:37 ` [PATCH V2 1/6] perf tools: Consolidate --control option parsing into one function Adrian Hunter
2020-09-02 16:06 ` Alexey Budankov
2020-09-03 20:15 ` Arnaldo Carvalho de Melo
2020-09-01 9:37 ` [PATCH V2 2/6] perf tools: Handle read errors from ctl_fd Adrian Hunter
2020-09-02 16:11 ` Alexey Budankov
2020-09-03 20:16 ` Arnaldo Carvalho de Melo
2020-09-01 9:37 ` [PATCH V2 3/6] perf tools: Use AsciiDoc formatting for --control option documentation Adrian Hunter
2020-09-02 16:12 ` Alexey Budankov
2020-09-03 20:17 ` Arnaldo Carvalho de Melo
2020-09-01 9:37 ` [PATCH V2 4/6] perf tools: Add FIFO file names as alternative options to --control Adrian Hunter
2020-09-01 20:06 ` Jiri Olsa
2020-09-02 10:57 ` [PATCH V3 " Adrian Hunter
2020-09-02 17:03 ` Alexey Budankov
2020-09-03 10:38 ` Adrian Hunter
2020-09-03 12:29 ` Adrian Hunter [this message]
2020-09-04 18:56 ` [PATCH] perf tools: Consolidate close_control_option()'s into one function Arnaldo Carvalho de Melo
2020-09-03 20:21 ` [PATCH V3 4/6] perf tools: Add FIFO file names as alternative options to --control Arnaldo Carvalho de Melo
2020-09-01 9:37 ` [PATCH V2 5/6] perf record: Add 'snapshot' control command Adrian Hunter
2020-09-02 17:03 ` Alexey Budankov
2020-09-03 10:44 ` Adrian Hunter
2020-09-01 9:37 ` [PATCH V2 6/6] perf intel-pt: Document snapshot " Adrian Hunter
2020-09-02 16:53 ` Alexey Budankov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200903122937.25691-1-adrian.hunter@intel.com \
--to=adrian.hunter@intel.com \
--cc=acme@kernel.org \
--cc=ak@linux.intel.com \
--cc=alexey.budankov@linux.intel.com \
--cc=jolsa@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=namhyung@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).