diff options
Diffstat (limited to 'ui/events')
-rw-r--r-- | ui/events/BUILD.gn | 3 | ||||
-rw-r--r-- | ui/events/events.gyp | 20 | ||||
-rw-r--r-- | ui/events/ipc/BUILD.gn | 6 | ||||
-rw-r--r-- | ui/events/ipc/events_ipc.gyp | 30 | ||||
-rw-r--r-- | ui/events/ipc/events_ipc_export.h | 29 | ||||
-rw-r--r-- | ui/events/ipc/latency_info_param_traits.cc | 72 | ||||
-rw-r--r-- | ui/events/ipc/latency_info_param_traits.h | 38 | ||||
-rw-r--r-- | ui/events/ipc/latency_info_param_traits_macros.h | 29 | ||||
-rw-r--r-- | ui/events/ipc/latency_info_param_traits_unittest.cc | 78 | ||||
-rw-r--r-- | ui/events/latency_info.cc | 157 | ||||
-rw-r--r-- | ui/events/latency_info.h | 54 | ||||
-rw-r--r-- | ui/events/latency_info_unittest.cc | 17 |
12 files changed, 351 insertions, 182 deletions
diff --git a/ui/events/BUILD.gn b/ui/events/BUILD.gn index 58fdaea..6b45bb9 100644 --- a/ui/events/BUILD.gn +++ b/ui/events/BUILD.gn @@ -323,6 +323,7 @@ test("events_unittests") { "gesture_detection/touch_disposition_gesture_filter_unittest.cc", "gesture_detection/velocity_tracker_unittest.cc", "gestures/fling_curve_unittest.cc", + "ipc/latency_info_param_traits_unittest.cc", "keycodes/dom/keycode_converter_unittest.cc", "keycodes/keyboard_code_conversion_unittest.cc", "latency_info_unittest.cc", @@ -337,9 +338,11 @@ test("events_unittests") { ":test_support", "//base", "//base/test:run_all_unittests", + "//ipc:test_support", "//skia", "//testing/gtest", "//ui/events/devices", + "//ui/events/ipc:events_ipc", "//ui/events/platform", "//ui/gfx:test_support", ] diff --git a/ui/events/events.gyp b/ui/events/events.gyp index 7dacf3a..22dfaec 100644 --- a/ui/events/events.gyp +++ b/ui/events/events.gyp @@ -291,6 +291,23 @@ ], }, { + # GN version: //ui/events/ipc:events_ipc + 'target_name': 'events_ipc', + 'type': '<(component)', + 'dependencies': [ + '<(DEPTH)/base/base.gyp:base', + '<(DEPTH)/ipc/ipc.gyp:ipc', + 'events_base', + ], + 'defines': [ + 'EVENTS_IPC_IMPLEMENTATION', + ], + 'sources': [ + 'ipc/latency_info_param_traits.cc', + 'ipc/latency_info_param_traits.h', + ], + }, + { # GN version: //ui/events:test_support 'target_name': 'events_test_support', 'type': 'static_library', @@ -354,6 +371,7 @@ '<(DEPTH)/base/base.gyp:base', '<(DEPTH)/base/base.gyp:run_all_unittests', '<(DEPTH)/base/base.gyp:test_support_base', + '<(DEPTH)/ipc/ipc.gyp:test_support_ipc', '<(DEPTH)/skia/skia.gyp:skia', '<(DEPTH)/testing/gtest.gyp:gtest', '<(DEPTH)/third_party/mesa/mesa.gyp:osmesa', @@ -364,6 +382,7 @@ 'dom_keycode_converter', 'events', 'events_base', + 'events_ipc', 'events_test_support', 'gesture_detection', 'gestures_blink', @@ -391,6 +410,7 @@ 'gestures/fling_curve_unittest.cc', 'gestures/gesture_provider_aura_unittest.cc', 'gestures/motion_event_aura_unittest.cc', + 'ipc/latency_info_param_traits_unittest.cc', 'keycodes/dom/keycode_converter_unittest.cc', 'keycodes/keyboard_code_conversion_unittest.cc', 'latency_info_unittest.cc', diff --git a/ui/events/ipc/BUILD.gn b/ui/events/ipc/BUILD.gn index 4adc3d2..f7eaf88 100644 --- a/ui/events/ipc/BUILD.gn +++ b/ui/events/ipc/BUILD.gn @@ -4,18 +4,18 @@ import("//build/config/ui.gni") -component("ipc") { +component("events_ipc") { output_name = "events_ipc" sources = [ "latency_info_param_traits.cc", "latency_info_param_traits.h", ] - defines = [ "EVENTS_IMPLEMENTATION" ] + defines = [ "EVENTS_IPC_IMPLEMENTATION" ] deps = [ "//base", "//ipc", - "//ui/events", + "//ui/events:events_base", ] } diff --git a/ui/events/ipc/events_ipc.gyp b/ui/events/ipc/events_ipc.gyp deleted file mode 100644 index 898bf2f..0000000 --- a/ui/events/ipc/events_ipc.gyp +++ /dev/null @@ -1,30 +0,0 @@ -# Copyright 2014 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. - -{ - 'variables': { - 'chromium_code': 1, - }, - 'targets': [ - { - # GN version: //ui/events/ipc - 'target_name': 'events_ipc', - 'type': '<(component)', - 'dependencies': [ - '<(DEPTH)/base/base.gyp:base', - '<(DEPTH)/ipc/ipc.gyp:ipc', - ], - 'defines': [ - 'EVENTS_IMPLEMENTATION', - ], - 'include_dirs': [ - '../..', - ], - 'sources': [ - 'latency_info_param_traits.cc', - 'latency_info_param_traits.h', - ], - }, - ], -} diff --git a/ui/events/ipc/events_ipc_export.h b/ui/events/ipc/events_ipc_export.h new file mode 100644 index 0000000..a02d669 --- /dev/null +++ b/ui/events/ipc/events_ipc_export.h @@ -0,0 +1,29 @@ +// Copyright (c) 2015 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_EVENTS_EVENTS_IPC_EXPORT_H_ +#define UI_EVENTS_EVENTS_IPC_EXPORT_H_ + +#if defined(COMPONENT_BUILD) +#if defined(WIN32) + +#if defined(EVENTS_IPC_IMPLEMENTATION) +#define EVENTS_IPC_EXPORT __declspec(dllexport) +#else +#define EVENTS_IPC_EXPORT __declspec(dllimport) +#endif // defined(EVENTS_IPC_IMPLEMENTATION) + +#else // defined(WIN32) +#if defined(EVENTS_IPC_IMPLEMENTATION) +#define EVENTS_IPC_EXPORT __attribute__((visibility("default"))) +#else +#define EVENTS_IPC_EXPORT +#endif +#endif + +#else // defined(COMPONENT_BUILD) +#define EVENTS_IPC_EXPORT +#endif + +#endif // UI_EVENTS_EVENTS_IPC_EXPORT_H_ diff --git a/ui/events/ipc/latency_info_param_traits.cc b/ui/events/ipc/latency_info_param_traits.cc index 0b36c31..0fcce352 100644 --- a/ui/events/ipc/latency_info_param_traits.cc +++ b/ui/events/ipc/latency_info_param_traits.cc @@ -2,25 +2,85 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "ui/events/ipc/latency_info_param_traits.h" +#include "ui/events/ipc/latency_info_param_traits_macros.h" // Generate param traits write methods. #include "ipc/param_traits_write_macros.h" namespace IPC { -#undef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_H_ -#include "ui/events/ipc/latency_info_param_traits.h" +#undef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_MACROS_H_ +#include "ui/events/ipc/latency_info_param_traits_macros.h" } // namespace IPC // Generate param traits read methods. #include "ipc/param_traits_read_macros.h" namespace IPC { -#undef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_H_ -#include "ui/events/ipc/latency_info_param_traits.h" +#undef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_MACROS_H_ +#include "ui/events/ipc/latency_info_param_traits_macros.h" } // namespace IPC // Generate param traits log methods. #include "ipc/param_traits_log_macros.h" namespace IPC { -#undef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_H_ +#undef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_MACROS_H_ +#include "ui/events/ipc/latency_info_param_traits_macros.h" +} // namespace IPC + +// Implemetation for ParamTraits<ui::LatencyInfo>. #include "ui/events/ipc/latency_info_param_traits.h" + +namespace IPC { +void ParamTraits<ui::LatencyInfo>::Write(Message* m, + const param_type& p) { + WriteParam(m, p.trace_name_); + WriteParam(m, p.latency_components_); + WriteParam(m, p.input_coordinates_size_); + for (size_t i = 0; i < p.input_coordinates_size_; i++) { + WriteParam(m, p.input_coordinates_[i]); + } + WriteParam(m, p.trace_id_); + WriteParam(m, p.terminated_); +} + +bool ParamTraits<ui::LatencyInfo>::Read(const Message* m, + base::PickleIterator* iter, + param_type* p) { + if (!ReadParam(m, iter, &p->trace_name_)) + return false; + if (!ReadParam(m, iter, &p->latency_components_)) + return false; + + ui::LatencyInfo::InputCoordinate input_coordinates; + uint32 input_coordinates_size; + if (!ReadParam(m, iter, &input_coordinates_size)) + return false; + for (size_t i = 0; i < input_coordinates_size; i++) { + if (!ReadParam(m, iter, &input_coordinates)) + return false; + p->AddInputCoordinate(input_coordinates); + } + if (!ReadParam(m, iter, &p->trace_id_)) + return false; + if (!ReadParam(m, iter, &p->terminated_)) + return false; + + return true; +} + +void ParamTraits<ui::LatencyInfo>::Log(const param_type& p, + std::string* l) { + LogParam(p.trace_name_, l); + l->append(" "); + LogParam(p.latency_components_, l); + l->append(" "); + LogParam(p.input_coordinates_size_, l); + l->append(" "); + for (size_t i = 0; i < p.input_coordinates_size_; i++) { + LogParam(p.input_coordinates_[i], l); + l->append(" "); + } + LogParam(p.trace_id_, l); + l->append(" "); + LogParam(p.terminated_, l); +} + } // namespace IPC diff --git a/ui/events/ipc/latency_info_param_traits.h b/ui/events/ipc/latency_info_param_traits.h index e33a044..0716f43 100644 --- a/ui/events/ipc/latency_info_param_traits.h +++ b/ui/events/ipc/latency_info_param_traits.h @@ -5,35 +5,17 @@ #ifndef UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_H_ #define UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_H_ -#include "ipc/ipc_message_macros.h" -#include "ui/events/events_export.h" +#include "ui/events/ipc/events_ipc_export.h" #include "ui/events/latency_info.h" -#undef IPC_MESSAGE_EXPORT -#define IPC_MESSAGE_EXPORT EVENTS_EXPORT - -IPC_ENUM_TRAITS_MAX_VALUE(ui::LatencyComponentType, - ui::LATENCY_COMPONENT_TYPE_LAST) - -IPC_STRUCT_TRAITS_BEGIN(ui::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(ui::LatencyInfo::InputCoordinate) -IPC_STRUCT_TRAITS_MEMBER(x) -IPC_STRUCT_TRAITS_MEMBER(y) -IPC_STRUCT_TRAITS_END() - -IPC_STRUCT_TRAITS_BEGIN(ui::LatencyInfo) - IPC_STRUCT_TRAITS_MEMBER(latency_components) - IPC_STRUCT_TRAITS_MEMBER(trace_id) - IPC_STRUCT_TRAITS_MEMBER(terminated) - IPC_STRUCT_TRAITS_MEMBER(input_coordinates_size) - IPC_STRUCT_TRAITS_MEMBER(input_coordinates[0]) - IPC_STRUCT_TRAITS_MEMBER(input_coordinates[1]) - IPC_STRUCT_TRAITS_MEMBER(trace_name) -IPC_STRUCT_TRAITS_END() +namespace IPC { +template <> +struct EVENTS_IPC_EXPORT ParamTraits<ui::LatencyInfo> { + typedef ui::LatencyInfo param_type; + static void Write(Message* m, const param_type& p); + static bool Read(const Message* m, base::PickleIterator* iter, param_type* p); + static void Log(const param_type& p, std::string* l); +}; +} // namespace IPC #endif // UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_H_ diff --git a/ui/events/ipc/latency_info_param_traits_macros.h b/ui/events/ipc/latency_info_param_traits_macros.h new file mode 100644 index 0000000..40bf738 --- /dev/null +++ b/ui/events/ipc/latency_info_param_traits_macros.h @@ -0,0 +1,29 @@ +// Copyright 2015 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_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_MACROS_H_ +#define UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_MACROS_H_ + +#include "ipc/ipc_message_macros.h" +#include "ui/events/ipc/events_ipc_export.h" +#include "ui/events/latency_info.h" + +#undef IPC_MESSAGE_EXPORT +#define IPC_MESSAGE_EXPORT EVENTS_IPC_EXPORT + +IPC_ENUM_TRAITS_MAX_VALUE(ui::LatencyComponentType, + ui::LATENCY_COMPONENT_TYPE_LAST) + +IPC_STRUCT_TRAITS_BEGIN(ui::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(ui::LatencyInfo::InputCoordinate) + IPC_STRUCT_TRAITS_MEMBER(x) + IPC_STRUCT_TRAITS_MEMBER(y) +IPC_STRUCT_TRAITS_END() + +#endif // UI_EVENTS_IPC_LATENCY_INFO_PARAM_TRAITS_MACROS_H_ diff --git a/ui/events/ipc/latency_info_param_traits_unittest.cc b/ui/events/ipc/latency_info_param_traits_unittest.cc new file mode 100644 index 0000000..0fa3e97 --- /dev/null +++ b/ui/events/ipc/latency_info_param_traits_unittest.cc @@ -0,0 +1,78 @@ +// Copyright 2015 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 "ipc/ipc_message_macros.h" +#include "testing/gtest/include/gtest/gtest.h" +#include "ui/events/ipc/latency_info_param_traits.h" +#include "ui/events/ipc/latency_info_param_traits_macros.h" + +namespace ui { + +TEST(LatencyInfoParamTraitsTest, Basic) { + LatencyInfo latency; + ASSERT_FALSE(latency.terminated()); + ASSERT_EQ(0u, latency.input_coordinates_size_); + latency.AddLatencyNumber(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, 1234, 0); + latency.AddLatencyNumber(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, 1234, 100); + latency.AddLatencyNumber(INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, + 1234, 0); + EXPECT_TRUE(latency.AddInputCoordinate( + LatencyInfo::InputCoordinate(100, 200))); + EXPECT_TRUE(latency.AddInputCoordinate( + LatencyInfo::InputCoordinate(101, 201))); + // Up to 2 InputCoordinate is allowed. + EXPECT_FALSE(latency.AddInputCoordinate( + LatencyInfo::InputCoordinate(102, 202))); + EXPECT_EQ(100, latency.trace_id()); + EXPECT_TRUE(latency.terminated()); + EXPECT_EQ(2u, latency.input_coordinates_size_); + + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + IPC::WriteParam(&msg, latency); + base::PickleIterator iter(msg); + LatencyInfo output; + EXPECT_TRUE(IPC::ReadParam(&msg, &iter, &output)); + + EXPECT_EQ(latency.trace_id(), output.trace_id()); + EXPECT_EQ(latency.terminated(), output.terminated()); + EXPECT_EQ(latency.input_coordinates_size_, output.input_coordinates_size_); + for (size_t i = 0; i < latency.input_coordinates_size_; i++) { + EXPECT_EQ(latency.input_coordinates_[i].x, + output.input_coordinates_[i].x); + EXPECT_EQ(latency.input_coordinates_[i].y, + output.input_coordinates_[i].y); + } + + EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, + 1234, + nullptr)); + + LatencyInfo::LatencyComponent rwh_comp; + EXPECT_TRUE(output.FindLatency(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT, + 1234, + &rwh_comp)); + EXPECT_EQ(100, rwh_comp.sequence_number); + EXPECT_EQ(1u, rwh_comp.event_count); + + EXPECT_TRUE(output.FindLatency( + INPUT_EVENT_LATENCY_TERMINATED_FRAME_SWAP_COMPONENT, 1234, nullptr)); +} + +TEST(LatencyInfoParamTraitsTest, InvalidData) { + IPC::Message msg(1, 2, IPC::Message::PRIORITY_NORMAL); + IPC::WriteParam(&msg, std::string()); + ui::LatencyInfo::LatencyMap components; + IPC::WriteParam(&msg, components); + // input_coordinates_size is 2 but only one InputCoordinate is written. + IPC::WriteParam(&msg, static_cast<uint32>(2)); + IPC::WriteParam(&msg, ui::LatencyInfo::InputCoordinate()); + IPC::WriteParam(&msg, static_cast<int64>(1234)); + IPC::WriteParam(&msg, true); + + base::PickleIterator iter(msg); + LatencyInfo output; + EXPECT_FALSE(IPC::ReadParam(&msg, &iter, &output)); +} + +} // namespace ui diff --git a/ui/events/latency_info.cc b/ui/events/latency_info.cc index 8bc94e2..fac3199 100644 --- a/ui/events/latency_info.cc +++ b/ui/events/latency_info.cc @@ -9,9 +9,7 @@ #include "base/json/json_writer.h" #include "base/lazy_instance.h" -#include "base/memory/scoped_ptr.h" #include "base/strings/stringprintf.h" -#include "base/trace_event/trace_event.h" namespace { @@ -111,35 +109,6 @@ LatencyInfoTracedValue::LatencyInfoTracedValue(base::Value* value) : value_(value) { } -// Converts latencyinfo into format that can be dumped into trace buffer. -scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsTraceableData( - const ui::LatencyInfo& latency) { - scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); - for (ui::LatencyInfo::LatencyMap::const_iterator it = - latency.latency_components.begin(); - it != latency.latency_components.end(); ++it) { - base::DictionaryValue* component_info = new base::DictionaryValue(); - component_info->SetDouble("comp_id", static_cast<double>(it->first.second)); - component_info->SetDouble( - "time", static_cast<double>(it->second.event_time.ToInternalValue())); - component_info->SetDouble("count", it->second.event_count); - component_info->SetDouble("sequence_number", it->second.sequence_number); - record_data->Set(GetComponentName(it->first.first), component_info); - } - record_data->SetDouble("trace_id", static_cast<double>(latency.trace_id)); - - scoped_ptr<base::ListValue> coordinates(new base::ListValue()); - for (size_t i = 0; i < latency.input_coordinates_size; i++) { - scoped_ptr<base::DictionaryValue> coordinate_pair( - new base::DictionaryValue()); - coordinate_pair->SetDouble("x", latency.input_coordinates[i].x); - coordinate_pair->SetDouble("y", latency.input_coordinates[i].y); - coordinates->Append(coordinate_pair.release()); - } - record_data->Set("coordinates", coordinates.release()); - return LatencyInfoTracedValue::FromValue(record_data.Pass()); -} - struct BenchmarkEnabledInitializer { BenchmarkEnabledInitializer() : benchmark_enabled(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( @@ -163,7 +132,7 @@ LatencyInfo::InputCoordinate::InputCoordinate(float x, float y) : x(x), y(y) { } LatencyInfo::LatencyInfo() - : input_coordinates_size(0), trace_id(-1), terminated(false) { + : input_coordinates_size_(0), trace_id_(-1), terminated_(false) { } LatencyInfo::~LatencyInfo() { @@ -176,44 +145,32 @@ bool LatencyInfo::Verify(const std::vector<LatencyInfo>& latency_info, << latency_info.size() << " is too big."; return false; } - for (size_t i = 0; i < latency_info.size(); i++) { - if (latency_info[i].input_coordinates_size > kMaxInputCoordinates) { - LOG(ERROR) << referring_msg << ", coordinate vector size " - << latency_info[i].input_coordinates_size << " is too big."; - return false; - } - } - return true; } void LatencyInfo::CopyLatencyFrom(const LatencyInfo& other, LatencyComponentType type) { - for (LatencyMap::const_iterator it = other.latency_components.begin(); - it != other.latency_components.end(); - ++it) { - if (it->first.first == type) { - AddLatencyNumberWithTimestamp(it->first.first, - it->first.second, - it->second.sequence_number, - it->second.event_time, - it->second.event_count); + for (const auto& lc : other.latency_components()) { + if (lc.first.first == type) { + AddLatencyNumberWithTimestamp(lc.first.first, + lc.first.second, + lc.second.sequence_number, + lc.second.event_time, + lc.second.event_count); } } } void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { - for (LatencyMap::const_iterator it = other.latency_components.begin(); - it != other.latency_components.end(); - ++it) { - if (!FindLatency(it->first.first, it->first.second, NULL)) { - AddLatencyNumberWithTimestamp(it->first.first, - it->first.second, - it->second.sequence_number, - it->second.event_time, - it->second.event_count); - } + for (const auto& lc : other.latency_components()) { + if (!FindLatency(lc.first.first, lc.first.second, NULL)) { + AddLatencyNumberWithTimestamp(lc.first.first, + lc.first.second, + lc.second.sequence_number, + lc.second.event_time, + lc.second.event_count); } + } } void LatencyInfo::AddLatencyNumber(LatencyComponentType component, @@ -254,8 +211,8 @@ void LatencyInfo::AddLatencyNumberWithTimestampImpl( if (IsBeginComponent(component)) { // Should only ever add begin component once. - CHECK_EQ(-1, trace_id); - trace_id = component_sequence_number; + CHECK_EQ(-1, trace_id_); + trace_id_ = component_sequence_number; if (*benchmark_enabled) { // The timestamp for ASYNC_BEGIN trace event is used for drawing the @@ -286,28 +243,28 @@ void LatencyInfo::AddLatencyNumberWithTimestampImpl( if (trace_name_str) { if (IsInputLatencyBeginComponent(component)) - trace_name = std::string("InputLatency::") + trace_name_str; + trace_name_ = std::string("InputLatency::") + trace_name_str; else - trace_name = std::string("Latency::") + trace_name_str; + trace_name_ = std::string("Latency::") + trace_name_str; } TRACE_EVENT_COPY_ASYNC_BEGIN_WITH_TIMESTAMP0( "benchmark,latencyInfo", - trace_name.c_str(), - TRACE_ID_DONT_MANGLE(trace_id), + trace_name_.c_str(), + TRACE_ID_DONT_MANGLE(trace_id_), ts); } TRACE_EVENT_FLOW_BEGIN1( - "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id), - "trace_id", trace_id); + "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id_), + "trace_id", trace_id_); } LatencyMap::key_type key = std::make_pair(component, id); - LatencyMap::iterator it = latency_components.find(key); - if (it == latency_components.end()) { + LatencyMap::iterator it = latency_components_.find(key); + if (it == latency_components_.end()) { LatencyComponent info = {component_sequence_number, time, event_count}; - latency_components[key] = info; + latency_components_[key] = info; } else { it->second.sequence_number = std::max(component_sequence_number, it->second.sequence_number); @@ -322,29 +279,58 @@ void LatencyInfo::AddLatencyNumberWithTimestampImpl( } } - if (IsTerminalComponent(component) && trace_id != -1) { + if (IsTerminalComponent(component) && trace_id_ != -1) { // Should only ever add terminal component once. - CHECK(!terminated); - terminated = true; + CHECK(!terminated_); + terminated_ = true; if (*benchmark_enabled) { TRACE_EVENT_COPY_ASYNC_END1("benchmark,latencyInfo", - trace_name.c_str(), - TRACE_ID_DONT_MANGLE(trace_id), - "data", AsTraceableData(*this)); + trace_name_.c_str(), + TRACE_ID_DONT_MANGLE(trace_id_), + "data", AsTraceableData()); } TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0( - "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id)); + "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id_)); + } +} + +scoped_refptr<base::trace_event::ConvertableToTraceFormat> +LatencyInfo::AsTraceableData() { + scoped_ptr<base::DictionaryValue> record_data(new base::DictionaryValue()); + for (const auto& lc : latency_components_) { + scoped_ptr<base::DictionaryValue> + component_info(new base::DictionaryValue()); + component_info->SetDouble("comp_id", static_cast<double>(lc.first.second)); + component_info->SetDouble( + "time", + static_cast<double>(lc.second.event_time.ToInternalValue())); + component_info->SetDouble("count", lc.second.event_count); + component_info->SetDouble("sequence_number", + lc.second.sequence_number); + record_data->Set(GetComponentName(lc.first.first), component_info.Pass()); + } + record_data->SetDouble("trace_id", static_cast<double>(trace_id_)); + + scoped_ptr<base::ListValue> coordinates(new base::ListValue()); + for (size_t i = 0; i < input_coordinates_size_; i++) { + scoped_ptr<base::DictionaryValue> coordinate_pair( + new base::DictionaryValue()); + coordinate_pair->SetDouble("x", input_coordinates_[i].x); + coordinate_pair->SetDouble("y", input_coordinates_[i].y); + coordinates->Append(coordinate_pair.release()); } + record_data->Set("coordinates", coordinates.release()); + return LatencyInfoTracedValue::FromValue(record_data.Pass()); } bool LatencyInfo::FindLatency(LatencyComponentType type, int64 id, LatencyComponent* output) const { - LatencyMap::const_iterator it = latency_components.find( + LatencyMap::const_iterator it = latency_components_.find( std::make_pair(type, id)); - if (it == latency_components.end()) + if (it == latency_components_.end()) return false; if (output) *output = it->second; @@ -352,20 +338,23 @@ bool LatencyInfo::FindLatency(LatencyComponentType type, } void LatencyInfo::RemoveLatency(LatencyComponentType type) { - LatencyMap::iterator it = latency_components.begin(); - while (it != latency_components.end()) { + LatencyMap::iterator it = latency_components_.begin(); + while (it != latency_components_.end()) { if (it->first.first == type) { LatencyMap::iterator tmp = it; ++it; - latency_components.erase(tmp); + latency_components_.erase(tmp); } else { it++; } } } -void LatencyInfo::Clear() { - latency_components.clear(); +bool LatencyInfo::AddInputCoordinate(const InputCoordinate& input_coordinate) { + if (input_coordinates_size_ >= kMaxInputCoordinates) + return false; + input_coordinates_[input_coordinates_size_++] = input_coordinate; + return true; } } // namespace ui diff --git a/ui/events/latency_info.h b/ui/events/latency_info.h index 4abcdc1..443e5fb 100644 --- a/ui/events/latency_info.h +++ b/ui/events/latency_info.h @@ -11,7 +11,11 @@ #include "base/basictypes.h" #include "base/containers/small_map.h" +#include "base/gtest_prod_util.h" +#include "base/memory/scoped_ptr.h" #include "base/time/time.h" +#include "base/trace_event/trace_event.h" +#include "ipc/ipc_param_traits.h" #include "ui/events/events_base_export.h" namespace ui { @@ -85,7 +89,8 @@ enum LatencyComponentType { INPUT_EVENT_LATENCY_TERMINATED_SWAP_FAILED_COMPONENT, }; -struct EVENTS_BASE_EXPORT LatencyInfo { +class EVENTS_BASE_EXPORT LatencyInfo { + public: 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 @@ -117,7 +122,6 @@ struct EVENTS_BASE_EXPORT LatencyInfo { kTypicalMaxComponentsPerLatencyInfo> LatencyMap; LatencyInfo(); - ~LatencyInfo(); // Returns true if the vector |latency_info| is valid. Returns false @@ -158,13 +162,6 @@ struct EVENTS_BASE_EXPORT LatencyInfo { base::TimeTicks time, uint32 event_count); - void AddLatencyNumberWithTimestampImpl(LatencyComponentType component, - int64 id, - int64 component_sequence_number, - base::TimeTicks time, - uint32 event_count, - const char* trace_name_str); - // Returns true if the a component with |type| and |id| is found in // the latency_components and the component is stored to |output| if // |output| is not NULL. Returns false if no such component is found. @@ -174,22 +171,47 @@ struct EVENTS_BASE_EXPORT LatencyInfo { void RemoveLatency(LatencyComponentType type); - void Clear(); + // Returns true if there is still room for keeping the |input_coordinate|, + // false otherwise. + bool AddInputCoordinate(const InputCoordinate& input_coordinate); + + uint32 input_coordinates_size() const { return input_coordinates_size_; } + const InputCoordinate* input_coordinates() const { + return input_coordinates_; + } + const LatencyMap& latency_components() const { return latency_components_; } + + bool terminated() const { return terminated_; } + int64 trace_id() const { return trace_id_; } + + private: + void AddLatencyNumberWithTimestampImpl(LatencyComponentType component, + int64 id, + int64 component_sequence_number, + base::TimeTicks time, + uint32 event_count, + const char* trace_name_str); + + // Converts latencyinfo into format that can be dumped into trace buffer. + scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsTraceableData(); // Shown as part of the name of the trace event for this LatencyInfo. // String is empty if no tracing is enabled. - std::string trace_name; + std::string trace_name_; - LatencyMap latency_components; + LatencyMap latency_components_; // These coordinates represent window coordinates of the original input event. - uint32 input_coordinates_size; - InputCoordinate input_coordinates[kMaxInputCoordinates]; + uint32 input_coordinates_size_; + InputCoordinate input_coordinates_[kMaxInputCoordinates]; // The unique id for matching the ASYNC_BEGIN/END trace event. - int64 trace_id; + int64 trace_id_; // Whether a terminal component has been added. - bool terminated; + bool terminated_; + + FRIEND_TEST_ALL_PREFIXES(LatencyInfoParamTraitsTest, Basic); + friend struct IPC::ParamTraits<ui::LatencyInfo>; }; } // namespace ui diff --git a/ui/events/latency_info_unittest.cc b/ui/events/latency_info_unittest.cc index 2f9ad05..26dcef2 100644 --- a/ui/events/latency_info_unittest.cc +++ b/ui/events/latency_info_unittest.cc @@ -21,7 +21,7 @@ TEST(LatencyInfoTest, AddTwoSeparateEvent) { base::TimeTicks::FromInternalValue(1000), 2); - EXPECT_EQ(info.latency_components.size(), 2u); + EXPECT_EQ(info.latency_components().size(), 2u); LatencyInfo::LatencyComponent component; EXPECT_FALSE( info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); @@ -52,7 +52,7 @@ TEST(LatencyInfoTest, AddTwoSameEvent) { base::TimeTicks::FromInternalValue(200), 3); - EXPECT_EQ(info.latency_components.size(), 1u); + EXPECT_EQ(info.latency_components().size(), 1u); LatencyInfo::LatencyComponent component; EXPECT_FALSE( info.FindLatency(INPUT_EVENT_LATENCY_UI_COMPONENT, 0, &component)); @@ -65,17 +65,4 @@ TEST(LatencyInfoTest, AddTwoSameEvent) { EXPECT_EQ(component.event_time.ToInternalValue(), (100 * 2 + 200 * 3) / 5); } -TEST(LatencyInfoTest, ClearEvents) { - LatencyInfo info; - info.AddLatencyNumberWithTimestamp(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT, - 0, - 30, - base::TimeTicks::FromInternalValue(100), - 2); - - EXPECT_EQ(info.latency_components.size(), 1u); - info.Clear(); - EXPECT_EQ(info.latency_components.size(), 0u); -} - } // namespace ui |