Bug 1566367 - [2.0] Add streaming telemetry Gecko-GV bridge. r=snorp,chutten
authorEugen Sawin <esawin@me73.com>
Fri, 09 Aug 2019 04:51:10 +0000
changeset 487140 7c7e74beed99941f27135143a29b8594751dc8bd
parent 487139 cf556b5d97f1f4fbe69d45ac4e0e852ebe599e2c
child 487141 45d2398750a203b61bad00233031bc98db63c4f4
push id36412
push usernbeleuzu@mozilla.com
push dateFri, 09 Aug 2019 09:56:11 +0000
treeherdermozilla-central@36c3240e5caf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssnorp, chutten
bugs1566367
milestone70.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 1566367 - [2.0] Add streaming telemetry Gecko-GV bridge. r=snorp,chutten Differential Revision: https://phabricator.services.mozilla.com/D38899
widget/android/GeckoTelemetryDelegate.h
widget/android/moz.build
widget/android/nsAppShell.cpp
new file mode 100644
--- /dev/null
+++ b/widget/android/GeckoTelemetryDelegate.h
@@ -0,0 +1,62 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=8 sts=2 et sw=2 tw=80: */
+/* 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 GeckoTelemetryDelegate_h__
+#define GeckoTelemetryDelegate_h__
+
+#include "geckoview/streaming/GeckoViewStreamingTelemetry.h"
+
+#include <jni.h>
+
+#include "mozilla/jni/Natives.h"
+#include "GeneratedJNIWrappers.h"
+
+namespace mozilla {
+namespace widget {
+
+class GeckoTelemetryDelegate final
+    : public GeckoViewStreamingTelemetry::StreamingTelemetryDelegate,
+      public mozilla::java::RuntimeTelemetry::Proxy::Natives<
+          GeckoTelemetryDelegate> {
+ public:
+  // Implement Proxy native.
+  static void RegisterDelegateProxy(
+      mozilla::java::RuntimeTelemetry::Proxy::Param aProxy) {
+    MOZ_ASSERT(aProxy);
+
+    GeckoViewStreamingTelemetry::RegisterDelegate(
+        new GeckoTelemetryDelegate(aProxy));
+  }
+
+  explicit GeckoTelemetryDelegate(
+      mozilla::java::RuntimeTelemetry::Proxy::Param aProxy)
+      : mProxy(aProxy) {}
+
+ private:
+  // Implement StreamingTelemetryDelegate.
+  void ReceiveHistogramSamples(const nsCString& aName,
+                               const nsTArray<uint32_t>& aSamples) override {
+    if (!mozilla::jni::IsAvailable() || !mProxy || aSamples.Length() < 1) {
+      return;
+    }
+
+    nsTArray<int64_t>* samples = new nsTArray<int64_t>();
+    for (size_t i = 0; i < aSamples.Length(); i++) {
+      samples->AppendElement(static_cast<int64_t>(aSamples[i]));
+    }
+
+    mProxy->DispatchTelemetry(
+        aName,
+        mozilla::jni::LongArray::New(samples->Elements(), samples->Length()));
+  }
+
+  mozilla::java::RuntimeTelemetry::Proxy::GlobalRef mProxy;
+};
+
+}  // namespace widget
+}  // namespace mozilla
+
+#endif  // GeckoTelemetryDelegate_h__
--- a/widget/android/moz.build
+++ b/widget/android/moz.build
@@ -93,16 +93,17 @@ LOCAL_INCLUDES += [
     '/docshell/base',
     '/dom/base',
     '/dom/system/android',
     '/gfx/2d',
     '/gfx/vr',
     '/layout/painting',
     '/netwerk/base',
     '/netwerk/cache',
+    '/toolkit/components/telemetry',
     '/widget',
     '/xpcom/threads',
 ]
 
 CXXFLAGS += ['-Wno-error=shadow']
 
 OS_LIBS += ['android']
 
--- a/widget/android/nsAppShell.cpp
+++ b/widget/android/nsAppShell.cpp
@@ -59,16 +59,17 @@
 #include "AndroidAlerts.h"
 #include "AndroidUiThread.h"
 #include "ANRReporter.h"
 #include "GeckoBatteryManager.h"
 #include "GeckoNetworkManager.h"
 #include "GeckoProcessManager.h"
 #include "GeckoScreenOrientation.h"
 #include "GeckoSystemStateListener.h"
+#include "GeckoTelemetryDelegate.h"
 #include "GeckoVRManager.h"
 #include "PrefsHelper.h"
 #include "ScreenHelperAndroid.h"
 #include "Telemetry.h"
 #include "fennec/MemoryMonitor.h"
 #include "fennec/ThumbnailHelper.h"
 #include "WebExecutorSupport.h"
 
@@ -382,16 +383,17 @@ nsAppShell::nsAppShell()
   hal::Init();
 
   if (!XRE_IsParentProcess()) {
     if (jni::IsAvailable()) {
       GeckoThreadSupport::Init();
       GeckoAppShellSupport::Init();
       mozilla::GeckoSystemStateListener::Init();
       mozilla::widget::Telemetry::Init();
+      mozilla::widget::GeckoTelemetryDelegate::Init();
 
       // Set the corresponding state in GeckoThread.
       java::GeckoThread::SetState(java::GeckoThread::State::RUNNING());
     }
     return;
   }
 
   if (jni::IsAvailable()) {
@@ -408,16 +410,17 @@ nsAppShell::nsAppShell()
     mozilla::GeckoScreenOrientation::Init();
     mozilla::GeckoSystemStateListener::Init();
     mozilla::PrefsHelper::Init();
     mozilla::widget::Telemetry::Init();
     mozilla::widget::WebExecutorSupport::Init();
     nsWindow::InitNatives();
     mozilla::gl::AndroidSurfaceTexture::Init();
     mozilla::WebAuthnTokenManager::Init();
+    mozilla::widget::GeckoTelemetryDelegate::Init();
 
     if (jni::IsFennec()) {
       BrowserLocaleManagerSupport::Init();
       mozilla::ANRReporter::Init();
       mozilla::MemoryMonitor::Init();
       mozilla::ThumbnailHelper::Init();
     }