Bug 1072906 - TraceLogger: Part 2: Improve the interface to setup the tracelogger, r=bbouvier
☠☠ backed out by c071589586ee ☠ ☠
authorHannes Verschore <hv1989@gmail.com>
Thu, 20 Nov 2014 17:44:02 +0100
changeset 240987 c54bb9df733be2f1ff48fd84ec87042933e70704
parent 240986 8db5d425405f17cdee986b86fe8658b3641e3fd5
child 240988 ba17a7e1ae7bafea27d0a2a890330614a92cbfbe
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbouvier
bugs1072906
milestone36.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1072906 - TraceLogger: Part 2: Improve the interface to setup the tracelogger, r=bbouvier
js/src/moz.build
js/src/vm/Debugger.cpp
js/src/vm/Debugger.h
js/src/vm/TraceLoggingTypes.cpp
js/src/vm/TraceLoggingTypes.h
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -308,16 +308,17 @@ if CONFIG['MOZ_INSTRUMENTS']:
     SOURCES += [
         'devtools/Instruments.cpp',
     ]
 
 if CONFIG['ENABLE_TRACE_LOGGING']:
     SOURCES += [
         'vm/TraceLogging.cpp',
         'vm/TraceLoggingGraph.cpp',
+        'vm/TraceLoggingTypes.cpp',
     ]
 
 if not CONFIG['ENABLE_ION']:
     UNIFIED_SOURCES += [
         'jit/none/Trampoline-none.cpp'
     ]
 elif CONFIG['JS_CODEGEN_X86'] or CONFIG['JS_CODEGEN_X64']:
     UNIFIED_SOURCES += [
--- a/js/src/vm/Debugger.cpp
+++ b/js/src/vm/Debugger.cpp
@@ -3767,30 +3767,78 @@ Debugger::makeGlobalObjectReference(JSCo
     if (!global)
         return false;
 
     args.rval().setObject(*global);
     return dbg->wrapDebuggeeValue(cx, args.rval());
 }
 
 bool
-Debugger::enableTraceItem(JSContext *cx, unsigned argc, Value *vp)
-{
-    THIS_DEBUGGER(cx, argc, vp, "enableTraceItem", args, dbg);
-    if (!args.requireAtLeast(cx, "Debugger.enableTraceItem", 1))
-        return false;
-
-    uint32_t id = args[0].toInt32();
-
-    if (!TLTextIdIsToggable(id)) {
-        args.rval().setBoolean(false);
+Debugger::setupTraceLogger(JSContext *cx, unsigned argc, Value *vp)
+{
+    THIS_DEBUGGER(cx, argc, vp, "setupTraceLogger", args, dbg);
+    if (!args.requireAtLeast(cx, "Debugger.setupTraceLogger", 1))
+        return false;
+
+    RootedObject obj(cx, ToObject(cx, args[0]));
+    if (!obj)
+        return false;
+
+    AutoIdVector ids(cx);
+    if (!GetPropertyKeys(cx, obj, JSITER_OWNONLY, &ids))
+        return false;
+
+    if (ids.length() == 0) {
+        args.rval().setBoolean(true);
         return true;
     }
 
-    TraceLogEnableTextId(cx, id);
+    Vector<uint32_t> textIds(cx);
+    if (!textIds.reserve(ids.length()))
+        return false;
+
+    Vector<bool> values(cx);
+    if (!values.reserve(ids.length()))
+        return false;
+
+    for (size_t i = 0; i < ids.length(); i++) {
+        if (!JSID_IS_STRING(ids[i])) {
+            args.rval().setBoolean(false);
+            return true;
+        }
+
+        JSString *id = JSID_TO_STRING(ids[i]);
+        JSLinearString *linear = id->ensureLinear(cx);
+        if (!linear)
+            return false;
+
+        uint32_t textId = TLStringToTextId(linear);
+
+        if (!TLTextIdIsToggable(textId)) {
+            args.rval().setBoolean(false);
+            return true;
+        }
+
+        RootedValue v(cx);
+        if (!JSObject::getGeneric(cx, obj, obj, ids[i], &v))
+            return false;
+
+        textIds.append(textId);
+        values.append(ToBoolean(v));
+    }
+
+    MOZ_ASSERT(ids.length() == textIds.length());
+    MOZ_ASSERT(textIds.length() == values.length());
+
+    for (size_t i = 0; i < textIds.length(); i++) {
+        if (values[i])
+            TraceLogEnableTextId(cx, textIds[i]);
+        else
+            TraceLogDisableTextId(cx, textIds[i]);
+    }
 
     args.rval().setBoolean(true);
     return true;
 }
 
 const JSPropertySpec Debugger::properties[] = {
     JS_PSGS("enabled", Debugger::getEnabled, Debugger::setEnabled, 0),
     JS_PSGS("onDebuggerStatement", Debugger::getOnDebuggerStatement,
@@ -3815,17 +3863,17 @@ const JSFunctionSpec Debugger::methods[]
     JS_FN("hasDebuggee", Debugger::hasDebuggee, 1, 0),
     JS_FN("getDebuggees", Debugger::getDebuggees, 0, 0),
     JS_FN("getNewestFrame", Debugger::getNewestFrame, 0, 0),
     JS_FN("clearAllBreakpoints", Debugger::clearAllBreakpoints, 0, 0),
     JS_FN("findScripts", Debugger::findScripts, 1, 0),
     JS_FN("findObjects", Debugger::findObjects, 1, 0),
     JS_FN("findAllGlobals", Debugger::findAllGlobals, 0, 0),
     JS_FN("makeGlobalObjectReference", Debugger::makeGlobalObjectReference, 1, 0),
-    JS_FN("enableTraceItem", Debugger::enableTraceItem, 1, 0),
+    JS_FN("setupTraceLogger", Debugger::setupTraceLogger, 1, 0),
     JS_FS_END
 };
 
 
 /*** Debugger.Script *****************************************************************************/
 
 static inline JSScript *
 GetScriptReferent(JSObject *obj)
--- a/js/src/vm/Debugger.h
+++ b/js/src/vm/Debugger.h
@@ -389,17 +389,17 @@ class Debugger : private mozilla::Linked
     static bool hasDebuggee(JSContext *cx, unsigned argc, Value *vp);
     static bool getDebuggees(JSContext *cx, unsigned argc, Value *vp);
     static bool getNewestFrame(JSContext *cx, unsigned argc, Value *vp);
     static bool clearAllBreakpoints(JSContext *cx, unsigned argc, Value *vp);
     static bool findScripts(JSContext *cx, unsigned argc, Value *vp);
     static bool findObjects(JSContext *cx, unsigned argc, Value *vp);
     static bool findAllGlobals(JSContext *cx, unsigned argc, Value *vp);
     static bool makeGlobalObjectReference(JSContext *cx, unsigned argc, Value *vp);
-    static bool enableTraceItem(JSContext *cx, unsigned argc, Value *vp);
+    static bool setupTraceLogger(JSContext *cx, unsigned argc, Value *vp);
     static bool construct(JSContext *cx, unsigned argc, Value *vp);
     static const JSPropertySpec properties[];
     static const JSFunctionSpec methods[];
 
     static bool getNewestAbstractFramePtr(JSContext *cx);
     static bool updateExecutionObservabilityOfFrames(JSContext *cx, const ExecutionObservableSet &obs,
                                                      IsObserving observing);
     static bool updateExecutionObservabilityOfScripts(JSContext *cx, const ExecutionObservableSet &obs,
new file mode 100644
--- /dev/null
+++ b/js/src/vm/TraceLoggingTypes.cpp
@@ -0,0 +1,20 @@
+/* -*- 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 "vm/TraceLoggingTypes.h"
+
+class JSLinearString;
+
+uint32_t
+TLStringToTextId(JSLinearString *str)
+{
+#define NAME(textId) if (js::StringEqualsAscii(str, #textId)) return TraceLogger_ ## textId;
+    TRACELOGGER_TREE_ITEMS(NAME)
+    TRACELOGGER_LOG_ITEMS(NAME)
+#undef NAME
+    return TraceLogger_Error;
+}
+
--- a/js/src/vm/TraceLoggingTypes.h
+++ b/js/src/vm/TraceLoggingTypes.h
@@ -3,16 +3,17 @@
  * 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 TraceLoggingTypes_h
 #define TraceLoggingTypes_h
 
 #include "jsalloc.h"
+#include "jsstr.h"
 
 #define TRACELOGGER_TREE_ITEMS(_)                     \
     _(Baseline)                                       \
     _(BaselineCompilation)                            \
     _(Engine)                                         \
     _(GC)                                             \
     _(GCAllocation)                                   \
     _(GCSweeping)                                     \
@@ -83,16 +84,19 @@ TLTextIdString(TraceLoggerTextId id)
         TRACELOGGER_TREE_ITEMS(NAME)
         TRACELOGGER_LOG_ITEMS(NAME)
 #undef NAME
       default:
         MOZ_CRASH();
     }
 }
 
+uint32_t
+TLStringToTextId(JSLinearString *str);
+
 inline bool
 TLTextIdIsToggable(uint32_t id)
 {
     if (id == TraceLogger_Error)
         return false;
     if (id == TraceLogger_Internal)
         return false;
     if (id == TraceLogger_Stop)