<font size=2 face="sans-serif">As before, I still prefer a more sophisticated
approach, that stores the format string in the metadata...</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">Mathieu Desnoyers <mathieu.desnoyers@efficios.com></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></font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date:      
 </font><font size=1 face="sans-serif">01/14/2014 08:10 PM</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">After some discussion, the
following solution seems to be simpler and not dependent on LTTng UST internals:</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Courier New">#define tracepoint_for_format_string(provider,
name, …) \</font>
<br><font size=2 color=#004080 face="Courier New">     
do { \</font>
<br><font size=2 color=#004080 face="Courier New">     
      char msg_buf[MAX_BUFFER_SIZE]; \</font>
<br><font size=2 color=#004080 face="Courier New">     
      tracepoint(provider, name, my_snprintf(msg_buf, MAX_BUFFER_SIZE,
__VA_ARGS__)); \</font>
<br><font size=2 color=#004080 face="Courier New">     
} while (0)</font>
<br><font size=2 color=#004080 face="Courier New"> </font>
<br><font size=2 color=#004080 face="Calibri">my_snprintf should return
the pointer to the msg_buf. Although this solution allocates the buffer
on the stack even if the tracepoint is disabled, this should be a very
fast operation, and as long as the buffer size is much smaller than the
maximum stack size should be ok. Another option is to allocate memory inside
the my_snprintf function by malloc, which would only be called if the tracepoint
is enabled, however in those cases the memory allocation would be more
expensive.</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Calibri">We would probably prefer
this solution compared to the attached patch, as it is independent of LTTng
implementation.</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Calibri">Any comments, suggestions
are appreciated.</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Calibri">Thanks,</font>
<br><font size=2 color=#004080 face="Calibri">mate</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 face="Tahoma"><b>From:</b> Mathieu Desnoyers [</font><a href=mailto:mathieu.desnoyers@efficios.com><font size=2 face="Tahoma">mailto:mathieu.desnoyers@efficios.com</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> lttng-dev@lists.lttng.org<b><br>
Subject:</b> Re: efficient use of LTTng in legacy codebase</font>
<br><font size=2 face="Calibri"> </font>
<br><font size=2 face="Calibri">Just to speed things up, please have a
look at the proposed UST patch. (it's not in mainline yet)</font>
<br><font size=2 face="Calibri"> </font>
<br><font size=2 face="Calibri">This is specifically for a demo program
example so far.</font>
<br><font size=2 face="Calibri"> </font>
<br><font size=2 face="Calibri">Comments are welcome,</font>
<br><font size=2 face="Calibri"> </font>
<br><font size=2 face="Calibri">Thanks,</font>
<br><font size=2 face="Calibri"> </font>
<br><font size=2 face="Calibri">Mathieu</font>
<br><font size=2 face="Calibri"> </font>
<br><font size=2 face="Calibri"> </font>
<div align=center>
<hr></div>
<br><font size=2 face="sans-serif"><b>From: </b>"Máté Ferenczy"
<</font><a href=mailto:mate.ferenczy@ericsson.com><font size=2 color=blue face="sans-serif"><u>mate.ferenczy@ericsson.com</u></font></a><font size=2 face="sans-serif">><b><br>
To: </b>"Mathieu Desnoyers" <</font><a href=mailto:mathieu.desnoyers@efficios.com><font size=2 color=blue face="sans-serif"><u>mathieu.desnoyers@efficios.com</u></font></a><font size=2 face="sans-serif">><b><br>
Cc: </b></font><a href="mailto:lttng-dev@lists.lttng.org"><font size=2 color=blue face="sans-serif"><u>lttng-dev@lists.lttng.org</u></font></a><font size=2 face="sans-serif"><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>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 color=#004080 face="Calibri">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>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Calibri">For example:</font>
<br><font size=2 color=#004080 face="Courier New">#define ctf_format_string(_item,
…)                    
          \</font>
<br><font size=2 color=#004080 face="Courier New">     
  do {                  
                     
             \</font>
<br><font size=2 color=#004080 face="Courier New">     
      char _buf[BUF_MAXLEN];        
                     
\</font>
<br><font size=2 color=#004080 face="Courier New">     
      snprintf(buf, sizeof(_buf), __VA_ARGS__);    
       \</font>
<br><font size=2 color=#004080 face="Courier New">     
      _ctf_string(_item, _buf, 0);      
                  \</font>
<br><font size=2 color=#004080 face="Courier New">     
 } while(0)</font>
<br><font size=2 color=#004080 face="Courier New">     
  </font>
<br><font size=2 color=#004080 face="Calibri">Or do you have some better
place to put this logic?</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 color=#004080 face="Calibri">Thanks,</font>
<br><font size=2 color=#004080 face="Calibri">Mate</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 face="Tahoma"><b>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>
<br><font size=2 face="Calibri"> </font>
<div align=center>
<hr></div>
<br><font size=2 face="sans-serif"><b>From: </b>"Máté Ferenczy"
<</font><a href=mailto:mate.ferenczy@ericsson.com target=_blank><font size=2 color=blue face="sans-serif"><u>mate.ferenczy@ericsson.com</u></font></a><font size=2 face="sans-serif">><b><br>
To: </b>"mathieu desnoyers" <</font><a href=mailto:mathieu.desnoyers@efficios.com target=_blank><font size=2 color=blue face="sans-serif"><u>mathieu.desnoyers@efficios.com</u></font></a><font size=2 face="sans-serif">><b><br>
Cc: </b></font><a href="mailto:lttng-dev@lists.lttng.org" target=_blank><font size=2 color=blue face="sans-serif"><u>lttng-dev@lists.lttng.org</u></font></a><font size=2 face="sans-serif"><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>
<br><font size=2 face="sans-serif"> </font>
<br><font size=2 face="Calibri">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>
<br><font size=2 face="Calibri">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>
<br><font size=3> </font>
<br><font size=3>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.</font>
<br><font size=3> </font>
<br><font size=3>Thoughts ?</font>
<br><font size=3> </font>
<br><font size=3>Thanks,</font>
<br><font size=3> </font>
<br><font size=3>Mathieu</font>
<br><font size=3> </font>
<br><font size=2 face="Calibri">Thanks,</font>
<br><font size=2 face="Calibri">Mate</font>
<br><font size=2 color=#004080 face="Calibri"> </font>
<br><font size=2 face="Tahoma"><b>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>
<br><font size=2 face="Calibri">Hello Mathieu,</font>
<br><font size=2 face="Calibri">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>
<br><font size=2 face="Calibri">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>
<br><font size=2 face="Calibri">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>
<br><font size=2 face="Calibri">Any suggestions are welcome.</font>
<br><font size=2 face="Calibri">Thank you,</font>
<br><font size=2 face="Calibri">Mate Ferenczy</font>
<br><font size=3> </font>
<br><font size=3> </font>
<br><font size=3>-- </font>
<br><font size=3>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>
<br><font size=3> </font>
<br><font size=3> </font>
<br><font size=3>-- </font>
<br><font size=3>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><tt><font size=2>_______________________________________________<br>
lttng-dev mailing list<br>
lttng-dev@lists.lttng.org<br>
</font></tt><a href="http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev"><tt><font size=2>http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</font></tt></a><tt><font size=2><br>
</font></tt>
<br>