Bug 1319682 - fix compile warning/error in TaskTracer, r=sinker
authorShih-Chiang Chien <schien@mozilla.com>
Thu, 24 Nov 2016 17:51:23 +0800
changeset 371431 cc39a32513fec7efc67055a934f226651807827f
parent 371318 efbc0c055fbc1511c181eadb728e135d9b7976eb
child 371432 2e7f1ee0d65b9cff4d43c989ecbd98040513b3cb
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssinker
bugs1319682
milestone53.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 1319682 - fix compile warning/error in TaskTracer, r=sinker MozReview-Commit-ID: 4E0ThIAZAxC
tools/profiler/tasktracer/GeckoTaskTracer.cpp
tools/profiler/tasktracer/GeckoTaskTracer.h
tools/profiler/tasktracer/GeckoTaskTracerImpl.h
tools/profiler/tasktracer/TracedTaskCommon.h
--- a/tools/profiler/tasktracer/GeckoTaskTracer.cpp
+++ b/tools/profiler/tasktracer/GeckoTaskTracer.cpp
@@ -11,20 +11,26 @@
 #include "mozilla/StaticMutex.h"
 #include "mozilla/ThreadLocal.h"
 #include "mozilla/TimeStamp.h"
 #include "mozilla/UniquePtr.h"
 #include "mozilla/Unused.h"
 
 #include "nsString.h"
 #include "nsThreadUtils.h"
+#include "platform.h"
 #include "prtime.h"
 
 #include <stdarg.h>
 
+#ifdef XP_WIN
+#include <windows.h>
+#define getpid GetCurrentProcessId
+#endif
+
 #define MAX_SIZE_LOG (1024 * 128)
 
 // NS_ENSURE_TRUE_VOID() without the warning on the debug build.
 #define ENSURE_TRUE_VOID(x)   \
   do {                        \
     if (MOZ_UNLIKELY(!(x))) { \
        return;                \
     }                         \
@@ -176,17 +182,21 @@ InitTaskTracer(uint32_t aFlags)
 
   if (aFlags & FORKED_AFTER_NUWA) {
     ObsoleteCurrentTraceInfos();
     return;
   }
 
   MOZ_ASSERT(!sTraceInfos);
 
-  sTraceInfoTLS.init();
+  bool success = sTraceInfoTLS.init();
+  if (!success) {
+    MOZ_CRASH();
+  }
+
   // A memory barrier is necessary here.
   sTraceInfos = new nsTArray<UniquePtr<TraceInfo>>();
 }
 
 void
 ShutdownTaskTracer()
 {
   if (IsStartLogging()) {
@@ -220,30 +230,30 @@ GetOrCreateTraceInfo()
   TraceInfo* info = sTraceInfoTLS.get();
   if (info && info->mObsolete) {
     // TraceInfo is obsolete: remove it.
     FreeTraceInfo(info);
     info = nullptr;
   }
 
   if (!info) {
-    info = AllocTraceInfo(gettid());
+    info = AllocTraceInfo(Thread::GetCurrentId());
     sTraceInfoTLS.set(info);
   }
 
   return info;
 }
 
 uint64_t
 GenNewUniqueTaskId()
 {
   TraceInfo* info = GetOrCreateTraceInfo();
   ENSURE_TRUE(info, 0);
 
-  pid_t tid = gettid();
+  Thread::tid_t tid = Thread::GetCurrentId();
   uint64_t taskid = ((uint64_t)tid << 32) | ++info->mLastUniqueTaskId;
   return taskid;
 }
 
 AutoSaveCurTraceInfo::AutoSaveCurTraceInfo()
 {
   GetCurTraceInfo(&mSavedSourceEventId, &mSavedTaskId, &mSavedSourceEventType);
 }
@@ -320,17 +330,17 @@ LogBegin(uint64_t aTaskId, uint64_t aSou
   // Log format:
   // [1 taskId beginTime processId threadId]
   TraceInfoLogType* log = info->AppendLog();
   if (log) {
     log->mBegin.mType = ACTION_BEGIN;
     log->mBegin.mTaskId = aTaskId;
     log->mBegin.mTime = GetTimestamp();
     log->mBegin.mPid = getpid();
-    log->mBegin.mTid = gettid();
+    log->mBegin.mTid = Thread::GetCurrentId();
   }
 }
 
 void
 LogEnd(uint64_t aTaskId, uint64_t aSourceEventId)
 {
   TraceInfo* info = GetOrCreateTraceInfo();
   ENSURE_TRUE_VOID(info);
@@ -474,17 +484,17 @@ GetLoggedData(TimeStamp aTimeStamp)
         MOZ_CRASH("Unknow TaskTracer log type!");
       }
     }
   }
 
   return result;
 }
 
