Bug 1612283 - Enforce max staleness of 60s in GV Streaming Telemetry r=janerik

Differential Revision: https://phabricator.services.mozilla.com/D61838

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Chris H-C 2020-02-06 16:48:01 +00:00
Родитель a0cebcbd90
Коммит 091402d039
3 изменённых файлов: 47 добавлений и 1 удалений

Просмотреть файл

@ -7958,6 +7958,11 @@
value: 5000
mirror: always
- name: toolkit.telemetry.geckoview.maxBatchStalenessMS
type: RelaxedAtomicUint32
value: 60000
mirror: always
- name: toolkit.telemetry.geckoview.streaming
type: RelaxedAtomicBool
value: false

Просмотреть файл

@ -246,9 +246,16 @@ GeckoView
``toolkit.telemetry.geckoview.batchDurationMS``
The duration in milliseconds over which `GeckoView Streaming Telemetry <../internals/geckoview-streaming>` will batch accumulations before passing it on to its delegate.
The duration in milliseconds over which :doc:`GeckoView Streaming Telemetry <../internals/geckoview-streaming>` will batch accumulations before passing it on to its delegate.
Defaults to 5000.
``toolkit.telemetry.geckoview.maxBatchStalenessMS``
The maximum time (in milliseconds) between flushes of the
:doc:`GeckoView Streaming Telemetry <../internals/geckoview-streaming>`
batch to its delegate.
Defaults to 60000.
Testing
-------

Просмотреть файл

@ -10,9 +10,11 @@
#include "mozilla/Services.h"
#include "mozilla/StaticMutex.h"
#include "mozilla/StaticPrefs_toolkit.h"
#include "mozilla/SystemGroup.h"
#include "mozilla/TimeStamp.h"
#include "nsDataHashtable.h"
#include "nsIObserverService.h"
#include "nsITimer.h"
#include "nsTArray.h"
#include "nsThreadUtils.h"
@ -20,6 +22,8 @@ using mozilla::Runnable;
using mozilla::StaticMutexAutoLock;
using mozilla::StaticMutexNotRecorded;
using mozilla::StaticRefPtr;
using mozilla::SystemGroup;
using mozilla::TaskCategory;
using mozilla::TimeStamp;
// Batches and streams Telemetry samples to a JNI delegate which will
@ -58,6 +62,10 @@ StaticRefPtr<LifecycleObserver> gObserver;
// -- End of gMutex-protected thread-unsafe-accessed data
// Timer that ensures data in the batch never gets too stale.
// This timer may only be manipulated on the Main Thread.
StaticRefPtr<nsITimer> gJICTimer;
class LifecycleObserver final : public nsIObserver {
public:
NS_DECL_ISUPPORTS
@ -106,6 +114,10 @@ class SendBatchRunnable : public Runnable {
MOZ_ASSERT(NS_IsMainThread());
MOZ_ASSERT(mDelegate);
if (gJICTimer) {
gJICTimer->Cancel();
}
for (auto iter = mBatch.Iter(); !iter.Done(); iter.Next()) {
const nsCString& histogramName = PromiseFlatCString(iter.Key());
const nsTArray<uint32_t>& samples = iter.Data();
@ -195,7 +207,29 @@ void BatchCheck(const StaticMutexAutoLock& aLock) {
}
}
if (gBatchBegan.IsNull()) {
// Time to begin a new batch.
gBatchBegan = TimeStamp::Now();
// Set a just-in-case timer to enforce an upper-bound on batch staleness.
NS_DispatchToMainThread(NS_NewRunnableFunction(
"GeckoviewStreamingTelemetry::ArmTimer", []() -> void {
if (!gJICTimer) {
gJICTimer =
NS_NewTimer(SystemGroup::EventTargetFor(TaskCategory::Other))
.take();
}
if (gJICTimer) {
gJICTimer->InitWithNamedFuncCallback(
[](nsITimer*, void*) -> void {
StaticMutexAutoLock locker(gMutex);
SendBatch(locker);
},
nullptr,
mozilla::StaticPrefs::
toolkit_telemetry_geckoview_maxBatchStalenessMS(),
nsITimer::TYPE_ONE_SHOT_LOW_PRIORITY,
"GeckoviewStreamingTelemetry::SendBatch");
}
}));
}
double batchDurationMs = (TimeStamp::Now() - gBatchBegan).ToMilliseconds();
if (batchDurationMs >