Eli Bendersky | 5262ad2 | 2012-03-13 08:33:15 +0000 | [diff] [blame] | 1 | //===-- IntelJITEventsWrapper.h - Intel JIT Events API Wrapper --*- C++ -*-===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
| 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) |
| 14 | // Amplifier XE 2011. |
| 15 | // |
| 16 | //===----------------------------------------------------------------------===// |
| 17 | |
| 18 | #ifndef INTEL_JIT_EVENTS_WRAPPER_H |
| 19 | #define INTEL_JIT_EVENTS_WRAPPER_H |
| 20 | |
Andrew Kaylor | 5808c7d | 2012-09-28 17:35:20 +0000 | [diff] [blame^] | 21 | #include "jitprofiling.h" |
Eli Bendersky | 5262ad2 | 2012-03-13 08:33:15 +0000 | [diff] [blame] | 22 | |
| 23 | namespace llvm { |
| 24 | |
| 25 | class IntelJITEventsWrapper { |
| 26 | // Function pointer types for testing implementation of Intel jitprofiling |
| 27 | // library |
| 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); |
| 34 | |
| 35 | NotifyEventPtr NotifyEventFunc; |
| 36 | RegisterCallbackExPtr RegisterCallbackExFunc; |
| 37 | IsProfilingActivePtr IsProfilingActiveFunc; |
| 38 | FinalizeThreadPtr FinalizeThreadFunc; |
| 39 | FinalizeProcessPtr FinalizeProcessFunc; |
| 40 | GetNewMethodIDPtr GetNewMethodIDFunc; |
| 41 | |
| 42 | public: |
| 43 | bool isAmplifierRunning() { |
| 44 | return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON; |
| 45 | } |
| 46 | |
| 47 | IntelJITEventsWrapper() |
| 48 | : NotifyEventFunc(::iJIT_NotifyEvent), |
| 49 | RegisterCallbackExFunc(::iJIT_RegisterCallbackEx), |
| 50 | IsProfilingActiveFunc(::iJIT_IsProfilingActive), |
| 51 | FinalizeThreadFunc(::FinalizeThread), |
| 52 | FinalizeProcessFunc(::FinalizeProcess), |
| 53 | GetNewMethodIDFunc(::iJIT_GetNewMethodID) { |
| 54 | } |
| 55 | |
| 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) { |
| 68 | } |
| 69 | |
| 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) { |
| 73 | if (!NotifyEventFunc) |
| 74 | return -1; |
| 75 | return NotifyEventFunc(EventType, EventSpecificData); |
| 76 | } |
| 77 | |
| 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); |
| 83 | } |
| 84 | |
| 85 | // Returns the current profiler mode |
| 86 | iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) { |
| 87 | if (!IsProfilingActiveFunc) |
| 88 | return iJIT_NOTHING_RUNNING; |
| 89 | return IsProfilingActiveFunc(); |
| 90 | } |
| 91 | |
| 92 | // Generates a locally unique method ID for use in code registration |
| 93 | unsigned int iJIT_GetNewMethodID(void) { |
| 94 | if (!GetNewMethodIDFunc) |
| 95 | return -1; |
| 96 | return GetNewMethodIDFunc(); |
| 97 | } |
| 98 | }; |
| 99 | |
| 100 | } //namespace llvm |
| 101 | |
| 102 | #endif //INTEL_JIT_EVENTS_WRAPPER_H |