Commit f86cf225 authored by Stephen Nusko's avatar Stephen Nusko Committed by Commit Bot

Use a static string in InputLatency::.* TraceEvent names.

Currently we use a dynamically created trace event name this has a
couple implications:

1) Has to be computed at run time and allocated dynamically, and copied
   by the TraceEvent implementation.
2) Will be stripped from traces when tracing with privacy filtering
   enabled.
3) Has to be serialized and sent over mojo and then parsed.

This fixes all of these by directly computing the trace name as a
static string. This comes potentially at the slight cost of binary size
(since now the strings need to be stored in the full form), but this is
limited to ("InputLatency::" + Name(num WebInputEvent::Type)) * number of
Types, and we get to remove some mojo code so it should end up close to a
wash in binary size (+528 bytes).

Change-Id: I285d8bb24f8497bc067480201fdd3bac0b390083
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2062286Reviewed-by: default avatarTimothy Dresser <tdresser@chromium.org>
Reviewed-by: default avatarDaniel Cheng <dcheng@chromium.org>
Reviewed-by: default avatarEric Seckler <eseckler@chromium.org>
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Auto-Submit: Stephen Nusko <nuskos@chromium.org>
Cr-Commit-Position: refs/heads/master@{#742963}
parent 78cde5e4
......@@ -85,45 +85,15 @@ class TracingRenderWidgetHost : public RenderWidgetHostImpl {
std::move(widget),
hidden,
std::make_unique<FrameTokenMessageQueue>()) {
ui::LatencyTracker::SetLatencyInfoProcessorForTesting(base::BindRepeating(
&TracingRenderWidgetHost::HandleLatencyInfoAfterGpuSwap,
base::Unretained(this)));
}
void HandleLatencyInfoAfterGpuSwap(
const std::vector<ui::LatencyInfo>& latency_infos) {
for (const auto& latency_info : latency_infos) {
if (latency_info.terminated())
RunClosureIfNecessary(latency_info);
}
}
void OnMouseEventAck(const MouseEventWithLatencyInfo& event,
InputEventAckSource ack_source,
InputEventAckState ack_result) override {
RenderWidgetHostImpl::OnMouseEventAck(event, ack_source, ack_result);
if (event.latency.terminated())
RunClosureIfNecessary(event.latency);
}
void WaitFor(const std::string& trace_name) {
trace_waiting_name_ = trace_name;
base::RunLoop run_loop;
closure_ = run_loop.QuitClosure();
run_loop.Run();
}
private:
void RunClosureIfNecessary(const ui::LatencyInfo& latency_info) {
if (!trace_waiting_name_.empty() && closure_ &&
latency_info.trace_name() == trace_waiting_name_) {
trace_waiting_name_.clear();
std::move(closure_).Run();
}
}
std::string trace_waiting_name_;
base::OnceClosure closure_;
};
class TracingRenderWidgetHostFactory : public RenderWidgetHostFactory {
......
......@@ -26,6 +26,58 @@ using blink::WebTouchEvent;
using ui::LatencyInfo;
namespace content {
namespace {
const char* GetTraceNameFromType(blink::WebInputEvent::Type type) {
#define CASE_TYPE(t) \
case WebInputEvent::k##t: \
return "InputLatency::" #t
switch (type) {
CASE_TYPE(Undefined);
CASE_TYPE(MouseDown);
CASE_TYPE(MouseUp);
CASE_TYPE(MouseMove);
CASE_TYPE(MouseEnter);
CASE_TYPE(MouseLeave);
CASE_TYPE(ContextMenu);
CASE_TYPE(MouseWheel);
CASE_TYPE(RawKeyDown);
CASE_TYPE(KeyDown);
CASE_TYPE(KeyUp);
CASE_TYPE(Char);
CASE_TYPE(GestureScrollBegin);
CASE_TYPE(GestureScrollEnd);
CASE_TYPE(GestureScrollUpdate);
CASE_TYPE(GestureFlingStart);
CASE_TYPE(GestureFlingCancel);
CASE_TYPE(GestureShowPress);
CASE_TYPE(GestureTap);
CASE_TYPE(GestureTapUnconfirmed);
CASE_TYPE(GestureTapDown);
CASE_TYPE(GestureTapCancel);
CASE_TYPE(GestureDoubleTap);
CASE_TYPE(GestureTwoFingerTap);
CASE_TYPE(GestureLongPress);
CASE_TYPE(GestureLongTap);
CASE_TYPE(GesturePinchBegin);
CASE_TYPE(GesturePinchEnd);
CASE_TYPE(GesturePinchUpdate);
CASE_TYPE(TouchStart);
CASE_TYPE(TouchMove);
CASE_TYPE(TouchEnd);
CASE_TYPE(TouchCancel);
CASE_TYPE(TouchScrollStarted);
CASE_TYPE(PointerDown);
CASE_TYPE(PointerUp);
CASE_TYPE(PointerMove);
CASE_TYPE(PointerRawUpdate);
CASE_TYPE(PointerCancel);
CASE_TYPE(PointerCausedUaAction);
}
#undef CASE_TYPE
NOTREACHED();
return "";
}
} // namespace
RenderWidgetHostLatencyTracker::RenderWidgetHostLatencyTracker(
RenderWidgetHostDelegate* delegate)
......@@ -148,7 +200,7 @@ void RenderWidgetHostLatencyTracker::OnInputEvent(
latency->AddLatencyNumberWithTraceName(
ui::INPUT_EVENT_LATENCY_BEGIN_RWH_COMPONENT,
WebInputEvent::GetName(event.GetType()));
GetTraceNameFromType(event.GetType()));
if (event.GetType() == blink::WebInputEvent::kGestureScrollBegin) {
has_seen_first_gesture_scroll_update_ = false;
......
......@@ -32,7 +32,6 @@ namespace IPC {
namespace IPC {
void ParamTraits<ui::LatencyInfo>::Write(base::Pickle* m, const param_type& p) {
WriteParam(m, p.trace_name_);
WriteParam(m, p.latency_components_);
WriteParam(m, p.trace_id_);
WriteParam(m, p.ukm_source_id_);
......@@ -47,8 +46,6 @@ void ParamTraits<ui::LatencyInfo>::Write(base::Pickle* m, const param_type& p) {
bool ParamTraits<ui::LatencyInfo>::Read(const base::Pickle* 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;
......@@ -73,8 +70,6 @@ bool ParamTraits<ui::LatencyInfo>::Read(const base::Pickle* m,
}
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.trace_id_, l);
......
......@@ -255,12 +255,8 @@ void LatencyInfo::AddLatencyNumberWithTimestampImpl(
ts = base::TimeTicks::Now();
}
if (trace_name_str) {
trace_name_ = std::string("InputLatency::") + trace_name_str;
}
TRACE_EVENT_COPY_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
kTraceCategoriesForAsyncEvents, trace_name_.c_str(),
TRACE_EVENT_NESTABLE_ASYNC_BEGIN_WITH_TIMESTAMP0(
kTraceCategoriesForAsyncEvents, trace_name_str,
TRACE_ID_GLOBAL(trace_id_), ts);
}
......@@ -286,9 +282,15 @@ void LatencyInfo::Terminate() {
terminated_ = true;
if (*g_latency_info_enabled.Get().latency_info_enabled) {
TRACE_EVENT_COPY_NESTABLE_ASYNC_END1(
kTraceCategoriesForAsyncEvents, trace_name_.c_str(),
TRACE_ID_GLOBAL(trace_id_), "data", AsTraceableData());
// The name field is not needed for NESTABLE events because we only need the
// category to know which event to close. In fact the name will not be
// emitted internally.
//
// TODO(nuskos): Once we have the new TraceEvent macros that support Tracks
// we can migrate this macro to it (and the name will no longer be there).
TRACE_EVENT_NESTABLE_ASYNC_END1(kTraceCategoriesForAsyncEvents,
/* name = */ "", TRACE_ID_GLOBAL(trace_id_),
"data", AsTraceableData());
}
TRACE_EVENT_WITH_FLOW0("input,benchmark", "LatencyInfo.Flow",
......
......@@ -183,7 +183,6 @@ class LatencyInfo {
void set_trace_id(int64_t trace_id) { trace_id_ = trace_id; }
ukm::SourceId ukm_source_id() const { return ukm_source_id_; }
void set_ukm_source_id(ukm::SourceId id) { ukm_source_id_ = id; }
const std::string& trace_name() const { return trace_name_; }
void set_scroll_update_delta(float delta) { scroll_update_delta_ = delta; }
float scroll_update_delta() const { return scroll_update_delta_; }
void set_predicted_scroll_update_delta(float delta) {
......@@ -202,10 +201,6 @@ class LatencyInfo {
std::unique_ptr<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_;
LatencyMap latency_components_;
// The unique id for matching the ASYNC_BEGIN/END trace event.
......
......@@ -60,7 +60,6 @@ enum SourceEventType {
// See ui/latency/latency_info.h
struct LatencyInfo {
string trace_name;
map<LatencyComponentType, mojo_base.mojom.TimeTicks> latency_components;
int64 trace_id;
int64 ukm_source_id;
......
......@@ -62,13 +62,6 @@ ui::SourceEventType MojoSourceEventTypeToUI(ui::mojom::SourceEventType type) {
} // namespace
// static
const std::string&
StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::trace_name(
const ui::LatencyInfo& info) {
return info.trace_name_;
}
// static
const ui::LatencyInfo::LatencyMap&
StructTraits<ui::mojom::LatencyInfoDataView,
......@@ -131,8 +124,6 @@ float StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::
bool StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo>::Read(
ui::mojom::LatencyInfoDataView data,
ui::LatencyInfo* out) {
if (!data.ReadTraceName(&out->trace_name_))
return false;
if (!data.ReadLatencyComponents(&out->latency_components_))
return false;
out->trace_id_ = data.trace_id();
......
......@@ -44,7 +44,6 @@ struct ArrayTraits<ui::LatencyInfo::LatencyMap> {
template <>
struct StructTraits<ui::mojom::LatencyInfoDataView, ui::LatencyInfo> {
static const std::string& trace_name(const ui::LatencyInfo& info);
static const ui::LatencyInfo::LatencyMap& latency_components(
const ui::LatencyInfo& info);
static int64_t trace_id(const ui::LatencyInfo& info);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment