| 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 <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/json/json_writer.h" | 10 #include "base/json/json_writer.h" |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { | 106 void LatencyInfoTracedValue::AppendAsTraceFormat(std::string* out) const { |
| 107 std::string tmp; | 107 std::string tmp; |
| 108 base::JSONWriter::Write(*value_, &tmp); | 108 base::JSONWriter::Write(*value_, &tmp); |
| 109 *out += tmp; | 109 *out += tmp; |
| 110 } | 110 } |
| 111 | 111 |
| 112 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) | 112 LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) |
| 113 : value_(value) { | 113 : value_(value) { |
| 114 } | 114 } |
| 115 | 115 |
| 116 struct BenchmarkEnabledInitializer { | 116 const char kTraceCategoriesForAsyncEvents[] = "benchmark,latencyInfo"; |
| 117 BenchmarkEnabledInitializer() : | 117 |
| 118 benchmark_enabled(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( | 118 struct LatencyInfoEnabledInitializer { |
| 119 "benchmark")) { | 119 LatencyInfoEnabledInitializer() : |
| 120 latency_info_enabled(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
| 121 kTraceCategoriesForAsyncEvents)) { |
| 120 } | 122 } |
| 121 | 123 |
| 122 const unsigned char* benchmark_enabled; | 124 const unsigned char* latency_info_enabled; |
| 123 }; | 125 }; |
| 124 | 126 |
| 125 static base::LazyInstance<BenchmarkEnabledInitializer>::Leaky | 127 static base::LazyInstance<LatencyInfoEnabledInitializer>::Leaky |
| 126 g_benchmark_enabled = LAZY_INSTANCE_INITIALIZER; | 128 g_latency_info_enabled = LAZY_INSTANCE_INITIALIZER; |
| 127 | 129 |
| 128 } // namespace | 130 } // namespace |
| 129 | 131 |
| 130 namespace ui { | 132 namespace ui { |
| 131 | 133 |
| 132 LatencyInfo::InputCoordinate::InputCoordinate() : x(0), y(0) { | 134 LatencyInfo::InputCoordinate::InputCoordinate() : x(0), y(0) { |
| 133 } | 135 } |
| 134 | 136 |
| 135 LatencyInfo::InputCoordinate::InputCoordinate(float x, float y) : x(x), y(y) { | 137 LatencyInfo::InputCoordinate::InputCoordinate(float x, float y) : x(x), y(y) { |
| 136 } | 138 } |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 } | 217 } |
| 216 | 218 |
| 217 void LatencyInfo::AddLatencyNumberWithTimestampImpl( | 219 void LatencyInfo::AddLatencyNumberWithTimestampImpl( |
| 218 LatencyComponentType component, | 220 LatencyComponentType component, |
| 219 int64 id, | 221 int64 id, |
| 220 int64 component_sequence_number, | 222 int64 component_sequence_number, |
| 221 base::TimeTicks time, | 223 base::TimeTicks time, |
| 222 uint32 event_count, | 224 uint32 event_count, |
| 223 const char* trace_name_str) { | 225 const char* trace_name_str) { |
| 224 | 226 |
| 225 const unsigned char* benchmark_enabled = | 227 const unsigned char* latency_info_enabled = |
| 226 g_benchmark_enabled.Get().benchmark_enabled; | 228 g_latency_info_enabled.Get().latency_info_enabled; |
| 227 | 229 |
| 228 if (IsBeginComponent(component)) { | 230 if (IsBeginComponent(component)) { |
| 229 // Should only ever add begin component once. | 231 // Should only ever add begin component once. |
| 230 CHECK_EQ(-1, trace_id_); | 232 CHECK_EQ(-1, trace_id_); |
| 231 trace_id_ = component_sequence_number; | 233 trace_id_ = component_sequence_number; |
| 232 | 234 |
| 233 if (*benchmark_enabled) { | 235 if (*latency_info_enabled) { |
| 234 // The timestamp for ASYNC_BEGIN trace event is used for drawing the | 236 // The timestamp for ASYNC_BEGIN trace event is used for drawing the |
| 235 // beginning of the trace event in trace viewer. For better visualization, | 237 // beginning of the trace event in trace viewer. For better visualization, |
| 236 // for an input event, we want to draw the beginning as when the event is | 238 // for an input event, we want to draw the beginning as when the event is |
| 237 // originally created, e.g. the timestamp of its ORIGINAL/UI_COMPONENT, | 239 // originally created, e.g. the timestamp of its ORIGINAL/UI_COMPONENT, |
| 238 // not when we actually issue the ASYNC_BEGIN trace event. | 240 // not when we actually issue the ASYNC_BEGIN trace event. |
| 239 LatencyComponent begin_component; | 241 LatencyComponent begin_component; |
| 240 int64 ts = 0; | 242 int64 ts = 0; |
| 241 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 243 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| 242 0, | 244 0, |
| 243 &begin_component) || | 245 &begin_component) || |
| 244 FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, | 246 FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, |
| 245 0, | 247 0, |
| 246 &begin_component)) { | 248 &begin_component)) { |
| 247 ts = begin_component.event_time.ToInternalValue(); | 249 ts = begin_component.event_time.ToInternalValue(); |
| 248 } else { | 250 } else { |
| 249 ts = base::TimeTicks::Now().ToInternalValue(); | 251 ts = base::TimeTicks::Now().ToInternalValue(); |
| 250 } | 252 } |
| 251 | 253 |
| 252 if (trace_name_str) { | 254 if (trace_name_str) { |
| 253 if (IsInputLatencyBeginComponent(component)) | 255 if (IsInputLatencyBeginComponent(component)) |
| 254 trace_name_ = std::string("InputLatency::") + trace_name_str; | 256 trace_name_ = std::string("InputLatency::") + trace_name_str; |
| 255 else | 257 else |
| 256 trace_name_ = std::string("Latency::") + trace_name_str; | 258 trace_name_ = std::string("Latency::") + trace_name_str; |
| 257 } | 259 } |
| 258 | 260 |
| 259 TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0( | 261 TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0( |
| 260 "benchmark,latencyInfo", | 262 kTraceCategoriesForAsyncEvents, |
| 261 trace_name_.c_str(), | 263 trace_name_.c_str(), |
| 262 TRACE_ID_DONT_MANGLE(trace_id_), | 264 TRACE_ID_DONT_MANGLE(trace_id_), |
| 263 ts); | 265 ts); |
| 264 } | 266 } |
| 265 | 267 |
| 266 TRACE_EVENT_WITH_FLOW1("input,benchmark", | 268 TRACE_EVENT_WITH_FLOW1("input,benchmark", |
| 267 "LatencyInfo.Flow", | 269 "LatencyInfo.Flow", |
| 268 TRACE_ID_DONT_MANGLE(trace_id_), | 270 TRACE_ID_DONT_MANGLE(trace_id_), |
| 269 TRACE_EVENT_FLAG_FLOW_OUT, | 271 TRACE_EVENT_FLAG_FLOW_OUT, |
| 270 "trace_id", trace_id_); | 272 "trace_id", trace_id_); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 287 new_count; | 289 new_count; |
| 288 it->second.event_count = new_count; | 290 it->second.event_count = new_count; |
| 289 } | 291 } |
| 290 } | 292 } |
| 291 | 293 |
| 292 if (IsTerminalComponent(component) && trace_id_ != -1) { | 294 if (IsTerminalComponent(component) && trace_id_ != -1) { |
| 293 // Should only ever add terminal component once. | 295 // Should only ever add terminal component once. |
| 294 CHECK(!terminated_); | 296 CHECK(!terminated_); |
| 295 terminated_ = true; | 297 terminated_ = true; |
| 296 | 298 |
| 297 if (*benchmark_enabled) { | 299 if (*latency_info_enabled) { |
| 298 TRACE_EVENT_COPY_ASYNC_END2("benchmark,latencyInfo", trace_name_.c_str(), | 300 TRACE_EVENT_COPY_ASYNC_END2(kTraceCategoriesForAsyncEvents, |
| 299 TRACE_ID_DONT_MANGLE(trace_id_), "data", | 301 trace_name_.c_str(), |
| 300 AsTraceableData(), "coordinates", | 302 TRACE_ID_DONT_MANGLE(trace_id_), |
| 301 CoordinatesAsTraceableData()); | 303 "data", AsTraceableData(), |
| 304 "coordinates", CoordinatesAsTraceableData()); |
| 302 } | 305 } |
| 303 | 306 |
| 304 TRACE_EVENT_WITH_FLOW0("input,benchmark", | 307 TRACE_EVENT_WITH_FLOW0("input,benchmark", |
| 305 "LatencyInfo.Flow", | 308 "LatencyInfo.Flow", |
| 306 TRACE_ID_DONT_MANGLE(trace_id_), | 309 TRACE_ID_DONT_MANGLE(trace_id_), |
| 307 TRACE_EVENT_FLAG_FLOW_IN); | 310 TRACE_EVENT_FLAG_FLOW_IN); |
| 308 } | 311 } |
| 309 } | 312 } |
| 310 | 313 |
| 311 scoped_refptr<base::trace_event::ConvertableToTraceFormat> | 314 scoped_refptr<base::trace_event::ConvertableToTraceFormat> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 } | 376 } |
| 374 | 377 |
| 375 bool LatencyInfo::AddCoalescedEventTimestamp(double timestamp) { | 378 bool LatencyInfo::AddCoalescedEventTimestamp(double timestamp) { |
| 376 if (coalesced_events_size_ >= kMaxCoalescedEventTimestamps) | 379 if (coalesced_events_size_ >= kMaxCoalescedEventTimestamps) |
| 377 return false; | 380 return false; |
| 378 timestamps_of_coalesced_events_[coalesced_events_size_++] = timestamp; | 381 timestamps_of_coalesced_events_[coalesced_events_size_++] = timestamp; |
| 379 return true; | 382 return true; |
| 380 } | 383 } |
| 381 | 384 |
| 382 } // namespace ui | 385 } // namespace ui |
| OLD | NEW |