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
GetNewMethodIDPtr GetNewMethodIDFunc;
41
bool isAmplifierRunning() {
42
return iJIT_IsProfilingActive() == iJIT_SAMPLING_ON;
45
IntelJITEventsWrapper()
46
: NotifyEventFunc(::iJIT_NotifyEvent),
47
RegisterCallbackExFunc(::iJIT_RegisterCallbackEx),
48
IsProfilingActiveFunc(::iJIT_IsProfilingActive),
49
GetNewMethodIDFunc(::iJIT_GetNewMethodID) {
52
IntelJITEventsWrapper(NotifyEventPtr NotifyEventImpl,
53
RegisterCallbackExPtr RegisterCallbackExImpl,
54
IsProfilingActivePtr IsProfilingActiveImpl,
55
FinalizeThreadPtr FinalizeThreadImpl,
56
FinalizeProcessPtr FinalizeProcessImpl,
57
GetNewMethodIDPtr GetNewMethodIDImpl)
58
: NotifyEventFunc(NotifyEventImpl),
59
RegisterCallbackExFunc(RegisterCallbackExImpl),
60
IsProfilingActiveFunc(IsProfilingActiveImpl),
61
GetNewMethodIDFunc(GetNewMethodIDImpl) {
64
// Sends an event announcing that a function has been emitted
65
// return values are event-specific. See Intel documentation for details.
66
int iJIT_NotifyEvent(iJIT_JVM_EVENT EventType, void *EventSpecificData) {
69
return NotifyEventFunc(EventType, EventSpecificData);
72
// Registers a callback function to receive notice of profiling state changes
73
void iJIT_RegisterCallbackEx(void *UserData,
74
iJIT_ModeChangedEx NewModeCallBackFuncEx) {
75
if (RegisterCallbackExFunc)
76
RegisterCallbackExFunc(UserData, NewModeCallBackFuncEx);
79
// Returns the current profiler mode
80
iJIT_IsProfilingActiveFlags iJIT_IsProfilingActive(void) {
81
if (!IsProfilingActiveFunc)
82
return iJIT_NOTHING_RUNNING;
83
return IsProfilingActiveFunc();
86
// Generates a locally unique method ID for use in code registration
87
unsigned int iJIT_GetNewMethodID(void) {
88
if (!GetNewMethodIDFunc)
90
return GetNewMethodIDFunc();
96
#endif //INTEL_JIT_EVENTS_WRAPPER_H