30 #define DEBUG_TYPE "oprofile-wrapper" 45 WriteNativeCodeFunc(0),
46 WriteDebugLineInfoFunc(0),
47 UnloadNativeCodeFunc(0),
50 IsOProfileRunningFunc(0),
54 bool OProfileWrapper::initialize() {
61 return OpenAgentFunc != 0;
66 if (!isOProfileRunning()) {
75 <<
"OProfile connector library libopagent.so could not be loaded: " 80 OpenAgentFunc = (op_open_agent_ptr_t)(
intptr_t)
82 CloseAgentFunc = (op_close_agent_ptr_t)(
intptr_t)
84 WriteNativeCodeFunc = (op_write_native_code_ptr_t)(
intptr_t)
86 WriteDebugLineInfoFunc = (op_write_debug_line_info_ptr_t)(
intptr_t)
88 UnloadNativeCodeFunc = (op_unload_native_code_ptr_t)(
intptr_t)
90 MajorVersionFunc = (op_major_version_ptr_t)(
intptr_t)
92 MinorVersionFunc = (op_major_version_ptr_t)(
intptr_t)
98 || !WriteNativeCodeFunc
99 || !WriteDebugLineInfoFunc
100 || !UnloadNativeCodeFunc) {
103 WriteNativeCodeFunc = 0;
104 WriteDebugLineInfoFunc = 0;
105 UnloadNativeCodeFunc = 0;
112 bool OProfileWrapper::isOProfileRunning() {
113 if (IsOProfileRunningFunc != 0)
114 return IsOProfileRunningFunc();
115 return checkForOProfileProcEntry();
118 bool OProfileWrapper::checkForOProfileProcEntry() {
121 ProcDir = opendir(
"/proc");
126 struct dirent* Entry;
127 while (0 != (Entry = readdir(ProcDir))) {
128 if (Entry->d_type == DT_DIR) {
135 int CmdLineFD = open(CmdLineFName.
c_str(), S_IRUSR);
136 if (CmdLineFD != -1) {
137 char ExeName[PATH_MAX+1];
141 ssize_t NumRead =
read(CmdLineFD, ExeName, PATH_MAX+1);
145 if (ExeName[0] !=
'/') {
150 while (Idx < NumRead-1 && ExeName[Idx] != 0) {
159 if (ExeName[Idx] ==
'/') {
160 BaseName = ExeName + Idx + 1;
167 if (BaseName != 0 && (!strcmp(
"oprofiled", BaseName) ||
168 !strcmp(
"operf", BaseName))) {
186 if (OpenAgentFunc != 0) {
187 Agent = OpenAgentFunc();
199 if (Agent && CloseAgentFunc) {
200 ret = CloseAgentFunc(Agent);
215 const unsigned int Size) {
219 if (Agent && WriteNativeCodeFunc)
220 return WriteNativeCodeFunc(Agent, Name, Addr, Code, Size);
228 struct debug_line_info
const*
Info) {
232 if (Agent && WriteDebugLineInfoFunc)
233 return WriteDebugLineInfoFunc(Agent, Code, NumEntries, Info);
242 if (Agent && MajorVersionFunc)
243 return MajorVersionFunc();
252 if (Agent && MinorVersionFunc)
253 return MinorVersionFunc();
262 if (Agent && UnloadNativeCodeFunc)
263 return UnloadNativeCodeFunc(Agent, Addr);
static void * SearchForAddressOfSymbol(const char *symbolName)
This function will search through all previously loaded dynamic libraries for the symbol symbolName...
This class represents lattice values for constants.
A raw_ostream that writes to an SmallVector or SmallString.
amdgpu Simplify well known AMD library false Value Value const Twine & Name
int op_write_debug_line_info(void const *code, size_t num_entries, struct debug_line_info const *info)
static bool LoadLibraryPermanently(const char *Filename, std::string *ErrMsg=nullptr)
This function permanently loads the dynamic library at the given path.
Analysis containing CSE Info
Instances of this class acquire a given Mutex Lock when constructed and hold that lock until destruct...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, ArrayRef< StringRef > 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)
value_type read(const void *memory, endianness endian)
Read a value of a particular endianness from memory.
int op_unload_native_code(uint64_t addr)