Bug 875097 - Telemetry for number of calls per session. r=derf
authorBen Brittain <ben@brittain.org>
Tue, 27 Aug 2013 19:22:19 -0400
changeset 158013 89e5c33999520cc7d2c26704b5c3755147c96296
parent 158012 02d1fa974bfd8297a2bac7cb09c3f230d306cb23
child 158014 26b6835a6dd39291f4c296ec477bf5e42a7871cb
push id2961
push userlsblakk@mozilla.com
push dateMon, 28 Oct 2013 21:59:28 +0000
treeherdermozilla-beta@73ef4f13486f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersderf
bugs875097
milestone26.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 875097 - Telemetry for number of calls per session. r=derf
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
toolkit/components/telemetry/Histograms.json
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.cpp
@@ -1,30 +1,33 @@
 /* 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/. */
 
 #include "CSFLog.h"
 
+#include "base/histogram.h"
 #include "CallControlManager.h"
 #include "CC_Device.h"
 #include "CC_Call.h"
 #include "CC_Observer.h"
 #include "ccapi_call_info.h"
 #include "CC_SIPCCCallInfo.h"
 #include "ccapi_device_info.h"
 #include "CC_SIPCCDeviceInfo.h"
 #include "vcm.h"
 #include "VcmSIPCCBinding.h"
 #include "PeerConnectionImpl.h"
 #include "PeerConnectionCtx.h"
 #include "runnable_utils.h"
 #include "cpr_socket.h"
 #include "debug-psipcc-types.h"
 
+#include "mozilla/Telemetry.h"
+
 #include "nsIObserverService.h"
 #include "nsIObserver.h"
 #include "mozilla/Services.h"
 #include "StaticPtr.h"
 extern "C" {
 #include "../sipcc/core/common/thread_monitor.h"
 }
 
@@ -228,16 +231,21 @@ nsresult PeerConnectionCtx::Initialize()
 
   // Now that everything is set up, we let the CCApp thread
   // know that it's okay to start processing messages.
   PR_Lock(ccAppReadyToStartLock);
   ccAppReadyToStart = 1;
   PR_NotifyAllCondVar(ccAppReadyToStartCond);
   PR_Unlock(ccAppReadyToStartLock);
 
+  mConnectionCounter = 0;
+#ifdef MOZILLA_INTERNAL_API
+  Telemetry::GetHistogramById(Telemetry::WEBRTC_CALL_COUNT)->Add(0);
+#endif
+
   return NS_OK;
 }
 
 nsresult PeerConnectionCtx::Cleanup() {
   CSFLogDebug(logTag, "%s", __FUNCTION__);
 
   mCCM->destroy();
   mCCM->removeCCObserver(this);
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionCtx.h
@@ -67,16 +67,19 @@ class PeerConnectionCtx : public CSF::CC
 
   nsresult Initialize();
   nsresult Cleanup();
 
   void ChangeSipccState(PeerConnectionImpl::SipccState aState) {
     mSipccState = aState;
   }
 
+  // Telemetry Peer conection counter
+  int mConnectionCounter;
+
   // SIPCC objects
   PeerConnectionImpl::SipccState mSipccState;  // TODO(ekr@rtfm.com): refactor this out? What does it do?
   CSF::CallControlManagerPtr mCCM;
   CSF::CC_DevicePtr mDevice;
 
   static PeerConnectionCtx *gInstance;
 public:
   static nsIThread *gMainThread;
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.cpp
@@ -1,14 +1,15 @@
 /* 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/. */
 
 #include <string>
 
+#include "base/histogram.h"
 #include "vcm.h"
 #include "CSFLog.h"
 #include "ccapi_call_info.h"
 #include "CC_SIPCCCallInfo.h"
 #include "ccapi_device_info.h"
 #include "CC_SIPCCDeviceInfo.h"
 #include "cpr_string.h"
 #include "cpr_stdlib.h"
@@ -243,17 +244,17 @@ public:
         // TODO: The SDP Parse error list should be copied out and sent up
         // to the Javascript layer before being cleared here. Even though
         // there was not a failure, it is possible that the SDP parse generated
         // warnings. The WebRTC spec does not currently have a mechanism for
         // providing non-fatal warnings.
         mPC->ClearSdpParseErrorMessages();
         mObserver->OnSetRemoteDescriptionSuccess();
 #ifdef MOZILLA_INTERNAL_API
-        mPC->setStartTime();
+        mPC->startCallTelem();
 #endif
         break;
 
       case SETLOCALDESCERROR:
         mObserver->OnSetLocalDescriptionError(mCode, mReason.c_str());
         break;
 
       case SETREMOTEDESCERROR:
@@ -1552,20 +1553,29 @@ PeerConnectionImpl::ClearSdpParseErrorMe
 }
 
 const std::vector<std::string> &
 PeerConnectionImpl::GetSdpParseErrors() {
   return mSDPParseErrorMessages;
 }
 
 #ifdef MOZILLA_INTERNAL_API
