michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: * This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "vm/Probes-inl.h" michael@0: michael@0: #include "jscntxt.h" michael@0: michael@0: #ifdef INCLUDE_MOZILLA_DTRACE michael@0: #include "jsscriptinlines.h" michael@0: #endif michael@0: michael@0: #define TYPEOF(cx,v) (JSVAL_IS_NULL(v) ? JSTYPE_NULL : JS_TypeOfValue(cx,v)) michael@0: michael@0: using namespace js; michael@0: michael@0: const char probes::nullName[] = "(null)"; michael@0: const char probes::anonymousName[] = "(anonymous)"; michael@0: michael@0: bool probes::ProfilingActive = true; michael@0: michael@0: probes::JITReportGranularity michael@0: probes::JITGranularityRequested(JSContext *cx) michael@0: { michael@0: if (cx->runtime()->spsProfiler.enabled()) michael@0: return JITREPORT_GRANULARITY_LINE; michael@0: return JITREPORT_GRANULARITY_NONE; michael@0: } michael@0: michael@0: /* ICs are unregistered in a batch */ michael@0: void michael@0: probes::DiscardExecutableRegion(void *start, size_t size) michael@0: { michael@0: /* michael@0: * Not needed for SPS because ICs are disposed of when the normal JITChunk michael@0: * is disposed of michael@0: */ michael@0: } michael@0: michael@0: #ifdef INCLUDE_MOZILLA_DTRACE michael@0: static const char * michael@0: ScriptFilename(const JSScript *script) michael@0: { michael@0: if (!script) michael@0: return probes::nullName; michael@0: if (!script->filename()) michael@0: return probes::anonymousName; michael@0: return script->filename(); michael@0: } michael@0: michael@0: static const char * michael@0: FunctionName(JSContext *cx, JSFunction *fun, JSAutoByteString* bytes) michael@0: { michael@0: if (!fun) michael@0: return probes::nullName; michael@0: if (!fun->displayAtom()) michael@0: return probes::anonymousName; michael@0: return bytes->encodeLatin1(cx, fun->displayAtom()) ? bytes->ptr() : probes::nullName; michael@0: } michael@0: michael@0: /* michael@0: * These functions call the DTrace macros for the JavaScript USDT probes. michael@0: * Originally this code was inlined in the JavaScript code; however since michael@0: * a number of operations are called, these have been placed into functions michael@0: * to reduce any negative compiler optimization effect that the addition of michael@0: * a number of usually unused lines of code would cause. michael@0: */ michael@0: void michael@0: probes::DTraceEnterJSFun(JSContext *cx, JSFunction *fun, JSScript *script) michael@0: { michael@0: JSAutoByteString funNameBytes; michael@0: JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script), probes::nullName, michael@0: FunctionName(cx, fun, &funNameBytes)); michael@0: } michael@0: michael@0: void michael@0: probes::DTraceExitJSFun(JSContext *cx, JSFunction *fun, JSScript *script) michael@0: { michael@0: JSAutoByteString funNameBytes; michael@0: JAVASCRIPT_FUNCTION_RETURN(ScriptFilename(script), probes::nullName, michael@0: FunctionName(cx, fun, &funNameBytes)); michael@0: } michael@0: #endif