Hello tracing warlords, I am attaching the patch like this since i can't quite get git send-email to work right. It is a simple trace hello world, comments are of course very welcome.
>From 0034aa04b06ff4db7ae33c183132d4792f6dc7d8 Mon Sep 17 00:00:00 2001 From: Matthew Khouzam <[email protected]> Date: Tue, 15 Nov 2011 15:01:12 -0500 Subject: [PATCH] Added easy_ust "test" it is more to show people how UST instrumentation works.
Signed-off-by: Matthew Khouzam <[email protected]> --- tests/easy_ust/Makefile | 26 ++++++++ tests/easy_ust/sample_provider.h | 121 +++++++++++++++++++++++++++++++++++ tests/easy_ust/tp.c | 28 ++++++++ tests/easy_ust/tracepoint_example.c | 7 ++ 4 files changed, 182 insertions(+), 0 deletions(-) create mode 100644 tests/easy_ust/Makefile create mode 100644 tests/easy_ust/sample_provider.h create mode 100644 tests/easy_ust/tp.c create mode 100644 tests/easy_ust/tracepoint_example.c diff --git a/tests/easy_ust/Makefile b/tests/easy_ust/Makefile new file mode 100644 index 0000000..d5ae72f --- /dev/null +++ b/tests/easy_ust/Makefile @@ -0,0 +1,26 @@ +# This makefile is not using automake so that people can see how to make +# simply. +# the HTML target helps for documentation + + +CC = gcc +LIBS = -llttng-ust +OUTPUT = example +SRC = tracepoint_example.c tp.c +HTMLOUT = sample_provider.html tracepoint_example.html tp.html +CFLAGS = -I. + +all: + $(CC) $(CFLAGS) $(SRC) $(LIBS) -o $(OUTPUT) + +clean: + rm -f *.html + rm -f $(OUTPUT) + +html: $(HTMLOUT) + +%.html: %.c + code2html -lc $< $@ + +%.html : %.h + code2html -lc $< $@ diff --git a/tests/easy_ust/sample_provider.h b/tests/easy_ust/sample_provider.h new file mode 100644 index 0000000..63591d2 --- /dev/null +++ b/tests/easy_ust/sample_provider.h @@ -0,0 +1,121 @@ +/* + * Copyright (C) 2011 Mathieu Desnoyers <[email protected]> + * Copyright (C) 2011 Matthew Khouzam <[email protected]> + * + * 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 + */ + +/* + * Sample lttng-ust tracepoint provider. + */ + +/* + * First part: defines + * We undef a macro before defining it as it can be used in several files. + */ + +/* + * Must be included before include tracepoint provider (company name + * goes here) + * ex com_efficios_project or com_ericsson_project + */ +#undef TRACEPOINT_PROVIDER +#define TRACEPOINT_PROVIDER sample_provider + +/* + * include path (add your own . directory here) + */ +#undef TRACEPOINT_INCLUDE_PATH +#define TRACEPOINT_INCLUDE_PATH . + +/* + * include file (this files's name minus the .h) + */ +#undef TRACEPOINT_INCLUDE_FILE +#define TRACEPOINT_INCLUDE_FILE sample_provider + +/* + * Add this macro and it's matching element to make sure the program + * works in c++. + */ +#ifdef __cplusplus +#extern "C"{ +#endif /*__cplusplus */ + +/* + * Add this block to make the following code section only entrable + * once by the user-side code. + */ +#if !defined(_SAMPLE_PROVIDER_H) || defined(TRACEPOINT_HEADER_MULTI_READ) +#define _SAMPLE_PROVIDER_H +/* + * Add this to allow programs to call "tracepoint(...): + */ +#include <lttng/tracepoint.h> + +/* + * The following tracepoint event writes a message (c string) into the + * field message of the traceevent message in the provider sample_provider + * in other words sample_provider:message:message = text. + */ +TRACEPOINT_EVENT( + /* + * provider name, not a variable but a string starting with a letter + * and containing either letters, numbers or underscores. + * Needs to be the same as TRACEPOINT_PROVIDER + */ + sample_provider, + /* + * message name, same format as sample provider. Does not need to be + * declared before. in this case the name is "message" + */ + message, + /* + * TP_ARGS macro contains the arguments passed for the tracepoint + * it is in the following format + * TP_ARGS( type1, name1, type2, name2, ... type10, name10) + * where there can be from zero to ten elements. + * typeN is the datatype, such as int, struct or double **. + * name is the variable name (in "int myInt" the name would be myint) + * TP_ARGS() is valid to mean no arguments + * TP_ARGS( void ) is valid too + */ + TP_ARGS(char *, text), + /* + * TP_FIELDS describes how to write the fields of the trace event. + * You can use the args here + */ + TP_FIELDS( + /* + * The ctf_string macro takes a c string and writes it into a field + * named "message" + */ + ctf_string(message, text) + ) +) +#endif /* _SAMPLE_PROVIDER_H */ + +/* + * Add this after defining the tracepoint events to expand the macros. + */ +#include <lttng/tracepoint-event.h> + +/* + * Add this macro and it's matching element to make sure the program + * works in c++. + */ +#ifdef __cplusplus +} +#endif /*__cplusplus */ diff --git a/tests/easy_ust/tp.c b/tests/easy_ust/tp.c new file mode 100644 index 0000000..87cd970 --- /dev/null +++ b/tests/easy_ust/tp.c @@ -0,0 +1,28 @@ +/* + * tp.c + * + * Copyright (c) 2011 Mathieu Desnoyers <[email protected]> + * + * 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 + */ +/* + * Defining macro creates the code objects of the traceprobes, only do + * it once per file + */ +#define TRACEPOINT_CREATE_PROBES +/* + * The header containing our TRACEPOINT_EVENTs. + */ +#include "sample_provider.h" diff --git a/tests/easy_ust/tracepoint_example.c b/tests/easy_ust/tracepoint_example.c new file mode 100644 index 0000000..61333b6 --- /dev/null +++ b/tests/easy_ust/tracepoint_example.c @@ -0,0 +1,7 @@ +#include "sample_provider.h" + +int main( ) +{ + tracepoint(sample_provider_message, "Hello World\n"); + return 0; +} -- 1.7.5.4
_______________________________________________ ltt-dev mailing list [email protected] http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
