llvm.org GIT mirror llvm / 8f6d9a7
Add a --with-oprofile flag to configure, which uses OProfile's agent library to tell it the addresses of JITted functions. For a particular program, this changes the opreport -l output from: samples % image name symbol name 48182 98.9729 anon (tgid:19412 range:0x7f12ccaab000-0x7f12cdaab000) anon (tgid:19412 range:0x7f12ccaab000-0x7f12cdaab000) 11 0.0226 libstdc++.so.6.0.9 /usr/lib/libstdc++.so.6.0.9 to: samples % image name symbol name 24565 60.7308 19814.jo fib_left 15365 37.9861 19814.jo fib_right 22 0.0544 ld-2.7.so do_lookup_x git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@75279 91177308-0d34-0410-b5e6-96231b3b80d8 Jeffrey Yasskin 11 years ago
5 changed file(s) with 150 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
921921 AC_DEFINE_UNQUOTED([USE_UDIS86],$USE_UDIS86,
922922 [Define if use udis86 library])
923923
924 dnl Allow OProfile support for JIT output.
925 AC_ARG_WITH(oprofile,
926 AS_HELP_STRING([--with-oprofile=],
927 [Tell OProfile >= 0.9.4 how to symbolize JIT output]),
928 [
929 AC_SUBST(USE_OPROFILE, [1])
930 case "$withval" in
931 /usr|yes) llvm_cv_oppath=/usr/lib/oprofile ;;
932 *) llvm_cv_oppath="${withval}/lib/oprofile"
933 CPPFLAGS="-I${withval}/include";;
934 esac
935 LIBS="$LIBS -L${llvm_cv_oppath} -Wl,-rpath,${llvm_cv_oppath}"
936 AC_SEARCH_LIBS(op_open_agent, opagent, [], [
937 echo "Error! You need to have libopagent around."
938 exit -1
939 ])
940 AC_CHECK_HEADER([opagent.h], [], [
941 echo "Error! You need to have opagent.h around."
942 exit -1
943 ])
944 ],
945 [
946 llvm_cv_old_LIBS="$LIBS"
947 LIBS="$LIBS -L/usr/lib/oprofile -Wl,-rpath,/usr/lib/oprofile"
948 dnl If either the library or header aren't present, omit oprofile support.
949 AC_SEARCH_LIBS(op_open_agent, opagent,
950 [AC_SUBST(USE_OPROFILE, [1])],
951 [LIBS="$llvm_cv_old_LIBS"
952 AC_SUBST(USE_OPROFILE, [0])])
953 AC_CHECK_HEADER([opagent.h], [], [
954 LIBS="$llvm_cv_old_LIBS"
955 AC_SUBST(USE_OPROFILE, [0])
956 ])
957 ])
958 AC_DEFINE_UNQUOTED([USE_OPROFILE],$USE_OPROFILE,
959 [Define if we have the oprofile JIT-support library])
960
924961 dnl===-----------------------------------------------------------------------===
925962 dnl===
926963 dnl=== SECTION 6: Check for header files
5151 virtual void NotifyFreeingMachineCode(const Function &F, void *OldPtr) {}
5252 };
5353
54 // These return NULL if support isn't available.
5455 JITEventListener *createMacOSJITEventListener();
56 JITEventListener *createOProfileJITEventListener();
5557
5658 } // end namespace llvm.
5759
77 JITEmitter.cpp
88 JITMemoryManager.cpp
99 MacOSJITEventListener.cpp
10 OProfileJITEventListener.cpp
1011 TargetSelect.cpp
1112 )
0 //===-- OProfileJITEventListener.cpp - Tell OProfile about JITted code ----===//
1 //
2 // The LLVM Compiler Infrastructure
3 //
4 // This file is distributed under the University of Illinois Open Source
5 // License. See LICENSE.TXT for details.
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file defines a JITEventListener object that calls into OProfile to tell
10 // it about JITted functions. For now, we only record function names and sizes,
11 // but eventually we'll also record line number information.
12 //
13 // See http://oprofile.sourceforge.net/doc/devel/jit-interface.html for the
14 // definition of the interface we're using.
15 //
16 //===----------------------------------------------------------------------===//
17
18 #define DEBUG_TYPE "oprofile-jit-event-listener"
19 #include "llvm/Function.h"
20 #include "llvm/ExecutionEngine/JITEventListener.h"
21 #include "llvm/Support/Debug.h"
22 #include "llvm/System/Errno.h"
23 #include "llvm/Config/config.h"
24 #include
25 using namespace llvm;
26
27 #if defined(USE_OPROFILE)
28
29 #include
30
31 namespace {
32
33 class OProfileJITEventListener : public JITEventListener {
34 op_agent_t Agent;
35 public:
36 OProfileJITEventListener();
37 ~OProfileJITEventListener();
38
39 virtual void NotifyFunctionEmitted(const Function &F,
40 void *FnStart, size_t FnSize,
41 const EmittedFunctionDetails &Details);
42 virtual void NotifyFreeingMachineCode(const Function &F, void *OldPtr);
43 };
44
45 OProfileJITEventListener::OProfileJITEventListener()
46 : Agent(op_open_agent()) {
47 if (Agent == NULL) {
48 const std::string err_str = sys::StrError();
49 DOUT << "Failed to connect to OProfile agent: " << err_str << "\n";
50 } else {
51 DOUT << "Connected to OProfile agent.\n";
52 }
53 }
54
55 OProfileJITEventListener::~OProfileJITEventListener() {
56 if (Agent != NULL) {
57 if (op_close_agent(Agent) == -1) {
58 const std::string err_str = sys::StrError();
59 DOUT << "Failed to disconnect from OProfile agent: " << err_str << "\n";
60 } else {
61 DOUT << "Disconnected from OProfile agent.\n";
62 }
63 }
64 }
65
66 // Adds the just-emitted function to the symbol table.
67 void OProfileJITEventListener::NotifyFunctionEmitted(
68 const Function &F, void *FnStart, size_t FnSize,
69 const EmittedFunctionDetails &) {
70 const char *const FnName = F.getNameStart();
71 assert(FnName != 0 && FnStart != 0 && "Bad symbol to add");
72 if (op_write_native_code(Agent, FnName,
73 reinterpret_cast(FnStart),
74 FnStart, FnSize) == -1) {
75 DOUT << "Failed to tell OProfile about native function " << FnName
76 << " at [" << FnStart << "-" << ((char*)FnStart + FnSize) << "]\n";
77 }
78 }
79
80 // Removes the to-be-deleted function from the symbol table.
81 void OProfileJITEventListener::NotifyFreeingMachineCode(
82 const Function &F, void *FnStart) {
83 assert(FnStart && "Invalid function pointer");
84 if (op_unload_native_code(Agent, reinterpret_cast(FnStart)) == -1) {
85 DOUT << "Failed to tell OProfile about unload of native function "
86 << F.getName() << " at " << FnStart << "\n";
87 }
88 }
89
90 } // anonymous namespace.
91
92 namespace llvm {
93 JITEventListener *createOProfileJITEventListener() {
94 return new OProfileJITEventListener;
95 }
96 }
97
98 #else // !defined(USE_OPROFILE)
99
100 namespace llvm {
101 // By defining this to return NULL, we can let clients call it unconditionally,
102 // even if they haven't configured with the OProfile libraries.
103 JITEventListener *createOProfileJITEventListener() {
104 return NULL;
105 }
106 } // namespace llvm
107
108 #endif // defined(USE_OPROFILE)
155155 }
156156
157157 EE->RegisterJITEventListener(createMacOSJITEventListener());
158 EE->RegisterJITEventListener(createOProfileJITEventListener());
158159
159160 if (NoLazyCompilation)
160161 EE->DisableLazyCompilation();