-//Telemetry set start time
+//Telemetry for when calls start
 void
-PeerConnectionImpl::setStartTime() {
+PeerConnectionImpl::startCallTelem() {
+  // Start time for calls
   mStartTime = mozilla::TimeStamp::Now();
+
+  // Increment session call counter
+#ifdef MOZILLA_INTERNAL_API
+  int &cnt = PeerConnectionCtx::GetInstance()->mConnectionCounter;
+  Telemetry::GetHistogramById(Telemetry::WEBRTC_CALL_COUNT)->Subtract(cnt);
+  cnt++;
+  Telemetry::GetHistogramById(Telemetry::WEBRTC_CALL_COUNT)->Add(cnt);
+#endif
 }
 #endif
 
 #ifdef MOZILLA_INTERNAL_API
 static nsresult
 GetStreams(JSContext* cx, PeerConnectionImpl* peerConnection,
            MediaStreamList::StreamType type, JS::Value* streams)
 {
--- a/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
+++ b/media/webrtc/signaling/src/peerconnection/PeerConnectionImpl.h
@@ -278,18 +278,18 @@ public:
 
   // Called to retreive the list of parsing errors.
   const std::vector<std::string> &GetSdpParseErrors();
 
   // Sets the RTC Signaling State
   void SetSignalingState_m(SignalingState aSignalingState);
 
 #ifdef MOZILLA_INTERNAL_API
-  // Set start time for Telemetry
-  void setStartTime();
+  // initialize telemetry for when calls start
+  void startCallTelem();
 #endif
 
 private:
   PeerConnectionImpl(const PeerConnectionImpl&rhs);
   PeerConnectionImpl& operator=(PeerConnectionImpl);
   nsresult Initialize(IPeerConnectionObserver* aObserver,
                       nsIDOMWindow* aWindow,
                       const IceConfiguration* aConfiguration,
--- a/toolkit/components/telemetry/Histograms.json
+++ b/toolkit/components/telemetry/Histograms.json
@@ -3513,16 +3513,22 @@
     "description": "The number of failed ICE Connections (0) vs. number of successful ICE connections (1)."
   },
   "WEBRTC_CALL_DURATION":{
     "kind": "exponential",
     "high": "10000",
     "n_buckets": "1000",
     "description": "The length of time (in seconds) that a call lasted."
   },
+  "WEBRTC_CALL_COUNT":{
+    "kind": "exponential",
+    "high": "500",
+    "n_buckets": "50",
+    "description": "The number of calls made during a session."
+  },
   "DEVTOOLS_DEBUGGER_RDP_LOCAL_TRACERDETACH_MS": {
     "kind": "exponential",
     "high": "10000",
     "n_buckets": "1000",
     "description": "The time (in milliseconds) that it took a 'detach' request to go round trip."
   },
   "DEVTOOLS_DEBUGGER_RDP_REMOTE_TRACERDETACH_MS": {
     "kind": "exponential",