OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
9 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
10 | 10 |
11 #include <algorithm> | 11 #include <algorithm> |
12 | 12 |
13 namespace { | 13 namespace { |
14 | 14 |
15 const size_t kMaxLatencyInfoNumber = 100; | 15 const size_t kMaxLatencyInfoNumber = 100; |
| 16 const size_t kMaxCoordinatesNumber = 12; |
16 | 17 |
17 const char* GetComponentName(ui::LatencyComponentType type) { | 18 const char* GetComponentName(ui::LatencyComponentType type) { |
18 #define CASE_TYPE(t) case ui::t: return #t | 19 #define CASE_TYPE(t) case ui::t: return #t |
19 switch (type) { | 20 switch (type) { |
20 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT); | 21 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT); |
21 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT); | 22 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT); |
22 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT); | 23 CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT); |
23 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT); | 24 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_RWH_COMPONENT); |
24 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT); | 25 CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT); |
25 CASE_TYPE(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); | 26 CASE_TYPE(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
110 for (ui::LatencyInfo::LatencyMap::const_iterator it = | 111 for (ui::LatencyInfo::LatencyMap::const_iterator it = |
111 latency.latency_components.begin(); | 112 latency.latency_components.begin(); |
112 it != latency.latency_components.end(); ++it) { | 113 it != latency.latency_components.end(); ++it) { |
113 base::DictionaryValue* component_info = new base::DictionaryValue(); | 114 base::DictionaryValue* component_info = new base::DictionaryValue(); |
114 component_info->SetDouble("comp_id", it->first.second); | 115 component_info->SetDouble("comp_id", it->first.second); |
115 component_info->SetDouble("time", it->second.event_time.ToInternalValue()); | 116 component_info->SetDouble("time", it->second.event_time.ToInternalValue()); |
116 component_info->SetDouble("count", it->second.event_count); | 117 component_info->SetDouble("count", it->second.event_count); |
117 record_data->Set(GetComponentName(it->first.first), component_info); | 118 record_data->Set(GetComponentName(it->first.first), component_info); |
118 } | 119 } |
119 record_data->SetDouble("trace_id", latency.trace_id); | 120 record_data->SetDouble("trace_id", latency.trace_id); |
| 121 |
| 122 scoped_ptr<base::ListValue> coordinates(new base::ListValue()); |
| 123 for (size_t i = 0; i < latency.coordinates.size(); i++) { |
| 124 scoped_ptr<base::DictionaryValue> coordinate_pair( |
| 125 new base::DictionaryValue()); |
| 126 coordinate_pair->SetDouble("x", latency.coordinates[i].x()); |
| 127 coordinate_pair->SetDouble("y", latency.coordinates[i].y()); |
| 128 coordinates->Append(coordinate_pair.release()); |
| 129 } |
| 130 record_data->Set("coordinates", coordinates.release()); |
120 return LatencyInfoTracedValue::FromValue(record_data.PassAs<base::Value>()); | 131 return LatencyInfoTracedValue::FromValue(record_data.PassAs<base::Value>()); |
121 } | 132 } |
122 | 133 |
123 } // namespace | 134 } // namespace |
124 | 135 |
125 namespace ui { | 136 namespace ui { |
126 | 137 |
127 LatencyInfo::LatencyInfo() : trace_id(-1), terminated(false) { | 138 LatencyInfo::LatencyInfo() : trace_id(-1), terminated(false) { |
128 } | 139 } |
129 | 140 |
130 LatencyInfo::~LatencyInfo() { | 141 LatencyInfo::~LatencyInfo() { |
131 } | 142 } |
132 | 143 |
133 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, | 144 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, |
134 const char* referring_msg) { | 145 const char* referring_msg) { |
135 if (latency_info.size() > kMaxLatencyInfoNumber) { | 146 if (latency_info.size() > kMaxLatencyInfoNumber) { |
136 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " | 147 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " |
137 << latency_info.size() << " is too big."; | 148 << latency_info.size() << " is too big."; |
138 return false; | 149 return false; |
139 } | 150 } |
| 151 for (size_t i = 0; i < latency_info.size(); i++) { |
| 152 if (latency_info[i].coordinates.size() > kMaxCoordinatesNumber) { |
| 153 LOG(ERROR) << referring_msg << ", coordinates vector size " |
| 154 << latency_info[i].coordinates.size() << " is too big."; |
| 155 return false; |
| 156 } |
| 157 } |
| 158 |
140 return true; | 159 return true; |
141 } | 160 } |
142 | 161 |
143 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, | 162 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, |
144 LatencyComponentType type) { | 163 LatencyComponentType type) { |
145 for (LatencyMap::const_iterator it = other.latency_components.begin(); | 164 for (LatencyMap::const_iterator it = other.latency_components.begin(); |
146 it != other.latency_components.end(); | 165 it != other.latency_components.end(); |
147 ++it) { | 166 ++it) { |
148 if (it->first.first == type) { | 167 if (it->first.first == type) { |
149 AddLatencyNumberWithTimestamp(it->first.first, | 168 AddLatencyNumberWithTimestamp(it->first.first, |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 } | 312 } |
294 | 313 |
295 void LatencyInfo::TraceEventType(const char* event_type) { | 314 void LatencyInfo::TraceEventType(const char* event_type) { |
296 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", | 315 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", |
297 "InputLatency", | 316 "InputLatency", |
298 TRACE_ID_DONT_MANGLE(trace_id), | 317 TRACE_ID_DONT_MANGLE(trace_id), |
299 event_type); | 318 event_type); |
300 } | 319 } |
301 | 320 |
302 } // namespace ui | 321 } // namespace ui |
OLD | NEW |