1 //===-- OProfileWrapper.h - OProfile JIT API Wrapper ------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 // This file defines a OProfileWrapper object that detects if the oprofile
9 // daemon is running, and provides wrappers for opagent functions used to
10 // communicate with the oprofile JIT interface. The dynamic library libopagent
11 // does not need to be linked directly as this object lazily loads the library
12 // when the first op_ function is called.
14 // See http://oprofile.sourceforge.net/doc/devel/jit-interface.html for the
15 // definition of the interface.
17 //===----------------------------------------------------------------------===//
19 #ifndef LLVM_EXECUTIONENGINE_OPROFILEWRAPPER_H
20 #define LLVM_EXECUTIONENGINE_OPROFILEWRAPPER_H
22 #include "llvm/Support/DataTypes.h"
28 class OProfileWrapper
{
29 typedef op_agent_t (*op_open_agent_ptr_t
)();
30 typedef int (*op_close_agent_ptr_t
)(op_agent_t
);
31 typedef int (*op_write_native_code_ptr_t
)(op_agent_t
,
36 typedef int (*op_write_debug_line_info_ptr_t
)(op_agent_t
,
39 struct debug_line_info
const*);
40 typedef int (*op_unload_native_code_ptr_t
)(op_agent_t
, uint64_t);
42 // Also used for op_minor_version function which has the same signature
43 typedef int (*op_major_version_ptr_t
)();
45 // This is not a part of the opagent API, but is useful nonetheless
46 typedef bool (*IsOProfileRunningPtrT
)();
50 op_open_agent_ptr_t OpenAgentFunc
;
51 op_close_agent_ptr_t CloseAgentFunc
;
52 op_write_native_code_ptr_t WriteNativeCodeFunc
;
53 op_write_debug_line_info_ptr_t WriteDebugLineInfoFunc
;
54 op_unload_native_code_ptr_t UnloadNativeCodeFunc
;
55 op_major_version_ptr_t MajorVersionFunc
;
56 op_major_version_ptr_t MinorVersionFunc
;
57 IsOProfileRunningPtrT IsOProfileRunningFunc
;
64 // For testing with a mock opagent implementation, skips the dynamic load and
65 // the function resolution.
66 OProfileWrapper(op_open_agent_ptr_t OpenAgentImpl
,
67 op_close_agent_ptr_t CloseAgentImpl
,
68 op_write_native_code_ptr_t WriteNativeCodeImpl
,
69 op_write_debug_line_info_ptr_t WriteDebugLineInfoImpl
,
70 op_unload_native_code_ptr_t UnloadNativeCodeImpl
,
71 op_major_version_ptr_t MajorVersionImpl
,
72 op_major_version_ptr_t MinorVersionImpl
,
73 IsOProfileRunningPtrT MockIsOProfileRunningImpl
= 0)
74 : OpenAgentFunc(OpenAgentImpl
),
75 CloseAgentFunc(CloseAgentImpl
),
76 WriteNativeCodeFunc(WriteNativeCodeImpl
),
77 WriteDebugLineInfoFunc(WriteDebugLineInfoImpl
),
78 UnloadNativeCodeFunc(UnloadNativeCodeImpl
),
79 MajorVersionFunc(MajorVersionImpl
),
80 MinorVersionFunc(MinorVersionImpl
),
81 IsOProfileRunningFunc(MockIsOProfileRunningImpl
),
86 // Calls op_open_agent in the oprofile JIT library and saves the returned
87 // op_agent_t handle internally so it can be used when calling all the other
88 // op_* functions. Callers of this class do not need to keep track of
89 // op_agent_t objects.
93 int op_write_native_code(const char* name
,
96 const unsigned int size
);
97 int op_write_debug_line_info(void const* code
,
99 struct debug_line_info
const* info
);
100 int op_unload_native_code(uint64_t addr
);
101 int op_major_version();
102 int op_minor_version();
104 // Returns true if the oprofiled process is running, the opagent library is
105 // loaded and a connection to the agent has been established, and false
107 bool isAgentAvailable();
110 // Loads the libopagent library and initializes this wrapper if the oprofile
114 // Searches /proc for the oprofile daemon and returns true if the process if
115 // found, or false otherwise.
116 bool checkForOProfileProcEntry();
118 bool isOProfileRunning();
123 #endif // LLVM_EXECUTIONENGINE_OPROFILEWRAPPER_H