Bug 1287392 - Part 2: Ignore obsolete TaskTracer data and fix vptr. r=cyu
☠☠ backed out by 915541925ea9 ☠ ☠
authorThinker K.F. Li <thinker@codemud.net>
Thu, 10 Nov 2016 07:58:00 -0500
changeset 322188 ac7da68e00f545bde0975b7a945f8e53b21b3b76
parent 322187 606c7cb149c9609edf694e571922af7cbc8175e7
child 322189 7d8ed1ceafd7cddb5ba8ef3de7582fc9a0df9600
push id21
push usermaklebus@msu.edu
push dateThu, 01 Dec 2016 06:22:08 +0000
reviewerscyu
bugs1287392
milestone52.0a1
Bug 1287392 - Part 2: Ignore obsolete TaskTracer data and fix vptr. r=cyu
tools/profiler/tasktracer/GeckoTaskTracer.cpp
tools/profiler/tasktracer/TracedTaskCommon.cpp
--- a/tools/profiler/tasktracer/GeckoTaskTracer.cpp
+++ b/tools/profiler/tasktracer/GeckoTaskTracer.cpp
@@ -34,16 +34,21 @@
     if (MOZ_UNLIKELY(!(x))) { \
        return ret;            \
     }                         \
   } while(0)
 
 namespace mozilla {
 namespace tasktracer {
 
+#define SOURCE_EVENT_NAME(type) \
+  const char* CreateSourceEvent##type () { return "SourceEvent" #type; }
+#include "SourceEventTypeMap.h"
+#undef SOURCE_EVENT_NAME
+
 static MOZ_THREAD_LOCAL(TraceInfo*) sTraceInfoTLS;
 static mozilla::StaticMutex sMutex;
 
 // The generation of TraceInfo. It will be > 0 if the Task Tracer is started and
 // <= 0 if stopped.
 static mozilla::Atomic<bool> sStarted;
 static nsTArray<UniquePtr<TraceInfo>>* sTraceInfos = nullptr;
 static PRTime sStartTime;
@@ -100,35 +105,34 @@ CreateSourceEvent(SourceEventType aType)
   uint64_t newId = GenNewUniqueTaskId();
   TraceInfo* info = GetOrCreateTraceInfo();
   ENSURE_TRUE_VOID(info);
 
   info->mCurTraceSourceId = newId;
   info->mCurTraceSourceType = aType;
   info->mCurTaskId = newId;
 
-  uintptr_t* namePtr;
+  uintptr_t namePtr;
 #define SOURCE_EVENT_NAME(type)         \
   case SourceEventType::type:           \
   {                                     \
-    static int CreateSourceEvent##type; \
-    namePtr = (uintptr_t*)&CreateSourceEvent##type; \
+    namePtr = (uintptr_t)&CreateSourceEvent##type; \
     break;                              \
   }
 
   switch (aType) {
 #include "SourceEventTypeMap.h"
     default:
       MOZ_CRASH("Unknown SourceEvent.");
   }
-#undef CREATE_SOURCE_EVENT_NAME
+#undef SOURCE_EVENT_NAME
 
   // Log a fake dispatch and start for this source event.
   LogDispatch(newId, newId, newId, aType);
-  LogVirtualTablePtr(newId, newId, namePtr);
+  LogVirtualTablePtr(newId, newId, &namePtr);
   LogBegin(newId, newId);
 }
 
 static void
 DestroySourceEvent()
 {
   // Log a fake end for this source event.
   TraceInfo* info = GetOrCreateTraceInfo();
@@ -219,17 +223,19 @@ ShutdownTaskTracer()
 }
 
 static void
 FreeTraceInfo(TraceInfo* aTraceInfo)
 {
   StaticMutexAutoLock lock(sMutex);
   if (aTraceInfo) {
     UniquePtr<TraceInfo> traceinfo(aTraceInfo);
-    sTraceInfos->RemoveElement(traceinfo);
+    mozilla::DebugOnly<bool> removed =
+      sTraceInfos->RemoveElement(traceinfo);
+    MOZ_ASSERT(removed);
     Unused << traceinfo.release(); // A dirty hack to prevent double free.
   }
 }
 
 void FreeTraceInfo()
 {
   FreeTraceInfo(sTraceInfoTLS.get());
 }
@@ -363,17 +369,20 @@ LogVirtualTablePtr(uint64_t aTaskId, uin
 {
   TraceInfo* info = GetOrCreateTraceInfo();
   ENSURE_TRUE_VOID(info);
 
   // Log format:
   // [4 taskId address]
   nsCString* log = info->AppendLog();
   if (log) {
-    log->AppendPrintf("%d %lld %p", ACTION_GET_VTABLE, aTaskId, aVptr);
+    // Since addr2line used by SPS addon can not solve non-function
+    // addresses, we use the first entry of vtable as the symbol to
+    // solve.  We should find a better solution later.
+    log->AppendPrintf("%d %lld %p", ACTION_GET_VTABLE, aTaskId, *aVptr);
   }
 }
 
 AutoSourceEvent::AutoSourceEvent(SourceEventType aType)
 {
   CreateSourceEvent(aType);
 }
 
@@ -421,17 +430,19 @@ UniquePtr<TraceInfoLogsType>
 GetLoggedData(TimeStamp aTimeStamp)
 {
   auto result = MakeUnique<TraceInfoLogsType>();
 
   // TODO: This is called from a signal handler. Use semaphore instead.
   StaticMutexAutoLock lock(sMutex);
 
   for (uint32_t i = 0; i < sTraceInfos->Length(); ++i) {
-    (*sTraceInfos)[i]->MoveLogsInto(*result);
+    if (!(*sTraceInfos)[i]->mObsolete) {
+      (*sTraceInfos)[i]->MoveLogsInto(*result);
+    }
   }
 
   return result;
 }
 
 const PRTime
 GetStartTime()
 {
--- a/tools/profiler/tasktracer/TracedTaskCommon.cpp
+++ b/tools/profiler/tasktracer/TracedTaskCommon.cpp
@@ -90,17 +90,17 @@ TracedTaskCommon::ClearTLSTraceInfo()
 /**
  * Implementation of class TracedRunnable.
  */
 TracedRunnable::TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj)
   : TracedTaskCommon()
   , mOriginalObj(Move(aOriginalObj))
 {
   Init();
-  LogVirtualTablePtr(mTaskId, mSourceEventId, reinterpret_cast<uintptr_t*>(mOriginalObj.get()));
+  LogVirtualTablePtr(mTaskId, mSourceEventId, *reinterpret_cast<uintptr_t**>(mOriginalObj.get()));
 }
 
 TracedRunnable::~TracedRunnable()
 {
 }
 
 NS_IMETHODIMP
 TracedRunnable::Run()