[lttng-dev] [Patch LTTng-ust 3/7] Add an example using CTF named enumerations

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Thu Jan 30 18:10:44 EST 2014


----- Original Message -----
> From: "Geneviève Bastien" <gbastien+lttng at versatic.net>
> To: lttng-dev at lists.lttng.org
> Sent: Friday, January 24, 2014 3:04:41 PM
> Subject: [lttng-dev] [Patch LTTng-ust 3/7] Add an example using CTF named	enumerations
> 
> A new test example is introduced in tests/ctf-metadata. This test application
> will be used to test the support of named CTF metadata. For now, it contains
> two tracepoints that use a named enumeration.

As I think you had as a separate comment, it will be important to add
automated tests of this feature within lttng-tools too.

Thanks,

Mathieu

> 
> Signed-off-by: Geneviève Bastien <gbastien+lttng at versatic.net>
> ---
>  configure.ac                                |  1 +
>  tests/Makefile.am                           |  2 +-
>  tests/ctf-metadata/Makefile.am              | 13 ++++++
>  tests/ctf-metadata/README                   |  2 +
>  tests/ctf-metadata/ctf-metadata.c           | 46 +++++++++++++++++++
>  tests/ctf-metadata/tp.c                     | 26 +++++++++++
>  tests/ctf-metadata/ust_tests_ctf_metadata.h | 71
>  +++++++++++++++++++++++++++++
>  7 files changed, 160 insertions(+), 1 deletion(-)
>  create mode 100644 tests/ctf-metadata/Makefile.am
>  create mode 100644 tests/ctf-metadata/README
>  create mode 100644 tests/ctf-metadata/ctf-metadata.c
>  create mode 100644 tests/ctf-metadata/tp.c
>  create mode 100644 tests/ctf-metadata/ust_tests_ctf_metadata.h
> 
> diff --git a/configure.ac b/configure.ac
> index 72a0314..1fb5796 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -295,6 +295,7 @@ AC_CONFIG_FILES([
>  	liblttng-ust-cyg-profile/Makefile
>  	tools/Makefile
>  	tests/Makefile
> +	tests/ctf-metadata/Makefile
>  	tests/hello/Makefile
>  	tests/hello.cxx/Makefile
>  	tests/same_line_tracepoint/Makefile
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index b5166f9..2ada575 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -1,4 +1,4 @@
> -SUBDIRS = utils hello same_line_tracepoint snprintf benchmark
> +SUBDIRS = utils hello same_line_tracepoint snprintf benchmark ctf-metadata
>  
>  if CXX_WORKS
>  SUBDIRS += hello.cxx
> diff --git a/tests/ctf-metadata/Makefile.am b/tests/ctf-metadata/Makefile.am
> new file mode 100644
> index 0000000..7b3ddbb
> --- /dev/null
> +++ b/tests/ctf-metadata/Makefile.am
> @@ -0,0 +1,13 @@
> +AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_builddir)/include
> -Wsystem-headers
> +
> +noinst_PROGRAMS = ctf-metadata
> +ctf_metadata_SOURCES = ctf-metadata.c tp.c ust_tests_ctf_metadata.h
> +ctf_metadata_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la
> +ctf_metadata_CFLAGS = -Werror=old-style-definition
> +
> +if LTTNG_UST_BUILD_WITH_LIBDL
> +ctf_metadata_LDADD += -ldl
> +endif
> +if LTTNG_UST_BUILD_WITH_LIBC_DL
> +ctf_metadata_LDADD += -lc
> +endif
> diff --git a/tests/ctf-metadata/README b/tests/ctf-metadata/README
> new file mode 100644
> index 0000000..8379556
> --- /dev/null
> +++ b/tests/ctf-metadata/README
> @@ -0,0 +1,2 @@
> +This is a "hello world" application used to verify that an instrumented
> program
> +with tracepoints using named CTF metadata can be built successfully.
> diff --git a/tests/ctf-metadata/ctf-metadata.c
> b/tests/ctf-metadata/ctf-metadata.c
> new file mode 100644
> index 0000000..53bd14b
> --- /dev/null
> +++ b/tests/ctf-metadata/ctf-metadata.c
> @@ -0,0 +1,46 @@
> +/*
> + * Copyright (C) 2014  Geneviève Bastien <gbastien at versatic.net>
> + *
> + * This library is free software; you can redistribute it and/or
> + * modify it under the terms of the GNU Lesser General Public
> + * License as published by the Free Software Foundation; version 2.1 of
> + * the License.
> + *
> + * 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
> + */
> +
> +#include <unistd.h>
> +
> +#define TRACEPOINT_DEFINE
> +#include "ust_tests_ctf_metadata.h"
> +
> +int main(int argc, char **argv)
> +{
> +	int i;
> +	int delay = 0;
> +
> +	if (argc == 2)
> +		delay = atoi(argv[1]);
> +
> +	fprintf(stderr, "Hello, World!\n");
> +
> +	sleep(delay);
> +
> +	fprintf(stderr, "Tracing... ");
> +	for (i = 0; i < 100; i++) {
> +		tracepoint(ust_tests_ctf_metadata, tptest, i, (i % 6));
> +	}
> +
> +	for (i = 0; i < 10; i++) {
> +		tracepoint(ust_tests_ctf_metadata, tptest_bis, i, (i % 5));
> +	}
> +	fprintf(stderr, " done.\n");
> +	return 0;
> +}
> diff --git a/tests/ctf-metadata/tp.c b/tests/ctf-metadata/tp.c
> new file mode 100644
> index 0000000..681fbea
> --- /dev/null
> +++ b/tests/ctf-metadata/tp.c
> @@ -0,0 +1,26 @@
> +/*
> + * tp.c
> + *
> + * Copyright (c) 2014 Geneviève Bastien <gbastien at versatic.net>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> copy
> + * of this software and associated documentation files (the "Software"), to
> deal
> + * in the Software without restriction, including without limitation the
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included
> in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE
> + * SOFTWARE.
> + */
> +
> +#define TRACEPOINT_CREATE_PROBES
> +#include "ust_tests_ctf_metadata.h"
> diff --git a/tests/ctf-metadata/ust_tests_ctf_metadata.h
> b/tests/ctf-metadata/ust_tests_ctf_metadata.h
> new file mode 100644
> index 0000000..25f49ac
> --- /dev/null
> +++ b/tests/ctf-metadata/ust_tests_ctf_metadata.h
> @@ -0,0 +1,71 @@
> +#undef TRACEPOINT_PROVIDER
> +#define TRACEPOINT_PROVIDER ust_tests_ctf_metadata
> +
> +#if !defined(_TRACEPOINT_UST_TESTS_CTF_METADATA_H) ||
> defined(TRACEPOINT_HEADER_MULTI_READ)
> +#define _TRACEPOINT_UST_TESTS_CTF_METADATA_H
> +
> +/*
> + * Copyright (C) 2014 Geneviève Bastien <gbastien at versatic.net>
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> copy
> + * of this software and associated documentation files (the "Software"), to
> deal
> + * in the Software without restriction, including without limitation the
> rights
> + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> + * copies of the Software, and to permit persons to whom the Software is
> + * furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice shall be included
> in
> + * all copies or substantial portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
> OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
> THE
> + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> FROM,
> + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE
> + * SOFTWARE.
> + */
> +
> +#include <lttng/tracepoint.h>
> +
> +TRACEPOINT_ENUM(ust_tests_ctf_metadata, testenum, int,
> +	TP_ENUM_VALUES(
> +		ctf_enum_value("even", 0)
> +		ctf_enum_value("uneven", 1)
> +		ctf_enum_range("twoto4", 2, 4)
> +		ctf_enum_value("modulo5", 5)
> +	)
> +)
> +
> +/*
> + * Enumeration field is used twice to make sure the named metadata is
> entered
> + * only once in the metadata file.
> + */
> +TRACEPOINT_EVENT(ust_tests_ctf_metadata, tptest,
> +	TP_ARGS(int, anint, int, enumval),
> +	TP_FIELDS(
> +		ctf_integer(int, intfield, anint)
> +		ctf_enum(ust_tests_ctf_metadata, testenum, enumfield, enumval)
> +		ctf_enum(ust_tests_ctf_metadata, testenum, enumfield_bis, enumval)
> +	)
> +)
> +
> +/*
> + * Another tracepoint using the named metadata to make sure each named
> metadata
> + * is entered only once in the metadata file.
> + */
> +TRACEPOINT_EVENT(ust_tests_ctf_metadata, tptest_bis,
> +	TP_ARGS(int, anint, int, enumval),
> +	TP_FIELDS(
> +		ctf_integer(int, intfield, anint)
> +		ctf_enum(ust_tests_ctf_metadata, testenum, enumfield, enumval)
> +	)
> +)
> +
> +#endif /* _TRACEPOINT_UST_TESTS_CTF_METADATA_H */
> +
> +#undef TRACEPOINT_INCLUDE
> +#define TRACEPOINT_INCLUDE "./ust_tests_ctf_metadata.h"
> +
> +/* This part must be outside ifdef protection */
> +#include <lttng/tracepoint-event.h>
> --
> 1.8.5.3
> 
> 
> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
> 

-- 
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list