llvm-capstone/llvm/tools
Andres Freund 376a3d3659 Add PerfJITEventListener for perf profiling support.
This new JIT event listener supports generating profiling data for
the linux 'perf' profiling tool, allowing it to generate function and
instruction level profiles.

Currently this functionality is not enabled by default, but must be
enabled with LLVM_USE_PERF=yes.  Given that the listener has no
dependencies, it might be sensible to enable by default once the
initial issues have been shaken out.

I followed existing precedent in registering the listener by default
in lli. Should there be a decision to enable this by default on linux,
that should probably be changed.

Please note that until https://reviews.llvm.org/D47343 is resolved,
using this functionality with mcjit rather than orcjit will not
reliably work.

Disregarding the previous comment, here's an example:

$ cat /tmp/expensive_loop.c

bool stupid_isprime(uint64_t num)
{
        if (num == 2)
                return true;
        if (num < 1 || num % 2 == 0)
                return false;
        for(uint64_t i = 3; i < num / 2; i+= 2) {
                if (num % i == 0)
                        return false;
        }
        return true;
}

int main(int argc, char **argv)
{
        int numprimes = 0;

        for (uint64_t num = argc; num < 100000; num++)
        {
                if (stupid_isprime(num))
                        numprimes++;
        }

        return numprimes;
}

$ clang -ggdb -S -c -emit-llvm /tmp/expensive_loop.c -o
/tmp/expensive_loop.ll

$ perf record -o perf.data -g -k 1 ./bin/lli -jit-kind=mcjit /tmp/expensive_loop.ll 1

$ perf inject --jit -i perf.data -o perf.jit.data

$ perf report -i perf.jit.data
-   92.59%  lli      jitted-5881-2.so                   [.] stupid_isprime
     stupid_isprime
     main
     llvm::MCJIT::runFunction
     llvm::ExecutionEngine::runFunctionAsMain
     main
     __libc_start_main
     0x4bf6258d4c544155
+    0.85%  lli      ld-2.27.so                         [.] do_lookup_x

