diff options
author | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 04:05:05 +0000 |
---|---|---|
committer | jbauman@chromium.org <jbauman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-05-29 04:05:05 +0000 |
commit | 4b15766b5d7cf3cf642d6c745f2ea87cda351063 (patch) | |
tree | 1c06997a265b6463a64b381636ab7618c28e4945 /ui | |
parent | 48ff0819e2af591419f0ac1209c4138123f8e9b8 (diff) | |
download | chromium_src-4b15766b5d7cf3cf642d6c745f2ea87cda351063.zip chromium_src-4b15766b5d7cf3cf642d6c745f2ea87cda351063.tar.gz chromium_src-4b15766b5d7cf3cf642d6c745f2ea87cda351063.tar.bz2 |
Move cc/debug/latency_info to ui/base.
This structure would be useful in ui/surface, which can't depend on cc/.
BUG=
Review URL: https://chromiumcodereview.appspot.com/14999012
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@202772 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui')
-rw-r--r-- | ui/base/OWNERS | 1 | ||||
-rw-r--r-- | ui/base/latency_info.cc | 66 | ||||
-rw-r--r-- | ui/base/latency_info.h | 70 | ||||
-rw-r--r-- | ui/ui.gyp | 2 |
4 files changed, 139 insertions, 0 deletions
diff --git a/ui/base/OWNERS b/ui/base/OWNERS new file mode 100644 index 0000000..5ff0082 --- /dev/null +++ b/ui/base/OWNERS @@ -0,0 +1 @@ +per-file latency_info.*=jbauman@chromium.org diff --git a/ui/base/latency_info.cc b/ui/base/latency_info.cc new file mode 100644 index 0000000..2d37585 --- /dev/null +++ b/ui/base/latency_info.cc @@ -0,0 +1,66 @@ +// Copyright 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 "ui/base/latency_info.h" + +#include <algorithm> + +namespace ui { + +LatencyInfo::LatencyInfo() { +} + +LatencyInfo::~LatencyInfo() { +} + +void LatencyInfo::MergeWith(const LatencyInfo& other) { + for (LatencyMap::const_iterator it = other.latency_components.begin(); + it != other.latency_components.end(); + ++it) { + AddLatencyNumberWithTimestamp(it->first.first, + it->first.second, + it->second.sequence_number, + it->second.event_time, + it->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 it = latency_components.find(key); + if (it == latency_components.end()) { + LatencyComponent info = {component_sequence_number, time, event_count}; + latency_components[key] = info; + return; + } + it->second.sequence_number = std::max(component_sequence_number, + it->second.sequence_number); + uint32 new_count = event_count + it->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. + it->second.event_time += (time - it->second.event_time) * event_count / + new_count; + it->second.event_count = new_count; + } +} + +void LatencyInfo::Clear() { + latency_components.clear(); +} + +} // namespace ui + diff --git a/ui/base/latency_info.h b/ui/base/latency_info.h new file mode 100644 index 0000000..718fbb4 --- /dev/null +++ b/ui/base/latency_info.h @@ -0,0 +1,70 @@ +// Copyright 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. + +#ifndef UI_BASE_LATENCY_INFO_H_ +#define UI_BASE_LATENCY_INFO_H_ + +#include <map> +#include <utility> + +#include "base/basictypes.h" +#include "base/time.h" +#include "ui/base/ui_export.h" + +namespace ui { + +enum LatencyComponentType { + INPUT_EVENT_LATENCY_COMPONENT, +}; + +struct UI_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; + + LatencyInfo(); + + ~LatencyInfo(); + + // Merges the contents of another LatencyInfo into this one. + void MergeWith(const LatencyInfo& other); + + // Modifies the current sequence number for a component, and adds a new + // sequence number with the current timestamp. + void AddLatencyNumber(LatencyComponentType component, + int64 id, + int64 component_sequence_number); + + // Modifies the current sequence number and adds a certain number of events + // for a specific component. + void AddLatencyNumberWithTimestamp(LatencyComponentType component, + int64 id, + int64 component_sequence_number, + base::TimeTicks time, + uint32 event_count); + + void Clear(); + + LatencyMap latency_components; + + // This represents the final time that a frame is displayed it. + base::TimeTicks swap_timestamp; +}; + +} // namespace ui + +#endif // UI_BASE_LATENCY_INFO_H_ + @@ -230,6 +230,8 @@ 'base/keycodes/keyboard_code_conversion_x.h', 'base/keycodes/keyboard_codes.h', 'base/keycodes/usb_keycode_map.h', + 'base/latency_info.cc', + 'base/latency_info.h', 'base/l10n/l10n_font_util.cc', 'base/l10n/l10n_font_util.h', 'base/l10n/l10n_util.cc', |