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"
24 class IntelJITEventsWrapper
{
25 // Function pointer types for testing implementation of Intel jitprofiling
27 typedef int (*NotifyEventPtr
)(iJIT_JVM_EVENT
, void*);
28 typedef void (*RegisterCallbackExPtr
)(void *, iJIT_ModeChangedEx
);
29 typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr
)(void);
30 typedef void (*FinalizeThreadPtr
)(void);
31 typedef void (*FinalizeProcessPtr
)(void);
32 typedef unsigned int (*GetNewMethodIDPtr
)(void);
34 NotifyEventPtr NotifyEventFunc
;
35 RegisterCallbackExPtr RegisterCallbackExFunc
;
36 IsProfilingActivePtr IsProfilingActiveFunc
;
37 GetNewMethodIDPtr GetNewMethodIDFunc
;
40 bool isAmplifierRunning() {
41 return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON
;
44 IntelJITEventsWrapper()
45 : NotifyEventFunc(::iJIT_NotifyEvent
),
46 RegisterCallbackExFunc(::iJIT_RegisterCallbackEx
),
47 IsProfilingActiveFunc(::iJIT_IsProfilingActive
),
48 GetNewMethodIDFunc(::iJIT_GetNewMethodID
) {
51 IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl
,
52 RegisterCallbackExPtr RegisterCallbackExImpl
,
53 IsProfilingActivePtr IsProfilingActiveImpl
,
54 FinalizeThreadPtr FinalizeThreadImpl
,
55 FinalizeProcessPtr FinalizeProcessImpl
,
56 GetNewMethodIDPtr GetNewMethodIDImpl
)
57 : NotifyEventFunc(NotifyEventImpl
),
58 RegisterCallbackExFunc(RegisterCallbackExImpl
),
59 IsProfilingActiveFunc(IsProfilingActiveImpl
),
60 GetNewMethodIDFunc(GetNewMethodIDImpl
) {
63 // Sends an event announcing that a function has been emitted
64 // return values are event-specific. See Intel documentation for details.
65 int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType
, void *EventSpecificData
) {
68 return NotifyEventFunc(EventType
, EventSpecificData
);
71 // Registers a callback function to receive notice of profiling state changes
72 void iJIT_RegisterCallbackEx(void *UserData
,
73 iJIT_ModeChangedEx NewModeCallBackFuncEx
) {
74 if (RegisterCallbackExFunc
)
75 RegisterCallbackExFunc(UserData
, NewModeCallBackFuncEx
);
78 // Returns the current profiler mode
79 iJIT_IsProfilingActiveFlags
iJIT_IsProfilingActive(void) {
80 if (!IsProfilingActiveFunc
)
81 return iJIT_NOTHING_RUNNING
;
82 return IsProfilingActiveFunc();
85 // Generates a locally unique method ID for use in code registration
86 unsigned int iJIT_GetNewMethodID(void) {
87 if (!GetNewMethodIDFunc
)
89 return GetNewMethodIDFunc();
95 #endif //INTEL_JIT_EVENTS_WRAPPER_H