Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(67)

Side by Side Diff: ui/latency/latency_info.cc

Issue 2804693002: Remove coordinates from LatencyInfo objects. (Closed)
Patch Set: Fix fuzzer test Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "ui/latency/latency_info.h" 5 #include "ui/latency/latency_info.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <string> 10 #include <string>
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 static base::LazyInstance<LatencyInfoEnabledInitializer>::Leaky 126 static base::LazyInstance<LatencyInfoEnabledInitializer>::Leaky
127 g_latency_info_enabled = LAZY_INSTANCE_INITIALIZER; 127 g_latency_info_enabled = LAZY_INSTANCE_INITIALIZER;
128 128
129 } // namespace 129 } // namespace
130 130
131 namespace ui { 131 namespace ui {
132 132
133 LatencyInfo::LatencyInfo() : LatencyInfo(SourceEventType::UNKNOWN) {} 133 LatencyInfo::LatencyInfo() : LatencyInfo(SourceEventType::UNKNOWN) {}
134 134
135 LatencyInfo::LatencyInfo(SourceEventType type) 135 LatencyInfo::LatencyInfo(SourceEventType type)
136 : input_coordinates_size_(0), 136 : trace_id_(-1),
137 trace_id_(-1),
138 coalesced_(false), 137 coalesced_(false),
139 terminated_(false), 138 terminated_(false),
140 source_event_type_(type) {} 139 source_event_type_(type) {}
141 140
142 LatencyInfo::LatencyInfo(const LatencyInfo& other) = default; 141 LatencyInfo::LatencyInfo(const LatencyInfo& other) = default;
143 142
144 LatencyInfo::~LatencyInfo() {} 143 LatencyInfo::~LatencyInfo() {}
145 144
146 LatencyInfo::LatencyInfo(int64_t trace_id, bool terminated) 145 LatencyInfo::LatencyInfo(int64_t trace_id, bool terminated)
147 : input_coordinates_size_(0), 146 : trace_id_(trace_id),
148 trace_id_(trace_id),
149 terminated_(terminated), 147 terminated_(terminated),
150 source_event_type_(SourceEventType::UNKNOWN) {} 148 source_event_type_(SourceEventType::UNKNOWN) {}
151 149
152 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, 150 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info,
153 const char* referring_msg) { 151 const char* referring_msg) {
154 if (latency_info.size() > kMaxLatencyInfoNumber) { 152 if (latency_info.size() > kMaxLatencyInfoNumber) {
155 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " 153 LOG(ERROR) << referring_msg << ", LatencyInfo vector size "
156 << latency_info.size() << " is too big."; 154 << latency_info.size() << " is too big.";
157 TRACE_EVENT_INSTANT1("input,benchmark", "LatencyInfo::Verify Fails", 155 TRACE_EVENT_INSTANT1("input,benchmark", "LatencyInfo::Verify Fails",
158 TRACE_EVENT_SCOPE_GLOBAL, 156 TRACE_EVENT_SCOPE_GLOBAL,
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 it->second.last_event_time = std::max(it->second.last_event_time, time); 286 it->second.last_event_time = std::max(it->second.last_event_time, time);
289 } 287 }
290 } 288 }
291 289
292 if (IsTerminalComponent(component) && trace_id_ != -1) { 290 if (IsTerminalComponent(component) && trace_id_ != -1) {
293 // Should only ever add terminal component once. 291 // Should only ever add terminal component once.
294 CHECK(!terminated_); 292 CHECK(!terminated_);
295 terminated_ = true; 293 terminated_ = true;
296 294
297 if (*latency_info_enabled) { 295 if (*latency_info_enabled) {
298 TRACE_EVENT_COPY_ASYNC_END2(kTraceCategoriesForAsyncEvents, 296 TRACE_EVENT_COPY_ASYNC_END1(
299 trace_name_.c_str(), 297 kTraceCategoriesForAsyncEvents, trace_name_.c_str(),
300 TRACE_ID_DONT_MANGLE(trace_id_), 298 TRACE_ID_DONT_MANGLE(trace_id_), "data", AsTraceableData());
301 "data", AsTraceableData(),
302 "coordinates", CoordinatesAsTraceableData());
303 } 299 }
304 300
305 TRACE_EVENT_WITH_FLOW0("input,benchmark", 301 TRACE_EVENT_WITH_FLOW0("input,benchmark",
306 "LatencyInfo.Flow", 302 "LatencyInfo.Flow",
307 TRACE_ID_DONT_MANGLE(trace_id_), 303 TRACE_ID_DONT_MANGLE(trace_id_),
308 TRACE_EVENT_FLAG_FLOW_IN); 304 TRACE_EVENT_FLAG_FLOW_IN);
309 } 305 }
310 } 306 }
311 307
312 std::unique_ptr<base::trace_event::ConvertableToTraceFormat> 308 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
(...skipping 10 matching lines...) Expand all
323 component_info->SetDouble("count", lc.second.event_count); 319 component_info->SetDouble("count", lc.second.event_count);
324 component_info->SetDouble("sequence_number", 320 component_info->SetDouble("sequence_number",
325 lc.second.sequence_number); 321 lc.second.sequence_number);
326 record_data->Set(GetComponentName(lc.first.first), 322 record_data->Set(GetComponentName(lc.first.first),
327 std::move(component_info)); 323 std::move(component_info));
328 } 324 }
329 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); 325 record_data->SetDouble("trace_id", static_cast<double>(trace_id_));
330 return LatencyInfoTracedValue::FromValue(std::move(record_data)); 326 return LatencyInfoTracedValue::FromValue(std::move(record_data));
331 } 327 }
332 328
333 std::unique_ptr<base::trace_event::ConvertableToTraceFormat>
334 LatencyInfo::CoordinatesAsTraceableData() {
335 std::unique_ptr<base::ListValue> coordinates(new base::ListValue());
336 for (size_t i = 0; i < input_coordinates_size_; i++) {
337 std::unique_ptr<base::DictionaryValue> coordinate_pair(
338 new base::DictionaryValue());
339 coordinate_pair->SetDouble("x", input_coordinates_[i].x());
340 coordinate_pair->SetDouble("y", input_coordinates_[i].y());
341 coordinates->Append(std::move(coordinate_pair));
342 }
343 return LatencyInfoTracedValue::FromValue(std::move(coordinates));
344 }
345
346 bool LatencyInfo::FindLatency(LatencyComponentType type, 329 bool LatencyInfo::FindLatency(LatencyComponentType type,
347 int64_t id, 330 int64_t id,
348 LatencyComponent* output) const { 331 LatencyComponent* output) const {
349 LatencyMap::const_iterator it = latency_components_.find( 332 LatencyMap::const_iterator it = latency_components_.find(
350 std::make_pair(type, id)); 333 std::make_pair(type, id));
351 if (it == latency_components_.end()) 334 if (it == latency_components_.end())
352 return false; 335 return false;
353 if (output) 336 if (output)
354 *output = it->second; 337 *output = it->second;
355 return true; 338 return true;
356 } 339 }
357 340
358 void LatencyInfo::RemoveLatency(LatencyComponentType type) { 341 void LatencyInfo::RemoveLatency(LatencyComponentType type) {
359 LatencyMap::iterator it = latency_components_.begin(); 342 LatencyMap::iterator it = latency_components_.begin();
360 while (it != latency_components_.end()) { 343 while (it != latency_components_.end()) {
361 if (it->first.first == type) 344 if (it->first.first == type)
362 it = latency_components_.erase(it); 345 it = latency_components_.erase(it);
363 else 346 else
364 it++; 347 it++;
365 } 348 }
366 } 349 }
367 350
368 bool LatencyInfo::AddInputCoordinate(const gfx::PointF& input_coordinate) {
369 if (input_coordinates_size_ >= kMaxInputCoordinates)
370 return false;
371 input_coordinates_[input_coordinates_size_++] = input_coordinate;
372 return true;
373 }
374
375 } // namespace ui 351 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698