Debian Codegraph @

js/src/vm/Probes.cpp

raw
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/. */
6
7 #include "vm/Probes-inl.h"
8
9 #ifdef INCLUDE_MOZILLA_DTRACE
10 # include "vm/JSScript-inl.h"
11 #endif
12
13 using namespace js;
14
15 const char probes::nullName[] = "(null)";
16 const char probes::anonymousName[] = "(anonymous)";
17
18 bool probes::ProfilingActive = true;
19
20 #ifdef INCLUDE_MOZILLA_DTRACE
21 static const char* ScriptFilename(const JSScript* script) {
22 if (!script) {
23 return probes::nullName;
24 }
25 if (!script->filename()) {
26 return probes::anonymousName;
27 }
28 return script->filename();
29 }
30
31 static const char* FunctionName(JSContext* cx, JSFunction* fun,
32 UniqueChars* bytes) {
33 if (!fun) {
34 return probes::nullName;
35 }
36 if (!fun->maybePartialDisplayAtom()) {
37 return probes::anonymousName;
38 }
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;
43 }
44
45 /*
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.
51 */
52 void probes::DTraceEnterJSFun(JSContext* cx, JSFunction* fun,
53 JSScript* script) {
54 UniqueChars funNameBytes;
55 JAVASCRIPT_FUNCTION_ENTRY(ScriptFilename(script), probes::nullName,
56 FunctionName(cx, fun, &funNameBytes));
57 }
58
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));
63 }
64 #endif