Ejemplo n.º 1
0
void TableTicker::BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile)
{
  // Put shared library info
  b.DefineProperty(profile, "libs", GetSharedLibraryInfoString().c_str());

  // Put meta data
  JSCustomObject *meta = GetMetaJSCustomObject(b);
  b.DefineProperty(profile, "meta", meta);

  // Lists the samples for each ThreadProfile
  JSCustomArray *threads = b.CreateArray();
  b.DefineProperty(profile, "threads", threads);

  SetPaused(true);

  {
    mozilla::MutexAutoLock lock(*sRegisteredThreadsMutex);

    for (size_t i = 0; i < sRegisteredThreads->size(); i++) {
      // Thread not being profiled, skip it
      if (!sRegisteredThreads->at(i)->Profile())
        continue;

      MutexAutoLock lock(*sRegisteredThreads->at(i)->Profile()->GetMutex());

      JSCustomObject* threadSamples = b.CreateObject();
      sRegisteredThreads->at(i)->Profile()->BuildJSObject(b, threadSamples);
      b.ArrayPush(threads, threadSamples);
    }
  }

#if defined(SPS_OS_android) && !defined(MOZ_WIDGET_GONK)
  if (ProfileJava()) {
    AndroidBridge::Bridge()->PauseJavaProfiling();

    JSCustomObject* javaThread = BuildJavaThreadJSObject(b);
    b.ArrayPush(threads, javaThread);

    AndroidBridge::Bridge()->UnpauseJavaProfiling();
  }
#endif

  SetPaused(false);
}
Ejemplo n.º 2
0
void TableTicker::BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile)
{
  // Put shared library info
  b.DefineProperty(profile, "libs", GetSharedLibraryInfoString().c_str());

  // Put meta data
  JSCustomObject *meta = GetMetaJSCustomObject(b);
  b.DefineProperty(profile, "meta", meta);

  // Lists the samples for each ThreadProfile
  JSCustomArray *threads = b.CreateArray();
  b.DefineProperty(profile, "threads", threads);

  // For now we only have one thread
  SetPaused(true);
  JSCustomObject* threadSamples = b.CreateObject();
  GetPrimaryThreadProfile()->BuildJSObject(b, threadSamples);
  b.ArrayPush(threads, threadSamples);
  SetPaused(false);
}
Ejemplo n.º 3
0
  void BuildJSObject(JSAObjectBuilder& b, JSCustomObject* profile) {
    JSCustomArray *samples = b.CreateArray();
    b.DefineProperty(profile, "samples", samples);

    JSCustomObject *sample = nullptr;
    JSCustomArray *frames = nullptr;
    JSCustomArray *marker = nullptr;

    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
      const char* tagStringData = entry.mTagData;
      int readAheadPos = (readPos + 1) % mEntrySize;
      char tagBuff[DYNAMIC_MAX_STRING];
      // Make sure the string is always null terminated if it fills up DYNAMIC_MAX_STRING-2
      tagBuff[DYNAMIC_MAX_STRING-1] = '\0';

      if (readAheadPos != mLastFlushPos && mEntries[readAheadPos].mTagName == 'd') {
        tagStringData = processDynamicTag(readPos, &incBy, tagBuff);
      }

      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;
        case 'f':
          {
            if (sample) {
              b.DefineProperty(sample, "frameNumber", entry.mTagLine);
            }
          }
          break;
        case 't':
          {
            if (sample) {
              b.DefineProperty(sample, "time", entry.mTagFloat);
            }
          }
          break;
        case 'c':
        case 'l':
          {
            if (sample) {
              JSCustomObject *frame = b.CreateObject();
              if (entry.mTagName == 'l') {
                // Bug 753041
                // We need a double cast here to tell GCC that we don't want to sign
                // extend 32-bit addresses starting with 0xFXXXXXX.
                unsigned long long pc = (unsigned long long)(uintptr_t)entry.mTagPtr;
                snprintf(tagBuff, DYNAMIC_MAX_STRING, "%#llx", pc);
                b.DefineProperty(frame, "location", tagBuff);
              } else {
                b.DefineProperty(frame, "location", tagStringData);
                readAheadPos = (readPos + incBy) % mEntrySize;
                if (readAheadPos != mLastFlushPos &&
                    mEntries[readAheadPos].mTagName == 'n') {
                  b.DefineProperty(frame, "line",
                                   mEntries[readAheadPos].mTagLine);
                  incBy++;
                }
              }
              b.ArrayPush(frames, frame);
            }
          }
      }
      readPos = (readPos + incBy) % mEntrySize;
    }
  }