Bug 970713 - Add 'Start Debug Mode' button to about:webrtc. r=smaug, r=Unfocused, r=jesup
authorJan-Ivar Bruaroey <jib@mozilla.com>
Sun, 08 Jun 2014 21:00:12 -0400
changeset 207832 73019c846afdcf5121e4e96ce780ced976ebc8cf
parent 207831 2800777928780b957d0372f00bc11cca522660e6
child 207833 bbe4ed7704532dc62289fd0d299a941f62641c5f
push id494
push userraliiev@mozilla.com
push dateMon, 25 Aug 2014 18:42:16 +0000
treeherdermozilla-release@a3cc3e46b571 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug, Unfocused, jesup
bugs970713
milestone32.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 970713 - Add 'Start Debug Mode' button to about:webrtc. r=smaug, r=Unfocused, r=jesup
dom/webidl/WebrtcGlobalInformation.webidl
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.h
toolkit/content/aboutWebrtc.xhtml
--- a/dom/webidl/WebrtcGlobalInformation.webidl
+++ b/dom/webidl/WebrtcGlobalInformation.webidl
@@ -16,11 +16,19 @@ interface WebrtcGlobalInformation {
 
   [Throws]
   static void getAllStats(WebrtcGlobalStatisticsCallback callback,
                           optional DOMString pcIdFilter);
 
   [Throws]
   static void getLogging(DOMString pattern,
                          WebrtcGlobalLoggingCallback callback);
+
+  // NSPR WebRTC Trace debug level (0 - 65535)
+  //
+  // Notes:
+  // - Setting a non-zero debug level turns on gathering of log for file output.
+  // - Subsequently setting a zero debug level writes that log to disk.
+
+  static attribute long debugLevel;
 };
 
 
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.cpp
@@ -3,17 +3,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "WebrtcGlobalInformation.h"
 
 #include <deque>
 #include <string>
 
 #include "CSFLog.h"
-
+#include "WebRtcLog.h"
 #include "mozilla/dom/WebrtcGlobalInformationBinding.h"
 
 #include "nsAutoPtr.h"
 #include "nsNetCID.h" // NS_SOCKETTRANSPORTSERVICE_CONTRACTID
 #include "nsServiceManagerUtils.h" // do_GetService
 #include "mozilla/ErrorResult.h"
 #include "mozilla/Vector.h"
 #include "nsProxyRelease.h"
@@ -227,16 +227,31 @@ WebrtcGlobalInformation::GetLogging(
 
   if (NS_FAILED(rv)) {
     aLoggingCallback.Release();
   }
 
   aRv = rv;
 }
 
+static int32_t sLastSetLevel = 0;
+
+void
+WebrtcGlobalInformation::SetDebugLevel(const GlobalObject& aGlobal, int32_t aLevel)
+{
+  StartWebRtcLog(webrtc::TraceLevel(aLevel));
+  sLastSetLevel = aLevel;
+}
+
+int32_t
+WebrtcGlobalInformation::DebugLevel(const GlobalObject& aGlobal)
+{
+  return sLastSetLevel;
+}
+
 struct StreamResult {
   StreamResult() : candidateTypeBitpattern(0), streamSucceeded(false) {}
   uint8_t candidateTypeBitpattern;
   bool streamSucceeded;
 };
 
 static void StoreLongTermICEStatisticsImpl_m(
     nsresult result,
--- a/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.h
+++ b/media/webrtc/signaling/src/peerconnection/WebrtcGlobalInformation.h
@@ -28,16 +28,19 @@ public:
                           const Optional<nsAString>& pcIdFilter,
                           ErrorResult& aRv);
 
   static void GetLogging(const GlobalObject& aGlobal,
                          const nsAString& aPattern,
                          WebrtcGlobalLoggingCallback& aLoggingCallback,
                          ErrorResult& aRv);
 
+  static void SetDebugLevel(const GlobalObject& aGlobal, int32_t aLevel);
+  static int32_t DebugLevel(const GlobalObject& aGlobal);
+
   static void StoreLongTermICEStatistics(sipcc::PeerConnectionImpl& aPc);
 
 private:
   WebrtcGlobalInformation() MOZ_DELETE;
   WebrtcGlobalInformation(const WebrtcGlobalInformation& aOrig) MOZ_DELETE;
   WebrtcGlobalInformation& operator=(
     const WebrtcGlobalInformation& aRhs) MOZ_DELETE;
 };
--- a/toolkit/content/aboutWebrtc.xhtml
+++ b/toolkit/content/aboutWebrtc.xhtml
@@ -379,22 +379,50 @@ function displayStats(globalReport) {
     if (pcDiv) {
       document.getElementById('stats').replaceChild(newPcDiv, pcDiv);
     } else {
       document.getElementById('stats').appendChild(newPcDiv);
     }
   });
 }
 
+function onLoad() {
+  WebrtcGlobalInformation.getAllStats(displayStats);
+  if (WebrtcGlobalInformation.debugLevel) {
+    setDebugButton(true);
+  } else {
+    setDebugButton(false);
+  }
+}
+
+function startDebugMode() {
+  WebrtcGlobalInformation.debugLevel = 65535;
+  setDebugButton(true);
+}
+
+function stopDebugMode() {
+  WebrtcGlobalInformation.debugLevel = 0;
+  setDebugButton(false);
+}
+
+function setDebugButton(on) {
+  var button = document.getElementById("debug-toggle-button");
+  button.innerHTML = on ? "Stop debug mode" : "Start debug mode";
+  button.onclick = on ? stopDebugMode : startDebugMode;
+}
+
   </script>
 
-  <body id="body" onload="WebrtcGlobalInformation.getAllStats(displayStats)">
+  <body id="body" onload="onLoad()">
     <div id="stats">
     </div>
     <button onclick="WebrtcGlobalInformation.getLogging('', displayLogs)">
-      Show/refresh logging
+      Connection log
+    </button>
+    <button id="debug-toggle-button" onclick="startDebugMode()">
+      Start debug mode
     </button>
     <div id="logs">
     </div>
   </body>
 </html>
 <!-- vim: softtabstop=2:shiftwidth=2:expandtab
 -->