[lttng-dev] singleton tracepoints?

Jesper Derehag jderehag at hotmail.com
Fri Apr 24 04:48:14 EDT 2015


Hi,

I have been thinking a little bit about if there is some way to both define/implement and call tracepoints in a single call.

Normally, defining tracepoints goes something along these lines:
1. Define tracepoint in tp.h 
        TRACE_EVENT(..)
2. Generate probes in tp.c
       &define TRACEPOINT_CREATE_PROBES
       &include "tp.h"
3. Call tracepoint in main.c
       tracepoint(...);

Obviously you could join points 1&2 if you use lttng-gen-tp. It requires that you have a tracepoint definintioin file somewhere.

So the use case would then be to both "define" and call tracepoints in a single call.
I was thinking of something like this:

(Bad name, I know..)
singleton_tracepoint(TRACE_WARN, provider, name, const char*, "Something bad has happened!");


So the hard question then, how could we implement this?

I have so far thought of 4 possible approaches (and they are really not very well thought through, kind of brainstorming here):

1. Continue with the macro-magic as previously used tracepoint-event.h
    Cant think of any way to make this work. tracepoint-event.h hevaily relies on recursively including itself and the calling tracepoint definition.
    To replicate this behavior from inside a function simply wont work, or?

2. Somehow circumvent the "recursive includes from inside a function" problem by utilizing c++ function templates (or possibly lambda functions from c++11)
    Will likely not work either since templates are expanded during compilation and not during preprocessing. So the idea of creating a new scope
    within the template to create probes will not work either?

3. Re-implement the entire tracepoint callstack
    Getting a little bit closer, by doing that we can atleast inject trace packets with the correct formating and so on.
    But I dont see how one could also maintain the user workflow of beeing able to list probes and so on without having registered it?
    
    3.1 Lazy register probes
          If probe was not registered previously (as we pass the singleton_tracepoint), register it then.
    3.2 Never register singleton probes
          Make it possible to enable unknown tracepoints, perhaps it is already?

4. Extend lttng-gen-tp to also parse src-code for singleton_tracepoints and then generate probes as usual based on the definition.
    Could maybe be a little bit tricky since you need to do a bit of fuzzy parsing (exclude mentions of singleton_tracepoint(..) in comments and so on).
    But definetly the easiest (and portable) implementation, but would significantly add to build times.


Thoughts?

Regards,
Jesper




 		 	   		  


More information about the lttng-dev mailing list