[lttng-dev] two tracepoints header files of one provider

Mathieu Desnoyers mathieu.desnoyers at efficios.com
Mon Oct 7 15:53:20 EDT 2019


----- On Oct 7, 2019, at 12:42 PM, Yonghong Yan <yanyh15 at gmail.com> wrote: 

> Thank you.

> I got most. To confirm, I have two header files, each defines its own
> tracepoint, they are from the same provider. The source files that use the
> header files have its own #define TRACEPOINT_CREATE_PROBES and #define
> TRACEPOINT_DEFINE. This won't work since two files have those defines. But if I
> remove #define TRACEPOINT_CREATE_PROBES#define TRACEPOINT_DEFINE from one of
> the two .c file, it should work.

The example below is bogus. 

Each of your tp_one.h and tp_two.h should have its own provider name, not "hello_world" for both. 

You should _only_ have a single header implementation file per provider name within an application. 

In my previous email, I was only refering to a case where you would want to define+create probes within 
a compile unit, and use the tracepoints (call them) from various other compile units in the program. 

Thanks, 

Mathieu 

> tp_one.h file:

> #undef TRACEPOINT_PROVIDER #define TRACEPOINT_PROVIDER hello_world #undef
> TRACEPOINT_INCLUDE #define TRACEPOINT_INCLUDE "./tp_one.h" #if
> !defined(_TP_ONE_H) || defined(TRACEPOINT_HEADER_MULTI_READ) #define _TP_ONE_H
> #include <lttng/tracepoint.h> TRACEPOINT_EVENT ( hello_world ,
> my_first_tracepoint , TP_ARGS ( int , my_integer_arg , char * , my_string_arg
> ), TP_FIELDS ( ctf_string ( my_string_field , my_string_arg ) ctf_integer ( int
> , my_integer_field , my_integer_arg ) ) ) #endif /* _TP_ONE_H */ #include
> <lttng/tracepoint-event.h>

> tp_one.c
> #define TRACEPOINT_CREATE_PROBES #define TRACEPOINT_DEFINE #include "tp_one.h"

> tp_two.h file:

> #undef TRACEPOINT_PROVIDER #define TRACEPOINT_PROVIDER hello_world #undef
> TRACEPOINT_INCLUDE #define TRACEPOINT_INCLUDE "./tp_two.h" #if
> !defined(_TP_TWO_H) || defined(TRACEPOINT_HEADER_MULTI_READ) #define _TP_TWO_H
> #include <lttng/tracepoint.h> TRACEPOINT_EVENT ( hello_world ,
> my_second_tracepoint , TP_ARGS ( int , my_integer_arg , char * , my_string_arg
> ), TP_FIELDS ( ctf_string ( my_string_field , my_string_arg ) ctf_integer ( int
> , my_integer_field , my_integer_arg ) ) ) #endif /* _TP_TWO_H */ #include
> <lttng/tracepoint-event.h>

> tp_two.c
> #define TRACEPOINT_CREATE_PROBES #define TRACEPOINT_DEFINE #include "tp_two.h"

> hello.c
> use the two tracepoints defined in the two files.

> To compile (compile file one by one).
> gcc -o hello tp-one.c tp-two.c hello.c -llttng-ust -ldl

> On Mon, Oct 7, 2019 at 12:22 PM Mathieu Desnoyers < [
> mailto:mathieu.desnoyers at efficios.com | mathieu.desnoyers at efficios.com ] >
> wrote:

>> ----- On Oct 7, 2019, at 9:59 AM, Yonghong Yan [ mailto:yanyh15 at gmail.com |
>> yanyh15 at gmail.com ] wrote:

>> > For lttng-ust, can I put the tracepoint definition in two files, but they use
>> > the same provider.

>> Based on the terminology here: [
>> https://lttng.org/docs/v2.10/#doc-tracing-your-own-user-application |
>> https://lttng.org/docs/v2.10/#doc-tracing-your-own-user-application ]

>> You need to have at most one instance of your tracepoint provider where
>> the header is included with TRACEPOINT_CREATE_PROBES, and exactly one
>> instance where TRACEPOINT_DEFINE is defined. (both can end up being within
>> the same object if you wish).

>> Then you can include your tracepoint provider header file at will across
>> other compile units in your program. Just make sure none of
>> TRACEPOINT_CREATE_PROBES nor TRACEPOINT_DEFINE are defined in those other
>> compile units. You can therefore call tracepoints from a given probe from
>> various compile units in your program.

>> Hoping this helps clarifying things,

>> Mathieu

>> > Thank you.
>> > Yonghong

>> > _______________________________________________
>> > lttng-dev mailing list
>> > [ mailto:lttng-dev at lists.lttng.org | lttng-dev at lists.lttng.org ]
>>> [ https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev |
>> > https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev ]
>> --
>> Mathieu Desnoyers
>> EfficiOS Inc.
>> [ http://www.efficios.com/ | http://www.efficios.com ]

> _______________________________________________
> lttng-dev mailing list
> lttng-dev at lists.lttng.org
> https://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev

-- 
Mathieu Desnoyers 
EfficiOS Inc. 
http://www.efficios.com 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.lttng.org/pipermail/lttng-dev/attachments/20191007/7873ed70/attachment-0001.html>


More information about the lttng-dev mailing list