js/src/vm/Probes.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/vm/Probes.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + * This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#include "vm/Probes-inl.h"
    1.11 +
    1.12 +#include "jscntxt.h"
    1.13 +
    1.14 +#ifdef INCLUDE_MOZILLA_DTRACE
    1.15 +#include "jsscriptinlines.h"
    1.16 +#endif
    1.17 +
    1.18 +#define TYPEOF(cx,v)    (JSVAL_IS_NULL(v) ? JSTYPE_NULL : JS_TypeOfValue(cx,v))
    1.19 +
    1.20 +using namespace js;
    1.21 +
    1.22 +const char probes::nullName[] = "(null)";
    1.23 +const char probes::anonymousName[] = "(anonymous)";
    1.24 +
    1.25 +bool probes::ProfilingActive = true;
    1.26 +
    1.27 +probes::JITReportGranularity
    1.28 +probes::JITGranularityRequested(JSContext *cx)
    1.29 +{
    1.30 +    if (cx->runtime()->spsProfiler.enabled())
    1.31 +        return JITREPORT_GRANULARITY_LINE;
    1.32 +    return JITREPORT_GRANULARITY_NONE;
    1.33 +}
    1.34 +
    1.35 +/* ICs are unregistered in a batch */
    1.36 +void
    1.37 +probes::DiscardExecutableRegion(void *start, size_t size)
    1.38 +{
    1.39 +    /*
    1.40 +     * Not needed for SPS because ICs are disposed of when the normal JITChunk
    1.41 +     * is disposed of
    1.42 +     */
    1.43 +}
    1.44 +
    1.45 +#ifdef INCLUDE_MOZILLA_DTRACE
    1.46 +static const char *
    1.47 +ScriptFilename(const JSScript *script)
    1.48 +{
    1.49 +    if (!script)
    1.50 +        return probes::nullName;
    1.51 +    if (!script->filename())
    1.52 +        return probes::anonymousName;
    1.53 +    return script->filename();
    1.54 +}
    1.55 +
    1.56 +static const char *
    1.57 +FunctionName(JSContext *cx, JSFunction *fun, JSAutoByteString* bytes)
    1.58 +{
    1.59 +    if (!fun)
    1.60 +        return probes::nullName;
    1.61 +    if (!fun->displayAtom())
    1.62 +        return probes::anonymousName;
    1.63 +    return bytes->encodeLatin1(cx, fun->displayAtom()) ? bytes->ptr() : probes::nullName;
    1.64 +}
    1.65 +
    1.66 +/*
    1.67 + * These functions call the DTrace macros for the JavaScript USDT probes.
    1.68 + * Originally this code was inlined in the JavaScript code; however since
    1.69 + * a number of operations are called, these have been placed into functions
    1.70 + * to reduce any negative compiler optimization effect that the addition of
    1.71 + * a number of usually unused lines of code would cause.
    1.72 + */
    1.73 +void
    1.74 +probes::DTraceEnterJSFun(JSContext *cx, JSFunction *fun, JSScript *script)
    1.75 +{
    1.76 +    JSAutoByteString funNameBytes;
    1.77 +    JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script), probes::nullName,
    1.78 +                              FunctionName(cx, fun, &funNameBytes));
    1.79 +}
    1.80 +
    1.81 +void
    1.82 +probes::DTraceExitJSFun(JSContext *cx, JSFunction *fun, JSScript *script)
    1.83 +{
    1.84 +    JSAutoByteString funNameBytes;
    1.85 +    JAVASCRIPT_FUNCTION_RETURN(ScriptFilename(script), probes::nullName,
    1.86 +                               FunctionName(cx, fun, &funNameBytes));
    1.87 +}
    1.88 +#endif

mercurial