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