| 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/latency/latency_info.h" | 5 #include "ui/latency/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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 | 128 |
| 129 } // namespace | 129 } // namespace |
| 130 | 130 |
| 131 namespace ui { | 131 namespace ui { |
| 132 | 132 |
| 133 LatencyInfo::LatencyInfo() : LatencyInfo(SourceEventType::UNKNOWN) {} | 133 LatencyInfo::LatencyInfo() : LatencyInfo(SourceEventType::UNKNOWN) {} |
| 134 | 134 |
| 135 LatencyInfo::LatencyInfo(SourceEventType type) | 135 LatencyInfo::LatencyInfo(SourceEventType type) |
| 136 : trace_id_(-1), | 136 : trace_id_(-1), |
| 137 coalesced_(false), | 137 coalesced_(false), |
| 138 began_(false), |
| 138 terminated_(false), | 139 terminated_(false), |
| 139 source_event_type_(type) {} | 140 source_event_type_(type) {} |
| 140 | 141 |
| 141 LatencyInfo::LatencyInfo(const LatencyInfo& other) = default; | 142 LatencyInfo::LatencyInfo(const LatencyInfo& other) = default; |
| 142 | 143 |
| 143 LatencyInfo::~LatencyInfo() {} | 144 LatencyInfo::~LatencyInfo() {} |
| 144 | 145 |
| 145 LatencyInfo::LatencyInfo(int64_t trace_id, bool terminated) | 146 LatencyInfo::LatencyInfo(int64_t trace_id, bool terminated) |
| 146 : trace_id_(trace_id), | 147 : trace_id_(trace_id), |
| 148 began_(false), |
| 147 terminated_(terminated), | 149 terminated_(terminated), |
| 148 source_event_type_(SourceEventType::UNKNOWN) {} | 150 source_event_type_(SourceEventType::UNKNOWN) {} |
| 149 | 151 |
| 150 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, | 152 bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, |
| 151 const char* referring_msg) { | 153 const char* referring_msg) { |
| 152 if (latency_info.size() > kMaxLatencyInfoNumber) { | 154 if (latency_info.size() > kMaxLatencyInfoNumber) { |
| 153 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " | 155 LOG(ERROR) << referring_msg << ", LatencyInfo vector size " |
| 154 << latency_info.size() << " is too big."; | 156 << latency_info.size() << " is too big."; |
| 155 TRACE_EVENT_INSTANT1("input,benchmark", "LatencyInfo::Verify Fails", | 157 TRACE_EVENT_INSTANT1("input,benchmark", "LatencyInfo::Verify Fails", |
| 156 TRACE_EVENT_SCOPE_GLOBAL, | 158 TRACE_EVENT_SCOPE_GLOBAL, |
| 157 "size", latency_info.size()); | 159 "size", latency_info.size()); |
| 158 return false; | 160 return false; |
| 159 } | 161 } |
| 160 return true; | 162 return true; |
| 161 } | 163 } |
| 162 | 164 |
| 163 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, | 165 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, |
| 164 LatencyComponentType type) { | 166 LatencyComponentType type) { |
| 165 for (const auto& lc : other.latency_components()) { | 167 for (const auto& lc : other.latency_components()) { |
| 166 if (lc.first.first == type) { | 168 if (lc.first.first == type) { |
| 167 AddLatencyNumberWithTimestamp(lc.first.first, | 169 AddLatencyNumberWithTimestamp(lc.first.first, |
| 168 lc.first.second, | 170 lc.first.second, |
| 169 lc.second.sequence_number, | 171 lc.second.sequence_number, |
| 170 lc.second.event_time, | 172 lc.second.event_time, |
| 171 lc.second.event_count); | 173 lc.second.event_count); |
| 172 } | 174 } |
| 173 } | 175 } |
| 176 trace_id_ = other.trace_id(); |
| 177 coalesced_ = other.coalesced(); |
| 178 // TODO(tdresser): Ideally we'd copy |began_| here as well, but |began_| isn't |
| 179 // very intuitive, and we can actually begin multiple times across copied |
| 180 // events. |
| 181 terminated_ = other.terminated(); |
| 174 } | 182 } |
| 175 | 183 |
| 176 void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { | 184 void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { |
| 177 for (const auto& lc : other.latency_components()) { | 185 for (const auto& lc : other.latency_components()) { |
| 178 if (!FindLatency(lc.first.first, lc.first.second, NULL)) { | 186 if (!FindLatency(lc.first.first, lc.first.second, NULL)) { |
| 179 AddLatencyNumberWithTimestamp(lc.first.first, | 187 AddLatencyNumberWithTimestamp(lc.first.first, |
| 180 lc.first.second, | 188 lc.first.second, |
| 181 lc.second.sequence_number, | 189 lc.second.sequence_number, |
| 182 lc.second.event_time, | 190 lc.second.event_time, |
| 183 lc.second.event_count); | 191 lc.second.event_count); |
| 184 } | 192 } |
| 185 } | 193 } |
| 194 trace_id_ = other.trace_id(); |
| 195 coalesced_ = other.coalesced(); |
| 196 // TODO(tdresser): Ideally we'd copy |began_| here as well, but |began_| isn't |
| 197 // very intuitive, and we can actually begin multiple times across copied |
| 198 // events. |
| 199 terminated_ = other.terminated(); |
| 186 } | 200 } |
| 187 | 201 |
| 188 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, | 202 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, |
| 189 int64_t id, | 203 int64_t id, |
| 190 int64_t component_sequence_number) { | 204 int64_t component_sequence_number) { |
| 191 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, | 205 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, |
| 192 base::TimeTicks::Now(), 1, nullptr); | 206 base::TimeTicks::Now(), 1, nullptr); |
| 193 } | 207 } |
| 194 | 208 |
| 195 void LatencyInfo::AddLatencyNumberWithTraceName( | 209 void LatencyInfo::AddLatencyNumberWithTraceName( |
| (...skipping 20 matching lines...) Expand all Loading... |
| 216 int64_t id, | 230 int64_t id, |
| 217 int64_t component_sequence_number, | 231 int64_t component_sequence_number, |
| 218 base::TimeTicks time, | 232 base::TimeTicks time, |
| 219 uint32_t event_count, | 233 uint32_t event_count, |
| 220 const char* trace_name_str) { | 234 const char* trace_name_str) { |
| 221 const unsigned char* latency_info_enabled = | 235 const unsigned char* latency_info_enabled = |
| 222 g_latency_info_enabled.Get().latency_info_enabled; | 236 g_latency_info_enabled.Get().latency_info_enabled; |
| 223 | 237 |
| 224 if (IsBeginComponent(component)) { | 238 if (IsBeginComponent(component)) { |
| 225 // Should only ever add begin component once. | 239 // Should only ever add begin component once. |
| 226 CHECK_EQ(-1, trace_id_); | 240 CHECK(!began_); |
| 227 trace_id_ = component_sequence_number; | 241 began_ = true; |
| 242 // We should have a trace ID assigned by now. |
| 243 DCHECK(trace_id_ != -1); |
| 228 | 244 |
| 229 if (*latency_info_enabled) { | 245 if (*latency_info_enabled) { |
| 230 // The timestamp for ASYNC_BEGIN trace event is used for drawing the | 246 // The timestamp for ASYNC_BEGIN trace event is used for drawing the |
| 231 // beginning of the trace event in trace viewer. For better visualization, | 247 // beginning of the trace event in trace viewer. For better visualization, |
| 232 // for an input event, we want to draw the beginning as when the event is | 248 // for an input event, we want to draw the beginning as when the event is |
| 233 // originally created, e.g. the timestamp of its ORIGINAL/UI_COMPONENT, | 249 // originally created, e.g. the timestamp of its ORIGINAL/UI_COMPONENT, |
| 234 // not when we actually issue the ASYNC_BEGIN trace event. | 250 // not when we actually issue the ASYNC_BEGIN trace event. |
| 235 LatencyComponent begin_component; | 251 LatencyComponent begin_component; |
| 236 base::TimeTicks ts; | 252 base::TimeTicks ts; |
| 237 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 253 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 280 // Do a weighted average, so that the new event_time is the average of | 296 // Do a weighted average, so that the new event_time is the average of |
| 281 // the times of events currently in this structure with the time passed | 297 // the times of events currently in this structure with the time passed |
| 282 // into this method. | 298 // into this method. |
| 283 it->second.event_time += (time - it->second.event_time) * event_count / | 299 it->second.event_time += (time - it->second.event_time) * event_count / |
| 284 new_count; | 300 new_count; |
| 285 it->second.event_count = new_count; | 301 it->second.event_count = new_count; |
| 286 it->second.last_event_time = std::max(it->second.last_event_time, time); | 302 it->second.last_event_time = std::max(it->second.last_event_time, time); |
| 287 } | 303 } |
| 288 } | 304 } |
| 289 | 305 |
| 290 if (IsTerminalComponent(component) && trace_id_ != -1) { | 306 if (IsTerminalComponent(component) && began_) { |
| 291 // Should only ever add terminal component once. | 307 // Should only ever add terminal component once. |
| 292 CHECK(!terminated_); | 308 CHECK(!terminated_); |
| 293 terminated_ = true; | 309 terminated_ = true; |
| 294 | 310 |
| 295 if (*latency_info_enabled) { | 311 if (*latency_info_enabled) { |
| 296 TRACE_EVENT_COPY_ASYNC_END1( | 312 TRACE_EVENT_COPY_ASYNC_END1( |
| 297 kTraceCategoriesForAsyncEvents, trace_name_.c_str(), | 313 kTraceCategoriesForAsyncEvents, trace_name_.c_str(), |
| 298 TRACE_ID_DONT_MANGLE(trace_id_), "data", AsTraceableData()); | 314 TRACE_ID_DONT_MANGLE(trace_id_), "data", AsTraceableData()); |
| 299 } | 315 } |
| 300 | 316 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 356 LatencyMap::iterator it = latency_components_.begin(); | 372 LatencyMap::iterator it = latency_components_.begin(); |
| 357 while (it != latency_components_.end()) { | 373 while (it != latency_components_.end()) { |
| 358 if (it->first.first == type) | 374 if (it->first.first == type) |
| 359 it = latency_components_.erase(it); | 375 it = latency_components_.erase(it); |
| 360 else | 376 else |
| 361 it++; | 377 it++; |
| 362 } | 378 } |
| 363 } | 379 } |
| 364 | 380 |
| 365 } // namespace ui | 381 } // namespace ui |
| OLD | NEW |