And line-level annotations also work:
       │              for(uint64_t i = 3; i < num / 2; i+= 2) {
       │1 30:   movq   $0x3,-0x18(%rbp)
  0.03 │1 38:   mov    -0x18(%rbp),%rax
  0.03 │        mov    -0x10(%rbp),%rcx
       │        shr    $0x1,%rcx
  3.63 │     ┌──cmp    %rcx,%rax
       │     ├──jae    6f
       │     │                if (num % i == 0)
  0.03 │     │  mov    -0x10(%rbp),%rax
       │     │  xor    %edx,%edx
 89.00 │     │  divq   -0x18(%rbp)
       │     │  cmp    $0x0,%rdx
  0.22 │     │↓ jne    5f
       │     │                        return false;
       │     │  movb   $0x0,-0x1(%rbp)
       │     │↓ jmp    73
       │     │        }
  3.22 │1 5f:│↓ jmp    61
       │     │        for(uint64_t i = 3; i < num / 2; i+= 2) {

Subscribers: mgorny, llvm-commits

Differential Revision: https://reviews.llvm.org/D44892

llvm-svn: 337789
2018-07-24 00:54:06 +00:00
..
bugpoint Refactor ExecuteAndWait to take StringRefs. 2018-06-12 17:43:52 +00:00
bugpoint-passes Remove redundant includes from tools. 2017-12-13 21:31:10 +00:00
dsymutil [MC] Add interface to finish pending labels. 2018-07-10 15:32:17 +00:00
gold [gold-plugin] Disable section ordering for relocatable links 2018-07-12 20:35:58 +00:00
llc [llc] Fix sanitizer failure. 2018-06-23 19:04:10 +00:00
lli Add PerfJITEventListener for perf profiling support. 2018-07-24 00:54:06 +00:00
llvm-ar [FileSystem] Split up the OpenFlags enumeration. 2018-06-07 19:58:58 +00:00
llvm-as [ThinLTO] Parse module summary index from assembly 2018-06-26 13:56:49 +00:00
llvm-as-fuzzer make add_llvm_fuzzer calls slightly more consisten with other cmake 2018-05-11 17:58:52 +00:00
llvm-bcanalyzer Fix for llvm-dis/llvm-bcanalyzer overflows 2018-06-04 19:20:02 +00:00
llvm-c-test [LLVM-C] Add DIBuilder Bindings For ObjC Classes 2018-05-21 16:27:35 +00:00
llvm-cat Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
llvm-cfi-verify [cfi-verify] Abort on unsupported targets 2018-07-16 15:26:44 +00:00
llvm-config [llvm-config] Use WithColor for printing errors. 2018-06-23 16:50:09 +00:00
llvm-cov Refactor ExecuteAndWait to take StringRefs. 2018-06-12 17:43:52 +00:00
llvm-cvtres [llvm-cvtres] Allow parameters preceded by '-' in addition to '/' 2018-05-02 21:15:13 +00:00
llvm-cxxdump Fixing a typo; NFC. 2018-07-23 18:09:43 +00:00
llvm-cxxfilt Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-demangle-fuzzer make add_llvm_fuzzer calls slightly more consisten with other cmake 2018-05-11 17:58:52 +00:00
llvm-diff Let llvm-diff correctly deal with Undef/ConstantAggregateZero/ConstantVector/IndirectBr 2018-04-12 21:28:04 +00:00
llvm-dis [ThinLTO] Print module summary index to assembly 2018-05-26 02:34:13 +00:00
llvm-dwarfdump [DWARF] Improved error reporting for range lists. 2018-06-20 22:56:37 +00:00
llvm-dwp MC: Change the streamer ctors to take an object writer instead of a stream. NFCI. 2018-05-18 18:26:45 +00:00
llvm-exegesis [llvm-exegesis] Add uop computation for more X87 instruction classes. 2018-07-05 13:54:51 +00:00
llvm-extract Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-go Update some code.google.com links 2017-11-13 23:47:58 +00:00
llvm-isel-fuzzer CodeGen: Add a dwo output file argument to addPassesToEmitFile and hook it up to dwo output. 2018-05-21 20:16:41 +00:00
llvm-jitlistener Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-link Restore "[ThinLTO] Ensure we always select the same function copy to import" 2018-07-16 15:30:27 +00:00
llvm-lto [ThinLTO] Rename index IsAnalysis flag to HaveGVs (NFC) 2018-06-06 22:22:01 +00:00
llvm-lto2 [LTO] Allow pass remarks with hotness to be set when emitting to stderr 2018-05-04 23:59:34 +00:00
llvm-mc Support -fdebug-prefix-map in llvm-mc. This is useful to omit the 2018-07-10 14:41:54 +00:00
llvm-mc-assemble-fuzzer make add_llvm_fuzzer calls slightly more consisten with other cmake 2018-05-11 17:58:52 +00:00
llvm-mc-disassemble-fuzzer make add_llvm_fuzzer calls slightly more consisten with other cmake 2018-05-11 17:58:52 +00:00
llvm-mca [llvm-mca][BtVer2] teach how to identify false dependencies on partially written 2018-07-15 11:01:38 +00:00
llvm-modextract Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
llvm-mt [llvm-mt] Use WithColor for printing errors. 2018-06-23 16:49:07 +00:00
llvm-nm nm: Add -no-weak flag for hiding weak symbols 2018-07-02 17:24:37 +00:00
llvm-objcopy [llvm-objcopy] Add basic support for --rename-section 2018-07-20 19:54:24 +00:00
llvm-objdump [llvm-objdump] Add -demangle (-C) option 2018-07-18 16:39:21 +00:00
llvm-opt-fuzzer make add_llvm_fuzzer calls slightly more consisten with other cmake 2018-05-11 17:58:52 +00:00
llvm-opt-report Remove \brief commands from doxygen comments. 2018-05-01 15:54:18 +00:00
llvm-pdbutil [PDB] One more fix for hasing GSI records. 2018-07-06 21:01:42 +00:00
llvm-profdata [NFC] Change sample profile format enum name SPF_Raw_Binary to SPF_Binary. 2018-06-12 05:53:49 +00:00
llvm-rc [FileSystem] Split up the OpenFlags enumeration. 2018-06-07 19:58:58 +00:00
llvm-readobj Fix -Wsign-compare in llvm-readobj 2018-07-19 19:58:22 +00:00
llvm-rtdyld Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-shlib [CMake] Support building shared library for OpenBSD 2018-06-23 21:26:44 +00:00
llvm-size [llvm-size] Make global variables static 2018-06-22 22:20:10 +00:00
llvm-special-case-list-fuzzer make add_llvm_fuzzer calls slightly more consisten with other cmake 2018-05-11 17:58:52 +00:00
llvm-split Pass a reference to a module to the bitcode writer. 2018-02-14 19:11:32 +00:00
llvm-stress [Support] Rename tool_output_file to ToolOutputFile, NFC 2017-09-23 01:03:17 +00:00
llvm-strings Define InitLLVM to do common initialization all at once. 2018-04-13 18:26:06 +00:00
llvm-symbolizer [llvm-symbolizer] Simplify 2018-05-26 02:29:14 +00:00
llvm-undname [llvm-undname] Flush output before demangling. 2018-07-21 15:39:05 +00:00
llvm-xray [XRay][compiler-rt] Add PID field to llvm-xray tool and add PID metadata record entry in FDR mode 2018-07-13 05:38:22 +00:00
lto s/LLVM_ON_WIN32/_WIN32/, llvm 2018-04-29 00:45:03 +00:00
msbuild Rewrite the VS integration scripts. 2018-07-20 16:30:02 +00:00
obj2yaml Fix debug build by adding missing dependencies on libBinaryFormat 2018-05-15 00:46:43 +00:00
opt [Debugify] Export per-pass debug info loss statistics 2018-07-24 00:41:29 +00:00
opt-viewer [opt-viewer] Kill parser processes before moving onto rendering 2018-02-26 21:15:51 +00:00
sancov Rename sancov.cc to sancov.cpp 2018-04-25 18:06:23 +00:00
sanstats Fix broken links to the Itanium CXX ABI 2017-09-12 00:19:11 +00:00
verify-uselistorder Rename DEBUG macro to LLVM_DEBUG. 2018-05-14 12:53:11 +00:00
xcode-toolchain [cmake][xcode-toolchain] add support for major Xcode version >= 10 2018-06-28 00:39:09 +00:00
yaml2obj [yaml2obj] Add default sh_entsize for dynamic sections 2018-07-23 18:49:04 +00:00
CMakeLists.txt
LLVMBuild.txt Add a Microsoft Demangler. 2018-07-20 17:27:48 +00:00