Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1761219AbbKTU6q (ORCPT ); Fri, 20 Nov 2015 15:58:46 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:7206 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1761125AbbKTU55 (ORCPT ); Fri, 20 Nov 2015 15:57:57 -0500 From: Josef Bacik To: , , Subject: [PATCH 09/11] trace-cmd: disentangle profile and read from record Date: Fri, 20 Nov 2015 15:57:31 -0500 Message-ID: <1448053053-24188-10-git-send-email-jbacik@fb.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1448053053-24188-1-git-send-email-jbacik@fb.com> References: <1448053053-24188-1-git-send-email-jbacik@fb.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [192.168.52.123] X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2015-11-20_12:,, signatures=0 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 8937 Lines: 304 trace-record has the bulk of the code we need for creating threads and dealing with instances. Rather than going through the trouble of separating all of that stuff out, just remove the trace-profile and trace-read dependancies from trace-record. This way we don't have to make libtracecmd a huge blob with all of the commands so that linking works. This is a little ugly, but it can be made prettier when/if we pull the thread creation and instance handling code out of trace-record. Thanks, Signed-off-by: Josef Bacik --- trace-cmd.c | 17 +++++++++++++++++ trace-local.h | 11 +++++++---- trace-profile.c | 36 +++++++++++++++++++++++++++++++++++- trace-read.c | 16 +++++++++------- trace-record.c | 22 +++++++++++----------- trace-stream.c | 8 +++++++- 6 files changed, 86 insertions(+), 24 deletions(-) diff --git a/trace-cmd.c b/trace-cmd.c index 49d3559..ab7c969 100644 --- a/trace-cmd.c +++ b/trace-cmd.c @@ -485,6 +485,21 @@ int main (int argc, char **argv) strcmp(argv[1], "profile") == 0 || strcmp(argv[1], "restart") == 0 || strcmp(argv[1], "reset") == 0) { + + /* Need to keep this stuff out of trace-record proper. */ + if (strcmp(argv[1], "stream") == 0) + trace_record_set_handle_init(trace_init_stream); + + /* + * A little ugly but we want to catch trace-cmd record --profile + * so we can let trace_profile be run properly. + */ + for (c = 2; c < argc; c++) { + if (strcmp(argv[c], "--profile") == 0) { + trace_profile(argc, argv); + exit(0); + } + } trace_record(argc, argv); exit(0); @@ -743,6 +758,8 @@ int main (int argc, char **argv) } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "help") == 0) { usage(argv); + } else if (strcmp(argv[1], "profile") == 0) { + trace_profile(argc, argv); } else { fprintf(stderr, "unknown command: %s\n", argv[1]); usage(argv); diff --git a/trace-local.h b/trace-local.h index f21f665..3ce5aa2 100644 --- a/trace-local.h +++ b/trace-local.h @@ -77,10 +77,12 @@ void trace_stat(int argc, char **argv); struct hook_list; -void trace_init_profile(struct tracecmd_input *handle, struct hook_list *hooks, - int global); -int trace_profile(void); +void trace_record_set_handle_init(tracecmd_handle_init_func func); void trace_profile_set_merge_like_comms(void); +void trace_init_profile(struct tracecmd_input *handle, struct hook_list *hook, + int global); +int trace_profile(int argc, char **argv); +int trace_profile_output(void); struct tracecmd_input * trace_stream_init(struct buffer_instance *instance, int cpu, int fd, int cpus, @@ -88,7 +90,8 @@ trace_stream_init(struct buffer_instance *instance, int cpu, int fd, int cpus, tracecmd_handle_init_func handle_init, int global); int trace_stream_read(struct pid_record_data *pids, int nr_pids, struct timeval *tv); -void trace_show_data(struct tracecmd_input *handle, struct pevent_record *record); +void trace_init_stream(struct tracecmd_input *handle, struct hook_list *hook, + int global); /* --- event interation --- */ diff --git a/trace-profile.c b/trace-profile.c index 1eac0b4..ac8a27a 100644 --- a/trace-profile.c +++ b/trace-profile.c @@ -23,6 +23,8 @@ #include #include #include +#include +#include #ifndef NO_AUDIT #include #endif @@ -2333,7 +2335,7 @@ static void merge_tasks(struct handle_data *h) } } -int trace_profile(void) +int trace_profile_output(void) { struct handle_data *h; @@ -2346,3 +2348,35 @@ int trace_profile(void) return 0; } + +enum { + OPT_bycomm = 250, +}; + +int trace_profile(int argc, char **argv) +{ + int option_index = 0; + int c; + struct option long_options[] = { + {"by-comm", no_argument, NULL, OPT_bycomm}, + {NULL, 0, NULL, 0}, + }; + + while ((c = getopt_long(argc-1, argv+1, NULL, long_options, + &option_index)) != -1) { + switch (c) { + case OPT_bycomm: + merge_like_comms = true; + break; + default: + /* We don't care, trace-record will take care of this */ + break; + } + } + + trace_record_set_handle_init(trace_init_profile); + optind = 1; + trace_record(argc, argv); + trace_profile_output(); + return 0; +} diff --git a/trace-read.c b/trace-read.c index 1a71629..b573842 100644 --- a/trace-read.c +++ b/trace-read.c @@ -739,9 +739,9 @@ static void finish_wakeup(void) trace_hash_free(&wakeup_hash); } -void trace_show_data(struct tracecmd_input *handle, struct pevent_record *record) +static void trace_show_data(struct tracecmd_input *handle, + struct pevent_record *record) { - tracecmd_show_data_func func = tracecmd_get_show_data_func(handle); struct pevent *pevent; struct trace_seq s; int cpu = record->cpu; @@ -749,10 +749,6 @@ void trace_show_data(struct tracecmd_input *handle, struct pevent_record *record test_save(record, cpu); - if (func) { - func(handle, record); - return; - } pevent = tracecmd_get_pevent(handle); trace_seq_init(&s); @@ -821,6 +817,12 @@ void trace_show_data(struct tracecmd_input *handle, struct pevent_record *record printf("\n"); } +void trace_init_stream(struct tracecmd_input *handle, struct hook_list *hook, + int global) +{ + tracecmd_set_show_data_func(handle, trace_show_data); +} + static void read_rest(void) { char buf[BUFSIZ + 1]; @@ -1164,7 +1166,7 @@ static void read_data_info(struct list_head *handle_list, enum output_type otype } while (last_record); if (profile) - trace_profile(); + trace_profile_output(); list_for_each_entry(handles, handle_list, list) { free_filters(handles->event_filters); diff --git a/trace-record.c b/trace-record.c index 2bf7815..337445d 100644 --- a/trace-record.c +++ b/trace-record.c @@ -3807,6 +3807,12 @@ void update_first_instance(struct buffer_instance *instance, int topt) first_instance = buffer_instances; } +static tracecmd_handle_init_func __handle_init = NULL; +void trace_record_set_handle_init(tracecmd_handle_init_func func) +{ + __handle_init = func; +} + enum { OPT_bycomm = 250, OPT_stderr = 251, @@ -3824,7 +3830,6 @@ void trace_record (int argc, char **argv) struct event_list *event = NULL; struct event_list *last_event; struct buffer_instance *instance = &top_instance; - tracecmd_handle_init_func handle_init = NULL; enum tracecmd_trace_type type = 0; char *pids; char *pid; @@ -3861,7 +3866,6 @@ void trace_record (int argc, char **argv) else if ((stream = strcmp(argv[1], "stream") == 0)) ; /* do nothing */ else if ((profile = strcmp(argv[1], "profile") == 0)) { - handle_init = trace_init_profile; events = 1; } else if (strcmp(argv[1], "stop") == 0) { for (;;) { @@ -4230,7 +4234,6 @@ void trace_record (int argc, char **argv) recorder_flags |= TRACECMD_RECORD_NOSPLICE; break; case OPT_profile: - handle_init = trace_init_profile; instance->profile = 1; events = 1; break; @@ -4243,7 +4246,7 @@ void trace_record (int argc, char **argv) dup2(2, 1); break; case OPT_bycomm: - trace_profile_set_merge_like_comms(); + /* Handled by trace-profile. */ break; default: usage(argv); @@ -4357,7 +4360,7 @@ void trace_record (int argc, char **argv) if (type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM)) { signal(SIGINT, finish); if (!latency) - tracecmd_start_threads(type, handle_init, global); + tracecmd_start_threads(type, __handle_init, global); } if (extract) { @@ -4367,7 +4370,7 @@ void trace_record (int argc, char **argv) if (!(type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM))) { update_task_filter(); tracecmd_enable_tracing(); - exit(0); + return; } if (run_command) @@ -4413,7 +4416,7 @@ void trace_record (int argc, char **argv) destroy_stats(); if (keep) - exit(0); + return; update_reset_files(); update_reset_triggers(); @@ -4433,8 +4436,5 @@ void trace_record (int argc, char **argv) if (host) tracecmd_output_close(network_handle); - if (profile) - trace_profile(); - - exit(0); + return; } diff --git a/trace-stream.c b/trace-stream.c index 0dbeaf2..c26e48f 100644 --- a/trace-stream.c +++ b/trace-stream.c @@ -127,7 +127,13 @@ int trace_stream_read(struct pid_record_data *pids, int nr_pids, struct timeval last_pid = pid; } if (last_pid) { - trace_show_data(last_pid->instance->handle, last_pid->record); + tracecmd_show_data_func func; + + func = tracecmd_get_show_data_func(last_pid->instance->handle); + if (func) + func(last_pid->instance->handle, last_pid->record); + else + printf("You haven't set a show data func!?!?!\n"); free_record(last_pid->record); last_pid->record = NULL; return 1; -- 2.1.0 -- 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/