diff options
-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 | ||||
-rw-r--r-- | content/common/cc_messages.h | 12 |
4 files changed, 116 insertions, 14 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 diff --git a/content/common/cc_messages.h b/content/common/cc_messages.h index 4b11d9b..04d7576 100644 --- a/content/common/cc_messages.h +++ b/content/common/cc_messages.h @@ -108,6 +108,7 @@ struct CONTENT_EXPORT ParamTraits<cc::DelegatedFrameData> { IPC_ENUM_TRAITS(cc::DrawQuad::Material) IPC_ENUM_TRAITS(cc::IOSurfaceDrawQuad::Orientation) +IPC_ENUM_TRAITS(cc::LatencyComponentType) IPC_ENUM_TRAITS(WebKit::WebFilterOperation::FilterType) IPC_STRUCT_TRAITS_BEGIN(cc::RenderPass::Id) @@ -211,11 +212,14 @@ IPC_STRUCT_TRAITS_BEGIN(cc::TransferableResource) IPC_STRUCT_TRAITS_MEMBER(mailbox) IPC_STRUCT_TRAITS_END() +IPC_STRUCT_TRAITS_BEGIN(cc::LatencyInfo::LatencyComponent) + IPC_STRUCT_TRAITS_MEMBER(sequence_number) + IPC_STRUCT_TRAITS_MEMBER(event_time) + IPC_STRUCT_TRAITS_MEMBER(event_count) +IPC_STRUCT_TRAITS_END() + IPC_STRUCT_TRAITS_BEGIN(cc::LatencyInfo) - IPC_STRUCT_TRAITS_MEMBER(renderer_main_frame_number) - IPC_STRUCT_TRAITS_MEMBER(renderer_impl_frame_number) - IPC_STRUCT_TRAITS_MEMBER(browser_main_frame_number) - IPC_STRUCT_TRAITS_MEMBER(browser_impl_frame_number) + IPC_STRUCT_TRAITS_MEMBER(latency_components) IPC_STRUCT_TRAITS_MEMBER(swap_timestamp) IPC_STRUCT_TRAITS_END() |