chromium/third_party/blink/renderer/core/timing/responsiveness_metrics.cc

// Copyright 2021 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "third_party/blink/renderer/core/timing/responsiveness_metrics.h"

#include <memory>

#include "base/metrics/histogram_functions.h"
#include "base/rand_util.h"
#include "base/strings/strcat.h"
#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_id_helper.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_recorder.h"
#include "third_party/blink/public/common/features.h"
#include "third_party/blink/public/common/responsiveness_metrics/user_interaction_latency.h"
#include "third_party/blink/renderer/core/dom/dom_high_res_time_stamp.h"
#include "third_party/blink/renderer/core/event_type_names.h"
#include "third_party/blink/renderer/core/events/pointer_event_factory.h"
#include "third_party/blink/renderer/core/frame/frame.h"
#include "third_party/blink/renderer/core/frame/local_dom_window.h"
#include "third_party/blink/renderer/core/frame/local_frame.h"
#include "third_party/blink/renderer/core/frame/local_frame_client.h"
#include "third_party/blink/renderer/core/timing/performance.h"
#include "third_party/blink/renderer/core/timing/performance_event_timing.h"
#include "third_party/blink/renderer/core/timing/window_performance.h"
#include "third_party/blink/renderer/platform/instrumentation/tracing/traced_value.h"
#include "third_party/blink/renderer/platform/runtime_enabled_features.h"
#include "third_party/perfetto/include/perfetto/tracing/track.h"

