<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2015-03-06 13:51 GMT-05:00 Brian Robbins <span dir="ltr"><<a href="mailto:brianrob@microsoft.com" target="_blank">brianrob@microsoft.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div lang="EN-US" link="blue" vlink="purple">
<div>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Thanks Francis.<u></u><u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)"><u></u> <u></u></span></p>
<p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">Is it accurate to say then that the array of addresses would need to be captured by app code by writing a stack walker by hand</span></p></div></div></blockquote><div><br></div><div>Yes, the callstack can be recorded in userspace. You would need a tracepoint with a varying length field:</div><div><br></div><div>TRACEPOINT_EVENT(myprovider, callstack,<br></div><div><div><span class="" style="white-space:pre"> </span>TP_ARGS(unsigned long *, buf, size_t, depth),</div><div><span class="" style="white-space:pre"> </span>TP_FIELDS(</div><div><span class="" style="white-space:pre"> </span>ctf_sequence(unsigned long, addr, buf, size_t, depth)</div><div><span class="" style="white-space:pre"> </span>)</div><div>)</div></div><div><br></div><div>In the app code, use libunwind [1] to get the addresses, then call the tracepoint: </div><div><br></div><div> do_unwind() // use libunwind here</div><div> tracepoint(myprovider, buf, depth);</div><div><br></div><div>However, the unwind will be done whether or not the tracepoint is active (~10us-100us in steady state, so it's may become expansive if called often). I know there was discussion about tp_code() for such use case (some code to call before the tracepoint only if it is enabled). Or you can cheat: </div><div><br></div><div>if (__builtin_expect(!!(__tracepoint_myprovider___callstack.state), 0)) {<br></div><div> do_unwind(...)</div><div> tracepoint(myprovider, buf, depth);<br></div><div>}</div><div><br></div><div>That said, instead of having a callstack tracepoint, IMHO the best solution would be instead extending lttng-ust to add callstack event context (itself linked to libunwind). Then, recording the callstack would be simple like that:</div><div><br></div><div> $ lttng add-context -u -t callstack<br></div><div><br></div><div> <br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div lang="EN-US" link="blue" vlink="purple"><div><p class="MsoNormal"><span style="font-size:11pt;font-family:Calibri,sans-serif;color:rgb(31,73,125)">or using the perf capture mechanism
that you describe below?</span></p></div></div></blockquote><div><br></div><div><br></div><div>Perf is peeking at the userspace from kernel space, it's another story. I guess that libunwind was not ported to the kernel because it is a large chunk of complicated code that performs a lot of I/O and computation, while copying a portion of the stack is really about KISS and low runtime overhead.</div><div><br></div><div>Cheers,</div><div><br></div><div>Francis</div></div></div></div>