Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: ui/latency/latency_info.cc

Issue 2914023002: Remove LatencyInfo::sequence_number. (May break metrics).
Patch Set: Rebase Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 } 161 }
162 return true; 162 return true;
163 } 163 }
164 164
165 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, 165 void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other,
166 LatencyComponentType type) { 166 LatencyComponentType type) {
167 for (const auto& lc : other.latency_components()) { 167 for (const auto& lc : other.latency_components()) {
168 if (lc.first.first == type) { 168 if (lc.first.first == type) {
169 AddLatencyNumberWithTimestamp(lc.first.first, 169 AddLatencyNumberWithTimestamp(lc.first.first,
170 lc.first.second, 170 lc.first.second,
171 lc.second.sequence_number,
172 lc.second.event_time, 171 lc.second.event_time,
173 lc.second.event_count); 172 lc.second.event_count);
174 } 173 }
175 } 174 }
176 175
177 expected_queueing_time_on_dispatch_ = 176 expected_queueing_time_on_dispatch_ =
178 other.expected_queueing_time_on_dispatch_; 177 other.expected_queueing_time_on_dispatch_;
179 178
180 trace_id_ = other.trace_id(); 179 trace_id_ = other.trace_id();
181 coalesced_ = other.coalesced(); 180 coalesced_ = other.coalesced();
182 // TODO(tdresser): Ideally we'd copy |began_| here as well, but |began_| isn't 181 // TODO(tdresser): Ideally we'd copy |began_| here as well, but |began_| isn't
183 // very intuitive, and we can actually begin multiple times across copied 182 // very intuitive, and we can actually begin multiple times across copied
184 // events. 183 // events.
185 terminated_ = other.terminated(); 184 terminated_ = other.terminated();
186 } 185 }
187 186
188 void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { 187 void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) {
189 for (const auto& lc : other.latency_components()) { 188 for (const auto& lc : other.latency_components()) {
190 if (!FindLatency(lc.first.first, lc.first.second, NULL)) { 189 if (!FindLatency(lc.first.first, lc.first.second, NULL)) {
191 AddLatencyNumberWithTimestamp(lc.first.first, 190 AddLatencyNumberWithTimestamp(lc.first.first,
192 lc.first.second, 191 lc.first.second,
193 lc.second.sequence_number,
194 lc.second.event_time, 192 lc.second.event_time,
195 lc.second.event_count); 193 lc.second.event_count);
196 } 194 }
197 } 195 }
198 196
199 expected_queueing_time_on_dispatch_ = 197 expected_queueing_time_on_dispatch_ =
200 other.expected_queueing_time_on_dispatch_; 198 other.expected_queueing_time_on_dispatch_;
201 199
202 trace_id_ = other.trace_id(); 200 trace_id_ = other.trace_id();
203 coalesced_ = other.coalesced(); 201 coalesced_ = other.coalesced();
204 // TODO(tdresser): Ideally we'd copy |began_| here as well, but |began_| isn't 202 // TODO(tdresser): Ideally we'd copy |began_| here as well, but |began_| isn't
205 // very intuitive, and we can actually begin multiple times across copied 203 // very intuitive, and we can actually begin multiple times across copied
206 // events. 204 // events.
207 terminated_ = other.terminated(); 205 terminated_ = other.terminated();
208 } 206 }
209 207
210 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, 208 void LatencyInfo::AddLatencyNumber(LatencyComponentType component, int64_t id) {
211 int64_t id, 209 AddLatencyNumberWithTimestampImpl(component, id, base::TimeTicks::Now(), 1,
212 int64_t component_sequence_number) { 210 nullptr);
213 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number,
214 base::TimeTicks::Now(), 1, nullptr);
215 } 211 }
216 212
217 void LatencyInfo::AddLatencyNumberWithTraceName( 213 void LatencyInfo::AddLatencyNumberWithTraceName(
218 LatencyComponentType component, 214 LatencyComponentType component,
219 int64_t id, 215 int64_t id,
220 int64_t component_sequence_number,
221 const char* trace_name_str) { 216 const char* trace_name_str) {
222 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, 217 AddLatencyNumberWithTimestampImpl(component, id, base::TimeTicks::Now(), 1,
223 base::TimeTicks::Now(), 1, trace_name_str); 218 trace_name_str);
224 } 219 }
225 220
226 void LatencyInfo::AddLatencyNumberWithTimestamp( 221 void LatencyInfo::AddLatencyNumberWithTimestamp(
227 LatencyComponentType component, 222 LatencyComponentType component,
228 int64_t id, 223 int64_t id,
229 int64_t component_sequence_number,
230 base::TimeTicks time, 224 base::TimeTicks time,
231 uint32_t event_count) { 225 uint32_t event_count) {
232 AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, 226 AddLatencyNumberWithTimestampImpl(component, id, time, event_count, nullptr);
233 time, event_count, nullptr);
234 } 227 }
235 228
236 void LatencyInfo::AddLatencyNumberWithTimestampImpl( 229 void LatencyInfo::AddLatencyNumberWithTimestampImpl(
237 LatencyComponentType component, 230 LatencyComponentType component,
238 int64_t id, 231 int64_t id,
239 int64_t component_sequence_number,
240 base::TimeTicks time, 232 base::TimeTicks time,
241 uint32_t event_count, 233 uint32_t event_count,
242 const char* trace_name_str) { 234 const char* trace_name_str) {
243 const unsigned char* latency_info_enabled = 235 const unsigned char* latency_info_enabled =
244 g_latency_info_enabled.Get().latency_info_enabled; 236 g_latency_info_enabled.Get().latency_info_enabled;
245 237
246 if (IsBeginComponent(component)) { 238 if (IsBeginComponent(component)) {
247 // Should only ever add begin component once. 239 // Should only ever add begin component once.
248 CHECK(!began_); 240 CHECK(!began_);
249 began_ = true; 241 began_ = true;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 TRACE_EVENT_WITH_FLOW1("input,benchmark", 278 TRACE_EVENT_WITH_FLOW1("input,benchmark",
287 "LatencyInfo.Flow", 279 "LatencyInfo.Flow",
288 TRACE_ID_DONT_MANGLE(trace_id_), 280 TRACE_ID_DONT_MANGLE(trace_id_),
289 TRACE_EVENT_FLAG_FLOW_OUT, 281 TRACE_EVENT_FLAG_FLOW_OUT,
290 "trace_id", trace_id_); 282 "trace_id", trace_id_);
291 } 283 }
292 284
293 LatencyMap::key_type key = std::make_pair(component, id); 285 LatencyMap::key_type key = std::make_pair(component, id);
294 LatencyMap::iterator it = latency_components_.find(key); 286 LatencyMap::iterator it = latency_components_.find(key);
295 if (it == latency_components_.end()) { 287 if (it == latency_components_.end()) {
296 LatencyComponent info = {component_sequence_number, time, event_count, time, 288 LatencyComponent info = {time, event_count, time, time};
297 time};
298 latency_components_[key] = info; 289 latency_components_[key] = info;
299 } else { 290 } else {
300 it->second.sequence_number = std::max(component_sequence_number,
301 it->second.sequence_number);
302 uint32_t new_count = event_count + it->second.event_count; 291 uint32_t new_count = event_count + it->second.event_count;
303 if (event_count > 0 && new_count != 0) { 292 if (event_count > 0 && new_count != 0) {
304 // Do a weighted average, so that the new event_time is the average of 293 // Do a weighted average, so that the new event_time is the average of
305 // the times of events currently in this structure with the time passed 294 // the times of events currently in this structure with the time passed
306 // into this method. 295 // into this method.
307 it->second.event_time += (time - it->second.event_time) * event_count / 296 it->second.event_time += (time - it->second.event_time) * event_count /
308 new_count; 297 new_count;
309 it->second.event_count = new_count; 298 it->second.event_count = new_count;
310 it->second.last_event_time = std::max(it->second.last_event_time, time); 299 it->second.last_event_time = std::max(it->second.last_event_time, time);
311 } 300 }
(...skipping 22 matching lines...) Expand all
334 std::unique_ptr<base::DictionaryValue> record_data( 323 std::unique_ptr<base::DictionaryValue> record_data(
335 new base::DictionaryValue()); 324 new base::DictionaryValue());
336 for (const auto& lc : latency_components_) { 325 for (const auto& lc : latency_components_) {
337 std::unique_ptr<base::DictionaryValue> component_info( 326 std::unique_ptr<base::DictionaryValue> component_info(
338 new base::DictionaryValue()); 327 new base::DictionaryValue());
339 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); 328 component_info->SetDouble("comp_id", static_cast<double>(lc.first.second));
340 component_info->SetDouble( 329 component_info->SetDouble(
341 "time", 330 "time",
342 static_cast<double>(lc.second.event_time.ToInternalValue())); 331 static_cast<double>(lc.second.event_time.ToInternalValue()));
343 component_info->SetDouble("count", lc.second.event_count); 332 component_info->SetDouble("count", lc.second.event_count);
344 component_info->SetDouble("sequence_number",
345 lc.second.sequence_number);
346 record_data->Set(GetComponentName(lc.first.first), 333 record_data->Set(GetComponentName(lc.first.first),
347 std::move(component_info)); 334 std::move(component_info));
348 } 335 }
349 record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); 336 record_data->SetDouble("trace_id", static_cast<double>(trace_id_));
350 return LatencyInfoTracedValue::FromValue(std::move(record_data)); 337 return LatencyInfoTracedValue::FromValue(std::move(record_data));
351 } 338 }
352 339
353 bool LatencyInfo::FindLatency(LatencyComponentType type, 340 bool LatencyInfo::FindLatency(LatencyComponentType type,
354 int64_t id, 341 int64_t id,
355 LatencyComponent* output) const { 342 LatencyComponent* output) const {
(...skipping 24 matching lines...) Expand all
380 LatencyMap::iterator it = latency_components_.begin(); 367 LatencyMap::iterator it = latency_components_.begin();
381 while (it != latency_components_.end()) { 368 while (it != latency_components_.end()) {
382 if (it->first.first == type) 369 if (it->first.first == type)
383 it = latency_components_.erase(it); 370 it = latency_components_.erase(it);
384 else 371 else
385 it++; 372 it++;
386 } 373 }
387 } 374 }
388 375
389 } // namespace ui 376 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698