1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "vm/Probes-inl.h"
9 #ifdef INCLUDE_MOZILLA_DTRACE
10 # include "vm/JSScript-inl.h"
15 const char probes::nullName
[] = "(null)";
16 const char probes::anonymousName
[] = "(anonymous)";
18 bool probes::ProfilingActive
= true;
20 #ifdef INCLUDE_MOZILLA_DTRACE
21 static const char* ScriptFilename(const JSScript
* script
) {
23 return probes::nullName
;
25 if (!script
->filename()) {
26 return probes::anonymousName
;
28 return script
->filename();
31 static const char* FunctionName(JSContext
* cx
, JSFunction
* fun
,
34 return probes::nullName
;
36 if (!fun
->maybePartialDisplayAtom()) {
37 return probes::anonymousName
;
39 // TODO: Should be JS_EncodeStringToUTF8, but that'd introduce a rooting
40 // hazard, because JS_EncodeStringToUTF8 can GC.
41 *bytes
= JS_EncodeStringToLatin1(cx
, fun
->maybePartialDisplayAtom());
42 return *bytes
? bytes
->get() : probes::nullName
;
46 * These functions call the DTrace macros for the JavaScript USDT probes.
47 * Originally this code was inlined in the JavaScript code; however since
48 * a number of operations are called, these have been placed into functions
49 * to reduce any negative compiler optimization effect that the addition of
50 * a number of usually unused lines of code would cause.
52 void probes::DTraceEnterJSFun(JSContext
* cx
, JSFunction
* fun
,
54 UniqueChars funNameBytes
;
55 JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script
), probes::nullName
,
56 FunctionName(cx
, fun
, &funNameBytes
));
59 void probes::DTraceExitJSFun(JSContext
* cx
, JSFunction
* fun
, JSScript
* script
) {
60 UniqueChars funNameBytes
;
61 JAVASCRIPT_FUNCTION_RETURN(ScriptFilename(script
), probes::nullName
,
62 FunctionName(cx
, fun
, &funNameBytes
));