mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
Bug 873522 - Perf integration for IonMonkey r=dvander
This commit is contained in:
parent
0f3d629dfa
commit
5121b27fe0
@ -215,6 +215,7 @@ CPPSRCS += MIR.cpp \
|
||||
IonMacroAssembler.cpp \
|
||||
IonSpewer.cpp \
|
||||
JSONSpewer.cpp \
|
||||
PerfSpewer.cpp \
|
||||
LICM.cpp \
|
||||
LinearScan.cpp \
|
||||
LIR.cpp \
|
||||
|
@ -3708,6 +3708,18 @@ if test -n "$JS_GC_ZEAL" -o -n "$MOZ_DEBUG"; then
|
||||
AC_DEFINE(JS_GC_ZEAL)
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
dnl = Enable perf logging for ion.
|
||||
dnl = Perf logging is OFF by default
|
||||
dnl ========================================================
|
||||
MOZ_ARG_ENABLE_BOOL(perf,
|
||||
[ --enable-perf Enable Linux perf integration],
|
||||
JS_ION_PERF=1,
|
||||
JS_ION_PERF= )
|
||||
if test -n "$JS_ION_PERF"; then
|
||||
AC_DEFINE(JS_ION_PERF)
|
||||
fi
|
||||
|
||||
dnl ========================================================
|
||||
dnl JS opt-mode assertions and minidump instrumentation
|
||||
dnl ========================================================
|
||||
|
@ -17,6 +17,7 @@ using namespace js;
|
||||
using namespace js::frontend;
|
||||
using namespace mozilla;
|
||||
|
||||
#include "ion/PerfSpewer.h"
|
||||
#include "ion/CodeGenerator.h"
|
||||
#include "ion/MIR.h"
|
||||
#include "ion/MIRGraph.h"
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "mozilla/DebugOnly.h"
|
||||
#include "mozilla/Util.h"
|
||||
|
||||
#include "PerfSpewer.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "IonLinker.h"
|
||||
#include "IonSpewer.h"
|
||||
@ -2501,6 +2502,9 @@ CodeGenerator::generateBody()
|
||||
return false;
|
||||
}
|
||||
|
||||
if (PerfBlockEnabled())
|
||||
perfSpewer_.startBasicBlock(current->mir(), masm);
|
||||
|
||||
for (; iter != current->end(); iter++) {
|
||||
IonSpew(IonSpew_Codegen, "instruction %s", iter->opName());
|
||||
|
||||
@ -2520,6 +2524,9 @@ CodeGenerator::generateBody()
|
||||
}
|
||||
if (masm.oom())
|
||||
return false;
|
||||
|
||||
if (PerfBlockEnabled())
|
||||
perfSpewer_.endBasicBlock(masm);
|
||||
}
|
||||
|
||||
JS_ASSERT(pushedArgumentSlots_.empty());
|
||||
@ -5257,6 +5264,9 @@ CodeGenerator::link()
|
||||
|
||||
ionScript->setDeoptTable(deoptTable_);
|
||||
|
||||
if (PerfEnabled())
|
||||
perfSpewer_.writeProfile(script, code, masm);
|
||||
|
||||
// for generating inline caches during the execution.
|
||||
if (runtimeData_.length())
|
||||
ionScript->copyRuntimeData(&runtimeData_[0]);
|
||||
|
@ -336,6 +336,8 @@ class CodeGenerator : public CodeGeneratorSpecific
|
||||
|
||||
// Script counts created when compiling code with no associated JSScript.
|
||||
IonScriptCounts *unassociatedScriptCounts_;
|
||||
|
||||
PerfSpewer perfSpewer_;
|
||||
};
|
||||
|
||||
} // namespace ion
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "vm/ThreadPool.h"
|
||||
#include "vm/ForkJoin.h"
|
||||
#include "IonCompartment.h"
|
||||
#include "PerfSpewer.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "jsworkers.h"
|
||||
#include "BacktrackingAllocator.h"
|
||||
@ -158,6 +159,7 @@ ion::InitializeIon()
|
||||
}
|
||||
#endif
|
||||
CheckLogging();
|
||||
CheckPerf();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -494,6 +496,11 @@ IonCode::finalize(FreeOp *fop)
|
||||
// Buffer can be freed at any time hereafter. Catch use-after-free bugs.
|
||||
JS_POISON(code_, JS_FREE_PATTERN, bufferSize_);
|
||||
|
||||
// Horrible hack: if we are using perf integration, we don't
|
||||
// want to reuse code addresses, so we just leak the memory instead.
|
||||
if (PerfEnabled())
|
||||
return;
|
||||
|
||||
// Code buffers are stored inside JSC pools.
|
||||
// Pools are refcounted. Releasing the pool may free it.
|
||||
if (pool_)
|
||||
|
@ -6,6 +6,7 @@
|
||||
|
||||
#include "mozilla/DebugOnly.h"
|
||||
|
||||
#include "PerfSpewer.h"
|
||||
#include "CodeGenerator.h"
|
||||
#include "Ion.h"
|
||||
#include "IonCaches.h"
|
||||
|
184
js/src/ion/PerfSpewer.cpp
Normal file
184
js/src/ion/PerfSpewer.cpp
Normal file
@ -0,0 +1,184 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include <stdarg.h>
|
||||
#if defined(__linux__)
|
||||
# include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "PerfSpewer.h"
|
||||
#include "IonSpewer.h"
|
||||
#include "LIR.h"
|
||||
#include "MIR.h"
|
||||
#include "MIRGraph.h"
|
||||
#include "LinearScan.h"
|
||||
#include "RangeAnalysis.h"
|
||||
|
||||
using namespace js;
|
||||
using namespace js::ion;
|
||||
|
||||
#define PERF_MODE_NONE 1
|
||||
#define PERF_MODE_FUNC 2
|
||||
#define PERF_MODE_BLOCK 3
|
||||
|
||||
static bool PerfChecked = false;
|
||||
static uint32_t PerfMode = 0;
|
||||
|
||||
#ifdef JS_ION_PERF
|
||||
|
||||
void
|
||||
js::ion::CheckPerf() {
|
||||
const char *env = getenv("IONPERF");
|
||||
if (env == NULL) {
|
||||
PerfMode = PERF_MODE_NONE;
|
||||
} else if (!strcmp(env, "none")) {
|
||||
PerfMode = PERF_MODE_NONE;
|
||||
} else if (!strcmp(env, "block")) {
|
||||
PerfMode = PERF_MODE_BLOCK;
|
||||
} else if (!strcmp(env, "func")) {
|
||||
PerfMode = PERF_MODE_FUNC;
|
||||
} else {
|
||||
fprintf(stderr, "Use IONPERF=func to record at basic block granularity\n");
|
||||
fprintf(stderr, "Use IONPERF=block to record at basic block granularity\n");
|
||||
fprintf(stderr, "\n");
|
||||
fprintf(stderr, "Be advised that using IONPERF will cause all scripts\n");
|
||||
fprintf(stderr, "to be leaked.\n");
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
js::ion::PerfBlockEnabled() {
|
||||
JS_ASSERT(PerfMode);
|
||||
return PerfMode == PERF_MODE_BLOCK;
|
||||
}
|
||||
|
||||
bool
|
||||
js::ion::PerfFuncEnabled() {
|
||||
JS_ASSERT(PerfMode);
|
||||
return PerfMode == PERF_MODE_FUNC;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
uint32_t PerfSpewer::nextFunctionIndex = 0;
|
||||
|
||||
PerfSpewer::PerfSpewer()
|
||||
: fp_(NULL)
|
||||
{
|
||||
if (!PerfEnabled())
|
||||
return;
|
||||
|
||||
# if defined(__linux__)
|
||||
// perf expects its data to be in a file /tmp/perf-PID.map
|
||||
const ssize_t bufferSize = 256;
|
||||
char filenameBuffer[bufferSize];
|
||||
if (snprintf(filenameBuffer, bufferSize,
|
||||
"/tmp/perf-%d.map",
|
||||
getpid()) >= bufferSize)
|
||||
return;
|
||||
|
||||
fp_ = fopen(filenameBuffer, "a");
|
||||
if (!fp_)
|
||||
return;
|
||||
# else
|
||||
fprintf(stderr, "Warning: PerfEnabled, but not running on linux\n");
|
||||
# endif
|
||||
}
|
||||
|
||||
PerfSpewer::~PerfSpewer()
|
||||
{
|
||||
if (fp_)
|
||||
fclose(fp_);
|
||||
}
|
||||
|
||||
bool
|
||||
PerfSpewer::startBasicBlock(MBasicBlock *blk,
|
||||
MacroAssembler &masm)
|
||||
{
|
||||
if (!PerfBlockEnabled() || !fp_)
|
||||
return true;
|
||||
|
||||
const char *filename = blk->info().script()->filename();
|
||||
unsigned lineNumber, columnNumber;
|
||||
if (blk->pc()) {
|
||||
lineNumber = PCToLineNumber(blk->info().script(),
|
||||
blk->pc(),
|
||||
&columnNumber);
|
||||
} else {
|
||||
lineNumber = 0;
|
||||
columnNumber = 0;
|
||||
}
|
||||
Record r(filename, lineNumber, columnNumber, blk->id());
|
||||
masm.bind(&r.start);
|
||||
return basicBlocks_.append(r);
|
||||
}
|
||||
|
||||
bool
|
||||
PerfSpewer::endBasicBlock(MacroAssembler &masm)
|
||||
{
|
||||
masm.bind(&basicBlocks_[basicBlocks_.length() - 1].end);
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
PerfSpewer::writeProfile(JSScript *script,
|
||||
IonCode *code,
|
||||
MacroAssembler &masm)
|
||||
{
|
||||
if (!fp_)
|
||||
return;
|
||||
|
||||
uint32_t thisFunctionIndex = nextFunctionIndex++;
|
||||
|
||||
if (PerfFuncEnabled()) {
|
||||
fprintf(fp_,
|
||||
"%lx %lx %s:%d: Func%02d\n",
|
||||
(unsigned long) code->raw(),
|
||||
(unsigned long) code->instructionsSize(),
|
||||
script->filename(),
|
||||
script->lineno,
|
||||
thisFunctionIndex);
|
||||
} else if (PerfBlockEnabled()) {
|
||||
unsigned long funcStart = (unsigned long) code->raw();
|
||||
unsigned long funcEnd = funcStart + code->instructionsSize();
|
||||
|
||||
unsigned long cur = funcStart;
|
||||
for (uint32_t i = 0; i < basicBlocks_.length(); i++) {
|
||||
Record &r = basicBlocks_[i];
|
||||
|
||||
unsigned long blockStart = funcStart + masm.actualOffset(r.start.offset());
|
||||
unsigned long blockEnd = funcStart + masm.actualOffset(r.end.offset());
|
||||
|
||||
JS_ASSERT(cur <= blockStart);
|
||||
if (cur < blockStart) {
|
||||
fprintf(fp_,
|
||||
"%lx %lx %s:%d: Func%02d-Block?\n",
|
||||
cur, blockStart - cur,
|
||||
script->filename(), script->lineno,
|
||||
thisFunctionIndex);
|
||||
}
|
||||
cur = blockEnd;
|
||||
|
||||
fprintf(fp_,
|
||||
"%lx %lx %s:%d:%d: Func%02d-Block%d\n",
|
||||
blockStart, blockEnd - blockStart,
|
||||
r.filename, r.lineNumber, r.columnNumber,
|
||||
thisFunctionIndex, r.id);
|
||||
}
|
||||
|
||||
// Any stuff after the basic blocks is presumably OOL code,
|
||||
// which I do not currently categorize.
|
||||
JS_ASSERT(cur <= funcEnd);
|
||||
if (cur < funcEnd) {
|
||||
fprintf(fp_,
|
||||
"%lx %lx %s:%d: Func%02d-OOL\n",
|
||||
cur, funcEnd - cur,
|
||||
script->filename(), script->lineno,
|
||||
thisFunctionIndex);
|
||||
}
|
||||
}
|
||||
}
|
79
js/src/ion/PerfSpewer.h
Normal file
79
js/src/ion/PerfSpewer.h
Normal file
@ -0,0 +1,79 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
* vim: set ts=8 sts=4 et sw=4 tw=99:
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#ifndef js_ion_perfspewer_h__
|
||||
#define js_ion_perfspewer_h__
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "jsscript.h"
|
||||
#include "IonMacroAssembler.h"
|
||||
#include "js/RootingAPI.h"
|
||||
|
||||
class JSScript;
|
||||
|
||||
namespace js {
|
||||
namespace ion {
|
||||
|
||||
class MBasicBlock;
|
||||
class MacroAssembler;
|
||||
|
||||
#ifdef JS_ION_PERF
|
||||
void CheckPerf();
|
||||
bool PerfBlockEnabled();
|
||||
bool PerfFuncEnabled();
|
||||
static inline bool PerfEnabled() {
|
||||
return PerfBlockEnabled() || PerfFuncEnabled();
|
||||
}
|
||||
#else
|
||||
static inline void CheckPerf() {}
|
||||
static inline bool PerfBlockEnabled() { return false; }
|
||||
static inline bool PerfFuncEnabled() { return false; }
|
||||
static inline bool PerfEnabled() { return false; }
|
||||
#endif
|
||||
|
||||
class PerfSpewer
|
||||
{
|
||||
private:
|
||||
static uint32_t nextFunctionIndex;
|
||||
|
||||
struct Record {
|
||||
const char *filename;
|
||||
unsigned lineNumber;
|
||||
unsigned columnNumber;
|
||||
uint32_t id;
|
||||
Label start, end;
|
||||
|
||||
Record(const char *filename,
|
||||
unsigned lineNumber,
|
||||
unsigned columnNumber,
|
||||
uint32_t id)
|
||||
: filename(filename), lineNumber(lineNumber),
|
||||
columnNumber(columnNumber), id(id)
|
||||
{}
|
||||
};
|
||||
|
||||
FILE *fp_;
|
||||
Vector<Record, 1, SystemAllocPolicy> basicBlocks_;
|
||||
|
||||
public:
|
||||
PerfSpewer();
|
||||
~PerfSpewer();
|
||||
|
||||
bool init(const char *path);
|
||||
|
||||
bool startBasicBlock(MBasicBlock *blk, MacroAssembler &masm);
|
||||
bool endBasicBlock(MacroAssembler &masm);
|
||||
void writeProfile(JSScript *script,
|
||||
IonCode *code,
|
||||
MacroAssembler &masm);
|
||||
};
|
||||
|
||||
} // namespace ion
|
||||
} // namespace js
|
||||
|
||||
#endif // js_ion_perfspewer_h__
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "jsnum.h"
|
||||
|
||||
#include "CodeGenerator-arm.h"
|
||||
#include "ion/PerfSpewer.h"
|
||||
#include "ion/CodeGenerator.h"
|
||||
#include "ion/IonCompartment.h"
|
||||
#include "ion/IonFrames.h"
|
||||
|
Loading…
Reference in New Issue
Block a user