Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: jp_ikaheimonen@mentor.com (JP Ikaheimonen)
Subject: [lttng-dev] [PATCH lttng-tools 21/28] Collate lttng_enable_event* code
Date: Thu,  7 Nov 2013 12:22:00 +0200	[thread overview]
Message-ID: <1383819727-6843-2-git-send-email-jp_ikaheimonen@mentor.com> (raw)
In-Reply-To: <1383819727-6843-1-git-send-email-jp_ikaheimonen@mentor.com>

Because the function lttng_enable_event_with_exclusions() can also
handle the duties of lttng_enable_event and lttng_enable_event_with_filter
as special cases, there's no need to have the same code duplicated in
each function. Let the other two functions fall the generic function
lttng_enable_event_with_exclusions() instead.

Signed-off-by: JP Ikaheimonen <jp_ikaheimonen at mentor.com>
---
 src/lib/lttng-ctl/lttng-ctl.c | 171 +-----------------------------------------
 1 file changed, 4 insertions(+), 167 deletions(-)

diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c
index 21173ca..9a21605 100644
--- a/src/lib/lttng-ctl/lttng-ctl.c
+++ b/src/lib/lttng-ctl/lttng-ctl.c
@@ -673,36 +673,8 @@ int lttng_add_context(struct lttng_handle *handle,
 int lttng_enable_event(struct lttng_handle *handle,
 		struct lttng_event *ev, const char *channel_name)
 {
-	struct lttcomm_session_msg lsm;
-
-	if (handle == NULL || ev == NULL) {
-		return -LTTNG_ERR_INVALID;
-	}
-
-	memset(&lsm, 0, sizeof(lsm));
-
-	/* If no channel name, send empty string. */
-	if (channel_name == NULL) {
-		lttng_ctl_copy_string(lsm.u.enable.channel_name, "",
-				sizeof(lsm.u.enable.channel_name));
-	} else {
-		lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
-				sizeof(lsm.u.enable.channel_name));
-	}
-
-	lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
-
-	if (ev->name[0] != '\0') {
-		lsm.cmd_type = LTTNG_ENABLE_EVENT;
-	} else {
-		lsm.cmd_type = LTTNG_ENABLE_ALL_EVENT;
-	}
-	memcpy(&lsm.u.enable.event, ev, sizeof(lsm.u.enable.event));
-
-	lttng_ctl_copy_string(lsm.session.name, handle->session_name,
-			sizeof(lsm.session.name));
-
-	return lttng_ctl_ask_sessiond(&lsm, NULL);
+	return lttng_enable_event_with_exclusions(handle, ev, channel_name,
+			NULL, 0, NULL);
 }
 
 /*
@@ -715,143 +687,8 @@ int lttng_enable_event_with_filter(struct lttng_handle *handle,
 		struct lttng_event *event, const char *channel_name,
 		const char *filter_expression)
 {
-	struct lttcomm_session_msg lsm;
-	struct filter_parser_ctx *ctx;
-	FILE *fmem;
-	int ret = 0;
-
-	if (!filter_expression) {
-		/*
-		 * Fall back to normal event enabling if no filter
-		 * specified.
-		 */
-		return lttng_enable_event(handle, event, channel_name);
-	}
-
-	/*
-	 * Empty filter string will always be rejected by the parser
-	 * anyway, so treat this corner-case early to eliminate
-	 * lttng_fmemopen error for 0-byte allocation.
-	 */
-	if (handle == NULL || filter_expression[0] == '\0') {
-		return -LTTNG_ERR_INVALID;
-	}
-
-	/*
-	 * casting const to non-const, as the underlying function will
-	 * use it in read-only mode.
-	 */
-	fmem = lttng_fmemopen((void *) filter_expression,
-			strlen(filter_expression), "r");
-	if (!fmem) {
-		fprintf(stderr, "Error opening memory as stream\n");
-		return -LTTNG_ERR_FILTER_NOMEM;
-	}
-	ctx = filter_parser_ctx_alloc(fmem);
-	if (!ctx) {
-		fprintf(stderr, "Error allocating parser\n");
-		ret = -LTTNG_ERR_FILTER_NOMEM;
-		goto alloc_error;
-	}
-	ret = filter_parser_ctx_append_ast(ctx);
-	if (ret) {
-		fprintf(stderr, "Parse error\n");
-		ret = -LTTNG_ERR_FILTER_INVAL;
-		goto parse_error;
-	}
-	ret = filter_visitor_set_parent(ctx);
-	if (ret) {
-		fprintf(stderr, "Set parent error\n");
-		ret = -LTTNG_ERR_FILTER_INVAL;
-		goto parse_error;
-	}
-	if (print_xml) {
-		ret = filter_visitor_print_xml(ctx, stdout, 0);
-		if (ret) {
-			fflush(stdout);
-			fprintf(stderr, "XML print error\n");
-			ret = -LTTNG_ERR_FILTER_INVAL;
-			goto parse_error;
-		}
-	}
-
-	dbg_printf("Generating IR... ");
-	fflush(stdout);
-	ret = filter_visitor_ir_generate(ctx);
-	if (ret) {
-		fprintf(stderr, "Generate IR error\n");
-		ret = -LTTNG_ERR_FILTER_INVAL;
-		goto parse_error;
-	}
-	dbg_printf("done\n");
-
-	dbg_printf("Validating IR... ");
-	fflush(stdout);
-	ret = filter_visitor_ir_check_binary_op_nesting(ctx);
-	if (ret) {
-		ret = -LTTNG_ERR_FILTER_INVAL;
-		goto parse_error;
-	}
-	dbg_printf("done\n");
-
-	dbg_printf("Generating bytecode... ");
-	fflush(stdout);
-	ret = filter_visitor_bytecode_generate(ctx);
-	if (ret) {
-		fprintf(stderr, "Generate bytecode error\n");
-		ret = -LTTNG_ERR_FILTER_INVAL;
-		goto parse_error;
-	}
-	dbg_printf("done\n");
-	dbg_printf("Size of bytecode generated: %u bytes.\n",
-		bytecode_get_len(&ctx->bytecode->b));
-
-	memset(&lsm, 0, sizeof(lsm));
-
-	lsm.cmd_type = LTTNG_ENABLE_EVENT_WITH_FILTER;
-
-	/* If no channel name, send empty string. */
-	if (channel_name == NULL) {
-		lttng_ctl_copy_string(lsm.u.enable.channel_name, "",
-				sizeof(lsm.u.enable.channel_name));
-	} else {
-		lttng_ctl_copy_string(lsm.u.enable.channel_name, channel_name,
-				sizeof(lsm.u.enable.channel_name));
-	}
-
-	/* Copy event name */
-	if (event) {
-		memcpy(&lsm.u.enable.event, event, sizeof(lsm.u.enable.event));
-	}
-
-	lsm.u.enable.bytecode_len = sizeof(ctx->bytecode->b)
-			+ bytecode_get_len(&ctx->bytecode->b);
-
-	lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
-
-	lttng_ctl_copy_string(lsm.session.name, handle->session_name,
-			sizeof(lsm.session.name));
-
-	ret = lttng_ctl_ask_sessiond_varlen(&lsm, &ctx->bytecode->b,
-				lsm.u.enable.bytecode_len, NULL);
-
-	filter_bytecode_free(ctx);
-	filter_ir_free(ctx);
-	filter_parser_ctx_free(ctx);
-	if (fclose(fmem) != 0) {
-		perror("fclose");
-	}
-	return ret;
-
-parse_error:
-	filter_bytecode_free(ctx);
-	filter_ir_free(ctx);
-	filter_parser_ctx_free(ctx);
-alloc_error:
-	if (fclose(fmem) != 0) {
-		perror("fclose");
-	}
-	return ret;
+	return lttng_enable_event_with_exclusions(handle, event, channel_name,
+			filter_expression, 0, NULL);
 }
 
 /*
-- 
1.8.1.2




  reply	other threads:[~2013-11-07 10:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-07 10:21 [lttng-dev] [PATCH lttng-tools 20/28] Send enable-event commands with exclusion data JP Ikaheimonen
2013-11-07 10:22 ` JP Ikaheimonen [this message]
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 22/28] Add -exclude option to enable-event command JP Ikaheimonen
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 23/28] Add usage for --exclude option JP Ikaheimonen
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 24/28] Add a function to check for legal exclusions JP Ikaheimonen
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 25/28] Parse exclusions and forward them to the control handler JP Ikaheimonen
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 26/28] Detect and report exclusion option errors JP Ikaheimonen
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 27/28] Add exclusion names to diagnostic printouts JP Ikaheimonen
2013-11-07 10:22 ` [lttng-dev] [PATCH lttng-tools 28/28] When listing events, show exclusions if they exist JP Ikaheimonen

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=1383819727-6843-2-git-send-email-jp_ikaheimonen@mentor.com \
    --to=jp_ikaheimonen@mentor.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