Bug 799638 - Export profiler markers when saving profiler profiles. r=ehsan
authorBenoit Girard <b56girard@gmail.com>
Mon, 15 Oct 2012 10:33:20 -0400
changeset 110416 2d29c74b9c9cb3014d7b53eb7cbffef99236da5e
parent 110415 6886bd9090c3d744aca44c95d494ba0d6fd66293
child 110417 b7f31a7368000ae093dca8ae21152af9a867fbe5
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersehsan
bugs799638
milestone19.0a1
Bug 799638 - Export profiler markers when saving profiler profiles. r=ehsan
tools/profiler/JSObjectBuilder.h
tools/profiler/TableTicker.cpp
--- a/tools/profiler/JSObjectBuilder.h
+++ b/tools/profiler/JSObjectBuilder.h
@@ -80,16 +80,36 @@ class JSObjectBuilder
     mOk = JS_GetArrayLength(mCx, aArray, &length);
 
     if (!mOk)
       return;
 
     mOk = JS_SetElement(mCx, aArray, length, &objval);
   }
 
+  void ArrayPush(JSObject *aArray, const char *value)
+  {
+    if (!mOk)
+      return;
+
+    JSString *string = JS_NewStringCopyN(mCx, value, strlen(value));
+    if (!string) {
+      mOk = JS_FALSE;
+      return;
+    }
+
+    jsval objval = STRING_TO_JSVAL(string);
+    uint32_t length;
+    mOk = JS_GetArrayLength(mCx, aArray, &length);
+
+    if (!mOk)
+      return;
+
+    mOk = JS_SetElement(mCx, aArray, length, &objval);
+  }
 
   void ArrayPush(JSObject *aArray, JSObject *aObject)
   {
     if (!mOk)
       return;
 
     jsval objval = OBJECT_TO_JSVAL(aObject);
     uint32_t length;
--- a/tools/profiler/TableTicker.cpp
+++ b/tools/profiler/TableTicker.cpp
@@ -285,16 +285,17 @@ public:
     JSObjectBuilder b(aCx);
 
     JSObject *profile = b.CreateObject();
     JSObject *samples = b.CreateArray();
     b.DefineProperty(profile, "samples", samples);
 
     JSObject *sample = NULL;
     JSObject *frames = NULL;
+    JSObject *marker = NULL;
 
     int readPos = mReadPos;
     while (readPos != mLastFlushPos) {
       // Number of tag consumed
       int incBy = 1;
       ProfileEntry entry = mEntries[readPos];
 
       // Read ahead to the next tag, if it's a 'd' tag process it now
@@ -310,16 +311,29 @@ public:
 
       switch (entry.mTagName) {
         case 's':
           sample = b.CreateObject();
           b.DefineProperty(sample, "name", tagStringData);
           frames = b.CreateArray();
           b.DefineProperty(sample, "frames", frames);
           b.ArrayPush(samples, sample);
+          // Created lazily
+          marker = NULL;
+          break;
+        case 'm':
+          {
+            if (sample) {
+              if (!marker) {
+                marker = b.CreateArray();
+                b.DefineProperty(sample, "marker", marker);
+              }
+              b.ArrayPush(marker, tagStringData);
+            }
+          }
           break;
         case 'r':
           {
             if (sample) {
               b.DefineProperty(sample, "responsiveness", entry.mTagFloat);
             }
           }
           break;