1 //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file defines a wrapper for the Intel JIT Events API. It allows for the
11 // implementation of the jitprofiling library to be swapped with an alternative
12 // implementation (for testing). To include this file, you must have the
13 // jitprofiling.h header available; it is available in Intel(R) VTune(TM)
16 //===----------------------------------------------------------------------===//
18 #ifndef INTEL_JIT_EVENTS_WRAPPER_H
19 #define INTEL_JIT_EVENTS_WRAPPER_H
21 #include <jitprofiling.h>
25 class IntelJITEventsWrapper {
26 // Function pointer types for testing implementation of Intel jitprofiling
28 typedef int (*NotifyEventPtr)(iJIT_JVM_EVENT, void*);
29 typedef void (*RegisterCallbackExPtr)(void *, iJIT_ModeChangedEx );
30 typedef iJIT_IsProfilingActiveFlags (*IsProfilingActivePtr)(void);
31 typedef void (*FinalizeThreadPtr)(void);
32 typedef void (*FinalizeProcessPtr)(void);
33 typedef unsigned int (*GetNewMethodIDPtr)(void);
35 NotifyEventPtr NotifyEventFunc;
36 RegisterCallbackExPtr RegisterCallbackExFunc;
37 IsProfilingActivePtr IsProfilingActiveFunc;
38 FinalizeThreadPtr FinalizeThreadFunc;
39 FinalizeProcessPtr FinalizeProcessFunc;
40 GetNewMethodIDPtr GetNewMethodIDFunc;
43 bool isAmplifierRunning() {
44 return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;
47 IntelJITEventsWrapper()
48 : NotifyEventFunc(::iJIT_NotifyEvent),
49 RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
50 IsProfilingActiveFunc(::iJIT_IsProfilingActive),
51 FinalizeThreadFunc(::FinalizeThread),
52 FinalizeProcessFunc(::FinalizeProcess),
53 GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
56 IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
57 RegisterCallbackExPtr RegisterCallbackExImpl,
58 IsProfilingActivePtr IsProfilingActiveImpl,
59 FinalizeThreadPtr FinalizeThreadImpl,
60 FinalizeProcessPtr FinalizeProcessImpl,
61 GetNewMethodIDPtr GetNewMethodIDImpl)
62 : NotifyEventFunc(NotifyEventImpl),
63 RegisterCallbackExFunc(RegisterCallbackExImpl),
64 IsProfilingActiveFunc(IsProfilingActiveImpl),
65 FinalizeThreadFunc(FinalizeThreadImpl),
66 FinalizeProcessFunc(FinalizeProcessImpl),
67 GetNewMethodIDFunc(GetNewMethodIDImpl) {
70 // Sends an event anncouncing that a function has been emitted
71 // return values are event-specific. See Intel documentation for details.
72 int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
75 return NotifyEventFunc(EventType, EventSpecificData);
78 // Registers a callback function to receive notice of profiling state changes
79 void iJIT_RegisterCallbackEx(void *UserData,
80 iJIT_ModeChangedEx NewModeCallBackFuncEx) {
81 if (RegisterCallbackExFunc)
82 RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
85 // Returns the current profiler mode
86 iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {
87 if (!IsProfilingActiveFunc)
88 return iJIT_NOTHING_RUNNING;
89 return IsProfilingActiveFunc();
92 // Generates a locally unique method ID for use in code registration
93 unsigned int iJIT_GetNewMethodID(void) {
94 if (!GetNewMethodIDFunc)
96 return GetNewMethodIDFunc();
102 #endif //INTEL_JIT_EVENTS_WRAPPER_H