1 //===-- IntelJITEventsWrapper.h - Intel JIT Events 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 //===----------------------------------------------------------------------===//
9 // This file defines a wrapper for the Intel JIT Events API. It allows for the
10 // implementation of the jitprofiling library to be swapped with an alternative
11 // implementation (for testing). To include this file, you must have the
12 // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
15 //===----------------------------------------------------------------------===//
17 #ifndef INTEL_JIT_EVENTS_WRAPPER_H
18 #define INTEL_JIT_EVENTS_WRAPPER_H
20 #include "jitprofiling.h"
31 class IntelJITEventsWrapper
{
32 // Function pointer types for testing implementation of Intel jitprofiling
34 typedef int (*NotifyEventPtr
)(iJIT_JVM_EVENT
, void*);
35 typedef int (*IttnotifyInfoPtr
)(IttEventType
, const char *, unsigned int);
36 typedef void (*RegisterCallbackExPtr
)(void *, iJIT_ModeChangedEx
);
37 typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr
)(void);
38 typedef void (*FinalizeThreadPtr
)(void);
39 typedef void (*FinalizeProcessPtr
)(void);
40 typedef unsigned int (*GetNewMethodIDPtr
)(void);
42 NotifyEventPtr NotifyEventFunc
;
43 IttnotifyInfoPtr IttnotifyInfoFunc
;
44 RegisterCallbackExPtr RegisterCallbackExFunc
;
45 IsProfilingActivePtr IsProfilingActiveFunc
;
46 GetNewMethodIDPtr GetNewMethodIDFunc
;
49 bool isAmplifierRunning() {
50 return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON
;
53 IntelJITEventsWrapper()
54 : NotifyEventFunc(::iJIT_NotifyEvent
), IttnotifyInfoFunc(0),
55 RegisterCallbackExFunc(::iJIT_RegisterCallbackEx
),
56 IsProfilingActiveFunc(::iJIT_IsProfilingActive
),
57 GetNewMethodIDFunc(::iJIT_GetNewMethodID
) {}
59 IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl
,
60 IttnotifyInfoPtr IttnotifyInfoImpl
,
61 RegisterCallbackExPtr RegisterCallbackExImpl
,
62 IsProfilingActivePtr IsProfilingActiveImpl
,
63 FinalizeThreadPtr FinalizeThreadImpl
,
64 FinalizeProcessPtr FinalizeProcessImpl
,
65 GetNewMethodIDPtr GetNewMethodIDImpl
)
66 : NotifyEventFunc(NotifyEventImpl
), IttnotifyInfoFunc(IttnotifyInfoImpl
),
67 RegisterCallbackExFunc(RegisterCallbackExImpl
),
68 IsProfilingActiveFunc(IsProfilingActiveImpl
),
69 GetNewMethodIDFunc(GetNewMethodIDImpl
) {}
71 // Sends an event announcing that a function has been emitted
72 // return values are event-specific. See Intel documentation for details.
73 int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType
, void *EventSpecificData
) {
76 return NotifyEventFunc(EventType
, EventSpecificData
);
79 int iJitIttNotifyInfo(IttEventType EventType
, const char *Name
,
81 if (!IttnotifyInfoFunc
)
83 return IttnotifyInfoFunc(EventType
, Name
, Size
);
86 // Registers a callback function to receive notice of profiling state changes
87 void iJIT_RegisterCallbackEx(void *UserData
,
88 iJIT_ModeChangedEx NewModeCallBackFuncEx
) {
89 if (RegisterCallbackExFunc
)
90 RegisterCallbackExFunc(UserData
, NewModeCallBackFuncEx
);
93 // Returns the current profiler mode
94 iJIT_IsProfilingActiveFlags
iJIT_IsProfilingActive(void) {
95 if (!IsProfilingActiveFunc
)
96 return iJIT_NOTHING_RUNNING
;
97 return IsProfilingActiveFunc();
100 // Generates a locally unique method ID for use in code registration
101 unsigned int iJIT_GetNewMethodID(void) {
102 if (!GetNewMethodIDFunc
)
104 return GetNewMethodIDFunc();
110 #endif //INTEL_JIT_EVENTS_WRAPPER_H