[LLVMdev] LLVM instrumentation

David Siegel david.siegel at artcom.de
Fri Jul 17 11:43:22 PDT 2015


> On 17.07.2015, at 19:54, Wehrli Johan <johan.wehrli at heig-vd.ch> wrote:
> 
> The PGO was my first guess but I can get a lot of information.
> 
> At first, I follow the explanation at http://clang.llvm.org/docs/UsersManual.html#profiling-with-instrumentation but instead of llvm-profdata merge, I used llvm-profdata show *.profraw.

Try

llvm-profdata show -all-functions -counts *.profraw

In any case the PGO stuff shows how to emit instrumentation and how to evaluate the gathered information in subsequent compilations. That should help to get you started.

d

> 
> Sadly, the information I get is the total number of function, the maximum function count and the maximum internal block count.
> 
> Do you know if you can tune the -fprofile-instr-generate parameter?
> 
> I find another way for doing instrumentation (http://logan.tw/posts/2015/04/28/check-code-coverage-with-clang-and-lcov/)
> 
> With this, I get the following information :
> 
> Function '_ZL8func_addii'
> Lines executed:100.00% of 5
> Branches executed:100.00% of 2
> Taken at least once:100.00% of 2
> No calls
> 
> Function 'main'
> Lines executed:100.00% of 6
> Branches executed:100.00% of 2
> Taken at least once:100.00% of 2
> No calls
> 
> File 'test.cpp'
> Lines executed:100.00% of 11
> Branches executed:100.00% of 4
> Taken at least once:100.00% of 4
> No calls
> test.cpp:creating 'test.cpp.gcov'
> 
> With the following code :
> 
> static int func_add(int a, int b){
> int res = 0;
> for(int i = 0; i < 2; ++i){
> res += a + b;
> }
> 
> return res;
> }
> 
> int main(int argc, char** argv){
> 
> int tab[10] = {5, 9, 7, 6, 2, 4, 3, 5, 8, 10};
> 
> for(int i = 0; i < 10; ++i){
> printf("%d, ",func_add(tab[i],2));
> }
>    printf("\n");
> return 0;
> }
> 
> I can’t understand the part “taken at leat once”, why main is executed two time?
> 
> Greetings,
> 
> Johan
> 
> On 17 Jul 2015, at 16:56, David Siegel <david.siegel at artcom.de<mailto:david.siegel at artcom.de>> wrote:
> 
> 
> On 17.07.2015, at 16:31, Wehrli Johan <johan.wehrli at heig-vd.ch<mailto:johan.wehrli at heig-vd.ch>> wrote:
> 
> […]
> 
> My goal with the instrumentation is, once I have the information (time + call), to choose (during a second compilation) if some of my passes are applicable or not.
> 
> Profile-guided optimization (PGO) [1] … mumble…mumble. Clang/LLVM has infrastructure for that [2]. I somehow can’t imagine that it doesn’t provide call frequencies and timing. In any case that’s probably where to start.
> 
> HTH,
> 
> d
> 
> [1] https://en.wikipedia.org/wiki/Profile-guided_optimization
> [2] http://clang.llvm.org/docs/UsersManual.html#profile-guided-optimization
> 
> 
> Greetings,
> 
> Johan
> 
> On 17 Jul 2015, at 16:09, Kenneth Adam Miller <kennethadammiller at gmail.com<mailto:kennethadammiller at gmail.com><mailto:kennethadammiller at gmail.com>> wrote:
> 
> Have you seen intel pintools? You might not need to write near as much code, however it may not suit your use case because the compiler can see information that otherwise might be missed in the context of a fully compiled binary. Please let me know your thoughts and then we can pick up from there.
> 
> On Fri, Jul 17, 2015 at 2:43 AM, Wehrli Johan <johan.wehrli at heig-vd.ch<mailto:johan.wehrli at heig-vd.ch><mailto:johan.wehrli at heig-vd.ch>> wrote:
> Hi everyone,
> 
> I would like to instrument my code in order to know the number of times a function is called and its execution time.
> 
> After some research, I find several leads in llvm/lib/ProfilData/ and llvm/lib/Transform/Instrumentation/ but nothing conclusive.
> 
> Does anyone know if this is already possible with LLVM or has a good suggestion for the beginning?
> 
> I saw the -fprofile-instr-generate, -fprofile-instr-use, -fprofile-arcs, -ftest-coverage parameters but I can’t get the information I want with it.
> 
> It seem that the easiest solution is to write a pass who will instrument the code.
> 
> Greetings,
> 
> Johan
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu><mailto:LLVMdev at cs.uiuc.edu>         http://llvm.cs.uiuc.edu<http://llvm.cs.uiuc.edu/>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu<mailto:LLVMdev at cs.uiuc.edu>         http://llvm.cs.uiuc.edu<http://llvm.cs.uiuc.edu/>
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
> 





More information about the llvm-dev mailing list