-const PRTime
+PRTime
 GetStartTime()
 {
   return sStartTime;
 }
 
 const char*
 GetJSLabelPrefix()
 {
--- a/tools/profiler/tasktracer/GeckoTaskTracer.h
+++ b/tools/profiler/tasktracer/GeckoTaskTracer.h
@@ -52,33 +52,33 @@ class AutoSaveCurTraceInfo
 public:
   AutoSaveCurTraceInfo();
   ~AutoSaveCurTraceInfo();
 };
 
 class AutoSourceEvent : public AutoSaveCurTraceInfo
 {
 public:
-  AutoSourceEvent(SourceEventType aType);
+  explicit AutoSourceEvent(SourceEventType aType);
   ~AutoSourceEvent();
 };
 
 void InitTaskTracer(uint32_t aFlags = 0);
 void ShutdownTaskTracer();
 
 // Add a label to the currently running task, aFormat is the message to log,
 // followed by corresponding parameters.
 void AddLabel(const char* aFormat, ...);
 
 void StartLogging();
 void StopLogging();
 UniquePtr<nsTArray<nsCString>> GetLoggedData(TimeStamp aStartTime);
 
 // Returns the timestamp when Task Tracer is enabled in this process.
-const PRTime GetStartTime();
+PRTime GetStartTime();
 
 /**
  * Internal functions.
  */
 
 already_AddRefed<nsIRunnable>
 CreateTracedRunnable(already_AddRefed<nsIRunnable>&& aRunnable);
 
--- a/tools/profiler/tasktracer/GeckoTaskTracerImpl.h
+++ b/tools/profiler/tasktracer/GeckoTaskTracerImpl.h
@@ -61,17 +61,17 @@ union TraceInfoLogType {
 
 struct TraceInfoLogNode {
   TraceInfoLogType mLog;
   TraceInfoLogNode* mNext;
 };
 
 struct TraceInfo
 {
-  TraceInfo(uint32_t aThreadId)
+  explicit TraceInfo(uint32_t aThreadId)
     : mCurTraceSourceId(0)
     , mCurTaskId(0)
     , mCurTraceSourceType(Unknown)
     , mThreadId(aThreadId)
     , mLastUniqueTaskId(0)
     , mObsolete(false)
     , mLogsMutex("TraceInfoMutex")
     , mLogsHead(nullptr)
--- a/tools/profiler/tasktracer/TracedTaskCommon.h
+++ b/tools/profiler/tasktracer/TracedTaskCommon.h
@@ -46,17 +46,17 @@ protected:
 };
 
 class TracedRunnable : public TracedTaskCommon
                      , public Runnable
 {
 public:
   NS_DECL_NSIRUNNABLE
 
-  TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj);
+  explicit TracedRunnable(already_AddRefed<nsIRunnable>&& aOriginalObj);
 
 private:
   virtual ~TracedRunnable();
 
   nsCOMPtr<nsIRunnable> mOriginalObj;
 };
 
 /**
@@ -90,17 +90,17 @@ public:
    * VirtualTask is not a real task, goes without a runnable, it's
    * instances are never dispatched and ran by event loops.  This
    * class used to define running time as the life-span of it's
    * instance.
    */
   class AutoRunTask : public AutoSaveCurTraceInfo {
     VirtualTask* mTask;
   public:
-    AutoRunTask(VirtualTask *aTask);
+    explicit AutoRunTask(VirtualTask *aTask);
     ~AutoRunTask();
   };
 };
 
 } // namespace tasktracer
 } // namespace mozilla
 
 #endif