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 "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 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 159 } | 159 } |
| 160 return true; | 160 return true; |
| 161 } | 161 } |
| 162 | 162 |
| 163 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, | 163 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, |
| 164 LatencyComponentType type) { | 164 LatencyComponentType type) { |
| 165 for (const auto& lc : other.latency_components()) { | 165 for (const auto& lc : other.latency_components()) { |
| 166 if (lc.first.first == type) { | 166 if (lc.first.first == type) { |
| 167 AddLatencyNumberWithTimestamp(lc.first.first, | 167 AddLatencyNumberWithTimestamp(lc.first.first, |
| 168 lc.first.second, | 168 lc.first.second, |
| 169 lc.second.sequence_number, | |
| 170 lc.second.event_time, | 169 lc.second.event_time, |
| 171 lc.second.event_count); | 170 lc.second.event_count); |
| 172 } | 171 } |
| 173 } | 172 } |
| 174 } | 173 } |
| 175 | 174 |
| 176 void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { | 175 void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { |
| 177 for (const auto& lc : other.latency_components()) { | 176 for (const auto& lc : other.latency_components()) { |
| 178 if (!FindLatency(lc.first.first, lc.first.second, NULL)) { | 177 if (!FindLatency(lc.first.first, lc.first.second, NULL)) { |
| 179 AddLatencyNumberWithTimestamp(lc.first.first, | 178 AddLatencyNumberWithTimestamp(lc.first.first, |
| 180 lc.first.second, | 179 lc.first.second, |
| 181 lc.second.sequence_number, | |
| 182 lc.second.event_time, | 180 lc.second.event_time, |
| 183 lc.second.event_count); | 181 lc.second.event_count); |
| 184 } | 182 } |
| 185 } | 183 } |
| 186 } | 184 } |
| 187 | 185 |
| 188 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, | 186 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, int64_t id) { |
| 189 int64_t id, | 187 AddLatencyNumberWithTimestampImpl(component, id, base::TimeTicks::Now(), 1, |
| 190 int64_t component_sequence_number) { | 188 nullptr); |
| 191 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, | |
| 192 base::TimeTicks::Now(), 1, nullptr); | |
| 193 } | 189 } |
| 194 | 190 |
| 195 void LatencyInfo::AddLatencyNumberWithTraceName( | 191 void LatencyInfo::AddLatencyNumberWithTraceName( |
| 196 LatencyComponentType component, | 192 LatencyComponentType component, |
| 197 int64_t id, | 193 int64_t id, |
| 198 int64_t component_sequence_number, | |
| 199 const char* trace_name_str) { | 194 const char* trace_name_str) { |
| 200 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, | 195 AddLatencyNumberWithTimestampImpl(component, id, base::TimeTicks::Now(), 1, |
| 201 base::TimeTicks::Now(), 1, trace_name_str); | 196 trace_name_str); |
| 202 } | 197 } |
| 203 | 198 |
| 204 void LatencyInfo::AddLatencyNumberWithTimestamp( | 199 void LatencyInfo::AddLatencyNumberWithTimestamp( |
| 205 LatencyComponentType component, | 200 LatencyComponentType component, |
| 206 int64_t id, | 201 int64_t id, |
| 207 int64_t component_sequence_number, | |
| 208 base::TimeTicks time, | 202 base::TimeTicks time, |
| 209 uint32_t event_count) { | 203 uint32_t event_count) { |
| 210 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, | 204 AddLatencyNumberWithTimestampImpl(component, id, time, event_count, nullptr); |
| 211 time, event_count, nullptr); | |
| 212 } | 205 } |
| 213 | 206 |
| 214 void LatencyInfo::AddLatencyNumberWithTimestampImpl( | 207 void LatencyInfo::AddLatencyNumberWithTimestampImpl( |
| 215 LatencyComponentType component, | 208 LatencyComponentType component, |
| 216 int64_t id, | 209 int64_t id, |
| 217 int64_t component_sequence_number, | |
| 218 base::TimeTicks time, | 210 base::TimeTicks time, |
| 219 uint32_t event_count, | 211 uint32_t event_count, |
| 220 const char* trace_name_str) { | 212 const char* trace_name_str) { |
| 221 const unsigned char* latency_info_enabled = | 213 const unsigned char* latency_info_enabled = |
| 222 g_latency_info_enabled.Get().latency_info_enabled; | 214 g_latency_info_enabled.Get().latency_info_enabled; |
| 223 | 215 |
| 224 if (IsBeginComponent(component)) { | 216 if (IsBeginComponent(component)) { |
| 217 static int global_trace_id = 0; | |
|
tdresser
2017/06/08 18:36:44
Real change.
dtapuska
2017/06/09 15:15:35
This is kind of scary because latency_info.cc coul
tdresser
2017/06/29 19:04:38
Dealt with in separate patch.
| |
| 225 // Should only ever add begin component once. | 218 // Should only ever add begin component once. |
| 226 CHECK_EQ(-1, trace_id_); | 219 CHECK_EQ(-1, trace_id_); |
| 227 trace_id_ = component_sequence_number; | 220 trace_id_ = global_trace_id++; // TODO. |
|
tdresser
2017/06/08 18:36:44
I'm not super happy with this naming. Any thoughts
dtapuska
2017/06/26 20:51:43
global trace id isn't ideal because this is actual
| |
| 228 | 221 |
| 229 if (*latency_info_enabled) { | 222 if (*latency_info_enabled) { |
| 230 // The timestamp for ASYNC_BEGIN trace event is used for drawing the | 223 // The timestamp for ASYNC_BEGIN trace event is used for drawing the |
| 231 // beginning of the trace event in trace viewer. For better visualization, | 224 // 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 | 225 // 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, | 226 // originally created, e.g. the timestamp of its ORIGINAL/UI_COMPONENT, |
| 234 // not when we actually issue the ASYNC_BEGIN trace event. | 227 // not when we actually issue the ASYNC_BEGIN trace event. |
| 235 LatencyComponent begin_component; | 228 LatencyComponent begin_component; |
| 236 base::TimeTicks ts; | 229 base::TimeTicks ts; |
| 237 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, | 230 if (FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 262 TRACE_EVENT_WITH_FLOW1("input,benchmark", | 255 TRACE_EVENT_WITH_FLOW1("input,benchmark", |
| 263 "LatencyInfo.Flow", | 256 "LatencyInfo.Flow", |
| 264 TRACE_ID_DONT_MANGLE(trace_id_), | 257 TRACE_ID_DONT_MANGLE(trace_id_), |
| 265 TRACE_EVENT_FLAG_FLOW_OUT, | 258 TRACE_EVENT_FLAG_FLOW_OUT, |
| 266 "trace_id", trace_id_); | 259 "trace_id", trace_id_); |
| 267 } | 260 } |
| 268 | 261 |
| 269 LatencyMap::key_type key = std::make_pair(component, id); | 262 LatencyMap::key_type key = std::make_pair(component, id); |
| 270 LatencyMap::iterator it = latency_components_.find(key); | 263 LatencyMap::iterator it = latency_components_.find(key); |
| 271 if (it == latency_components_.end()) { | 264 if (it == latency_components_.end()) { |
| 272 LatencyComponent info = {component_sequence_number, time, event_count, time, | 265 LatencyComponent info = {time, event_count, time, time}; |
| 273 time}; | |
| 274 latency_components_[key] = info; | 266 latency_components_[key] = info; |
| 275 } else { | 267 } else { |
| 276 it->second.sequence_number = std::max(component_sequence_number, | |
| 277 it->second.sequence_number); | |
| 278 uint32_t new_count = event_count + it->second.event_count; | 268 uint32_t new_count = event_count + it->second.event_count; |
| 279 if (event_count > 0 && new_count != 0) { | 269 if (event_count > 0 && new_count != 0) { |
| 280 // Do a weighted average, so that the new event_time is the average of | 270 // 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 | 271 // the times of events currently in this structure with the time passed |
| 282 // into this method. | 272 // into this method. |
| 283 it->second.event_time += (time - it->second.event_time) * event_count / | 273 it->second.event_time += (time - it->second.event_time) * event_count / |
| 284 new_count; | 274 new_count; |
| 285 it->second.event_count = new_count; | 275 it->second.event_count = new_count; |
| 286 it->second.last_event_time = std::max(it->second.last_event_time, time); | 276 it->second.last_event_time = std::max(it->second.last_event_time, time); |
| 287 } | 277 } |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 310 std::unique_ptr<base::DictionaryValue> record_data( | 300 std::unique_ptr<base::DictionaryValue> record_data( |
| 311 new base::DictionaryValue()); | 301 new base::DictionaryValue()); |
| 312 for (const auto& lc : latency_components_) { | 302 for (const auto& lc : latency_components_) { |
| 313 std::unique_ptr<base::DictionaryValue> component_info( | 303 std::unique_ptr<base::DictionaryValue> component_info( |
| 314 new base::DictionaryValue()); | 304 new base::DictionaryValue()); |
| 315 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); | 305 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); |
| 316 component_info->SetDouble( | 306 component_info->SetDouble( |
| 317 "time", | 307 "time", |
| 318 static_cast<double>(lc.second.event_time.ToInternalValue())); | 308 static_cast<double>(lc.second.event_time.ToInternalValue())); |
| 319 component_info->SetDouble("count", lc.second.event_count); | 309 component_info->SetDouble("count", lc.second.event_count); |
| 320 component_info->SetDouble("sequence_number", | |
| 321 lc.second.sequence_number); | |
| 322 record_data->Set(GetComponentName(lc.first.first), | 310 record_data->Set(GetComponentName(lc.first.first), |
| 323 std::move(component_info)); | 311 std::move(component_info)); |
| 324 } | 312 } |
| 325 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); | 313 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); |
| 326 return LatencyInfoTracedValue::FromValue(std::move(record_data)); | 314 return LatencyInfoTracedValue::FromValue(std::move(record_data)); |
| 327 } | 315 } |
| 328 | 316 |
| 329 bool LatencyInfo::FindLatency(LatencyComponentType type, | 317 bool LatencyInfo::FindLatency(LatencyComponentType type, |
| 330 int64_t id, | 318 int64_t id, |
| 331 LatencyComponent* output) const { | 319 LatencyComponent* output) const { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 356 LatencyMap::iterator it = latency_components_.begin(); | 344 LatencyMap::iterator it = latency_components_.begin(); |
| 357 while (it != latency_components_.end()) { | 345 while (it != latency_components_.end()) { |
| 358 if (it->first.first == type) | 346 if (it->first.first == type) |
| 359 it = latency_components_.erase(it); | 347 it = latency_components_.erase(it); |
| 360 else | 348 else |
| 361 it++; | 349 it++; |
| 362 } | 350 } |
| 363 } | 351 } |
| 364 | 352 |
| 365 } // namespace ui | 353 } // namespace ui |
| OLD | NEW |