Bug 1371927: Build KeyedStackCapture only if profiler enabled. r?gfritzsche draft
authorIaroslav (yarik) Sheptykin <yarik.sheptykin@googlemail.com>
Sat, 10 Jun 2017 19:59:16 +0200
changeset 592479 3f1e26c28393f9877cb23ab263854bd6b481f790
parent 592464 27cad9749cddf68e11fdd4e5d73dad84a8f8cf23
child 632844 d81833787b5e8ca5b63582949eee955f81608168
push id63415
push userbmo:yarik.sheptykin@googlemail.com
push dateMon, 12 Jun 2017 09:51:47 +0000
reviewersgfritzsche
bugs1371927
milestone55.0a1
Bug 1371927: Build KeyedStackCapture only if profiler enabled. r?gfritzsche MozReview-Commit-ID: 9IoVY2K5hXc
toolkit/components/telemetry/HangReports.cpp
toolkit/components/telemetry/KeyedStackCapturer.cpp
toolkit/components/telemetry/KeyedStackCapturer.h
toolkit/components/telemetry/Telemetry.cpp
toolkit/components/telemetry/moz.build
--- a/toolkit/components/telemetry/HangReports.cpp
+++ b/toolkit/components/telemetry/HangReports.cpp
@@ -6,19 +6,16 @@
 
 #include "HangReports.h"
 
 namespace mozilla {
 namespace Telemetry {
 
 using namespace HangMonitor;
 
-/** The maximum number of stacks that we're keeping for hang reports. */
-const size_t kMaxHangStacksKept = 50;
-
 // This utility function generates a string key that is used to index the annotations
 // in a hash map from |HangReports::AddHang|.
 nsresult
 ComputeAnnotationsKey(const HangAnnotationsPtr& aAnnotations, nsAString& aKeyOut)
 {
   UniquePtr<HangAnnotations::Enumerator> annotationsEnum = aAnnotations->GetEnumerator();
   if (!annotationsEnum) {
     return NS_ERROR_FAILURE;
@@ -31,16 +28,19 @@ ComputeAnnotationsKey(const HangAnnotati
     aKeyOut.Append(key);
     aKeyOut.Append(value);
   }
 
   return NS_OK;
 }
 
 #if defined(MOZ_GECKO_PROFILER)
+/** The maximum number of stacks that we're keeping for hang reports. */
+const size_t kMaxHangStacksKept = 50;
+
 void
 HangReports::AddHang(const Telemetry::ProcessedStack& aStack,
                      uint32_t aDuration,
                      int32_t aSystemUptime,
                      int32_t aFirefoxUptime,
                      HangAnnotationsPtr aAnnotations) {
   // Append the new stack to the stack's circular queue.
   size_t hangIndex = mStacks.AddStack(aStack);
--- a/toolkit/components/telemetry/KeyedStackCapturer.cpp
+++ b/toolkit/components/telemetry/KeyedStackCapturer.cpp
@@ -7,18 +7,16 @@
 #include "KeyedStackCapturer.h"
 #include "nsPrintfCString.h"
 #include "mozilla/StackWalk.h"
 #include "ProcessedStack.h"
 #include "jsapi.h"
 
 namespace {
 
-#if defined(MOZ_GECKO_PROFILER)
-
 /** Defines the size of the keyed stack dictionary. */
 const uint8_t kMaxKeyLength = 50;
 
 /** The maximum number of captured stacks that we're keeping. */
 const size_t kMaxCapturedStacksKept = 50;
 
 /**
  * Checks if a single character of the key string is valid.
@@ -156,12 +154,11 @@ KeyedStackCapturer::ReflectCapturedStack
 
 void
 KeyedStackCapturer::Clear()
 {
   MutexAutoLock captureStackMutex(mStackCapturerMutex);
   mStackInfos.Clear();
   mStacks.Clear();
 }
-#endif
 
 } // namespace Telemetry
 } // namespace mozilla
--- a/toolkit/components/telemetry/KeyedStackCapturer.h
+++ b/toolkit/components/telemetry/KeyedStackCapturer.h
@@ -1,18 +1,16 @@
 /* -*-  Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2; -*- */
 /* 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 KeyedStackCapturer_h__
 #define KeyedStackCapturer_h__
 
-#ifdef MOZ_GECKO_PROFILER
-
 #include "Telemetry.h"
 #include "nsString.h"
 #include "nsClassHashtable.h"
 #include "mozilla/Mutex.h"
 #include "CombinedStacks.h"
 
 struct JSContext;
 
@@ -69,11 +67,9 @@ private:
   FrequencyInfoMapType mStackInfos;
   CombinedStacks mStacks;
   Mutex mStackCapturerMutex;
 };
 
 } // namespace Telemetry
 } // namespace mozilla
 
-#endif // MOZ_GECKO_PROFILER
-
 #endif // KeyedStackCapturer_h__
--- a/toolkit/components/telemetry/Telemetry.cpp
+++ b/toolkit/components/telemetry/Telemetry.cpp
@@ -94,20 +94,23 @@
 namespace {
 
 using namespace mozilla;
 using namespace mozilla::HangMonitor;
 using Telemetry::Common::AutoHashtable;
 using mozilla::dom::Promise;
 using mozilla::dom::AutoJSAPI;
 using mozilla::Telemetry::HangReports;
-using mozilla::Telemetry::KeyedStackCapturer;
 using mozilla::Telemetry::CombinedStacks;
 using mozilla::Telemetry::ComputeAnnotationsKey;
 
+#if defined(MOZ_GECKO_PROFILER)
+using mozilla::Telemetry::KeyedStackCapturer;
+#endif
+
 /**
  * IOInterposeObserver recording statistics of main-thread I/O during execution,
  * aimed at consumption by TelemetryImpl
  */
 class TelemetryIOInterposeObserver : public IOInterposeObserver
 {
   /** File-level statistics structure */
   struct FileStats {
--- a/toolkit/components/telemetry/moz.build
+++ b/toolkit/components/telemetry/moz.build
@@ -52,25 +52,30 @@ EXPORTS.mozilla += [
     'ThreadHangStats.h',
 ]
 
 SOURCES += [
     'CombinedStacks.cpp',
     'HangReports.cpp',
     'ipc/TelemetryIPC.cpp',
     'ipc/TelemetryIPCAccumulator.cpp',
-    'KeyedStackCapturer.cpp',
     'Telemetry.cpp',
     'TelemetryCommon.cpp',
     'TelemetryEvent.cpp',
     'TelemetryHistogram.cpp',
     'TelemetryScalar.cpp',
     'WebrtcTelemetry.cpp',
 ]
 
+# KeyedStackCapturer entirely relies on profiler to be enabled.
+if CONFIG['MOZ_GECKO_PROFILER']:
+    SOURCES += [
+      'KeyedStackCapturer.cpp'
+    ]
+
 EXTRA_COMPONENTS += [
     'TelemetryStartup.js',
     'TelemetryStartup.manifest'
 ]
 
 EXTRA_JS_MODULES += [
     'GCTelemetry.jsm',
     'TelemetryArchive.jsm',