diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 21:38:51 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-04-17 21:38:51 +0000 |
commit | 6edd05335ce37b4518006486a1732d02514541c6 (patch) | |
tree | 436f39bc3cec2db2b385dcd39d1737a55e940c6a /cc | |
parent | 5ba43a6b9db6c81219486951340f665fc53b75f3 (diff) | |
download | chromium_src-6edd05335ce37b4518006486a1732d02514541c6.zip chromium_src-6edd05335ce37b4518006486a1732d02514541c6.tar.gz chromium_src-6edd05335ce37b4518006486a1732d02514541c6.tar.bz2 |
Switch LatencyInfo struct to use a map.
This allows us to have multiple instances of a specific component, for example each renderer will have a separate main thread and compositor.
BUG=155367
Review URL: https://codereview.chromium.org/13874002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@194687 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/cc.gyp | 1 | ||||
-rw-r--r-- | cc/debug/latency_info.cc | 61 | ||||
-rw-r--r-- | cc/debug/latency_info.h | 56 |
3 files changed, 108 insertions, 10 deletions
@@ -98,6 +98,7 @@ 'layers/io_surface_layer_impl.h', 'animation/keyframed_animation_curve.cc', 'animation/keyframed_animation_curve.h', + 'debug/latency_info.cc', 'debug/latency_info.h', 'layers/layer.cc', 'layers/layer.h', diff --git a/cc/debug/latency_info.cc b/cc/debug/latency_info.cc new file mode 100644 index 0000000..0664dfb --- /dev/null +++ b/cc/debug/latency_info.cc @@ -0,0 +1,61 @@ +// Copyright (c) 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "cc/debug/latency_info.h" + +#include <algorithm> + +namespace cc { + +LatencyInfo::LatencyInfo() { +} + +LatencyInfo::~LatencyInfo() { +} + +void LatencyInfo::MergeWith(const LatencyInfo& other) { + for (LatencyMap::const_iterator b = other.latency_components.begin(); + b != other.latency_components.end(); ++b) { + AddLatencyNumberWithTimestamp(b->first.first, b->first.second, + b->second.sequence_number, + b->second.event_time, + b->second.event_count); + } +} + +void LatencyInfo::AddLatencyNumber(LatencyComponentType component, + int64 id, int64 component_sequence_number) { + AddLatencyNumberWithTimestamp(component, id, component_sequence_number, + base::TimeTicks::Now(), 1); +} + +void LatencyInfo::AddLatencyNumberWithTimestamp( + LatencyComponentType component, int64 id, int64 component_sequence_number, + base::TimeTicks time, uint32 event_count) { + LatencyMap::key_type key = std::make_pair(component, id); + LatencyMap::iterator f = latency_components.find(key); + if (f == latency_components.end()) { + LatencyComponent info = {component_sequence_number, time, event_count}; + latency_components[key] = info; + } else { + f->second.sequence_number = std::max(component_sequence_number, + f->second.sequence_number); + uint32 new_count = event_count + f->second.event_count; + if (event_count > 0 && new_count != 0) { + // Do a weighted average, so that the new event_time is the average of + // the times of events currently in this structure with the time passed + // into this method. + f->second.event_time += (time - f->second.event_time) * event_count / + new_count; + f->second.event_count += new_count; + } + } +} + +void LatencyInfo::Clear() { + latency_components.clear(); +} + +} // namespace cc + diff --git a/cc/debug/latency_info.h b/cc/debug/latency_info.h index 1e75db8..e967caf 100644 --- a/cc/debug/latency_info.h +++ b/cc/debug/latency_info.h @@ -5,23 +5,59 @@ #ifndef CC_DEBUG_LATENCY_INFO_H_ #define CC_DEBUG_LATENCY_INFO_H_ +#include <map> +#include <utility> + +#include "base/basictypes.h" #include "base/time.h" +#include "cc/base/cc_export.h" namespace cc { -struct LatencyInfo { - int64 renderer_main_frame_number; - int64 renderer_impl_frame_number; - int64 browser_main_frame_number; - int64 browser_impl_frame_number; +enum LatencyComponentType { + kRendererMainThread, + kRendererImplThread, + kBrowserMainThread, + kBrowserImplThread, + kInputEvent, +}; + +struct CC_EXPORT LatencyInfo { + struct LatencyComponent { + // Nondecreasing number that can be used to determine what events happened + // in the component at the time this struct was sent on to the next + // component. + int64 sequence_number; + // Average time of events that happened in this component. + base::TimeTicks event_time; + // Count of events that happened in this component + uint32 event_count; + }; + + // Map a Latency Component (with a component-specific int64 id) to a + // component info. + typedef std::map<std::pair<LatencyComponentType, int64>, LatencyComponent> + LatencyMap; + + LatencyMap latency_components; + // This represents the final time that a frame is displayed it. base::TimeTicks swap_timestamp; - LatencyInfo() : - renderer_main_frame_number(0), - renderer_impl_frame_number(0), - browser_main_frame_number(0), - browser_impl_frame_number(0) {} + LatencyInfo(); + + ~LatencyInfo(); + + void MergeWith(const LatencyInfo& other); + + void AddLatencyNumber(LatencyComponentType component, int64 id, + int64 component_sequence_number); + void AddLatencyNumberWithTimestamp(LatencyComponentType component, + int64 id, int64 component_sequence_number, + base::TimeTicks time, + uint32 event_count); + + void Clear(); }; } // namespace cc |