namespace blink {

namespace {
// Minimum potentially generated value for UKM sampling.
constexpr int kMinValueForSampling =;
// Maximum potentially generated value for UKM sampling.
constexpr int kMaxValueForSampling =;
// UKM sampling rate. The sampling strategy is 1/N.
constexpr int kUkmSamplingRate =;
// Minimum potential value for the first Interaction ID.
constexpr uint32_t kMinFirstInteractionID =;
// Maximum potential value for the first Interaction ID.
constexpr uint32_t kMaxFirstInteractionID =;
// Interaction ID increment. We increase this value by an integer greater than 1
// to discourage developers from using the value to 'count' the number of user
// interactions. This is consistent with the spec, which allows the increasing
// the user interaction value by a small number chosen by the user agent.
constexpr uint32_t kInteractionIdIncrement =;
// The maximum tap delay we can handle for assigning interaction id.
constexpr blink::DOMHighResTimeStamp kMaxDelayForEntries =;
// The length of the timer to flush entries from the time pointerup occurs.
constexpr base::TimeDelta kFlushTimerLength =;
// The name for the histogram which records interaction timings, and the names
// of the variants for keyboard, click/tap, and drag interactions.
const char kHistogramMaxEventDuration[] =;
const char kHistogramAllTypes[] =;
const char kHistogramKeyboard[] =;
const char kHistogramTapOrClick[] =;
const char kHistogramDrag[] =;

constexpr char kSlowInteractionToNextPaintTraceEventCategory[] =;
constexpr char kSlowInteractionToNextPaintTraceEventName[] =;

const char kPageLoadInternalEventTimingClickInteractionEvents[] =;

// These values are logged to UMA. Please keep in sync with
// "EventTimingClickInteractionEvents" in tools/metrics/histograms/enums.xml.
// LINT.IfChange
enum ClickInteractionEvents {};
// LINT.ThenChange(/tools/metrics/histograms/enums.xml:EventTimingClickInteractionEvents)

void EmitSlowInteractionToNextPaintTraceEvent(
    const ResponsivenessMetrics::EventTimestamps& event) {}

// Returns the longest event in `timestamps`.
ResponsivenessMetrics::EventTimestamps LongestEvent(
    const WTF::Vector<ResponsivenessMetrics::EventTimestamps>& events) {}

base::TimeDelta TotalEventDuration(
    // timestamps is sorted by the start_time of EventTimestamps.
    const WTF::Vector<ResponsivenessMetrics::EventTimestamps>& timestamps) {}

WTF::String InteractionTypeToString(UserInteractionType interaction_type) {}

std::unique_ptr<TracedValue> UserInteractionTraceData(
    base::TimeDelta max_duration,
    base::TimeDelta total_duration,
    UserInteractionType interaction_type) {}

void LogResponsivenessHistogram(base::TimeDelta max_event_duration,
                                const char* suffix) {}

}  // namespace

ResponsivenessMetrics::ResponsivenessMetrics(
    WindowPerformance* window_performance)
    :{}

ResponsivenessMetrics::~ResponsivenessMetrics() = default;

void ResponsivenessMetrics::RecordUserInteractionUKM(
    LocalDOMWindow* window,
    UserInteractionType interaction_type,
    const WTF::Vector<EventTimestamps>& timestamps,
    uint32_t interaction_offset) {}

void ResponsivenessMetrics::NotifyPotentialDrag(PointerId pointer_id) {}

void ResponsivenessMetrics::RecordDragTapOrClickUKM(
    LocalDOMWindow* window,
    PointerEntryAndInfo& pointer_info) {}

// Event timing pointer events processing
//
// See also ./Pointer_interaction_state_machine.md
// (https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/core/timing/Pointer_interaction_state_machine.md)
// to help understand the logic below that how event timing group up pointer
// events as interactions.
bool ResponsivenessMetrics::SetPointerIdAndRecordLatency(
    PerformanceEventTiming* entry,
    EventTimestamps event_timestamps) {}

void ResponsivenessMetrics::RecordKeyboardUKM(
    LocalDOMWindow* window,
    const WTF::Vector<EventTimestamps>& event_timestamps,
    uint32_t interaction_offset) {}

// Event timing keyboard events processing
//
// See also ./Key_interaction_state_machine.md
// (https://chromium.googlesource.com/chromium/src/+/main/third_party/blink/renderer/core/timing/Key_interaction_state_machine.md)
// to help understand the logic below that how event timing group up keyboard
// events as interactions.
bool ResponsivenessMetrics::SetKeyIdAndRecordLatency(
    PerformanceEventTiming* entry,
    EventTimestamps event_timestamps) {}

bool ResponsivenessMetrics::SetKeyIdAndRecordLatencyExperimental(
    PerformanceEventTiming* entry,
    EventTimestamps event_timestamps) {}

void ResponsivenessMetrics::FlushExpiredKeydown(
    DOMHighResTimeStamp current_time) {}

void ResponsivenessMetrics::FlushKeydown() {}

void ResponsivenessMetrics::FlushAllEventsAtPageHidden() {}

uint32_t ResponsivenessMetrics::GetInteractionCount() const {}

void ResponsivenessMetrics::UpdateInteractionId() {}

uint32_t ResponsivenessMetrics::GetCurrentInteractionId() const {}

void ResponsivenessMetrics::SetCurrentInteractionEventQueuedTimestamp(
    base::TimeTicks queued_time) {}

base::TimeTicks ResponsivenessMetrics::CurrentInteractionEventQueuedTimestamp()
    const {}

void ResponsivenessMetrics::FlushCompositionEndTimerFired(TimerBase*) {}

void ResponsivenessMetrics::FlushSequenceBasedKeyboardEvents() {}

// Determines if the key is is being held (pressed) for a sustained period of
// time. It is used when keyup does not appear in the end of a interaction (e.g
// Windows). In such cases the interaction is reported using
// sequence_based_keyboard_interaction_info_.
bool ResponsivenessMetrics::IsHoldingKey(std::optional<int> key_code) {}

void ResponsivenessMetrics::FlushPointerTimerFired(TimerBase*) {}

void ResponsivenessMetrics::FlushPointerup() {}

void ResponsivenessMetrics::ContextmenuFlushTimerFired(TimerBase*) {}

void ResponsivenessMetrics::FlushPointerdownAndPointerup() {}

void ResponsivenessMetrics::NotifyPointerdown(
    PerformanceEventTiming* entry) const {}

// Flush UKM timestamps of composition events for testing.
void ResponsivenessMetrics::FlushAllEventsForTesting() {}

void ResponsivenessMetrics::KeyboardEntryAndTimestamps::Trace(
    Visitor* visitor) const {}

void ResponsivenessMetrics::PointerEntryAndInfo::Trace(Visitor* visitor) const {}

void ResponsivenessMetrics::Trace(Visitor* visitor) const {}

perfetto::protos::pbzero::WebContentInteraction::Type
ResponsivenessMetrics::UserInteractionTypeToProto(
    UserInteractionType interaction_type) const {}

void ResponsivenessMetrics::EmitInteractionToNextPaintTraceEvent(
    const ResponsivenessMetrics::EventTimestamps& event,
    UserInteractionType interaction_type,
    base::TimeDelta total_event_duration) {}

// TODO(crbug.com/355605691): Report simulated clicks to UKM. We assume click
// is dispatched/simulated during handling of the keydown or keyup. Hence it is
// contained in either the duration of keydown or keyup. The total duration and
// max duration won't be affected. This assumption may not be true in all
// keyboard click scenarios and regardless whether it is true, we should report
// them.
bool ResponsivenessMetrics::TryHandleKeyboardEventSimulatedClick(
    PerformanceEventTiming* entry,
    const std::optional<PointerId>& pointer_id) {}
}  // namespace blink