Received: by 10.223.164.202 with SMTP id h10csp650748wrb; Thu, 30 Nov 2017 05:25:13 -0800 (PST) X-Google-Smtp-Source: AGs4zMYoasP54Xqpb21/dNV42bmuZ5TQ3q3pJ5/dLRarninW+Y2Z/U4JFxlBSewM5Yu+3A/9jOZz X-Received: by 10.84.168.226 with SMTP id f89mr2665233plb.176.1512048313411; Thu, 30 Nov 2017 05:25:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512048313; cv=none; d=google.com; s=arc-20160816; b=0RZBOHLDj+GntJPkZtYGOclWKjncPfgKEVXyo+kBMT1hafcgv1ZaREjjE/VZuJ3gYp mb1Ju5Mshc5j3PrzmiiMAt5ge8QcvK7V9ZbPy1M2T12JBPlbDVPZIm7dXTNT2hp5Ui9u 3W/uAzOOQoU9xwCiQsYZGdSFNE35caQ4+sApuBlgiCccAKvXrC5rN5g+kKcve/X06zWT Q9yHANKmjF0FqrFngbA2gOzcps2se+Fhtvr/4ZSdJKlC8RUQUQ43L4FN7dZXvbFxhwUZ 2PfT/OFz1Ea7l/tPm2+wrihZZBumC6K+hAf9+EVQ6Gyc3Xly2i5BC0HD43q92XjIITkV nGwg== 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=pATs8l/WtHbC+Z0DLo1/ELgYrWZgRI1lwkiaUzcPG4Q=; b=nWfSZCJEI5ADCEGq4TyAXx3fHObIEqNcoF3qkNt7PgvZQyOZOfnIpkMxsiU2PPcoGh 2ePEAHu+XNeMuSAeUbmLmT8BcthjrmInyMHx+ILp6b2AYnN23XEMDc41CwPbSM7H0VO7 uQ0M2OLW2w1RFnfJAcWj53EnPFgkwWpBxAsikDpejBlCIX11i6R/AAjNN7M/5Gy4Zi4c iEgEqxPmHP6wVgENNKQiqdMYXyL1+SRrdx+oWGG1yHCTWdL3xLiKVdkJJAnYu7OlRSOV BUTKko4m8GMUL6LNLsGD8mzQrZthVWTamEk9P0eigtXJQZTlXDIEA1y7DIA7itvv/vgx Ru0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=uMp+I5A2; 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 o2si3009463pge.198.2017.11.30.05.24.59; Thu, 30 Nov 2017 05:25:13 -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=uMp+I5A2; 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 S1752916AbdK3NUk (ORCPT + 99 others); Thu, 30 Nov 2017 08:20:40 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:44358 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751125AbdK3NUh (ORCPT ); Thu, 30 Nov 2017 08:20:37 -0500 Received: by mail-wr0-f194.google.com with SMTP id l22so6553601wrc.11 for ; Thu, 30 Nov 2017 05:20:36 -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=pATs8l/WtHbC+Z0DLo1/ELgYrWZgRI1lwkiaUzcPG4Q=; b=uMp+I5A2dnQ/YzTKBvSKnvaRxCTYvqAUeg8R2AUDh+7/XJFNmQMWLWtl/QrfcM2xoc 1Y8g9Dsv1v41MSIhUmRKq03OppgvVQdKt0kokKnRJrkIkhFSyIBwoOBkBm17Wy6/VSbr 4UzsDlxbL4mfL8aZvTZvtdISleARM9aoZ3kI1x3jIxj/tmkRgYVjMCZxc3785Gt6x8Ou PJbx5s5hoGFZgbXgDO+bpsie2QulstQzF36pQahqPA57HSUwf7W+xEqhQsZyUMHPoaV3 ETA7MBFLHh9Dd0qFc7KzceTXtoGSciXu0Sa5O7IWYxzCZ5HcLFNEXKkG3qUqRPJ8FXxh Ut4g== 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=pATs8l/WtHbC+Z0DLo1/ELgYrWZgRI1lwkiaUzcPG4Q=; b=Wf7DwGs0Ar6wwXxmynUi5xXkfcaaBsU78fL+w1BdiMWpVfJ9r0jz3Z7rLzb4eA0x1d hbhJkUcnmJoQ1Q/KsKWRAB+bNXBNxcZeQgVbw2RD2DeI+6k/PRCl/vdHzEXxgt8fYIct dilfgAjOOOSnGniAOgP94Cn0hrK6w4iu265Rh+CAZXpgoPI7P2VghNdD18zBKwccyaDB nFe0fSkHPTro2igY1tu5mknvCfaaIV0NISIbblmiXNVG7cUNuVHE9hiGGuWLOTiV8Q72 VXWZ+msiwa4fnKTSVvd/2MWYYyn3QvplckxMFQguEnzDYItEVgPK7ofwqoJbnsuOS5dV l1Tw== X-Gm-Message-State: AJaThX7h7yIH0Cv1KfaSKMzJKN5+DbMBpZ/c7B0NgeFI9wY16pNipPxf I3RzcgNVGXgW81mORdFJZjM= X-Received: by 10.223.179.209 with SMTP id x17mr2104378wrd.145.1512048035721; Thu, 30 Nov 2017 05:20:35 -0800 (PST) Received: from localhost.localdomain ([87.121.44.226]) by smtp.gmail.com with ESMTPSA id p200sm3539734wmd.9.2017.11.30.05.20.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Nov 2017 05:20:35 -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 02/10] trace-cmd: Replacing cmd flags w/ a trace_cmd enum Date: Thu, 30 Nov 2017 15:19:49 +0200 Message-Id: <20171130131957.21617-3-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 replaces 5 mutually exclusive flag variables (extract, start, stream, record, profile) in trace_record() with a more convenient enum. The point of doing that is to make the code simpler and easier to maintain. Signed-off-by: Vladislav Valtchev (VMware) --- trace-record.c | 94 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 52 insertions(+), 42 deletions(-) diff --git a/trace-record.c b/trace-record.c index 487d35e..9e35de4 100644 --- a/trace-record.c +++ b/trace-record.c @@ -4358,7 +4358,16 @@ void trace_reset(int argc, char **argv) exit(0); } +enum trace_cmd { + CMD_extract, + CMD_start, + CMD_stream, + CMD_profile, + CMD_record +}; + struct common_record_context { + enum trace_cmd curr_cmd; struct buffer_instance *instance; const char *output; char *date2ts; @@ -4376,12 +4385,6 @@ struct common_record_context { int topt; int do_child; int run_command; - - int extract; - int start; - int stream; - int profile; - int record; }; static void init_common_record_context(struct common_record_context *ctx) @@ -4392,6 +4395,12 @@ static void init_common_record_context(struct common_record_context *ctx) cpu_count = count_cpus(); } +#define IS_EXTRACT(ctx) ((ctx)->curr_cmd == CMD_extract) +#define IS_START(ctx) ((ctx)->curr_cmd == CMD_start) +#define IS_STREAM(ctx) ((ctx)->curr_cmd == CMD_stream) +#define IS_PROFILE(ctx) ((ctx)->curr_cmd == CMD_profile) +#define IS_RECORD(ctx) ((ctx)->curr_cmd == CMD_record) + static void parse_record_options(int argc, char **argv, struct common_record_context *ctx) @@ -4426,7 +4435,7 @@ static void parse_record_options(int argc, {NULL, 0, NULL, 0} }; - if (ctx->extract) + if (IS_EXTRACT(ctx)) opts = "+haf:Fp:co:O:sr:g:l:n:P:N:tb:B:ksiT"; else opts = "+hae:f:Fp:cC:dDGo:O:s:r:vg:l:n:P:N:tb:R:B:ksSiTm:M:H:q"; @@ -4438,7 +4447,7 @@ static void parse_record_options(int argc, usage(argv); break; case 'a': - if (ctx->extract) { + if (IS_EXTRACT(ctx)) { add_all_instances(); } else { ctx->record_all = 1; @@ -4557,17 +4566,17 @@ static void parse_record_options(int argc, case 'o': if (host) die("-o incompatible with -N"); - if (ctx->start) + if (IS_START(ctx)) die("start does not take output\n" "Did you mean 'record'?"); - if (ctx->stream) + if (IS_STREAM(ctx)) die("stream does not take output\n" "Did you mean 'record'?"); if (ctx->output) die("only one output file allowed"); ctx->output = optarg; - if (ctx->profile) { + if (IS_PROFILE(ctx)) { int fd; /* pipe the output to this file instead of stdout */ @@ -4594,7 +4603,7 @@ static void parse_record_options(int argc, ctx->events = 1; break; case 's': - if (ctx->extract) { + if (IS_EXTRACT(ctx)) { if (optarg) usage(argv); recorder_flags |= TRACECMD_RECORD_SNAPSHOT; @@ -4614,7 +4623,7 @@ static void parse_record_options(int argc, rt_prio = atoi(optarg); break; case 'N': - if (!ctx->record) + if (!IS_RECORD(ctx)) die("-N only available with record"); if (ctx->output) die("-N incompatible with -o"); @@ -4623,7 +4632,7 @@ static void parse_record_options(int argc, case 'm': if (max_kb) die("-m can only be specified once"); - if (!ctx->record) + if (!IS_RECORD(ctx)) die("only record take 'm' option"); max_kb = atoi(optarg); break; @@ -4631,7 +4640,7 @@ static void parse_record_options(int argc, ctx->instance->cpumask = alloc_mask_from_hex(optarg); break; case 't': - if (ctx->extract) + if (IS_EXTRACT(ctx)) ctx->topt = 1; /* Extract top instance also */ else use_tcp = 1; @@ -4644,7 +4653,7 @@ static void parse_record_options(int argc, if (!ctx->instance) die("Failed to create instance"); add_instance(ctx->instance); - if (ctx->profile) + if (IS_PROFILE(ctx)) ctx->instance->profile = 1; break; case 'k': @@ -4722,10 +4731,10 @@ static void parse_record_options(int argc, die(" -c can only be used with -P or -F"); if ((argc - optind) >= 2) { - if (ctx->start) + if (IS_START(ctx)) die("Command start does not take any commands\n" "Did you mean 'record'?"); - if (ctx->extract) + if (IS_EXTRACT(ctx)) die("Command extract does not take any commands\n" "Did you mean 'record'?"); ctx->run_command = 1; @@ -4740,15 +4749,16 @@ void trace_record(int argc, char **argv) init_common_record_context(&ctx); - if ((ctx.record = (strcmp(argv[1], "record") == 0))) - ; /* do nothing */ - else if ((ctx.start = strcmp(argv[1], "start") == 0)) - ; /* do nothing */ - else if ((ctx.extract = strcmp(argv[1], "extract") == 0)) - ; /* do nothing */ - else if ((ctx.stream = strcmp(argv[1], "stream") == 0)) - ; /* do nothing */ - else if ((ctx.profile = strcmp(argv[1], "profile") == 0)) { + if (strcmp(argv[1], "record") == 0) + ctx.curr_cmd = CMD_record; + else if (strcmp(argv[1], "start") == 0) + ctx.curr_cmd = CMD_start; + else if (strcmp(argv[1], "extract") == 0) + ctx.curr_cmd = CMD_extract; + else if (strcmp(argv[1], "stream") == 0) + ctx.curr_cmd = CMD_stream; + else if (strcmp(argv[1], "profile") == 0) { + ctx.curr_cmd = CMD_profile; handle_init = trace_init_profile; ctx.events = 1; } else @@ -4762,21 +4772,21 @@ void trace_record(int argc, char **argv) * If this is a profile run, and no instances were set, * then enable profiling on the top instance. */ - if (ctx.profile && !buffer_instances) + if (IS_PROFILE(&ctx) && !buffer_instances) top_instance.profile = 1; /* * If top_instance doesn't have any plugins or events, then * remove it from being processed. */ - if (!ctx.extract && !__check_doing_something(&top_instance)) + if (!IS_EXTRACT(&ctx) && !__check_doing_something(&top_instance)) first_instance = buffer_instances; else ctx.topt = 1; update_first_instance(ctx.instance, ctx.topt); - if (!ctx.extract) + if (!IS_EXTRACT(&ctx)) check_doing_something(); check_function_plugin(); @@ -4796,10 +4806,10 @@ void trace_record(int argc, char **argv) } /* Extracting data records all events in the system. */ - if (ctx.extract && !ctx.record_all) + if (IS_EXTRACT(&ctx) && !ctx.record_all) record_all_events(); - if (!ctx.extract) + if (!IS_EXTRACT(&ctx)) make_instances(); if (ctx.events) @@ -4807,7 +4817,7 @@ void trace_record(int argc, char **argv) page_size = getpagesize(); - if (!ctx.extract) { + if (!IS_EXTRACT(&ctx)) { fset = set_ftrace(!ctx.disable, ctx.total_disable); tracecmd_disable_all_tracing(1); @@ -4815,7 +4825,7 @@ void trace_record(int argc, char **argv) set_clock(ctx.instance); /* Record records the date first */ - if (ctx.record && ctx.date) + if (IS_RECORD(&ctx) && ctx.date) ctx.date2ts = get_date_to_ts(); for_all_instances(ctx.instance) { @@ -4830,13 +4840,13 @@ void trace_record(int argc, char **argv) set_buffer_size(); } - if (ctx.record) + if (IS_RECORD(&ctx)) type = TRACE_TYPE_RECORD; - else if (ctx.stream) + else if (IS_STREAM(&ctx)) type = TRACE_TYPE_STREAM; - else if (ctx.extract) + else if (IS_EXTRACT(&ctx)) type = TRACE_TYPE_EXTRACT; - else if (ctx.profile) + else if (IS_PROFILE(&ctx)) type = TRACE_TYPE_STREAM; else type = TRACE_TYPE_START; @@ -4859,7 +4869,7 @@ void trace_record(int argc, char **argv) start_threads(type, ctx.global); } - if (ctx.extract) { + if (IS_EXTRACT(&ctx)) { flush_threads(); } else { @@ -4894,7 +4904,7 @@ void trace_record(int argc, char **argv) tracecmd_disable_all_tracing(0); /* extract records the date after extraction */ - if (ctx.extract && ctx.date) { + if (IS_EXTRACT(&ctx) && ctx.date) { /* * We need to start tracing, don't let other traces * screw with our trace_marker. @@ -4903,7 +4913,7 @@ void trace_record(int argc, char **argv) ctx.date2ts = get_date_to_ts(); } - if (ctx.record || ctx.extract) { + if (IS_RECORD(&ctx) || IS_EXTRACT(&ctx)) { record_data(ctx.date2ts, ctx.data_flags); delete_thread_data(); } else @@ -4933,7 +4943,7 @@ void trace_record(int argc, char **argv) if (host) tracecmd_output_close(network_handle); - if (ctx.profile) + if (IS_PROFILE(&ctx)) trace_profile(); exit(0); -- 2.14.1 From 1585436587863567649@xxx Wed Nov 29 21:15:54 +0000 2017 X-GM-THRID: 1584454378809684710 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread