15 #include "llvm/Config/config.h"
31 using namespace llvm::object;
33 #define DEBUG_TYPE "oprofile-jit-event-listener"
38 std::unique_ptr<OProfileWrapper>
Wrapper;
41 std::map<const char*, OwningBinary<ObjectFile>> DebugObjects;
44 OProfileJITEventListener(std::unique_ptr<OProfileWrapper> LibraryWrapper)
45 :
Wrapper(std::move(LibraryWrapper)) {
49 ~OProfileJITEventListener();
51 void NotifyObjectEmitted(
const ObjectFile &Obj,
54 void NotifyFreeingObject(
const ObjectFile &Obj)
override;
58 if (!
Wrapper->op_open_agent()) {
60 DEBUG(
dbgs() <<
"Failed to connect to OProfile agent: " << err_str <<
"\n");
62 DEBUG(
dbgs() <<
"Connected to OProfile agent.\n");
66 OProfileJITEventListener::~OProfileJITEventListener() {
67 if (
Wrapper->isAgentAvailable()) {
68 if (
Wrapper->op_close_agent() == -1) {
70 DEBUG(
dbgs() <<
"Failed to disconnect from OProfile agent: "
73 DEBUG(
dbgs() <<
"Disconnected from OProfile agent.\n");
78 void OProfileJITEventListener::NotifyObjectEmitted(
81 if (!
Wrapper->isAgentAvailable()) {
101 uint64_t Addr = *AddrOrErr;
102 uint64_t Size =
P.second;
104 if (
Wrapper->op_write_native_code(Name.
data(), Addr, (
void *)Addr, Size) ==
106 DEBUG(
dbgs() <<
"Failed to tell OProfile about native function " << Name
107 <<
" at [" << (
void *)Addr <<
"-" << ((
char *)Addr + Size)
114 DebugObjects[Obj.
getData().
data()] = std::move(DebugObjOwner);
117 void OProfileJITEventListener::NotifyFreeingObject(
const ObjectFile &Obj) {
118 if (
Wrapper->isAgentAvailable()) {
122 if (DebugObjects.find(Obj.
getData().
data()) == DebugObjects.end())
135 uint64_t Addr = *AddrOrErr;
137 if (
Wrapper->op_unload_native_code(Addr) == -1) {
139 <<
"Failed to tell OProfile about unload of native function at "
140 << (
void*)Addr <<
"\n");
154 return new OProfileJITEventListener(llvm::make_unique<OProfileWrapper>());
Information about the loaded object.
std::error_code getError() const
Represents either an error or a value T.
JITEventListener - Abstract interface for use by the JIT to notify clients about significant events d...
This class is the base class for all object file types.
std::string StrError()
Returns a string representation of the errno value, using whatever thread-safe variant of strerror() ...
StringRef getData() const
SymbolRef::Type getType() const
basic_symbol_iterator symbol_begin() const
const char * data() const
data - Get a pointer to the start of the string (which may not be null terminated).
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const char *const *StandardNames)
initialize - Initialize the set of available library functions based on the specified target triple...
basic_symbol_iterator symbol_end() const
virtual object::OwningBinary< object::ObjectFile > getObjectForDebug(const object::ObjectFile &Obj) const =0
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
std::vector< std::pair< SymbolRef, uint64_t > > computeSymbolSizes(const ObjectFile &O)
This is a value type class that represents a single symbol in the list of symbols in the object file...
ErrorOr< StringRef > getName() const
StringRef - Represent a constant reference to a string, i.e.
ErrorOr< uint64_t > getAddress() const
Returns the symbol virtual address (i.e.
static JITEventListener * createOProfileJITEventListener()