Received: by 10.223.164.202 with SMTP id h10csp647018wrb; Thu, 30 Nov 2017 05:21:44 -0800 (PST) X-Google-Smtp-Source: AGs4zMYUn3PucH6b6nKpi0iHVUdyn1x6gyPE0ZyUJ9pTylPxOcB99DtkabZjHFvox2pet9KfKfuD X-Received: by 10.98.152.25 with SMTP id q25mr6694170pfd.58.1512048104152; Thu, 30 Nov 2017 05:21:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512048104; cv=none; d=google.com; s=arc-20160816; b=EGt+sNYjX07lJ+montWZ+HPr61mdxmd/gkZH1U0iz/atYWiOof8Im2VUP/z3GeF9Ud U/+ooIPblUj3/N7JDS6XJmIAHBvLjvRHuRxDgryz/1NgKJGjgDfUB6JEmfrznFnQhkEp L3dBKy8XRCkRKNvEw4jElUCiDqkCyUIet6BfXg91odf8A3Uqe1pEEG9URbVbQyvQK7es RZxsnko18LEuWUEk6av6+csMejfkh5Lb6NMGkGFmcIeOYHYwju+qcz07DIAq8Y3U6SE5 R9n1BoR25n3V/yjz+SxsR7fCfJ/3BYTXIBSRw7CAsJQZfNwdIw2M2YBqIKT3EezowySL nb6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=h6shjyUHn9zD0UlLFlQQjN9br0Xk5Zsg3xga4BmOWEs=; b=1A4J2IrCrhSaa5gKGxZmwzy32T1CfYVgYVcBk3JLp36o7BH60gplZN9OvFvvR9I3SO LivNqRLPkCFSaOACsOyfLRHYn+WLOhr4XrjHsRtjJhWx1yenYHeEjO8o4QLkIrvDm5N6 3tY+ES+XrsE0c3IAkb90eNYFsi2g8UF4xS1C9vDwGUzbHdFMfB/URPmdJYEBXq4aPhjl CyTaEUJ0rFptTNSko8rXKMvrNguBNYshz+d6r7Zjujs4wXTWGb1dqE+wddRh6f76jkhY tFcq4GmRRM0C8E3ZtpdzpubfRL2SuQPOYmWdazjHs3g8P8YRy1srtwAdV8to3gFGgsKk 05Yw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PfjzX+Bg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p186si2951458pga.385.2017.11.30.05.21.30; Thu, 30 Nov 2017 05:21:44 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PfjzX+Bg; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753143AbdK3NVB (ORCPT + 99 others); Thu, 30 Nov 2017 08:21:01 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36559 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752644AbdK3NUq (ORCPT ); Thu, 30 Nov 2017 08:20:46 -0500 Received: by mail-wr0-f193.google.com with SMTP id v105so6549182wrc.3 for ; Thu, 30 Nov 2017 05:20:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=h6shjyUHn9zD0UlLFlQQjN9br0Xk5Zsg3xga4BmOWEs=; b=PfjzX+BguAgp4VcBqgwRFjJotfdyl4XGuQlFCiCVhxUr7EYdR373t54+ClZtmmSFWC BlEX8lH2LAWgGLc0ic/uAMPPgHGgcp413Th9Pnd2jC+dv5YLrEqfWO76cl/ZKvJ7KOB5 DZ7Bca8D3rdq/sUg5afGt0dOJpY1uRbcrJpAj3crUzcVXoLki+i9Prc7R52mCPT/APJ9 oWUfqshq2hvLfhmz+JN9nZaozCzkjJD7bdx4g2wd3diFtCebq3ZMzV1SvkThTqPPq4b3 2bWEVN76Yuna1BOPwiLXWUKUrmWSAeJl5GQRjTLnZDubzc9tC82LffNmUUePZxjDgab+ I6tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=h6shjyUHn9zD0UlLFlQQjN9br0Xk5Zsg3xga4BmOWEs=; b=WNRprlRq4q/RHvbXegjALgSgDrzU1zpgEqbLbK7QEHnHHCmW44KwSD92BrKkS0HfB7 eH5rR2K6ZgMM1tNBUByEmy9gMSUWTc2setBQo/WBiEiSNCQVhXhAD0LZrsV+kfHMsUe9 UK8AgRGOR61sFFCOr/yGWyFi0+kpJTTNDLpxcpGOEAJCMO9BwucM7tsXHiPV1CSpZxo0 0WCUEovO9Gw+T1sF8WB8xNMa2qrLFXf/u4SH0nUVobtxxPi5/25NlJBiRn+yIDj6Ufj8 60ijfDVN768Zq4EtjKoCqjdz3IywqEdo9y4am2mifJcZeBHkjUrOS2I3JG/we4EkfSGA BWnw== X-Gm-Message-State: AJaThX5YRW05P7uZuOtzgNPQHaahQ+EsbrI8BJBPxmSIQZDwN7HQ9NuZ pUpTbUu6TAs4w4ip3H2v8zo= X-Received: by 10.223.187.7 with SMTP id r7mr1974620wrg.253.1512048044991; Thu, 30 Nov 2017 05:20:44 -0800 (PST) Received: from localhost.localdomain ([87.121.44.226]) by smtp.gmail.com with ESMTPSA id p200sm3539734wmd.9.2017.11.30.05.20.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 05:20:44 -0800 (PST) From: "Vladislav Valtchev (VMware)" To: rostedt@goodmis.org Cc: linux-kernel@vger.kernel.org, y.karadz@gmail.com, "Vladislav Valtchev (VMware)" Subject: [PATCH v2 10/10] trace-cmd: Fork record_trace() for the extract case Date: Thu, 30 Nov 2017 15:19:57 +0200 Message-Id: <20171130131957.21617-11-vladislav.valtchev@gmail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171130131957.21617-1-vladislav.valtchev@gmail.com> References: <20171130131957.21617-1-vladislav.valtchev@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch inlines record_trace() into trace_extract() by removing the code not related to extract, by replacing IS_EXTRACT(ctx) with true and then removing the dead code, as well as the if statements when their condition always evalutates to true. The opposite change [IS_EXTRACT(ctx) evaluated as false] has been applyed to record_trace(). The purpose of doing that is to reduce the amount of branches in both the cases (extract and everything else), making the code simpler to understand and follow but at the price of having some copy-pasted code. Signed-off-by: Vladislav Valtchev (VMware) --- trace-record.c | 172 ++++++++++++++++++++++++++++++++++----------------------- 1 file changed, 102 insertions(+), 70 deletions(-) diff --git a/trace-record.c b/trace-record.c index 749c205..48426e5 100644 --- a/trace-record.c +++ b/trace-record.c @@ -4794,7 +4794,7 @@ static void finalize_record_trace(struct common_record_context *ctx) /* * This function contains common code for the following commands: - * record, start, extract, stream, profile. + * record, start, stream, profile. */ static void record_trace(int argc, char **argv, struct common_record_context *ctx) @@ -4805,15 +4805,13 @@ static void record_trace(int argc, char **argv, * If top_instance doesn't have any plugins or events, then * remove it from being processed. */ - if (!IS_EXTRACT(ctx) && !__check_doing_something(&top_instance)) + if (!__check_doing_something(&top_instance)) first_instance = buffer_instances; else ctx->topt = 1; update_first_instance(ctx->instance, ctx->topt); - - if (!IS_EXTRACT(ctx)) - check_doing_something(); + check_doing_something(); check_function_plugin(); if (ctx->output) @@ -4831,43 +4829,35 @@ static void record_trace(int argc, char **argv, ctx->instance->tracing_on_init_val = 1; } - /* Extracting data records all events in the system. */ - if (IS_EXTRACT(ctx) && !ctx->record_all) - record_all_events(); - - if (!IS_EXTRACT(ctx)) - make_instances(); + make_instances(); if (ctx->events) expand_event_list(); page_size = getpagesize(); - if (!IS_EXTRACT(ctx)) { - fset = set_ftrace(!ctx->disable, ctx->total_disable); - tracecmd_disable_all_tracing(1); + fset = set_ftrace(!ctx->disable, ctx->total_disable); + tracecmd_disable_all_tracing(1); + for_all_instances(ctx->instance) + set_clock(ctx->instance); + + /* Record records the date first */ + if (IS_RECORD(ctx) && ctx->date) + ctx->date2ts = get_date_to_ts(); + + for_all_instances(ctx->instance) { + set_funcs(ctx->instance); + set_mask(ctx->instance); + } + + if (ctx->events) { for_all_instances(ctx->instance) - set_clock(ctx->instance); - - /* Record records the date first */ - if (IS_RECORD(ctx) && ctx->date) - ctx->date2ts = get_date_to_ts(); - - for_all_instances(ctx->instance) { - set_funcs(ctx->instance); - set_mask(ctx->instance); - } - - if (ctx->events) { - for_all_instances(ctx->instance) - enable_events(ctx->instance); - } - set_buffer_size(); + enable_events(ctx->instance); } + set_buffer_size(); update_plugins(type); - set_options(); if (ctx->max_graph_depth) { @@ -4882,53 +4872,36 @@ static void record_trace(int argc, char **argv, signal(SIGINT, finish); if (!latency) start_threads(type, ctx->global); - } - - if (IS_EXTRACT(ctx)) { - flush_threads(); - } else { - if (!(type & (TRACE_TYPE_RECORD | TRACE_TYPE_STREAM))) { - update_task_filter(); - tracecmd_enable_tracing(); - exit(0); - } - - if (ctx->run_command) - run_cmd(type, (argc - optind) - 1, &argv[optind + 1]); - else { - update_task_filter(); - tracecmd_enable_tracing(); - /* We don't ptrace ourself */ - if (do_ptrace && filter_pid >= 0) - ptrace_attach(filter_pid); - /* sleep till we are woken with Ctrl^C */ - printf("Hit Ctrl^C to stop recording\n"); - while (!finished) - trace_or_sleep(type); - } + update_task_filter(); + tracecmd_enable_tracing(); + exit(0); + } - tracecmd_disable_tracing(); - if (!latency) - stop_threads(type); + if (ctx->run_command) + run_cmd(type, (argc - optind) - 1, &argv[optind + 1]); + else { + update_task_filter(); + tracecmd_enable_tracing(); + /* We don't ptrace ourself */ + if (do_ptrace && filter_pid >= 0) + ptrace_attach(filter_pid); + /* sleep till we are woken with Ctrl^C */ + printf("Hit Ctrl^C to stop recording\n"); + while (!finished) + trace_or_sleep(type); } + tracecmd_disable_tracing(); + if (!latency) + stop_threads(type); + record_stats(); if (!keep) tracecmd_disable_all_tracing(0); - /* extract records the date after extraction */ - if (IS_EXTRACT(ctx) && ctx->date) { - /* - * We need to start tracing, don't let other traces - * screw with our trace_marker. - */ - tracecmd_disable_all_tracing(1); - ctx->date2ts = get_date_to_ts(); - } - - if (IS_RECORD(ctx) || IS_EXTRACT(ctx)) { + if (IS_RECORD(ctx)) { record_data(ctx->date2ts, ctx->data_flags); delete_thread_data(); } else @@ -4950,9 +4923,68 @@ void trace_start(int argc, char **argv) void trace_extract(int argc, char **argv) { struct common_record_context ctx; + enum trace_type type; parse_record_options(argc, argv, CMD_extract, &ctx); - record_trace(argc, argv, &ctx); + + type = get_trace_cmd_type(ctx.curr_cmd); + + update_first_instance(ctx.instance, 1); + check_function_plugin(); + + if (ctx.output) + output_file = ctx.output; + + /* Save the state of tracing_on before starting */ + for_all_instances(ctx.instance) { + + if (!ctx.manual && ctx.instance->profile) + enable_profile(ctx.instance); + + ctx.instance->tracing_on_init_val = read_tracing_on(ctx.instance); + /* Some instances may not be created yet */ + if (ctx.instance->tracing_on_init_val < 0) + ctx.instance->tracing_on_init_val = 1; + } + + /* Extracting data records all events in the system. */ + if (!ctx.record_all) + record_all_events(); + + if (ctx.events) + expand_event_list(); + + page_size = getpagesize(); + update_plugins(type); + set_options(); + + if (ctx.max_graph_depth) { + for_all_instances(ctx.instance) + set_max_graph_depth(ctx.instance, ctx.max_graph_depth); + free(ctx.max_graph_depth); + } + + allocate_seq(); + flush_threads(); + record_stats(); + + if (!keep) + tracecmd_disable_all_tracing(0); + + /* extract records the date after extraction */ + if (ctx.date) { + /* + * We need to start tracing, don't let other traces + * screw with our trace_marker. + */ + tracecmd_disable_all_tracing(1); + ctx.date2ts = get_date_to_ts(); + } + + record_data(ctx.date2ts, ctx.data_flags); + delete_thread_data(); + destroy_stats(); + finalize_record_trace(&ctx); exit(0); } -- 2.14.1 From 1585465066680048844@xxx Thu Nov 30 04:48:33 +0000 2017 X-GM-THRID: 1582777349862922949 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread