Bug 861440 - Add VTune Instrumentation to OdinMonkey. r=luke

This commit is contained in:
Sean Stangl 2013-04-15 14:30:12 -07:00
parent d4f55235aa
commit be79970657
6 changed files with 136 additions and 4 deletions

View File

@ -705,10 +705,13 @@ NSPR_STATIC_PATH = $(DIST)/lib
endif
ifdef MOZ_VTUNE
#CXXFLAGS += -IC:/Program\ Files/Intel/VTune/Analyzer/Include
#EXTRA_DSO_LDOPTS += C:/Program\ Files/Intel/VTune/Analyzer/Lib/VtuneApi.lib
#LIBS += C:/Program\ Files/Intel/VTune/Analyzer/Lib/VtuneApi.lib
endif
ifeq ($(OS_ARCH), WINNT)
EXTRA_DSO_LDOPTS += $(VTUNE_LIBRARIES)
LIBS += $(VTUNE_LIBRARIES)
else
SHARED_LIBRARY_LIBS += $(VTUNE_LIBRARIES)
endif # WINNT
endif # MOZ_VTUNE
ifdef MOZ_ETW
# This will get the ETW provider resources into the library mozjs.dll

View File

@ -3708,6 +3708,25 @@ MOZ_ARG_ENABLE_BOOL(vtune,
MOZ_VTUNE=1,
MOZ_VTUNE= )
if test -n "$MOZ_VTUNE"; then
if test -z "$VTUNE_AMPLIFIER_XE_2013_DIR"; then
echo "Error: VTUNE_AMPLIFIER_XE_2013_DIR undefined."
exit 1
fi
VTUNE_DIR=`echo "$VTUNE_AMPLIFIER_XE_2013_DIR" | sed 's,\\\,/,g'`
VTUNE_DIR=`echo "$VTUNE_DIR" | sed 's,(,\\\(,g'`
VTUNE_DIR=`echo "$VTUNE_DIR" | sed 's,),\\\),g'`
VTUNE_DIR=`echo "$VTUNE_DIR" | sed 's, ,\\\ ,g'`
VTUNE_LIB=lib32
if test "x86_64" = "$TARGET_CPU"; then
VTUNE_LIB=lib64
fi
VTUNE_LIBRARIES="${VTUNE_DIR}/${VTUNE_LIB}/${LIB_PREFIX}jitprofiling.${LIB_SUFFIX}"
AC_SUBST(VTUNE_LIBRARIES)
CXXFLAGS="$CXXFLAGS -I${VTUNE_DIR}/include"
MOZ_PROFILING=1
AC_DEFINE(MOZ_VTUNE)
fi

View File

@ -23,6 +23,10 @@ using namespace mozilla;
using namespace js::ion;
#ifdef MOZ_VTUNE
# include "jitprofiling.h"
#endif
#ifdef JS_ASMJS
/*****************************************************************************/
@ -1360,6 +1364,14 @@ class ModuleCompiler
Move(argCoercions), returnType);
}
#ifdef MOZ_VTUNE
bool trackProfiledFunction(const Func &func, unsigned endCodeOffset) {
JSAtom *name = FunctionName(func.fn());
unsigned startCodeOffset = func.codeLabel()->offset();
return module_->trackProfiledFunction(name, startCodeOffset, endCodeOffset);
}
#endif
void setFirstPassComplete() {
JS_ASSERT(currentPass_ == 1);
currentPass_ = 2;
@ -4589,6 +4601,13 @@ GenerateAsmJSCode(ModuleCompiler &m, ModuleCompiler::Func &func,
return false;
}
#ifdef MOZ_VTUNE
if (iJIT_IsProfilingActive() == iJIT_SAMPLING_ON) {
if (!m.trackProfiledFunction(func, m.masm().size()))
return false;
}
#endif
// A single MacroAssembler is reused for all function compilations so
// that there is a single linear code segment for each module. To avoid
// spiking memory, a LifoAllocScope in the caller frees all MIR/LIR

View File

@ -15,6 +15,10 @@
#include "Ion.h"
#ifdef MOZ_VTUNE
# include "jitprofiling.h"
#endif
using namespace js;
using namespace js::ion;
using namespace mozilla;
@ -423,6 +427,46 @@ HandleDynamicLinkFailure(JSContext *cx, CallArgs args, AsmJSModule &module, Hand
return true;
}
#ifdef MOZ_VTUNE
static bool
SendFunctionsToVTune(JSContext *cx, AsmJSModule &module)
{
uint8_t *base = module.functionCode();
for (unsigned i = 0; i < module.numProfiledFunctions(); i++) {
const AsmJSModule::ProfiledFunction &func = module.profiledFunction(i);
uint8_t *start = base + func.startCodeOffset;
uint8_t *end = base + func.endCodeOffset;
JS_ASSERT(end >= start);
unsigned method_id = iJIT_GetNewMethodID();
if (method_id == 0)
return false;
JSAutoByteString bytes;
const char *method_name = js_AtomToPrintableString(cx, func.name, &bytes);
if (!method_name)
return false;
iJIT_Method_Load method;
method.method_id = method_id;
method.method_name = const_cast<char *>(method_name);
method.method_load_address = (void *)start;
method.method_size = unsigned(end - start);
method.line_number_size = 0;
method.line_number_table = NULL;
method.class_id = 0;
method.class_file_name = NULL;
method.source_file_name = NULL;
iJIT_NotifyEvent(iJVM_EVENT_TYPE_METHOD_LOAD_FINISHED, (void *)&method);
}
return true;
}
#endif
JSBool
js::LinkAsmJS(JSContext *cx, unsigned argc, JS::Value *vp)
{
@ -438,6 +482,11 @@ js::LinkAsmJS(JSContext *cx, unsigned argc, JS::Value *vp)
return HandleDynamicLinkFailure(cx, args, module, name);
}
#if defined(MOZ_VTUNE)
if (!SendFunctionsToVTune(cx, module))
return false;
#endif
if (module.numExportedFunctions() == 1) {
const AsmJSModule::ExportedFunction &func = module.exportedFunction(0);
if (!func.maybeFieldName()) {

View File

@ -264,6 +264,20 @@ class AsmJSModule
}
};
#if defined(MOZ_VTUNE)
// Function information to add to the VTune JIT profiler following linking.
struct ProfiledFunction
{
JSAtom *name;
unsigned startCodeOffset;
unsigned endCodeOffset;
ProfiledFunction(JSAtom *name, unsigned start, unsigned end)
: name(name), startCodeOffset(start), endCodeOffset(end)
{ }
};
#endif
// If linking fails, we recompile the function as if it's ordinary JS.
// This struct holds the data required to do this.
struct PostLinkFailureInfo
@ -306,6 +320,9 @@ class AsmJSModule
typedef Vector<ion::AsmJSBoundsCheck, 0, SystemAllocPolicy> BoundsCheckVector;
#endif
typedef Vector<ion::IonScriptCounts *, 0, SystemAllocPolicy> FunctionCountsVector;
#if defined(MOZ_VTUNE)
typedef Vector<ProfiledFunction, 0, SystemAllocPolicy> ProfiledFunctionVector;
#endif
GlobalVector globals_;
ExitVector exits_;
@ -314,6 +331,10 @@ class AsmJSModule
#if defined(JS_CPU_ARM)
BoundsCheckVector boundsChecks_;
#endif
#if defined(MOZ_VTUNE)
ProfiledFunctionVector profiledFunctions_;
#endif
uint32_t numGlobalVars_;
uint32_t numFFIs_;
uint32_t numFuncPtrTableElems_;
@ -449,6 +470,18 @@ class AsmJSModule
ExportedFunction &exportedFunction(unsigned i) {
return exports_[i];
}
#ifdef MOZ_VTUNE
bool trackProfiledFunction(JSAtom *name, unsigned startCodeOffset, unsigned endCodeOffset) {
ProfiledFunction func(name, startCodeOffset, endCodeOffset);
return profiledFunctions_.append(func);
}
unsigned numProfiledFunctions() const {
return profiledFunctions_.length();
}
const ProfiledFunction &profiledFunction(unsigned i) const {
return profiledFunctions_[i];
}
#endif
bool hasArrayView() const {
return hasArrayView_;
}

View File

@ -59,6 +59,15 @@ SHELL_INSTALL_AUTOLOAD_DEST := $(DIST)/bin
include $(topsrcdir)/config/rules.mk
ifdef MOZ_VTUNE
ifeq ($(OS_ARCH), WINNT)
EXTRA_DSO_LDOPTS += $(VTUNE_LIBRARIES)
LIBS += $(VTUNE_LIBRARIES)
else
SHARED_LIBRARY_LIBS += $(VTUNE_LIBRARIES)
endif # WINNT
endif # MOZ_VTUNE
# People expect the js shell to wind up in the top-level JS dir.
libs::
$(INSTALL) $(IFLAGS2) $(PROGRAM) $(DEPTH)