Chromium Code Reviews| 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/debug/trace_event.h" | 5 #include "base/debug/trace_event.h" |
| 6 #include "base/json/json_writer.h" | 6 #include "base/json/json_writer.h" |
| 7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "ui/events/latency_info.h" | 9 #include "ui/events/latency_info.h" |
| 10 | 10 |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 97 std::string tmp; | 97 std::string tmp; |
| 98 base::JSONWriter::Write(value_.get(), &tmp); | 98 base::JSONWriter::Write(value_.get(), &tmp); |
| 99 *out += tmp; | 99 *out += tmp; |
| 100 } | 100 } |
| 101 | 101 |
| 102 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) | 102 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) |
| 103 : value_(value) { | 103 : value_(value) { |
| 104 } | 104 } |
| 105 | 105 |
| 106 // Converts latencyinfo into format that can be dumped into trace buffer. | 106 // Converts latencyinfo into format that can be dumped into trace buffer. |
| 107 scoped_refptr<base::debug::ConvertableToTraceFormat> AsTraceableData( | 107 scoped_refptr<base::debug::ConvertableToTraceFormat> AsTraceableData( |
|
jdduke (slow)
2014/09/17 17:43:34
Just to be clear, this method is only called when
Yufeng Shen (Slow to review)
2014/09/17 18:27:53
It is called below as an argument in TRACE_EVENT_A
Sami
2014/09/18 14:52:37
That's right. When tracing is disabled this code d
| |
| 108 const ui::LatencyInfo& latency) { | 108 const ui::LatencyInfo& latency) { |
| 109 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); | 109 scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); |
| 110 for (ui::LatencyInfo::LatencyMap::const_iterator it = | 110 for (ui::LatencyInfo::LatencyMap::const_iterator it = |
| 111 latency.latency_components.begin(); | 111 latency.latency_components.begin(); |
| 112 it != latency.latency_components.end(); ++it) { | 112 it != latency.latency_components.end(); ++it) { |
| 113 base::DictionaryValue* component_info = new base::DictionaryValue(); | 113 base::DictionaryValue* component_info = new base::DictionaryValue(); |
| 114 component_info->SetDouble("comp_id", it->first.second); | 114 component_info->SetDouble("comp_id", it->first.second); |
| 115 component_info->SetDouble("time", it->second.event_time.ToInternalValue()); | 115 component_info->SetDouble("time", it->second.event_time.ToInternalValue()); |
| 116 component_info->SetDouble("count", it->second.event_count); | 116 component_info->SetDouble("count", it->second.event_count); |
| 117 record_data->Set(GetComponentName(it->first.first), component_info); | 117 record_data->Set(GetComponentName(it->first.first), component_info); |
| 118 } | 118 } |
| 119 record_data->SetDouble("trace_id", latency.trace_id); | 119 record_data->SetDouble("trace_id", latency.trace_id); |
| 120 | |
| 121 scoped_ptr<base::ListValue> coordinates(new base::ListValue()); | |
| 122 for (size_t i = 0; i < latency.input_coordinates_size; i++) { | |
| 123 scoped_ptr<base::DictionaryValue> coordinate_pair( | |
| 124 new base::DictionaryValue()); | |
| 125 coordinate_pair->SetDouble("x", latency.input_coordinates[i][0]); | |
| 126 coordinate_pair->SetDouble("y", latency.input_coordinates[i][1]); | |
| 127 coordinates->Append(coordinate_pair.release()); | |
| 128 } | |
| 129 record_data->Set("coordinates", coordinates.release()); | |
| 120 return LatencyInfoTracedValue::FromValue(record_data.PassAs<base::Value>()); | 130 return LatencyInfoTracedValue::FromValue(record_data.PassAs<base::Value>()); |
| 121 } | 131 } |
| 122 | 132 |
| 123 } // namespace | 133 } // namespace |
| 124 | 134 |
| 125 namespace ui { | 135 namespace ui { |
| 126 | 136 |
| 127 LatencyInfo::LatencyInfo() : trace_id(-1), terminated(false) { | 137 LatencyInfo::LatencyInfo() |
| 138 : input_coordinates_size(0), trace_id(-1), terminated(false) { | |
| 139 for (size_t i = 0; i < arraysize(input_coordinates); ++i) | |
| 140 for (size_t j = 0; j < arraysize(input_coordinates[i]); ++j) | |
| 141 input_coordinates[i][j] = 0; | |
| 128 } | 142 } |
| 129 | 143 |
| 130 LatencyInfo::~LatencyInfo() { | 144 LatencyInfo::~LatencyInfo() { |
| 131 } | 145 } |
| 132 | 146 |
| 133 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, | 147 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, |
| 134 const char* referring_msg) { | 148 const char* referring_msg) { |
| 135 if (latency_info.size() > kMaxLatencyInfoNumber) { | 149 if (latency_info.size() > kMaxLatencyInfoNumber) { |
| 136 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " | 150 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " |
| 137 << latency_info.size() << " is too big."; | 151 << latency_info.size() << " is too big."; |
| 138 return false; | 152 return false; |
| 139 } | 153 } |
| 154 for (size_t i = 0; i < latency_info.size(); i++) { | |
| 155 if (latency_info[i].input_coordinates_size > kMaxInputCoordinates) { | |
| 156 LOG(ERROR) << referring_msg << ", coordinate vector size " | |
| 157 << latency_info[i].input_coordinates_size << " is too big."; | |
| 158 return false; | |
| 159 } | |
| 160 } | |
| 161 | |
| 140 return true; | 162 return true; |
| 141 } | 163 } |
| 142 | 164 |
| 143 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, | 165 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, |
| 144 LatencyComponentType type) { | 166 LatencyComponentType type) { |
| 145 for (LatencyMap::const_iterator it = other.latency_components.begin(); | 167 for (LatencyMap::const_iterator it = other.latency_components.begin(); |
| 146 it != other.latency_components.end(); | 168 it != other.latency_components.end(); |
| 147 ++it) { | 169 ++it) { |
| 148 if (it->first.first == type) { | 170 if (it->first.first == type) { |
| 149 AddLatencyNumberWithTimestamp(it->first.first, | 171 AddLatencyNumberWithTimestamp(it->first.first, |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 293 } | 315 } |
| 294 | 316 |
| 295 void LatencyInfo::TraceEventType(const char* event_type) { | 317 void LatencyInfo::TraceEventType(const char* event_type) { |
| 296 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", | 318 TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", |
| 297 "InputLatency", | 319 "InputLatency", |
| 298 TRACE_ID_DONT_MANGLE(trace_id), | 320 TRACE_ID_DONT_MANGLE(trace_id), |
| 299 event_type); | 321 event_type); |
| 300 } | 322 } |
| 301 | 323 |
| 302 } // namespace ui | 324 } // namespace ui |
| OLD | NEW |