| 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 "ui/events/latency_info.h" | 5 #include "ui/events/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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 } | 77 } |
| 78 | 78 |
| 79 bool IsInputLatencyBeginComponent(ui::LatencyComponentType type) { | 79 bool IsInputLatencyBeginComponent(ui::LatencyComponentType type) { |
| 80 return type == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT; | 80 return type == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT; |
| 81 } | 81 } |
| 82 | 82 |
| 83 // This class is for converting latency info to trace buffer friendly format. | 83 // This class is for converting latency info to trace buffer friendly format. |
| 84 class LatencyInfoTracedValue | 84 class LatencyInfoTracedValue |
| 85 : public base::trace_event::ConvertableToTraceFormat { | 85 : public base::trace_event::ConvertableToTraceFormat { |
| 86 public: | 86 public: |
| 87 static scoped_refptr<ConvertableToTraceFormat> FromValue( | 87 static scoped_ptr<ConvertableToTraceFormat> FromValue( |
| 88 scoped_ptr<base::Value> value); | 88 scoped_ptr<base::Value> value); |
| 89 | 89 |
| 90 void AppendAsTraceFormat(std::string* out) const override; | 90 void AppendAsTraceFormat(std::string* out) const override; |
| 91 | 91 |
| 92 private: | 92 private: |
| 93 explicit LatencyInfoTracedValue(base::Value* value); | 93 explicit LatencyInfoTracedValue(base::Value* value); |
| 94 ~LatencyInfoTracedValue() override; | 94 ~LatencyInfoTracedValue() override; |
| 95 | 95 |
| 96 scoped_ptr<base::Value> value_; | 96 scoped_ptr<base::Value> value_; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(LatencyInfoTracedValue); | 98 DISALLOW_COPY_AND_ASSIGN(LatencyInfoTracedValue); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 101 scoped_ptr<base::trace_event::ConvertableToTraceFormat> |
| 102 LatencyInfoTracedValue::FromValue(scoped_ptr<base::Value> value) { | 102 LatencyInfoTracedValue::FromValue(scoped_ptr<base::Value> value) { |
| 103 return scoped_refptr<base::trace_event::ConvertableToTraceFormat>( | 103 return scoped_ptr<base::trace_event::ConvertableToTraceFormat>( |
| 104 new LatencyInfoTracedValue(value.release())); | 104 new LatencyInfoTracedValue(value.release())); |
| 105 } | 105 } |
| 106 | 106 |
| 107 LatencyInfoTracedValue::~LatencyInfoTracedValue() { | 107 LatencyInfoTracedValue::~LatencyInfoTracedValue() { |
| 108 } | 108 } |
| 109 | 109 |
| 110 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { | 110 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { |
| 111 std::string tmp; | 111 std::string tmp; |
| 112 base::JSONWriter::Write(*value_, &tmp); | 112 base::JSONWriter::Write(*value_, &tmp); |
| 113 *out += tmp; | 113 *out += tmp; |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 "coordinates", CoordinatesAsTraceableData()); | 308 "coordinates", CoordinatesAsTraceableData()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 TRACE_EVENT_WITH_FLOW0("input,benchmark", | 311 TRACE_EVENT_WITH_FLOW0("input,benchmark", |
| 312 "LatencyInfo.Flow", | 312 "LatencyInfo.Flow", |
| 313 TRACE_ID_DONT_MANGLE(trace_id_), | 313 TRACE_ID_DONT_MANGLE(trace_id_), |
| 314 TRACE_EVENT_FLAG_FLOW_IN); | 314 TRACE_EVENT_FLAG_FLOW_IN); |
| 315 } | 315 } |
| 316 } | 316 } |
| 317 | 317 |
| 318 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 318 scoped_ptr<base::trace_event::ConvertableToTraceFormat> |
| 319 LatencyInfo::AsTraceableData() { | 319 LatencyInfo::AsTraceableData() { |
| 320 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); | 320 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); |
| 321 for (const auto& lc : latency_components_) { | 321 for (const auto& lc : latency_components_) { |
| 322 scoped_ptr<base::DictionaryValue> | 322 scoped_ptr<base::DictionaryValue> |
| 323 component_info(new base::DictionaryValue()); | 323 component_info(new base::DictionaryValue()); |
| 324 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); | 324 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); |
| 325 component_info->SetDouble( | 325 component_info->SetDouble( |
| 326 "time", | 326 "time", |
| 327 static_cast<double>(lc.second.event_time.ToInternalValue())); | 327 static_cast<double>(lc.second.event_time.ToInternalValue())); |
| 328 component_info->SetDouble("count", lc.second.event_count); | 328 component_info->SetDouble("count", lc.second.event_count); |
| 329 component_info->SetDouble("sequence_number", | 329 component_info->SetDouble("sequence_number", |
| 330 lc.second.sequence_number); | 330 lc.second.sequence_number); |
| 331 record_data->Set(GetComponentName(lc.first.first), | 331 record_data->Set(GetComponentName(lc.first.first), |
| 332 std::move(component_info)); | 332 std::move(component_info)); |
| 333 } | 333 } |
| 334 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); | 334 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); |
| 335 return LatencyInfoTracedValue::FromValue(std::move(record_data)); | 335 return LatencyInfoTracedValue::FromValue(std::move(record_data)); |
| 336 } | 336 } |
| 337 | 337 |
| 338 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 338 scoped_ptr<base::trace_event::ConvertableToTraceFormat> |
| 339 LatencyInfo::CoordinatesAsTraceableData() { | 339 LatencyInfo::CoordinatesAsTraceableData() { |
| 340 scoped_ptr<base::ListValue> coordinates(new base::ListValue()); | 340 scoped_ptr<base::ListValue> coordinates(new base::ListValue()); |
| 341 for (size_t i = 0; i < input_coordinates_size_; i++) { | 341 for (size_t i = 0; i < input_coordinates_size_; i++) { |
| 342 scoped_ptr<base::DictionaryValue> coordinate_pair( | 342 scoped_ptr<base::DictionaryValue> coordinate_pair( |
| 343 new base::DictionaryValue()); | 343 new base::DictionaryValue()); |
| 344 coordinate_pair->SetDouble("x", input_coordinates_[i].x); | 344 coordinate_pair->SetDouble("x", input_coordinates_[i].x); |
| 345 coordinate_pair->SetDouble("y", input_coordinates_[i].y); | 345 coordinate_pair->SetDouble("y", input_coordinates_[i].y); |
| 346 coordinates->Append(coordinate_pair.release()); | 346 coordinates->Append(coordinate_pair.release()); |
| 347 } | 347 } |
| 348 return LatencyInfoTracedValue::FromValue(std::move(coordinates)); | 348 return LatencyInfoTracedValue::FromValue(std::move(coordinates)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 381 } |
| 382 | 382 |
| 383 bool LatencyInfo::AddCoalescedEventTimestamp(double timestamp) { | 383 bool LatencyInfo::AddCoalescedEventTimestamp(double timestamp) { |
| 384 if (coalesced_events_size_ >= kMaxCoalescedEventTimestamps) | 384 if (coalesced_events_size_ >= kMaxCoalescedEventTimestamps) |
| 385 return false; | 385 return false; |
| 386 timestamps_of_coalesced_events_[coalesced_events_size_++] = timestamp; | 386 timestamps_of_coalesced_events_[coalesced_events_size_++] = timestamp; |
| 387 return true; | 387 return true; |
| 388 } | 388 } |
| 389 | 389 |
| 390 } // namespace ui | 390 } // namespace ui |
| OLD | NEW |