29#define DEBUG_TYPE "oprofile-wrapper"
44 WriteNativeCodeFunc(0),
45 WriteDebugLineInfoFunc(0),
46 UnloadNativeCodeFunc(0),
49 IsOProfileRunningFunc(0),
53bool OProfileWrapper::initialize() {
57 std::lock_guard<sys::Mutex> Guard(OProfileInitializationMutex);
60 return OpenAgentFunc != 0;
65 if (!isOProfileRunning()) {
74 <<
"OProfile connector library libopagent.so could not be loaded: "
79 OpenAgentFunc = (op_open_agent_ptr_t)(intptr_t)
81 CloseAgentFunc = (op_close_agent_ptr_t)(intptr_t)
83 WriteNativeCodeFunc = (op_write_native_code_ptr_t)(intptr_t)
85 WriteDebugLineInfoFunc = (op_write_debug_line_info_ptr_t)(intptr_t)
87 UnloadNativeCodeFunc = (op_unload_native_code_ptr_t)(intptr_t)
89 MajorVersionFunc = (op_major_version_ptr_t)(intptr_t)
91 MinorVersionFunc = (op_major_version_ptr_t)(intptr_t)
97 || !WriteNativeCodeFunc
98 || !WriteDebugLineInfoFunc
99 || !UnloadNativeCodeFunc) {
102 WriteNativeCodeFunc = 0;
103 WriteDebugLineInfoFunc = 0;
104 UnloadNativeCodeFunc = 0;
111bool OProfileWrapper::isOProfileRunning() {
112 if (IsOProfileRunningFunc != 0)
113 return IsOProfileRunningFunc();
114 return checkForOProfileProcEntry();
117bool OProfileWrapper::checkForOProfileProcEntry() {
120 ProcDir = opendir(
"/proc");
125 struct dirent*
Entry;
126 while (0 != (Entry = readdir(ProcDir))) {
127 if (
Entry->d_type == DT_DIR) {
134 int CmdLineFD = open(CmdLineFName.
c_str(), S_IRUSR);
135 if (CmdLineFD != -1) {
144 if (ExeName[0] !=
'/') {
149 while (
Idx < NumRead-1 && ExeName[
Idx] != 0) {
158 if (ExeName[
Idx] ==
'/') {
159 BaseName = ExeName +
Idx + 1;
166 if (BaseName != 0 && (!strcmp(
"oprofiled", BaseName) ||
167 !strcmp(
"operf", BaseName))) {
185 if (OpenAgentFunc != 0) {
186 Agent = OpenAgentFunc();
198 if (Agent && CloseAgentFunc) {
199 ret = CloseAgentFunc(Agent);
214 const unsigned int Size) {
218 if (Agent && WriteNativeCodeFunc)
219 return WriteNativeCodeFunc(Agent,
Name,
Addr, Code,
Size);
227 struct debug_line_info
const*
Info) {
231 if (Agent && WriteDebugLineInfoFunc)
232 return WriteDebugLineInfoFunc(Agent, Code, NumEntries,
Info);
241 if (Agent && MajorVersionFunc)
242 return MajorVersionFunc();
251 if (Agent && MinorVersionFunc)
252 return MinorVersionFunc();
261 if (Agent && UnloadNativeCodeFunc)
262 return UnloadNativeCodeFunc(Agent,
Addr);
Analysis containing CSE Info
Returns the sub type a function will return at a given Idx Should correspond to the result type of an ExtractValue instruction executed with just that one unsigned Idx
This file defines the SmallString class.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringLiteral > StandardNames)
Initialize the set of available library functions based on the specified target triple.
int op_write_native_code(const char *name, uint64_t addr, void const *code, const unsigned int size)
int op_unload_native_code(uint64_t addr)
int op_write_debug_line_info(void const *code, size_t num_entries, struct debug_line_info const *info)
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
A raw_ostream that writes to an SmallVector or SmallString.
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName.
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
This is an optimization pass for GlobalISel generic memory operations.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.