| 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/json/json_writer.h" | 5 #include "base/json/json_writer.h" |
| 6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
| 7 #include "base/strings/stringprintf.h" | 7 #include "base/strings/stringprintf.h" |
| 8 #include "base/trace_event/trace_event.h" | 8 #include "base/trace_event/trace_event.h" |
| 9 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
| 10 | 10 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 63 } | 63 } |
| 64 } | 64 } |
| 65 | 65 |
| 66 bool IsBeginComponent(ui::LatencyComponentType type) { | 66 bool IsBeginComponent(ui::LatencyComponentType type) { |
| 67 return (type == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || | 67 return (type == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
| 68 type == ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT || | 68 type == ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT || |
| 69 type == ui::INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT); | 69 type == ui::INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT); |
| 70 } | 70 } |
| 71 | 71 |
| 72 // This class is for converting latency info to trace buffer friendly format. | 72 // This class is for converting latency info to trace buffer friendly format. |
| 73 class LatencyInfoTracedValue : public base::debug::ConvertableToTraceFormat { | 73 class LatencyInfoTracedValue |
| 74 : public base::trace_event::ConvertableToTraceFormat { |
| 74 public: | 75 public: |
| 75 static scoped_refptr<ConvertableToTraceFormat> FromValue( | 76 static scoped_refptr<ConvertableToTraceFormat> FromValue( |
| 76 scoped_ptr<base::Value> value); | 77 scoped_ptr<base::Value> value); |
| 77 | 78 |
| 78 void AppendAsTraceFormat(std::string* out) const override; | 79 void AppendAsTraceFormat(std::string* out) const override; |
| 79 | 80 |
| 80 private: | 81 private: |
| 81 explicit LatencyInfoTracedValue(base::Value* value); | 82 explicit LatencyInfoTracedValue(base::Value* value); |
| 82 ~LatencyInfoTracedValue() override; | 83 ~LatencyInfoTracedValue() override; |
| 83 | 84 |
| 84 scoped_ptr<base::Value> value_; | 85 scoped_ptr<base::Value> value_; |
| 85 | 86 |
| 86 DISALLOW_COPY_AND_ASSIGN(LatencyInfoTracedValue); | 87 DISALLOW_COPY_AND_ASSIGN(LatencyInfoTracedValue); |
| 87 }; | 88 }; |
| 88 | 89 |
| 89 scoped_refptr<base::debug::ConvertableToTraceFormat> | 90 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| 90 LatencyInfoTracedValue::FromValue(scoped_ptr<base::Value> value) { | 91 LatencyInfoTracedValue::FromValue(scoped_ptr<base::Value> value) { |
| 91 return scoped_refptr<base::debug::ConvertableToTraceFormat>( | 92 return scoped_refptr<base::trace_event::ConvertableToTraceFormat>( |
| 92 new LatencyInfoTracedValue(value.release())); | 93 new LatencyInfoTracedValue(value.release())); |
| 93 } | 94 } |
| 94 | 95 |
| 95 LatencyInfoTracedValue::~LatencyInfoTracedValue() { | 96 LatencyInfoTracedValue::~LatencyInfoTracedValue() { |
| 96 } | 97 } |
| 97 | 98 |
| 98 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { | 99 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { |
| 99 std::string tmp; | 100 std::string tmp; |
| 100 base::JSONWriter::Write(value_.get(), &tmp); | 101 base::JSONWriter::Write(value_.get(), &tmp); |
| 101 *out += tmp; | 102 *out += tmp; |
| 102 } | 103 } |
| 103 | 104 |
| 104 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) | 105 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) |
| 105 : value_(value) { | 106 : value_(value) { |
| 106 } | 107 } |
| 107 | 108 |
| 108 // Converts latencyinfo into format that can be dumped into trace buffer. | 109 // Converts latencyinfo into format that can be dumped into trace buffer. |
| 109 scoped_refptr<base::debug::ConvertableToTraceFormat> AsTraceableData( | 110 scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsTraceableData( |
| 110 const ui::LatencyInfo& latency) { | 111 const ui::LatencyInfo& latency) { |
| 111 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); | 112 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); |
| 112 for (ui::LatencyInfo::LatencyMap::const_iterator it = | 113 for (ui::LatencyInfo::LatencyMap::const_iterator it = |
| 113 latency.latency_components.begin(); | 114 latency.latency_components.begin(); |
| 114 it != latency.latency_components.end(); ++it) { | 115 it != latency.latency_components.end(); ++it) { |
| 115 base::DictionaryValue* component_info = new base::DictionaryValue(); | 116 base::DictionaryValue* component_info = new base::DictionaryValue(); |
| 116 component_info->SetDouble("comp_id", static_cast<double>(it->first.second)); | 117 component_info->SetDouble("comp_id", static_cast<double>(it->first.second)); |
| 117 component_info->SetDouble( | 118 component_info->SetDouble( |
| 118 "time", static_cast<double>(it->second.event_time.ToInternalValue())); | 119 "time", static_cast<double>(it->second.event_time.ToInternalValue())); |
| 119 component_info->SetDouble("count", it->second.event_count); | 120 component_info->SetDouble("count", it->second.event_count); |
| (...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 321 } | 322 } |
| 322 | 323 |
| 323 void LatencyInfo::TraceEventType(const char* event_type) { | 324 void LatencyInfo::TraceEventType(const char* event_type) { |
| 324 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", | 325 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", |
| 325 "InputLatency", | 326 "InputLatency", |
| 326 TRACE_ID_DONT_MANGLE(trace_id), | 327 TRACE_ID_DONT_MANGLE(trace_id), |
| 327 event_type); | 328 event_type); |
| 328 } | 329 } |
| 329 | 330 |
| 330 } // namespace ui | 331 } // namespace ui |
| OLD | NEW |