summaryrefslogtreecommitdiffstats
path: root/ui/events/latency_info.h
blob: ea3293cb3783c98b1516b8b21caeb62a9bb97af9 (plain)
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
115
116
117
118
119
120
121
122
123
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_EVENTS_LATENCY_INFO_H_
#define UI_EVENTS_LATENCY_INFO_H_

#include <map>
#include <utility>

#include "base/basictypes.h"
#include "base/time/time.h"
#include "ui/events/events_base_export.h"

namespace ui {

enum LatencyComponentType {
  // ---------------------------BEGIN COMPONENT-------------------------------
  // BEGIN COMPONENT is when we show the latency begin in chrome://tracing.
  // Timestamp when the input event is sent from RenderWidgetHost to renderer.
  INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
  // ---------------------------NORMAL COMPONENT-------------------------------
  // Timestamp when the scroll update gesture event is sent from RWH to
  // renderer. In Aura, touch event's LatencyInfo is carried over to the gesture
  // event. So gesture event's INPUT_EVENT_LATENCY_RWH_COMPONENT is the
  // timestamp when its original touch events is sent from RWH to renderer.
  // In non-aura platform, INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT
  // is the same as INPUT_EVENT_LATENCY_RWH_COMPONENT.
  INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT,
  // The original timestamp of the touch event which converts to scroll update.
  INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT,
  // Original timestamp for input event (e.g. timestamp from kernel).
  INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
  // Timestamp when the UI event is created.
  INPUT_EVENT_LATENCY_UI_COMPONENT,
  // This is special component indicating there is rendering scheduled for
  // the event associated with this LatencyInfo.
  INPUT_EVENT_LATENCY_RENDERING_SCHEDULED_COMPONENT,
  // Timestamp when the touch event is acked.
  INPUT_EVENT_LATENCY_ACKED_TOUCH_COMPONENT,
  // ---------------------------TERMINAL COMPONENT-----------------------------
  // TERMINAL COMPONENT is when we show the latency end in chrome://tracing.
  // Timestamp when the mouse event is acked from renderer and it does not
  // cause any rendering scheduled.
  INPUT_EVENT_LATENCY_TERMINATED_MOUSE_COMPONENT,
  // Timestamp when the touch event is acked from renderer and it does not
  // cause any rendering schedueld and does not generate any gesture event.
  INPUT_EVENT_LATENCY_TERMINATED_TOUCH_COMPONENT,
  // Timestamp when the gesture event is acked from renderer, and it does not
  // cause any rendering schedueld.
  INPUT_EVENT_LATENCY_TERMINATED_GESTURE_COMPONENT,
  // Timestamp when the frame is swapped (i.e. when the rendering caused by
  // input event actually takes effect).
  INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT,
  // Frame number when a window snapshot was requested. The snapshot
  // is taken when the rendering results actually reach the screen.
  WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT
};

struct EVENTS_BASE_EXPORT LatencyInfo {
  struct LatencyComponent {
    // Nondecreasing number that can be used to determine what events happened
    // in the component at the time this struct was sent on to the next
    // component.
    int64 sequence_number;
    // Average time of events that happened in this component.
    base::TimeTicks event_time;
    // Count of events that happened in this component
    uint32 event_count;
  };

  // Map a Latency Component (with a component-specific int64 id) to a
  // component info.
  typedef std::map<std::pair<LatencyComponentType, int64>, LatencyComponent>
      LatencyMap;

  LatencyInfo();

  ~LatencyInfo();

  // Merges the contents of another LatencyInfo into this one.
  void MergeWith(const LatencyInfo& other);

  // Add LatencyComponents that are in |other| but not in |this|.
  void AddNewLatencyFrom(const LatencyInfo& other);

  // Modifies the current sequence number for a component, and adds a new
  // sequence number with the current timestamp.
  void AddLatencyNumber(LatencyComponentType component,
                        int64 id,
                        int64 component_sequence_number);

  // Modifies the current sequence number and adds a certain number of events
  // for a specific component.
  // TODO(miletus): Remove the |dump_to_trace| once we remove MergeWith().
  void AddLatencyNumberWithTimestamp(LatencyComponentType component,
                                     int64 id,
                                     int64 component_sequence_number,
                                     base::TimeTicks time,
                                     uint32 event_count,
                                     bool dump_to_trace);

  // Returns true if the a component with |type| and |id| is found in
  // the latency_components and the component is stored to |output| if
  // |output| is not NULL. Returns false if no such component is found.
  bool FindLatency(LatencyComponentType type,
                   int64 id,
                   LatencyComponent* output) const;

  void RemoveLatency(LatencyComponentType type);

  void Clear();

  LatencyMap latency_components;
  // The unique id for matching the ASYNC_BEGIN/END trace event.
  int64 trace_id;
  // Whether a terminal component has been added.
  bool terminated;
};

}  // namespace ui

#endif  // UI_EVENTS_LATENCY_INFO_H_