Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755410Ab3DWId7 (ORCPT ); Tue, 23 Apr 2013 04:33:59 -0400 Received: from LGEMRELSE7Q.lge.com ([156.147.1.151]:46785 "EHLO LGEMRELSE7Q.lge.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756022Ab3DWIbW (ORCPT ); Tue, 23 Apr 2013 04:31:22 -0400 X-AuditID: 9c930197-b7bb3ae000000fa9-9a-517646d246fc 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 Subject: [PATCH 08/14] perf ftrace: Split "live" sub-command Date: Tue, 23 Apr 2013 17:31:06 +0900 Message-Id: <1366705872-12132-9-git-send-email-namhyung@kernel.org> X-Mailer: git-send-email 1.7.11.7 In-Reply-To: <1366705872-12132-1-git-send-email-namhyung@kernel.org> References: <1366705872-12132-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: 5701 Lines: 187 From: Namhyung Kim Separate out the default behavior to "live" subcommand. It's a preparation to support more subcommands like "record" and "report". Cc: Steven Rostedt Cc: Frederic Weisbecker Signed-off-by: Namhyung Kim --- tools/perf/builtin-ftrace.c | 109 +++++++++++++++++++++++++++----------------- 1 file changed, 68 insertions(+), 41 deletions(-) diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c index 04ca2303b63b..6d991c44948f 100644 --- a/tools/perf/builtin-ftrace.c +++ b/tools/perf/builtin-ftrace.c @@ -131,7 +131,7 @@ static int set_tracing_cpu(struct perf_ftrace *ftrace) return 0; } -static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) +static int do_ftrace_live(struct perf_ftrace *ftrace) { char *trace_file; int trace_fd; @@ -140,11 +140,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) .events = POLLIN, }; - if (geteuid() != 0) { - pr_err("ftrace only works for root!\n"); - return -1; - } - signal(SIGINT, sig_handler); signal(SIGUSR1, sig_handler); signal(SIGCHLD, sig_handler); @@ -156,12 +151,6 @@ static int __cmd_ftrace(struct perf_ftrace *ftrace, int argc, const char **argv) if (write_tracing_file("trace", "0") < 0) goto out; - if (argc && perf_evlist__prepare_workload(ftrace->evlist, - &ftrace->target, - argv, false, true) < 0) { - goto out; - } - if (set_tracing_pid(ftrace) < 0) { pr_err("failed to set ftrace pid\n"); goto out_reset; @@ -234,61 +223,99 @@ out: return done ? 0 : -1; } -int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused) +static int +__cmd_ftrace_live(struct perf_ftrace *ftrace, int argc, const char **argv) { - int ret; - struct perf_ftrace ftrace = { - .target = { .uid = UINT_MAX, }, - }; - const char * const ftrace_usage[] = { - "perf ftrace [] []", - "perf ftrace [] -- []", + int ret = -1; + const char * const live_usage[] = { + "perf ftrace live [] []", + "perf ftrace live [] -- []", NULL }; - const struct option ftrace_options[] = { - OPT_STRING('t', "tracer", &ftrace.tracer, "tracer", + const struct option live_options[] = { + OPT_STRING('t', "tracer", &ftrace->tracer, "tracer", "tracer to use"), - OPT_STRING('p', "pid", &ftrace.target.tid, "pid", + OPT_STRING('p', "pid", &ftrace->target.tid, "pid", "trace on existing process id"), OPT_INCR('v', "verbose", &verbose, "be more verbose"), - OPT_BOOLEAN('a', "all-cpus", &ftrace.target.system_wide, + OPT_BOOLEAN('a', "all-cpus", &ftrace->target.system_wide, "system-wide collection from all CPUs"), - OPT_STRING('C', "cpu", &ftrace.target.cpu_list, "cpu", + OPT_STRING('C', "cpu", &ftrace->target.cpu_list, "cpu", "list of cpus to monitor"), OPT_END() }; - argc = parse_options(argc, argv, ftrace_options, ftrace_usage, - PARSE_OPT_STOP_AT_NON_OPTION); - if (!argc && perf_target__none(&ftrace.target)) - usage_with_options(ftrace_usage, ftrace_options); + argc = parse_options(argc, argv, live_options, live_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + if (!argc && perf_target__none(&ftrace->target)) + usage_with_options(live_usage, live_options); - ret = perf_target__validate(&ftrace.target); + ret = perf_target__validate(&ftrace->target); if (ret) { char errbuf[512]; - perf_target__strerror(&ftrace.target, ret, 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) + ftrace->evlist = perf_evlist__new(); + if (ftrace->evlist == NULL) return -ENOMEM; - ret = perf_evlist__create_maps(ftrace.evlist, &ftrace.target); + ret = perf_evlist__create_maps(ftrace->evlist, &ftrace->target); if (ret < 0) - goto out_delete_evlist; + goto out; - if (ftrace.tracer == NULL) - ftrace.tracer = DEFAULT_TRACER; + if (ftrace->tracer == NULL) + ftrace->tracer = DEFAULT_TRACER; - ret = __cmd_ftrace(&ftrace, argc, argv); + if (argc && perf_evlist__prepare_workload(ftrace->evlist, + &ftrace->target, + argv, false, true) < 0) + goto out_maps; + + ret = do_ftrace_live(ftrace); - perf_evlist__delete_maps(ftrace.evlist); -out_delete_evlist: - perf_evlist__delete(ftrace.evlist); +out_maps: + perf_evlist__delete_maps(ftrace->evlist); +out: + perf_evlist__delete(ftrace->evlist); + + return ret; +} + +int cmd_ftrace(int argc, const char **argv, const char *prefix __maybe_unused) +{ + int ret; + struct perf_ftrace ftrace = { + .target = { .uid = UINT_MAX, }, + }; + const char * const ftrace_usage[] = { + "perf ftrace {live} [] []", + "perf ftrace {live} [] -- []", + NULL + }; + const struct option ftrace_options[] = { + OPT_END() + }; + + argc = parse_options(argc, argv, ftrace_options, ftrace_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + if (!argc) + usage_with_options(ftrace_usage, ftrace_options); + + if (geteuid() != 0) { + pr_err("ftrace only works for root!\n"); + return -1; + } + + if (strcmp(argv[0], "live") == 0) { + ret = __cmd_ftrace_live(&ftrace, argc, argv); + } else { + usage_with_options(ftrace_usage, ftrace_options); + } 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/