Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932203Ab3G3JV1 (ORCPT ); Tue, 30 Jul 2013 05:21:27 -0400 Received: from LGEMRELSE6Q.lge.com ([156.147.1.121]:64877 "EHLO LGEMRELSE6Q.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758495Ab3G3JT3 (ORCPT ); Tue, 30 Jul 2013 05:19:29 -0400 X-AuditID: 9c930179-b7c49ae000000e68-f3-51f7851a8b64 From: Namhyung Kim To: Arnaldo Carvalho de Melo Cc: Peter Zijlstra , Paul Mackerras , Ingo Molnar , Namhyung Kim , LKML , Steven Rostedt , Frederic Weisbecker , Jiri Olsa , David Ahern , Stephane Eranian , Jeremy Eder Subject: [PATCH 12/17] perf ftrace: Cleanup using ftrace_setup/teardown() Date: Tue, 30 Jul 2013 18:19:09 +0900 Message-Id: <1375175954-798-13-git-send-email-namhyung@kernel.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1375175954-798-1-git-send-email-namhyung@kernel.org> References: <1375175954-798-1-git-send-email-namhyung@kernel.org> X-Brightmail-Tracker: AAAAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 6922 Lines: 274 From: Namhyung Kim The ftrace sub-commands share some common code so that factor it out to ftrace_setup() and ftrace_teardown() helpers. Cc: Steven Rostedt Cc: Frederic Weisbecker Signed-off-by: Namhyung Kim --- tools/perf/builtin-ftrace.c | 168 +++++++++++++++++--------------------------- 1 file changed, 64 insertions(+), 104 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index f8e363b3c06d..ad71d0412a7e 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -1393,10 +1393,59 @@ out: return ret; } +static int ftrace_setup(struct perf_ftrace *ftrace, int argc, const char **argv) +{ + int ret; + char errbuf[512]; + + ret = perf_target__validate(&ftrace->target); + if (ret) { + perf_target__strerror(&ftrace->target, ret, errbuf, 512); + pr_err("%s\n", errbuf); + return -EINVAL; + } + + ftrace->evlist = perf_evlist__new(); + if (ftrace->evlist == NULL) + return -ENOMEM; + + ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target); + if (ret < 0) + goto out; + + if (ftrace->tracer == NULL) + ftrace->tracer = DEFAULT_TRACER; + + if (ftrace->dirname == NULL) + ftrace->dirname = DEFAULT_DIRNAME; + + if (argc) { + ret = perf_evlist__prepare_workload(ftrace->evlist, + &ftrace->target, + argv, false, true); + if (ret < 0) + goto out_maps; + } + return 0; + +out_maps: + perf_evlist__delete_maps(ftrace->evlist); +out: + perf_evlist__delete(ftrace->evlist); + + return ret; +} + +static void ftrace_teardown(struct perf_ftrace *ftrace) +{ + perf_evlist__delete_maps(ftrace->evlist); + perf_evlist__delete(ftrace->evlist); +} + static int __cmd_ftrace_live(struct perf_ftrace *ftrace, int argc, const char **argv) { - int ret = -1; + int ret; const char * const live_usage[] = { "perf ftrace live [] []", "perf ftrace live [] -- []", @@ -1421,47 +1470,22 @@ __cmd_ftrace_live(struct perf_ftrace *ftrace, int argc, const char **argv) if (!argc && perf_target__none(&ftrace->target)) usage_with_options(live_usage, live_options); - ret = perf_target__validate(&ftrace->target); - if (ret) { - char errbuf[512]; - - perf_target__strerror(&ftrace->target, ret, errbuf, 512); - pr_err("%s\n", errbuf); - return -EINVAL; - } - - ftrace->evlist = perf_evlist__new(); - if (ftrace->evlist == NULL) - return -ENOMEM; - - ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target); + ret = ftrace_setup(ftrace, argc, argv); if (ret < 0) - goto out; - - if (ftrace->tracer == NULL) - ftrace->tracer = DEFAULT_TRACER; - - if (argc && perf_evlist__prepare_workload(ftrace->evlist, - &ftrace->target, - argv, false, true) < 0) - goto out_maps; + return ret; setup_pager(); ret = do_ftrace_live(ftrace); -out_maps: - perf_evlist__delete_maps(ftrace->evlist); -out: - perf_evlist__delete(ftrace->evlist); - + ftrace_teardown(ftrace); return ret; } static int __cmd_ftrace_record(struct perf_ftrace *ftrace, int argc, const char **argv) { - int ret = -1; + int ret; const char * const record_usage[] = { "perf ftrace record [] []", "perf ftrace record [] -- []", @@ -1488,39 +1512,13 @@ __cmd_ftrace_record(struct perf_ftrace *ftrace, int argc, const char **argv) if (!argc && perf_target__none(&ftrace->target)) usage_with_options(record_usage, record_options); - ret = perf_target__validate(&ftrace->target); - if (ret) { - char errbuf[512]; - - perf_target__strerror(&ftrace->target, ret, errbuf, 512); - pr_err("%s\n", errbuf); - return -EINVAL; - } - - ftrace->evlist = perf_evlist__new(); - if (ftrace->evlist == NULL) - return -ENOMEM; - - ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target); + ret = ftrace_setup(ftrace, argc, argv); if (ret < 0) - goto out; - - if (ftrace->tracer == NULL) - ftrace->tracer = DEFAULT_TRACER; - - if (ftrace->dirname == NULL) - ftrace->dirname = DEFAULT_DIRNAME; - - if (argc && perf_evlist__prepare_workload(ftrace->evlist, - &ftrace->target, - argv, false, true) < 0) - goto out_maps; + return ret; ret = do_ftrace_record(ftrace); -out_maps: perf_evlist__delete_maps(ftrace->evlist); -out: perf_evlist__delete(ftrace->evlist); return ret; @@ -1529,7 +1527,7 @@ out: static int __cmd_ftrace_show(struct perf_ftrace *ftrace, int argc, const char **argv) { - int ret = -1; + int ret; const char * const show_usage[] = { "perf ftrace show []", NULL @@ -1549,41 +1547,22 @@ __cmd_ftrace_show(struct perf_ftrace *ftrace, int argc, const char **argv) if (argc) usage_with_options(show_usage, show_options); - ret = perf_target__validate(&ftrace->target); - if (ret) { - char errbuf[512]; - - perf_target__strerror(&ftrace->target, ret, errbuf, 512); - pr_err("%s\n", errbuf); - return -EINVAL; - } - - ftrace->evlist = perf_evlist__new(); - if (ftrace->evlist == NULL) - return -ENOMEM; - - ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target); + ret = ftrace_setup(ftrace, argc, argv); if (ret < 0) - goto out; - - if (ftrace->dirname == NULL) - ftrace->dirname = DEFAULT_DIRNAME; + return ret; setup_pager(); ret = do_ftrace_show(ftrace); - perf_evlist__delete_maps(ftrace->evlist); -out: - perf_evlist__delete(ftrace->evlist); - + ftrace_teardown(ftrace); return ret; } static int __cmd_ftrace_report(struct perf_ftrace *ftrace, int argc, const char **argv) { - int ret = -1; + int ret; const char * const report_usage[] = { "perf ftrace report []", NULL @@ -1609,25 +1588,9 @@ __cmd_ftrace_report(struct perf_ftrace *ftrace, int argc, const char **argv) if (argc) usage_with_options(report_usage, report_options); - ret = perf_target__validate(&ftrace->target); - if (ret) { - char errbuf[512]; - - perf_target__strerror(&ftrace->target, ret, errbuf, 512); - pr_err("%s\n", errbuf); - return -EINVAL; - } - - ftrace->evlist = perf_evlist__new(); - if (ftrace->evlist == NULL) - return -ENOMEM; - - ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target); + ret = ftrace_setup(ftrace, argc, argv); if (ret < 0) - goto out; - - if (ftrace->dirname == NULL) - ftrace->dirname = DEFAULT_DIRNAME; + return ret; perf_hpp__init(); @@ -1640,10 +1603,7 @@ __cmd_ftrace_report(struct perf_ftrace *ftrace, int argc, const char **argv) ret = do_ftrace_report(ftrace); - perf_evlist__delete_maps(ftrace->evlist); -out: - perf_evlist__delete(ftrace->evlist); - + ftrace_teardown(ftrace); return ret; } -- 1.7.11.7 -- 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/