File: autocomplete_controller_metrics.h

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (114 lines) | stat: -rw-r--r-- 5,385 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
// Copyright 2022 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_CONTROLLER_METRICS_H_
#define COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_CONTROLLER_METRICS_H_

#include <string>

#include "base/memory/raw_ptr.h"
#include "base/memory/raw_ref.h"
#include "components/omnibox/browser/autocomplete_result.h"

class AutocompleteController;
class AutocompleteProvider;

// Used to track and log timing metrics for `AutocompleteController`. Logs 3
// sets of metrics:
// 1) How long until each async provider completes.
//    - Does not track intermediate updates if an async provider updates results
//      multiple times.
//    - Does not track sync providers (i.e., providers that don't use
//      `AutocompleteProvider::NotifyListeners()` to notify the
//      `AutocompleteController`.
//    - Tracks async providers completing syncly (i.e., providers that invoke
//      `AutocompleteProvider::NotifyListeners()` syncly; see the comment in
//      `AutocompleteController::OnProviderUpdate()`).
// 2) How long until the suggestions finalize.
//    - Does not track sync requests (i.e.,
//      `AutocompleteInput::omit_asynchronous_matches()` set to true).
//    - Does track async requests that complete syncly.
//    - Tracks suggestion additions, changes, and removals.
// 3) How many suggestions change during updates.
//    - Does not track sync request.
//    - Tracks both sync and async updates.
//    - Does not track suggestion removals.
//    - Tracks suggestion additions and changes.
class AutocompleteControllerMetrics {
 public:
  explicit AutocompleteControllerMetrics(
      const AutocompleteController& controller);

  // Called when `AutocompleteController::Start()` is called. Will 1) log
  // suggestion finalization metrics for the previous request if it hasn't
  // already (i.e. if it hasn't completed and is being interrupted), and 2)
  // reset state to track the new request. Should be called before
  // `AutocompleteController::done()`,
  // `::expire_timer_done()`, or `AutocompleteProvider::done()` have been
  // updated for the new request.
  void OnStart();

  // Called when `AutocompleteController::NotifyChanged()` is called. Will log
  // metrics on how many suggestions changed with this update. If the controller
  // is done, will also log suggestion finalization metrics; otherwise, future
  // calls to `OnProviderUpdate()`, `OnStop()`, or `OnStart()` will log
  // suggestion finalization metrics.
  void OnNotifyChanged(
      std::vector<AutocompleteResult::MatchDedupComparator> last_result,
      std::vector<AutocompleteResult::MatchDedupComparator> new_result);

  // Called when `AutocompleteController::OnProviderUpdate()` is called. If the
  // provider is done, will log how long it took; otherwise, future calls to
  // `OnProviderUpdate()`, `OnStop()`, or `OnStart()` will log how long the
  // provider took.
  void OnProviderUpdate(const AutocompleteProvider& provider) const;

  // Called when either `AutocompleteController::StopHelper()` or `OnStart()`
  // are called; i.e., when the ongoing request, if incomplete, will be
  // interrupted, e.g., because the input was updated, the popup was closed, or
  // the `AutocompleteController::stop_timer_` expired. Should be called before
  // `AutocompleteController::done()`, `::expire_timer_done()`, or
  // `AutocompleteProvider::done()` have been updated.
  void OnStop();

 private:
  friend class AutocompleteControllerMetricsTest;

  // Logs
  // 'Omnibox.AsyncAutocompletionTime.[Done|LastChange|LastDefaultChange]'.
  // Additionally logs either '*.Completed' or '*.Interrupted' for each of the
  // 3 depending on whether the controller completed or was interrupted.
  void LogSuggestionFinalizationMetrics();

  // Logs 'Omnibox.AsyncAutocompletionTime.Provider.<provider name>'.
  // Additionally logs either '*.Completed' or '*.Interrupted' depending
  // whether the provider completed or was interrupted.
  void LogProviderTimeMetrics(const AutocompleteProvider& provider) const;

  // Logs 'Omnibox.MatchStability.MatchChangeIndex'. Additionally logs
  // '*.CrossInput' or '*.Async' depending on `controller_.in_start()`.
  void LogSuggestionChangeIndexMetrics(size_t change_index) const;

  // Logs 'Omnibox.MatchStability.MatchChangeInAnyPosition'. Additionally logs
  // '*.CrossInput' or '*.Async' depending on `controller_.in_start()`.
  void LogSuggestionChangeInAnyPositionMetrics(bool changed) const;

  const raw_ref<const AutocompleteController> controller_;

  // When `OnStart()` was last invoked. Used for measuring latency. Valid even
  // if `controller_.in_start_` is false.
  base::TimeTicks start_time_;
  // When `OnProviderUpdate()` was last invoked and detected any change to the
  // suggestions.
  base::TimeTicks last_change_time_;
  // When `OnProviderUpdate()` was last invoked and detected a change to the
  // default suggestion.
  base::TimeTicks last_default_change_time_;
  // Whether `LogSuggestionFinalizationMetrics()` has been invoked for the
  // current request. Used for `DCHECK`s and iOS only. The autocomplete
  // controller state should be the source of truth instead.
  bool logged_finalization_metrics_ = true;
};

#endif  // COMPONENTS_OMNIBOX_BROWSER_AUTOCOMPLETE_CONTROLLER_METRICS_H_