| 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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 "coordinates", CoordinatesAsTraceableData()); | 310 "coordinates", CoordinatesAsTraceableData()); |
| 311 } | 311 } |
| 312 | 312 |
| 313 TRACE_EVENT_WITH_FLOW0("input,benchmark", | 313 TRACE_EVENT_WITH_FLOW0("input,benchmark", |
| 314 "LatencyInfo.Flow", | 314 "LatencyInfo.Flow", |
| 315 TRACE_ID_DONT_MANGLE(trace_id_), | 315 TRACE_ID_DONT_MANGLE(trace_id_), |
| 316 TRACE_EVENT_FLAG_FLOW_IN); | 316 TRACE_EVENT_FLAG_FLOW_IN); |
| 317 } | 317 } |
| 318 } | 318 } |
| 319 | 319 |
| 320 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 320 scoped_ptr<base::trace_event::ConvertableToTraceFormat> |
| 321 LatencyInfo::AsTraceableData() { | 321 LatencyInfo::AsTraceableData() { |
| 322 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); | 322 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); |
| 323 for (const auto& lc : latency_components_) { | 323 for (const auto& lc : latency_components_) { |
| 324 scoped_ptr<base::DictionaryValue> | 324 scoped_ptr<base::DictionaryValue> |
| 325 component_info(new base::DictionaryValue()); | 325 component_info(new base::DictionaryValue()); |
| 326 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); | 326 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); |
| 327 component_info->SetDouble( | 327 component_info->SetDouble( |
| 328 "time", | 328 "time", |
| 329 static_cast<double>(lc.second.event_time.ToInternalValue())); | 329 static_cast<double>(lc.second.event_time.ToInternalValue())); |
| 330 component_info->SetDouble("count", lc.second.event_count); | 330 component_info->SetDouble("count", lc.second.event_count); |
| 331 component_info->SetDouble("sequence_number", | 331 component_info->SetDouble("sequence_number", |
| 332 lc.second.sequence_number); | 332 lc.second.sequence_number); |
| 333 record_data->Set(GetComponentName(lc.first.first), | 333 record_data->Set(GetComponentName(lc.first.first), |
| 334 std::move(component_info)); | 334 std::move(component_info)); |
| 335 } | 335 } |
| 336 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); | 336 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); |
| 337 return LatencyInfoTracedValue::FromValue(std::move(record_data)); | 337 return LatencyInfoTracedValue::FromValue(std::move(record_data)); |
| 338 } | 338 } |
| 339 | 339 |
| 340 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 340 scoped_ptr<base::trace_event::ConvertableToTraceFormat> |
| 341 LatencyInfo::CoordinatesAsTraceableData() { | 341 LatencyInfo::CoordinatesAsTraceableData() { |
| 342 scoped_ptr<base::ListValue> coordinates(new base::ListValue()); | 342 scoped_ptr<base::ListValue> coordinates(new base::ListValue()); |
| 343 for (size_t i = 0; i < input_coordinates_size_; i++) { | 343 for (size_t i = 0; i < input_coordinates_size_; i++) { |
| 344 scoped_ptr<base::DictionaryValue> coordinate_pair( | 344 scoped_ptr<base::DictionaryValue> coordinate_pair( |
| 345 new base::DictionaryValue()); | 345 new base::DictionaryValue()); |
| 346 coordinate_pair->SetDouble("x", input_coordinates_[i].x); | 346 coordinate_pair->SetDouble("x", input_coordinates_[i].x); |
| 347 coordinate_pair->SetDouble("y", input_coordinates_[i].y); | 347 coordinate_pair->SetDouble("y", input_coordinates_[i].y); |
| 348 coordinates->Append(coordinate_pair.release()); | 348 coordinates->Append(coordinate_pair.release()); |
| 349 } | 349 } |
| 350 return LatencyInfoTracedValue::FromValue(std::move(coordinates)); | 350 return LatencyInfoTracedValue::FromValue(std::move(coordinates)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 } | 383 } |
| 384 | 384 |
| 385 bool LatencyInfo::AddCoalescedEventTimestamp(double timestamp) { | 385 bool LatencyInfo::AddCoalescedEventTimestamp(double timestamp) { |
| 386 if (coalesced_events_size_ >= kMaxCoalescedEventTimestamps) | 386 if (coalesced_events_size_ >= kMaxCoalescedEventTimestamps) |
| 387 return false; | 387 return false; |
| 388 timestamps_of_coalesced_events_[coalesced_events_size_++] = timestamp; | 388 timestamps_of_coalesced_events_[coalesced_events_size_++] = timestamp; |
| 389 return true; | 389 return true; |
| 390 } | 390 } |
| 391 | 391 |
| 392 } // namespace ui | 392 } // namespace ui |
| OLD | NEW |