<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 20, 2017 at 12:38 PM, Moshtaghi, Alireza <span dir="ltr"><<a href="mailto:Alireza.Moshtaghi@netapp.com" target="_blank">Alireza.Moshtaghi@netapp.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">







<div bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<div class="m_5408394753988164394WordSection1">
<p class="MsoNormal">For __llvm_profile_get_size_for_<wbr>buffer_internal and __llvm_profile_write_buffer_<wbr>internal to work in our system, we have to modify the compiler-rt to use our kernel’s memory allocation. To avoid that, I was hoping to be able to do all the
 processing offline by copying only the sections to that offline process.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">We currently have a workaround, but please let me know if you think just copying the __llvm_prf_xxx sections and doing the processing offline is not possible with the current API of compiler-rt profiling.</p></div></div></blockquote><div><br></div><div>It should work if the raw profile header is initialized properly with sizes of data, counter, and name sections as well as counter base address.</div><div><br></div><div>David</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div bgcolor="white" lang="EN-US" link="blue" vlink="purple"><div class="m_5408394753988164394WordSection1"><p class="MsoNormal"><u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks<u></u><u></u></p>
<p class="MsoNormal">A<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<div style="border:none;border-top:solid #b5c4df 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Xinliang David Li <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br>
<b>Date: </b>Tuesday, December 19, 2017 at 5:38 PM<br>
<b>To: </b>Vedant Kumar <<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>><br>
<b>Cc: </b>"Moshtaghi, Alireza" <<a href="mailto:Alireza.Moshtaghi@netapp.com" target="_blank">Alireza.Moshtaghi@netapp.com</a>><wbr>, llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>></span></p><div><div class="h5"><br>
<b>Subject: </b>Re: [llvm-dev] Question about : lprofValueProfNodes<u></u><u></u></div></div><p></p>
</div><div><div class="h5">
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">What Vedant said -- the profiler runtime provides buffer API for profile dumping.  Note that value profiling dumping is not yet supported for buffer API, but since you are using Front-end based instrumentation/profile-use, value profiler
 is not turned on by default anyway. <u></u><u></u></p>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">David<u></u><u></u></p>
</div>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<p class="MsoNormal">On Tue, Dec 19, 2017 at 5:29 PM, Vedant Kumar <<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>> wrote:<u></u><u></u></p>
<blockquote style="border:none;border-left:solid #cccccc 1.0pt;padding:0cm 0cm 0cm 6.0pt;margin-left:4.8pt;margin-right:0cm">
<div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<div>
<p class="MsoNormal">On Dec 19, 2017, at 5:16 PM, Moshtaghi, Alireza <<a href="mailto:Alireza.Moshtaghi@netapp.com" target="_blank">Alireza.Moshtaghi@netapp.com</a>> wrote:<u></u><u></u></p>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
<div>
<div>
<div>
<p class="MsoNormal" style="background:white">Thank you<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="background:white">So it does not seem to be relevant for what I’m trying to do.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="background:white">I’m doing something unconventional.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="background:white">The objective is to implement PGO and code coverage on a system that does not exit and does not have any file io, or any of  stdc libraries that libclang-profile is using. (more like a kernel)<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal" style="background:white">So what I’m trying to do is instead of calling __llvm_profile_write_file () from the application, read the sections __llvm_prf_data, __llvm_prf_names, __llvm_prf_cnts and __llvm_prf_vnds after the critical tasks
 are done and transfer them to outside of the system.<u></u><u></u></p>
</div>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal">You may already have worked this out, but for completeness I'll mention that this is typically done by:<u></u><u></u></p>
</div>
<p class="MsoNormal">1. Allocating a buffer big enough to contain all the data (see __llvm_profile_get_size_<wbr>for_buffer_internal),<br>
2. Filling out the buffer (see __llvm_profile_write_buffer_<wbr>internal), and <u></u><u></u></p>
<div>
<p class="MsoNormal">3. Transferring the buffer to some host machine.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><br>
<br>
<br>
<u></u><u></u></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal">Then dump these sections in a char * array in a c file and attribute them to be in the associated section.<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">I'm not sure I follow -- why is a C file needed?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">Once you have the buffer from step 3 on the host machine, you've got a well-formed raw profile. You should be able to fwrite() it to e.g 'default.profraw' and test that it's a valid profile with llvm-profdata.<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<p class="MsoNormal"><br>
<br>
<u></u><u></u></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal"> Then compile that file with –u__llvm_profile_runtime to create an executable that calls __llvm_profile_write_file to dump my profraw data.<br>
 <br>
Sofar, I’m able to do the mechanics but seems like something is going wrong because because fprofile-instr-use does not find profile data for the source files.<u></u><u></u></p>
</blockquote>
<div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
<div>
<p class="MsoNormal">What error are you getting exactly? Have you confirmed that your profile is valid?<u></u><u></u></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#888888"><u></u> <u></u></span></p>
</div>
<div>
<p class="MsoNormal"><span style="color:#888888">vedant<u></u><u></u></span></p>
</div>
<div>
<div>
<p class="MsoNormal"><br>
<br>
<u></u><u></u></p>
<blockquote style="margin-top:5.0pt;margin-bottom:5.0pt">
<p class="MsoNormal" style="margin-bottom:12.0pt"> <br>
Any suggestion?<br>
 <br>
Thanks<br>
A<br>
 <br>
From: <<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>> on behalf of Vedant Kumar <<a href="mailto:vsk@apple.com" target="_blank">vsk@apple.com</a>><br>
Date: Tuesday, December 19, 2017 at 11:32 AM<br>
To: "Moshtaghi, Alireza" <<a href="mailto:Alireza.Moshtaghi@netapp.com" target="_blank">Alireza.Moshtaghi@netapp.com</a>><br>
Cc: llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>, Xinliang David Li <<a href="mailto:davidxl@google.com" target="_blank">davidxl@google.com</a>><br>
Subject: Re: [llvm-dev] Question about : lprofValueProfNodes<br>
 <br>
Hi,<br>
 <br>
 <br>
On Dec 19, 2017, at 10:26 AM, Moshtaghi, Alireza via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br>
 <br>
Hi<br>
This array is defined in compiler-rt: InstrProfilingValue.c but I can’t find where it is used?<br>
 <br>
It's used in allocateOneNode(). Incrementing the current vnode pointer gives a fresh node (possibly backed by the shared pool).<br>
 <br>
<br>
<br>
And the comment on it does not say much about why we need it either.<br>
 <br>
It's used to avoid calling malloc(), which David (CC'd) found to be a performance improvement.<br>
 <br>
best,<br>
vedant<br>
<br>
<br>
Can someone explain why we need this and where it is used?<br>
 <br>
/* A shared static pool in addition to the vnodes statically<br>
* allocated by the compiler.  */<br>
COMPILER_RT_VISIBILITY ValueProfNode<br>
    lprofValueProfNodes[INSTR_<wbr>PROF_VNODE_POOL_SIZE] COMPILER_RT_SECTION(COMPILER_<wbr>RT_SEG INSTR_PROF_VNODES_SECT_NAME_<wbr>STR);<br>
 <br>
Thanks<br>
A<br>
 <br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
<br>
<u></u><u></u></p>
</blockquote>
</div>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div>
</blockquote>
</div>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
</div></div></div>
</div>

</blockquote></div><br></div></div>