mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: Vaibhav Nagarnaik <vnagarnaik@google.com>
Cc: Michael Rubin <mrubin@google.com>,
	David Sharp <dhsharp@google.com>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/4] trace-cmd: Add parse error checking target
Date: Mon, 25 Jul 2011 09:32:53 -0400	[thread overview]
Message-ID: <1311600773.3526.13.camel@gandalf.stny.rr.com> (raw)
In-Reply-To: <1310785241-3799-1-git-send-email-vnagarnaik@google.com>

On Fri, 2011-07-15 at 20:00 -0700, Vaibhav Nagarnaik wrote:
> Add another target 'check-events' which parses all the event formats and
> returns whether there are any issues with the print format strings.
> 
> With an error in the format, the return value is 22 (EINVAL) and for
> success, it is 0.
> 
> Signed-off-by: Vaibhav Nagarnaik <vnagarnaik@google.com>
> ---
>  trace-capture.c |    2 +-
>  trace-cmd.c     |   22 ++++++++++++++++++++++
>  trace-cmd.h     |    2 +-
>  trace-usage.c   |    5 +++++
>  trace-util.c    |   48 ++++++++++++++++++++++++++++++++----------------
>  5 files changed, 61 insertions(+), 18 deletions(-)
> 
> diff --git a/trace-capture.c b/trace-capture.c
> index 61ff165..5708945 100644
> --- a/trace-capture.c
> +++ b/trace-capture.c
> @@ -1295,7 +1295,7 @@ static void tracing_dialog(struct shark_info *info, const char *tracing)
>  	/* Send parse warnings to status display */
>  	trace_dialog_register_alt_warning(vpr_stat);
>  
> -	pevent = tracecmd_local_events(tracing);
> +	tracecmd_local_events(tracing, &pevent);

Ug, please no. I don't see any good reason to move the creation of a
pevent into a pointer than just return it. If you require a different
return code, or (a even better reason) that this may be called without
needing to create a pevent at all, then I can understand this. But
creating an object (sturcture) by passing its address is an anomaly of C
and I like to avoid when possible. Passing an address of a atom value
(int, long) or even maybe a string that is allocated is one thing. But
doing it with a constructor function is just plain ugly.


>  	trace_dialog_register_alt_warning(NULL);
>  
>  	cap.pevent = pevent;
> diff --git a/trace-cmd.c b/trace-cmd.c
> index bff5bbf..a2b6b91 100644
> --- a/trace-cmd.c
> +++ b/trace-cmd.c
> @@ -158,6 +158,28 @@ int main (int argc, char **argv)
>  	} else if (strcmp(argv[1], "stack") == 0) {
>  		trace_stack(argc, argv);
>  		exit(0);
> +	} else if (strcmp(argv[1], "check-events") == 0) {
> +		char *tracing;
> +		int ret;
> +		struct pevent *pevent = NULL;
> +
> +		tracing = tracecmd_find_tracing_dir();
> +
> +		if (!tracing) {
> +			printf("Can not find or mount tracing directory!\n"
> +				"Either tracing is not configured for this "
> +				"kernel\n"
> +				"or you do not have the proper permissions to "
> +				"mount the directory");
> +			exit(EINVAL);
> +		}
> +
> +		ret = tracecmd_local_events(tracing, &pevent);
> +		if (pevent)
> +			pevent_free(pevent);
> +
> +		ret ? exit(0) : exit(EINVAL);
> +

And here the code is even uglier. You just free pevent and the ret is
just a boolean!  Also, that ?: trick is even uglier.


		pevent = tracecmd_local_events(tracing);
		if (!pevent)
			exit(EINVAL);
		pevent_free(pevent);
		exit(0);

Is much more readable.

-- Steve





  parent reply	other threads:[~2011-07-25 13:32 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-16  3:00 Vaibhav Nagarnaik
2011-07-16  3:00 ` [PATCH 2/4] trace-cmd: Handle invalid opcode parsing gracefully Vaibhav Nagarnaik
2011-07-25 14:03   ` Steven Rostedt
2012-05-21  9:39   ` [tip:perf/core] parse-events: " tip-bot for Vaibhav Nagarnaik
2011-07-16  3:00 ` [PATCH 3/4] trace-cmd: Handle opcode parsing error Vaibhav Nagarnaik
2011-07-25 14:01   ` Steven Rostedt
2011-07-25 18:06     ` Vaibhav Nagarnaik
2011-07-25 18:40   ` Vaibhav Nagarnaik
2012-05-21  9:39     ` [tip:perf/core] parse-events: " tip-bot for Vaibhav Nagarnaik
2011-07-16  3:00 ` [PATCH 4/4] trace-cmd: Support '+' opcode in print format Vaibhav Nagarnaik
2011-07-25 14:02   ` Steven Rostedt
2012-05-21  9:41   ` [tip:perf/core] parse-events: " tip-bot for Vaibhav Nagarnaik
2011-07-25 13:32 ` Steven Rostedt [this message]
2011-07-25 18:06   ` [PATCH 1/4] trace-cmd: Add parse error checking target Vaibhav Nagarnaik
2011-07-25 18:39 ` [PATCH v2 " Vaibhav Nagarnaik
2011-07-29 14:19   ` Steven Rostedt
2011-07-29 17:41     ` Vaibhav Nagarnaik
2011-07-29 17:53       ` Steven Rostedt
2011-07-29 19:07         ` Vaibhav Nagarnaik
2011-07-30  1:33           ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1311600773.3526.13.camel@gandalf.stny.rr.com \
    --to=rostedt@goodmis.org \
    --cc=dhsharp@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mrubin@google.com \
    --cc=vnagarnaik@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®