From eb5c4f4e1670ed6637b2c36f6b474f94a2dcc948 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Sun, 15 Oct 2017 16:07:29 -0400 Subject: [PATCH] lttng-ctl: move lttng_event functions to a new file MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérémie Galarneau --- src/lib/lttng-ctl/Makefile.am | 2 +- src/lib/lttng-ctl/event.c | 120 ++++++++++++++++++++++++++++++++++ src/lib/lttng-ctl/lttng-ctl.c | 96 +-------------------------- 3 files changed, 122 insertions(+), 96 deletions(-) create mode 100644 src/lib/lttng-ctl/event.c diff --git a/src/lib/lttng-ctl/Makefile.am b/src/lib/lttng-ctl/Makefile.am index bc340d20f..d18328e4b 100644 --- a/src/lib/lttng-ctl/Makefile.am +++ b/src/lib/lttng-ctl/Makefile.am @@ -6,7 +6,7 @@ lib_LTLIBRARIES = liblttng-ctl.la liblttng_ctl_la_SOURCES = lttng-ctl.c snapshot.c lttng-ctl-helper.h \ lttng-ctl-health.c save.c load.c deprecated-symbols.c \ - channel.c rotate.c + channel.c rotate.c event.c liblttng_ctl_la_LDFLAGS = \ $(LT_NO_UNDEFINED) diff --git a/src/lib/lttng-ctl/event.c b/src/lib/lttng-ctl/event.c new file mode 100644 index 000000000..541e37113 --- /dev/null +++ b/src/lib/lttng-ctl/event.c @@ -0,0 +1,120 @@ +/* + * event.c + * + * Linux Trace Toolkit Control Library + * + * Copyright (C) 2017 - Jérémie Galarneau + * + * This library is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License, version 2.1 only, + * as published by the Free Software Foundation. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#define _LGPL_SOURCE +#include +#include +#include +#include + +int lttng_event_get_filter_expression(struct lttng_event *event, + const char **filter_expression) +{ + int ret = 0; + struct lttcomm_event_extended_header *ext_header; + + if (!event || !filter_expression) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + + if (!ext_header) { + /* + * This can happen since the lttng_event structure is + * used for other tasks where this pointer is never set. + */ + *filter_expression = NULL; + goto end; + } + + if (ext_header->filter_len) { + *filter_expression = ((const char *) (ext_header)) + + sizeof(*ext_header); + } else { + *filter_expression = NULL; + } + +end: + return ret; +} + +int lttng_event_get_exclusion_name_count(struct lttng_event *event) +{ + int ret; + struct lttcomm_event_extended_header *ext_header; + + if (!event) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + if (!ext_header) { + /* + * This can happen since the lttng_event structure is + * used for other tasks where this pointer is never set. + */ + ret = 0; + goto end; + } + + if (ext_header->nb_exclusions > INT_MAX) { + ret = -LTTNG_ERR_OVERFLOW; + goto end; + } + ret = (int) ext_header->nb_exclusions; +end: + return ret; +} + +int lttng_event_get_exclusion_name(struct lttng_event *event, + size_t index, const char **exclusion_name) +{ + int ret = 0; + struct lttcomm_event_extended_header *ext_header; + void *at; + + if (!event || !exclusion_name) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + ext_header = event->extended.ptr; + if (!ext_header) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + if (index >= ext_header->nb_exclusions) { + ret = -LTTNG_ERR_INVALID; + goto end; + } + + at = (void *) ext_header + sizeof(*ext_header); + at += ext_header->filter_len; + at += index * LTTNG_SYMBOL_NAME_LEN; + *exclusion_name = at; + +end: + return ret; +} diff --git a/src/lib/lttng-ctl/lttng-ctl.c b/src/lib/lttng-ctl/lttng-ctl.c index f0f2e801c..37b253102 100644 --- a/src/lib/lttng-ctl/lttng-ctl.c +++ b/src/lib/lttng-ctl/lttng-ctl.c @@ -1,5 +1,5 @@ /* - * liblttngctl.c + * lttng-ctl.c * * Linux Trace Toolkit Control Library * @@ -1913,100 +1913,6 @@ error: return ret; } -int lttng_event_get_filter_expression(struct lttng_event *event, - const char **filter_expression) -{ - int ret = 0; - struct lttcomm_event_extended_header *ext_header; - - if (!event || !filter_expression) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - ext_header = event->extended.ptr; - - if (!ext_header) { - /* - * This can happen since the lttng_event structure is - * used for other tasks where this pointer is never set. - */ - *filter_expression = NULL; - goto end; - } - - if (ext_header->filter_len) { - *filter_expression = ((const char *) (ext_header)) + - sizeof(*ext_header); - } else { - *filter_expression = NULL; - } - -end: - return ret; -} - -int lttng_event_get_exclusion_name_count(struct lttng_event *event) -{ - int ret; - struct lttcomm_event_extended_header *ext_header; - - if (!event) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - ext_header = event->extended.ptr; - if (!ext_header) { - /* - * This can happen since the lttng_event structure is - * used for other tasks where this pointer is never set. - */ - ret = 0; - goto end; - } - - if (ext_header->nb_exclusions > INT_MAX) { - ret = -LTTNG_ERR_OVERFLOW; - goto end; - } - ret = (int) ext_header->nb_exclusions; -end: - return ret; -} - -int lttng_event_get_exclusion_name(struct lttng_event *event, - size_t index, const char **exclusion_name) -{ - int ret = 0; - struct lttcomm_event_extended_header *ext_header; - void *at; - - if (!event || !exclusion_name) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - ext_header = event->extended.ptr; - if (!ext_header) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - if (index >= ext_header->nb_exclusions) { - ret = -LTTNG_ERR_INVALID; - goto end; - } - - at = (void *) ext_header + sizeof(*ext_header); - at += ext_header->filter_len; - at += index * LTTNG_SYMBOL_NAME_LEN; - *exclusion_name = at; - -end: - return ret; -} - /* * Sets the tracing_group variable with name. * This function allocates memory pointed to by tracing_group. -- 2.34.1