Index: ui/events/latency_info.cc |
diff --git a/ui/events/latency_info.cc b/ui/events/latency_info.cc |
index f3c38589cc6aea4f1985a700cd24471e68306c41..413d28a1cb1942672d96749e26661c9c867b14e1 100644 |
--- a/ui/events/latency_info.cc |
+++ b/ui/events/latency_info.cc |
@@ -2,13 +2,16 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
+#include "ui/events/latency_info.h" |
+ |
+#include <algorithm> |
+#include <string> |
+ |
#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" |
-#include "ui/events/latency_info.h" |
- |
-#include <algorithm> |
namespace { |
@@ -19,7 +22,7 @@ const char* GetComponentName(ui::LatencyComponentType type) { |
switch (type) { |
CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT); |
CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT); |
- CASE_TYPE(INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT); |
+ CASE_TYPE(LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT); |
CASE_TYPE(INPUT_EVENT_LATENCY_SCROLL_UPDATE_ORIGINAL_COMPONENT); |
CASE_TYPE(INPUT_EVENT_LATENCY_FIRST_SCROLL_UPDATE_ORIGINAL_COMPONENT); |
CASE_TYPE(INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT); |
@@ -29,7 +32,6 @@ const char* GetComponentName(ui::LatencyComponentType type) { |
CASE_TYPE(INPUT_EVENT_LATENCY_FORWARD_SCROLL_UPDATE_TO_MAIN_COMPONENT); |
CASE_TYPE(INPUT_EVENT_LATENCY_ACK_RWH_COMPONENT); |
CASE_TYPE(WINDOW_SNAPSHOT_FRAME_NUMBER_COMPONENT); |
- CASE_TYPE(WINDOW_OLD_SNAPSHOT_FRAME_NUMBER_COMPONENT); |
CASE_TYPE(TAB_SHOW_COMPONENT); |
CASE_TYPE(INPUT_EVENT_LATENCY_RENDERER_SWAP_COMPONENT); |
CASE_TYPE(INPUT_EVENT_BROWSER_RECEIVED_RENDERER_SWAP_COMPONENT); |
@@ -69,7 +71,12 @@ bool IsTerminalComponent(ui::LatencyComponentType type) { |
bool IsBeginComponent(ui::LatencyComponentType type) { |
return (type == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
type == ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT || |
- type == ui::INPUT_EVENT_LATENCY_BEGIN_SCROLL_UPDATE_MAIN_COMPONENT); |
+ type == ui::LATENCY_BEGIN_SCROLL_LISTENER_UPDATE_MAIN_COMPONENT); |
+} |
+ |
+bool IsInputLatencyBeginComponent(ui::LatencyComponentType type) { |
+ return (type == ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT || |
+ type == ui::INPUT_EVENT_LATENCY_BEGIN_PLUGIN_COMPONENT); |
} |
// This class is for converting latency info to trace buffer friendly format. |
@@ -121,6 +128,7 @@ scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsTraceableData( |
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)); |
@@ -137,6 +145,18 @@ scoped_refptr<base::trace_event::ConvertableToTraceFormat> AsTraceableData( |
return LatencyInfoTracedValue::FromValue(record_data.Pass()); |
} |
+struct BenchmarkEnabledInitializer { |
+ BenchmarkEnabledInitializer() : |
+ benchmark_enabled(TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED( |
+ "benchmark")) { |
+ } |
+ |
+ const unsigned char* benchmark_enabled; |
+}; |
+ |
+static base::LazyInstance<BenchmarkEnabledInitializer>::Leaky |
+ g_benchmark_enabled = LAZY_INSTANCE_INITIALIZER; |
+ |
} // namespace |
namespace ui { |
@@ -204,8 +224,17 @@ void LatencyInfo::AddNewLatencyFrom(const LatencyInfo& other) { |
void LatencyInfo::AddLatencyNumber(LatencyComponentType component, |
int64 id, |
int64 component_sequence_number) { |
- AddLatencyNumberWithTimestamp(component, id, component_sequence_number, |
- base::TimeTicks::Now(), 1); |
+ AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, |
+ base::TimeTicks::Now(), 1, nullptr); |
+} |
+ |
+void LatencyInfo::AddLatencyNumberWithTraceName( |
+ LatencyComponentType component, |
+ int64 id, |
+ int64 component_sequence_number, |
+ const char* trace_name_str) { |
+ AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, |
+ base::TimeTicks::Now(), 1, trace_name_str); |
} |
void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component, |
@@ -213,9 +242,20 @@ void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component, |
int64 component_sequence_number, |
base::TimeTicks time, |
uint32 event_count) { |
+ AddLatencyNumberWithTimestampImpl(component, id, component_sequence_number, |
+ time, event_count, nullptr); |
+} |
- static const unsigned char* benchmark_enabled = |
- TRACE_EVENT_API_GET_CATEGORY_GROUP_ENABLED("benchmark"); |
+void LatencyInfo::AddLatencyNumberWithTimestampImpl( |
+ LatencyComponentType component, |
+ int64 id, |
+ int64 component_sequence_number, |
+ base::TimeTicks time, |
+ uint32 event_count, |
+ const char* trace_name_str) { |
+ |
+ const unsigned char* benchmark_enabled = |
+ g_benchmark_enabled.Get().benchmark_enabled; |
if (IsBeginComponent(component)) { |
// Should only ever add begin component once. |
@@ -248,15 +288,24 @@ void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component, |
} else { |
ts = base::TraceTicks::Now().ToInternalValue(); |
} |
- TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP0( |
- "benchmark", |
- "InputLatency", |
+ |
+ if (trace_name_str) { |
+ if (IsInputLatencyBeginComponent(component)) |
+ trace_name = std::string("InputLatency::") + trace_name_str; |
+ else |
+ 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), |
ts); |
} |
- TRACE_EVENT_FLOW_BEGIN0( |
- "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id)); |
+ TRACE_EVENT_FLOW_BEGIN1( |
+ "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id), |
+ "trace_id", trace_id); |
} |
LatencyMap::key_type key = std::make_pair(component, id); |
@@ -284,14 +333,15 @@ void LatencyInfo::AddLatencyNumberWithTimestamp(LatencyComponentType component, |
terminated = true; |
if (*benchmark_enabled) { |
- TRACE_EVENT_ASYNC_END1("benchmark", |
- "InputLatency", |
- TRACE_ID_DONT_MANGLE(trace_id), |
- "data", AsTraceableData(*this)); |
+ TRACE_EVENT_COPY_ASYNC_END1("benchmark,latencyInfo", |
+ trace_name.c_str(), |
+ TRACE_ID_DONT_MANGLE(trace_id), |
+ "data", AsTraceableData(*this)); |
} |
- TRACE_EVENT_FLOW_END0( |
- "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id)); |
+ // Removed - does not compile |
+ // TRACE_EVENT_FLOW_END_BIND_TO_ENCLOSING0( |
+ // "input,benchmark", "LatencyInfo.Flow", TRACE_ID_DONT_MANGLE(trace_id)); |
} |
} |
@@ -324,11 +374,4 @@ void LatencyInfo::Clear() { |
latency_components.clear(); |
} |
-void LatencyInfo::TraceEventType(const char* event_type) { |
- TRACE_EVENT_ASYNC_STEP_INTO0("benchmark", |
- "InputLatency", |
- TRACE_ID_DONT_MANGLE(trace_id), |
- event_type); |
-} |
- |
} // namespace ui |