Bug 1322574 - 2. Measure Android event loop latency; r=snorp
Measure the latency of each event in the Android event loop by tagging each event with the time that the event was posted, and then recording the time interval between posting and processing the event. Latencies for UI events and non-UI events are recorded separately in Telemetry.
This commit is contained in:
@@ -30,6 +30,8 @@
|
||||
#include "nsToolkitCompsCID.h"
|
||||
#include "nsGeoPosition.h"
|
||||
|
||||
#include "mozilla/ArrayUtils.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/Services.h"
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/Hal.h"
|
||||
@@ -81,6 +83,9 @@ nsIGeolocationUpdate *gLocationCallback = nullptr;
|
||||
nsAppShell* nsAppShell::sAppShell;
|
||||
StaticAutoPtr<Mutex> nsAppShell::sAppShellLock;
|
||||
|
||||
uint32_t nsAppShell::Queue::sLatencyCount[];
|
||||
uint64_t nsAppShell::Queue::sLatencyTime[];
|
||||
|
||||
NS_IMPL_ISUPPORTS_INHERITED(nsAppShell, nsBaseAppShell, nsIObserver)
|
||||
|
||||
class WakeLockListener final : public nsIDOMMozWakeLockListener {
|
||||
@@ -430,6 +435,43 @@ nsAppShell::NotifyNativeEvent()
|
||||
mEventQueue.Signal();
|
||||
}
|
||||
|
||||
void
|
||||
nsAppShell::RecordLatencies()
|
||||
{
|
||||
if (!mozilla::Telemetry::CanRecordExtended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const mozilla::Telemetry::ID timeIDs[] = {
|
||||
mozilla::Telemetry::ID::FENNEC_LOOP_UI_LATENCY,
|
||||
mozilla::Telemetry::ID::FENNEC_LOOP_OTHER_LATENCY
|
||||
};
|
||||
|
||||
static_assert(ArrayLength(Queue::sLatencyCount) == Queue::LATENCY_COUNT,
|
||||
"Count array length mismatch");
|
||||
static_assert(ArrayLength(Queue::sLatencyTime) == Queue::LATENCY_COUNT,
|
||||
"Time array length mismatch");
|
||||
static_assert(ArrayLength(timeIDs) == Queue::LATENCY_COUNT,
|
||||
"Time ID array length mismatch");
|
||||
|
||||
for (size_t i = 0; i < Queue::LATENCY_COUNT; i++) {
|
||||
if (!Queue::sLatencyCount[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const uint64_t time = Queue::sLatencyTime[i] / 1000ull /
|
||||
Queue::sLatencyCount[i];
|
||||
if (time) {
|
||||
mozilla::Telemetry::Accumulate(
|
||||
timeIDs[i], uint32_t(std::min<uint64_t>(UINT32_MAX, time)));
|
||||
}
|
||||
|
||||
// Reset latency counts.
|
||||
Queue::sLatencyCount[i] = 0;
|
||||
Queue::sLatencyTime[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define PREFNAME_COALESCE_TOUCHES "dom.event.touch.coalescing.enabled"
|
||||
static const char* kObservedPrefs[] = {
|
||||
PREFNAME_COALESCE_TOUCHES,
|
||||
|
||||
Reference in New Issue
Block a user