<font size=2 face="sans-serif">You are absolutely right. However, looking
at several existing code bases that I am working with (our internal code,
and a couple of open-source projects I am adding LTTng support for), it
is clear that the vast majority of existing debug log statements have the
following general form:</font>
<br>
<br><font size=2 face="sans-serif">DEBUG_MACRO ( some_args, "lliteral
format string", more args )</font>
<br>
<br><font size=2 face="sans-serif">Amit</font>
<br>
<br><font size=2 color=#000080 face="sans-serif">Amit Margalit</font>
<br><font size=2 color=#808000 face="sans-serif">IBM XIV </font><font size=2 face="sans-serif">-
<i>Storage Reinvented</i></font>
<br><font size=2 face="sans-serif">XIV-NAS Development Team</font>
<br><font size=2 face="sans-serif">Tel. 03</font><font size=2 face="Arial">-689-7774</font>
<br><font size=2 face="Arial">Fax. 03-689-7230</font>
<br>
<br>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From:      
 </font><font size=1 face="sans-serif">Máté Ferenczy <mate.ferenczy@ericsson.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">To:      
 </font><font size=1 face="sans-serif">Amit Margalit/Israel/IBM@IBMIL</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Cc:      
 </font><font size=1 face="sans-serif">"lttng-dev@lists.lttng.org"
<lttng-dev@lists.lttng.org>, Mathieu Desnoyers <mathieu.desnoyers@efficios.com></font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:      
 </font><font size=1 face="sans-serif">12/16/2013 03:11 AM</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject:    
   </font><font size=1 face="sans-serif">RE: [lttng-dev]
efficient use of LTTng in legacy codebase</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=2 color=#004080 face="Calibri">I agree that in the long
term it would be nice if the trace reader could perform the formatting.</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Calibri">However, I am not sure how
#2 would work if the format strings and argument lists are passed through
a couple of function calls before calling the tracepoint API (which is
the case in our code).</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 face="Tahoma"><b>From:</b> Amit Margalit [</font><a href=mailto:AMITM@il.ibm.com><font size=2 face="Tahoma">mailto:AMITM@il.ibm.com</font></a><font size=2 face="Tahoma">]
<b><br>
Sent:</b> Sunday, December 15, 2013 4:56 AM<b><br>
To:</b> Máté Ferenczy<b><br>
Cc:</b> lttng-dev@lists.lttng.org; Mathieu Desnoyers<b><br>
Subject:</b> Re: [lttng-dev] efficient use of LTTng in legacy codebase</font>
<br><font size=3> </font>
<br><font size=2 face="Arial">The macro is elegant and solves the problem
nicely.</font><font size=3> <br>
</font><font size=2 face="Arial"><br>
I find that it does not make the biggest issue go away - the entire formatted
string gets stored in the trace file multiple times.</font><font size=3>
<br>
</font><font size=2 face="Arial"><br>
The best solution would be:</font><font size=3> </font>
<br><font size=2 face="sans-serif">1.        </font><font size=2 face="Arial">To
modify CTF and define a type that indicates a printf-style format string.</font><font size=3>
</font>
<br><font size=2 face="sans-serif">2.        </font><font size=2 face="Arial">To
have a LTTng macro that provides this string to the tracer, so that it
can record it <u>only once</u> in the metadata.</font><font size=3> </font>
<br><font size=2 face="sans-serif">3.        </font><font size=2 face="Arial">To
have the tracepoint store all the arguments in binary form, possibly with
the addition of some identifying value of the format string.</font><font size=3>
</font>
<br><font size=2 face="sans-serif">4.        </font><font size=2 face="Arial">And
to have babeltrace (the CTF trace reader) perform the formatting off-line.</font>
<br><font size=2 face="Arial"><br>
I mean - consider a trace message that includes a long format string, with
say - 5 integer arguments. Something like:</font><font size=3> </font><font size=2 face="Arial"><br>
"Buffer vacancy threshold warning: curr_limit=%d, curr_threshold=%d,
channel_num=%d, high_mark=%d, hit_count=%d"</font><font size=3> <br>
</font><font size=2 face="Arial"><br>
This stores > 105 bytes with <u>every</u> trace line. But the real information
here is only 20 bytes (assuming the integers are 32-bits).</font><font size=3>
<br>
</font><font size=2 face="Arial"><br>
Storing the format string once in the metadata will effectively boost performance
for a system trying to trace like this.</font><font size=3> <br>
</font><font size=2 color=#000080 face="Arial"><br>
Amit Margalit</font><font size=3> </font><font size=2 color=#808000 face="Arial"><br>
IBM XIV </font><font size=2 face="Arial">- <i>Storage Reinvented</i></font><font size=3>
</font><font size=2 face="Arial"><br>
XIV-NAS Development Team</font><font size=3> </font><font size=2 face="Arial"><br>
Tel. 03-689-7774</font><font size=3> </font><font size=2 face="Arial"><br>
Fax. 03-689-7230</font><font size=3> <br>
<br>
<br>
</font><font size=1 color=#5f5f5f face="Arial"><br>
From:        </font><font size=1 face="Arial">Máté
Ferenczy <</font><a href=mailto:mate.ferenczy@ericsson.com><font size=1 color=blue face="Arial"><u>mate.ferenczy@ericsson.com</u></font></a><font size=1 face="Arial">></font><font size=3>
</font><font size=1 color=#5f5f5f face="Arial"><br>
To:        </font><font size=1 face="Arial">Mathieu
Desnoyers <</font><a href=mailto:mathieu.desnoyers@efficios.com><font size=1 color=blue face="Arial"><u>mathieu.desnoyers@efficios.com</u></font></a><font size=1 face="Arial">></font><font size=3>
</font><font size=1 color=#5f5f5f face="Arial"><br>
Cc:        </font><font size=1 face="Arial">"</font><a href="mailto:lttng-dev@lists.lttng.org"><font size=1 color=blue face="Arial"><u>lttng-dev@lists.lttng.org</u></font></a><font size=1 face="Arial">"
<</font><a href="mailto:lttng-dev@lists.lttng.org"><font size=1 color=blue face="Arial"><u>lttng-dev@lists.lttng.org</u></font></a><font size=1 face="Arial">></font><font size=3>
</font><font size=1 color=#5f5f5f face="Arial"><br>
Date:        </font><font size=1 face="Arial">12/12/2013
07:39 PM</font><font size=3> </font><font size=1 color=#5f5f5f face="Arial"><br>
Subject:        </font><font size=1 face="Arial">Re:
[lttng-dev] efficient use of LTTng in legacy codebase</font><font size=3>
</font>
<div align=center>
<hr noshade></div>
<br><font size=3><br>
<br>
</font><font size=2 color=#004080 face="Calibri"><br>
That’s even better, as far as I see we do not even have to touch the liblttng
code itself.</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
Will get back with comments if any after testing.</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
Thanks so much! <br>
mate</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Tahoma"><b><br>
From:</b> Mathieu Desnoyers [</font><a href=mailto:mathieu.desnoyers@efficios.com><font size=2 color=blue face="Tahoma"><u>mailto:mathieu.desnoyers@efficios.com</u></font></a><font size=2 face="Tahoma">]
<b><br>
Sent:</b> Thursday, December 12, 2013 4:35 AM<b><br>
To:</b> Máté Ferenczy<b><br>
Cc:</b> </font><a href="mailto:lttng-dev@lists.lttng.org"><font size=2 color=blue face="Tahoma"><u>lttng-dev@lists.lttng.org</u></font></a><font size=2 face="Tahoma"><b><br>
Subject:</b> Re: efficient use of LTTng in legacy codebase</font><font size=3>
</font><font size=2 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
Just to speed things up, please have a look at the proposed UST patch.
(it's not in mainline yet)</font><font size=3> </font><font size=2 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
This is specifically for a demo program example so far.</font><font size=3>
</font><font size=2 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
Comments are welcome,</font><font size=3> </font><font size=2 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
Thanks,</font><font size=3> </font><font size=2 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
Mathieu</font><font size=3> </font><font size=2 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
 </font><font size=3> </font>
<div align=center>
<hr></div>
<br><font size=2 face="Helvetica"><b><br>
From: </b>"Máté Ferenczy" <</font><a href=mailto:mate.ferenczy@ericsson.com><font size=2 color=blue face="Helvetica"><u>mate.ferenczy@ericsson.com</u></font></a><font size=2 face="Helvetica">><b><br>
To: </b>"Mathieu Desnoyers" <</font><a href=mailto:mathieu.desnoyers@efficios.com><font size=2 color=blue face="Helvetica"><u>mathieu.desnoyers@efficios.com</u></font></a><font size=2 face="Helvetica">><b><br>
Cc: </b></font><a href="mailto:lttng-dev@lists.lttng.org"><font size=2 color=blue face="Helvetica"><u>lttng-dev@lists.lttng.org</u></font></a><font size=2 face="Helvetica"><b><br>
Sent: </b>Wednesday, December 11, 2013 8:52:30 PM<b><br>
Subject: </b>RE: efficient use of LTTng in legacy codebase</font><font size=3>
</font><font size=2 face="Helvetica"><br>
 </font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
It sounds great, I like the idea. Just to make sure I understand your suggestion,
are we talking about converting the variable argument list to string in
include/lttng/ust-tracepoint-event-write.h?</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
For example:</font><font size=3> </font><font size=2 color=#004080><br>
#define ctf_format_string(_item, …)          
                    \</font><font size=3>
</font><font size=2 color=#004080><br>
        do {            
                     
                   \</font><font size=3>
</font><font size=2 color=#004080><br>
            char _buf[BUF_MAXLEN];  
                     
      \</font><font size=3> </font><font size=2 color=#004080><br>
            snprintf(buf, sizeof(_buf), __VA_ARGS__);
           \</font><font size=3> </font><font size=2 color=#004080><br>
            _ctf_string(_item, _buf, 0);
                     
  \</font><font size=3> </font><font size=2 color=#004080><br>
       } while(0)</font><font size=3> </font><font size=2 color=#004080><br>
        </font><font size=2 color=#004080 face="Calibri"><br>
Or do you have some better place to put this logic?</font><font size=3>
</font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
Thanks,</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
Mate</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Tahoma"><b><br>
From:</b> Mathieu Desnoyers [</font><a href=mailto:mathieu.desnoyers@efficios.com><font size=2 color=blue face="Tahoma"><u>mailto:mathieu.desnoyers@efficios.com</u></font></a><font size=2 face="Tahoma">]
<b><br>
Sent:</b> Wednesday, December 11, 2013 4:48 PM<b><br>
To:</b> Máté Ferenczy<b><br>
Cc:</b> </font><a href="mailto:lttng-dev@lists.lttng.org"><font size=2 color=blue face="Tahoma"><u>lttng-dev@lists.lttng.org</u></font></a><font size=2 face="Tahoma"><b><br>
Subject:</b> Re: efficient use of LTTng in legacy codebase</font><font size=3>
</font><font size=2 face="Calibri"><br>
 </font><font size=3> </font>
<div align=center>
<hr></div>
<br><font size=2 face="Helvetica"><b><br>
From: </b>"Máté Ferenczy" <</font><a href=mailto:mate.ferenczy@ericsson.com target=_blank><font size=2 color=blue face="Helvetica"><u>mate.ferenczy@ericsson.com</u></font></a><font size=2 face="Helvetica">><b><br>
To: </b>"mathieu desnoyers" <</font><a href=mailto:mathieu.desnoyers@efficios.com target=_blank><font size=2 color=blue face="Helvetica"><u>mathieu.desnoyers@efficios.com</u></font></a><font size=2 face="Helvetica">><b><br>
Cc: </b></font><a href="mailto:lttng-dev@lists.lttng.org" target=_blank><font size=2 color=blue face="Helvetica"><u>lttng-dev@lists.lttng.org</u></font></a><font size=2 face="Helvetica"><b><br>
Sent: </b>Wednesday, December 11, 2013 6:52:22 PM<b><br>
Subject: </b>RE: efficient use of LTTng in legacy codebase</font><font size=3>
</font><font size=2 face="Helvetica"><br>
 </font><font size=3> </font><font size=2 face="Calibri"><br>
I found this email thread: </font><a href="https://www.mail-archive.com/lttng-dev@lists.lttng.org/msg02278.html" target=_blank><font size=2 color=blue face="Calibri"><u>https://www.mail-archive.com/lttng-dev@lists.lttng.org/msg02278.html</u></font></a><font size=3>
</font><font size=2 face="Calibri"><br>
According to this I could just check caa_unlikely(__tracepoint_##provider##___##name.state).
However, Dave claims that this state will stay true even if the tracepoint
is disabled. Is there anything else I should check for?</font><font size=3>
<br>
  <br>
I would recommend doing this in the UST probe provider instead. Within
the TRACEPOINT_EVENT "TP_FIELD" section, when you declare your
string field, you could parse the format string there in the last argument
of a ctf_string() (a statement expression). The format string would be
received as parameter by the tracepoint, along with a variable arg list
(...). In the probe, it would be turned into a va_list (see stdarg(3)),
and the parameters could be decoded into a string there. This has the benefit
of moving the serialization call out-of-line into the probe provider rather
than clobbering the tracepoint call site. <br>
  <br>
Thoughts ? <br>
  <br>
Thanks, <br>
  <br>
Mathieu <br>
  </font><font size=2 face="Calibri"><br>
Thanks,</font><font size=3> </font><font size=2 face="Calibri"><br>
Mate</font><font size=3> </font><font size=2 color=#004080 face="Calibri"><br>
 </font><font size=3> </font><font size=2 face="Tahoma"><b><br>
From:</b> Máté Ferenczy <b><br>
Sent:</b> Wednesday, December 11, 2013 12:17 PM<b><br>
To:</b> 'mathieu.desnoyers@efficios.com'<b><br>
Cc:</b> 'lttng-dev@lists.lttng.org'<b><br>
Subject:</b> efficient use of LTTng in legacy codebase</font><font size=3>
</font><font size=2 face="Calibri"><br>
Hello Mathieu,</font><font size=3> </font><font size=2 face="Calibri"><br>
Our team was asked to support LTTng UST solution in a legacy codebase.
The existing codebase is fairly large, and the requirement is that we provide
all the existing logs and debugs in the system as LTTng traces.</font><font size=3>
</font><font size=2 face="Calibri"><br>
The planned solution so far was just to pass everything we have as text
(strings) to LTTng. For that we obviously have to convert the printf-like
format string and parameter list to a string by calling snprintf before
giving the string to the LTTng API. That would however mean, that these
snprintfs are getting called every time even if there is no listener/active
trace session for the given trace. In this case, all those unnecessary
snprintf calls may end up significantly impacting the performance of our
applications.</font><font size=3> </font><font size=2 face="Calibri"><br>
In order to work around this, we were thinking that if there was a way
to query the LTTng library from our application code whether there is an
active tracing session for the given trace level, we could avoid calling
those snprintfs in case they are not needed. Do you think it would be feasible
to easily get this data from LTTng lib? If yes, can you provide us some
pointers where to look at in order to do those changes ourselves?</font><font size=3>
</font><font size=2 face="Calibri"><br>
Any suggestions are welcome.</font><font size=3> </font><font size=2 face="Calibri"><br>
Thank you,</font><font size=3> </font><font size=2 face="Calibri"><br>
Mate Ferenczy</font><font size=3> <br>
  <br>
  <br>
-- <br>
Mathieu Desnoyers<br>
EfficiOS Inc.</font><font size=3 color=blue><u><br>
</u></font><a href=http://www.efficios.com/ target=_blank><font size=3 color=blue><u>http://www.efficios.com</u></font></a><font size=3>
<br>
  <br>
  <br>
-- <br>
Mathieu Desnoyers<br>
EfficiOS Inc.</font><font size=3 color=blue><u><br>
</u></font><a href=http://www.efficios.com/><font size=3 color=blue><u>http://www.efficios.com</u></font></a><font size=2>_______________________________________________<br>
lttng-dev mailing list</font><font size=2 color=blue><u><br>
</u></font><a href="mailto:lttng-dev@lists.lttng.org"><font size=2 color=blue><u>lttng-dev@lists.lttng.org</u></font></a><font size=3 color=blue><u><br>
</u></font><a href="http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev"><font size=2 color=blue><u>http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</u></font></a>
<br>