This is an archive of the discontinued LLVM Phabricator instance.

Add debug info for OProfile porifling support
ClosedPublic

Authored by gipri on Jun 7 2018, 7:24 PM.

Details

Summary

The LLVM implementation of the OProfile interface is almost complete, except for the support of line level code annotations.
This is an attempt to fill this gap, as the Oprofile wrapper is already capable of registering debug events.

For example in Julia we can now target user-level functions.
As an example we set

>sudo operf -Vdebug ./julia pidigits.jl
>opreport -l `which ./julia`
...
1         0.0095  sys-debug.so             japi1_widen_all_consts!_995
1         0.0095  sys-debug.so             jlcall_pidigits_2258
1         0.0095  sys-debug.so             jlcall_lower_sum_2188
1         0.0095  sys-debug.so             jlcall_upper_sum_2923
1         0.0095  sys-debug.so             jlcall_<=_417
1         0.0095  sys-debug.so             jlcall_==_219
1         0.0095  sys-debug.so             jlcall_==_2322
1         0.0095  sys-debug.so             jlcall_done_216
1         0.0095  sys-debug.so             jlcall_fill_2011
1         0.0095  sys-debug.so             jlcall_in_2246
1         0.0095  sys-debug.so             jlcall_isbits_2230
1         0.0095  sys-debug.so             jlcall_next_217
1         0.0095  sys-debug.so             jlcall_record_ssa_assign_926
1         0.0095  sys-debug.so             jlcall_setindex!_533
1         0.0095  sys-debug.so             julia_+_431
1         0.0095  sys-debug.so             julia_-_646
1         0.0095  sys-debug.so             julia_<=_418
1         0.0095  sys-debug.so             julia_==_2225

Diff Detail

Repository
rL LLVM

Event Timeline

gipri created this revision.Jun 7 2018, 7:24 PM
aprantl added inline comments.Jun 8 2018, 8:51 AM
lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp
132 ↗(On Diff #150439)

please clang-format your patch.

gipri updated this revision to Diff 150552.Jun 8 2018, 12:15 PM
gipri edited the summary of this revision. (Show Details)

Clang-format

aprantl added inline comments.Jun 8 2018, 12:24 PM
lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp
132 ↗(On Diff #150439)

sorry for being obnoxious :-) but this still doesn't look clang-formatted...

gipri added a comment.Jun 8 2018, 12:24 PM

Yeah sorry, I am new to SVN and in particular LLVM standards.
The output diff is obtained by revisioning on a git branch, so it seems that is not redirecting correctly.
The diff can still be applied with patch to trunk, but I don't know if it is still a problem.

aprantl added inline comments.Jun 8 2018, 2:11 PM
lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp
132 ↗(On Diff #150439)

Thanks for the patch!

I assume you've tested this and it works? It looks correct, but I'm not in a position to set up an OProfile environment to verify it and I don't know the OProfile interface well enough to know without testing.

lib/ExecutionEngine/OProfileJIT/OProfileJITEventListener.cpp
120 ↗(On Diff #150552)

DILineInfoTable is an alias of llvm::SmallVector, so you can use Lines.size() here.

121 ↗(On Diff #150552)

Why is this static?

124 ↗(On Diff #150552)

Also because DILineInfoTable is a SmallVector, you can use a range-based iterator here:

for (auto InfoPair : Lines) {
  <fill in debug_line[i]>
  ++i;
}

The IntelJITEventListener is old code and I don't think we had range-based iterators when it was last updated.

128 ↗(On Diff #150552)

I'm not sure this copy is going to do anything useful. It's copying the file name into a string that will be destructed at the end of the out loop iteration. I realize this part of the code is copied directly from the IntelJITEventListener, but it's wrong there too. Maybe we get away with it there because the Intel debug info registration function doesn't need the string pointer to outlive the function call. Maybe that's true with OProfile too. In any event, I can't see a reason to copy the string here.

gipri updated this revision to Diff 150846.Jun 11 2018, 2:32 PM
gipri added a comment.EditedJun 11 2018, 2:43 PM

Ok now the files are redirected correctly.

You can easily test this if you have a Linux Arch as Oprofile is mainted by the community!

Yeah effectively it does not need to be static.
The reason why I did in the first place is that the Oprofile Wrapper is not calling the op_write_debug_line_info function directly but dinamically binds it to a pointer function.
By being abit scared from that, I made it static so that it could have the same lifetime of the program, whenever so the binded function was called the memory section would outlive it.
But yeah now I tested it and it is not necessary.
Regarding the formatting I am sorry but I did not knew this praxis, hope that now it fits the standards!

This revision is now accepted and ready to land.Jun 13 2018, 2:32 PM
gipri added a comment.Jun 13 2018, 3:56 PM

Great! Sorry but I do not have merge access, can you land this for me? Thanks!

Great! Sorry but I do not have merge access, can you land this for me? Thanks!

I'm having some trouble getting the build to work with OProfile support turned on. It doesn't seem to be related to these changes. I'll commit the patch as soon as I figure it out.

This revision was automatically updated to reflect the committed changes.