<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 14 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Helvetica;
        panose-1:2 11 6 4 2 2 2 2 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Tahoma;
        panose-1:2 11 6 4 3 5 4 4 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:12.0pt;
        font-family:"Times New Roman","serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
tt
        {mso-style-priority:99;
        font-family:"Courier New";}
span.EmailStyle18
        {mso-style-type:personal-reply;
        font-family:"Calibri","sans-serif";
        color:#1F497D;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
/* List Definitions */
@list l0
        {mso-list-id:1930380874;
        mso-list-template-ids:-2062149948;}
@list l0:level1 lfo3
        {mso-level-start-at:2;}
@list l0:level1 lfo4
        {mso-level-start-at:3;}
@list l0:level1 lfo5
        {mso-level-start-at:4;}
ol
        {margin-bottom:0in;}
ul
        {margin-bottom:0in;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">I agree that in the long term it would be nice if the trace reader could perform the formatting.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D">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).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri","sans-serif";color:#1F497D"><o:p> </o:p></span></p>
<p class="MsoNormal"><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Amit Margalit [mailto:AMITM@il.ibm.com]
<br>
<b>Sent:</b> Sunday, December 15, 2013 4:56 AM<br>
<b>To:</b> Máté Ferenczy<br>
<b>Cc:</b> lttng-dev@lists.lttng.org; Mathieu Desnoyers<br>
<b>Subject:</b> Re: [lttng-dev] efficient use of LTTng in legacy codebase<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">The macro is elegant and solves the problem nicely.</span>
<br>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">I find that it does not make the biggest issue go away - the entire formatted string gets stored in the trace file multiple times.</span>
<br>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">The best solution would be:</span>
<o:p></o:p></p>
<ol start="1" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo2">
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">To modify CTF and define a type that indicates a printf-style format string.</span>
<o:p></o:p></li></ol>
<ol start="2" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo3">
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">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.</span> <o:p></o:p></li></ol>
<ol start="3" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo4">
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">To have the tracepoint store all the arguments in binary form, possibly with the addition of some identifying value of the format string.</span>
<o:p></o:p></li></ol>
<ol start="4" type="1">
<li class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto;mso-list:l0 level1 lfo5">
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">And to have babeltrace (the CTF trace reader) perform the formatting off-line.</span><o:p></o:p></li></ol>
<p class="MsoNormal"><br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">I mean - consider a trace message that includes a long format string, with say - 5 integer arguments. Something like:</span>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">"Buffer vacancy threshold warning: curr_limit=%d, curr_threshold=%d, channel_num=%d, high_mark=%d, hit_count=%d"</span>
<br>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">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).</span>
<br>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Storing the format string once in the metadata will effectively boost performance for a system trying to trace like this.</span>
<br>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:navy">Amit Margalit</span>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif";color:olive">IBM XIV
</span><span style="font-size:10.0pt;font-family:"Arial","sans-serif"">- <i>Storage Reinvented</i></span>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">XIV-NAS Development Team</span>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Tel. 03-689-7774</span>
<br>
<span style="font-size:10.0pt;font-family:"Arial","sans-serif"">Fax. 03-689-7230</span>
<br>
<br>
<br>
<br>
<span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#5F5F5F">From:        </span><span style="font-size:7.5pt;font-family:"Arial","sans-serif"">Máté Ferenczy <<a href="mailto:mate.ferenczy@ericsson.com">mate.ferenczy@ericsson.com</a>></span>
<br>
<span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#5F5F5F">To:        </span><span style="font-size:7.5pt;font-family:"Arial","sans-serif"">Mathieu Desnoyers <<a href="mailto:mathieu.desnoyers@efficios.com">mathieu.desnoyers@efficios.com</a>></span>
<br>
<span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#5F5F5F">Cc:        </span><span style="font-size:7.5pt;font-family:"Arial","sans-serif"">"<a href="mailto:lttng-dev@lists.lttng.org">lttng-dev@lists.lttng.org</a>" <<a href="mailto:lttng-dev@lists.lttng.org">lttng-dev@lists.lttng.org</a>></span>
<br>
<span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#5F5F5F">Date:        </span><span style="font-size:7.5pt;font-family:"Arial","sans-serif"">12/12/2013 07:39 PM</span>
<br>
<span style="font-size:7.5pt;font-family:"Arial","sans-serif";color:#5F5F5F">Subject:        </span><span style="font-size:7.5pt;font-family:"Arial","sans-serif"">Re: [lttng-dev] efficient use of LTTng in legacy codebase</span>
<o:p></o:p></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="100%" noshade="" style="color:#A0A0A0" align="center">
</div>
<p class="MsoNormal"><br>
<br>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">That’s even better, as far as I see we do not even have to touch the liblttng code itself.</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">Will get back with comments if any after testing.</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">Thanks so much!
</span><br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">mate</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Mathieu Desnoyers [</span><a href="mailto:mathieu.desnoyers@efficios.com"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">mailto:mathieu.desnoyers@efficios.com</span></a><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">]
<b><br>
Sent:</b> Thursday, December 12, 2013 4:35 AM<b><br>
To:</b> Máté Ferenczy<b><br>
Cc:</b> <a href="mailto:lttng-dev@lists.lttng.org">lttng-dev@lists.lttng.org</a><b><br>
Subject:</b> Re: efficient use of LTTng in legacy codebase</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Just to speed things up, please have a look at the proposed UST patch. (it's not in mainline yet)</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">This is specifically for a demo program example so far.</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Comments are welcome,</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Thanks,</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Mathieu</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <o:p></o:p></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="100%" align="center">
</div>
<p class="MsoNormal"><br>
<b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">From: </span>
</b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">"Máté Ferenczy" <</span><a href="mailto:mate.ferenczy@ericsson.com"><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">mate.ferenczy@ericsson.com</span></a><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">><b><br>
To: </b>"Mathieu Desnoyers" <</span><a href="mailto:mathieu.desnoyers@efficios.com"><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">mathieu.desnoyers@efficios.com</span></a><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">><b><br>
Cc: </b></span><a href="mailto:lttng-dev@lists.lttng.org"><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">lttng-dev@lists.lttng.org</span></a><b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif""><br>
Sent: </span></b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">Wednesday, December 11, 2013 8:52:30 PM<b><br>
Subject: </b>RE: efficient use of LTTng in legacy codebase</span> <br>
<span style="font-size:10.0pt;font-family:"Helvetica","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">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?</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">For example:</span>
<br>
<span style="font-size:10.0pt;color:#004080">#define ctf_format_string(_item, …)                               \</span>
<br>
<span style="font-size:10.0pt;color:#004080">        do {                                                      \</span>
<br>
<span style="font-size:10.0pt;color:#004080">            char _buf[BUF_MAXLEN];                               \</span>
<br>
<span style="font-size:10.0pt;color:#004080">            snprintf(buf, sizeof(_buf), __VA_ARGS__);            \</span>
<br>
<span style="font-size:10.0pt;color:#004080">            _ctf_string(_item, _buf, 0);                         \</span>
<br>
<span style="font-size:10.0pt;color:#004080">       } while(0)</span> <br>
<span style="font-size:10.0pt;color:#004080">        </span><br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">Or do you have some better place to put this logic?</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">Thanks,</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080">Mate</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Mathieu Desnoyers [</span><a href="mailto:mathieu.desnoyers@efficios.com"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">mailto:mathieu.desnoyers@efficios.com</span></a><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">]
<b><br>
Sent:</b> Wednesday, December 11, 2013 4:48 PM<b><br>
To:</b> Máté Ferenczy<b><br>
Cc:</b> </span><a href="mailto:lttng-dev@lists.lttng.org"><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">lttng-dev@lists.lttng.org</span></a><b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""><br>
Subject:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> Re: efficient use of LTTng in legacy codebase</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif""> </span> <o:p></o:p></p>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="3" width="100%" align="center">
</div>
<p class="MsoNormal" style="margin-bottom:12.0pt"><br>
<b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">From: </span>
</b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">"Máté Ferenczy" <</span><a href="mailto:mate.ferenczy@ericsson.com" target="_blank"><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">mate.ferenczy@ericsson.com</span></a><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">><b><br>
To: </b>"mathieu desnoyers" <</span><a href="mailto:mathieu.desnoyers@efficios.com" target="_blank"><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">mathieu.desnoyers@efficios.com</span></a><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">><b><br>
Cc: </b></span><a href="mailto:lttng-dev@lists.lttng.org" target="_blank"><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">lttng-dev@lists.lttng.org</span></a><b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif""><br>
Sent: </span></b><span style="font-size:10.0pt;font-family:"Helvetica","sans-serif"">Wednesday, December 11, 2013 6:52:22 PM<b><br>
Subject: </b>RE: efficient use of LTTng in legacy codebase</span> <br>
<span style="font-size:10.0pt;font-family:"Helvetica","sans-serif""> </span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">I found this email thread:
</span><a href="https://www.mail-archive.com/lttng-dev@lists.lttng.org/msg02278.html" target="_blank"><span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">https://www.mail-archive.com/lttng-dev@lists.lttng.org/msg02278.html</span></a>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">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?</span> <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>
  <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Thanks,</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Mate</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif";color:#004080"> </span>
<br>
<b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif"">From:</span></b><span style="font-size:10.0pt;font-family:"Tahoma","sans-serif""> 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</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Hello Mathieu,</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">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.</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">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.</span> <br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">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?</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Any suggestions are welcome.</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Thank you,</span>
<br>
<span style="font-size:10.0pt;font-family:"Calibri","sans-serif"">Mate Ferenczy</span>
<br>
  <br>
  <br>
-- <br>
Mathieu Desnoyers<br>
EfficiOS Inc.<u><span style="color:blue"><br>
</span></u><a href="http://www.efficios.com/" target="_blank">http://www.efficios.com</a>
<br>
  <br>
  <br>
-- <br>
Mathieu Desnoyers<br>
EfficiOS Inc.<u><span style="color:blue"><br>
</span></u><a href="http://www.efficios.com/">http://www.efficios.com</a><tt><span style="font-size:10.0pt">_______________________________________________</span></tt><span style="font-size:10.0pt;font-family:"Courier New""><br>
<tt>lttng-dev mailing list</tt><br>
<tt><a href="mailto:lttng-dev@lists.lttng.org">lttng-dev@lists.lttng.org</a></tt><br>
</span><a href="http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev"><tt><span style="font-size:10.0pt">http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev</span></tt></a><o:p></o:p></p>
</div>
</body>
</html>