Skip to content

Commit 2dd72f9

Browse files
huntiefacebook-github-bot
authored andcommitted
Align InteractionEntry payload to match Chrome (#52840)
Summary: Pull Request resolved: #52840 **Context** Experimental V2 Performance Monitor prototype, beginning by bringing the [Interaction to Next Paint (INP)](https://web.dev/articles/inp) metric to React Native. **This diff** Completes populating a full `InteractionEntry` Live Event payload by implementing remaining fields sufficient to be rendered by Chrome DevTools. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D78904747 fbshipit-source-id: 7473602f6f1efe3ac71e07a2b88e6ad7020dcbbf
1 parent a3bf989 commit 2dd72f9

3 files changed

Lines changed: 106 additions & 3 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "CdpInteractionTypes.h"
9+
10+
namespace facebook::react {
11+
12+
const InteractionTypesMap& getInteractionTypes() {
13+
static InteractionTypesMap INTERACTION_TYPES = {
14+
{"auxclick", "pointer"},
15+
{"click", "pointer"},
16+
{"contextmenu", "pointer"},
17+
{"dblclick", "pointer"},
18+
{"mousedown", "pointer"},
19+
{"mouseenter", "pointer"},
20+
{"mouseleave", "pointer"},
21+
{"mouseout", "pointer"},
22+
{"mouseover", "pointer"},
23+
{"mouseup", "pointer"},
24+
{"pointerover", "pointer"},
25+
{"pointerenter", "pointer"},
26+
{"pointerdown", "pointer"},
27+
{"pointerup", "pointer"},
28+
{"pointercancel", "pointer"},
29+
{"pointerout", "pointer"},
30+
{"pointerleave", "pointer"},
31+
{"gotpointercapture", "pointer"},
32+
{"lostpointercapture", "pointer"},
33+
{"touchstart", "touch"},
34+
{"touchend", "touch"},
35+
{"touchcancel", "touch"},
36+
{"keydown", "keyboard"},
37+
{"keypress", "keyboard"},
38+
{"keyup", "keyboard"},
39+
{"beforeinput", "keyboard"},
40+
{"input", "keyboard"},
41+
{"compositionstart", "composition"},
42+
{"compositionupdate", "composition"},
43+
{"compositionend", "composition"},
44+
{"dragstart", "drag"},
45+
{"dragend", "drag"},
46+
{"dragenter", "drag"},
47+
{"dragleave", "drag"},
48+
{"dragover", "drag"},
49+
{"drop", "drag"},
50+
};
51+
return INTERACTION_TYPES;
52+
}
53+
54+
const std::string_view getInteractionTypeForEvent(std::string_view eventName) {
55+
const auto& interactionTypes = getInteractionTypes();
56+
auto it = interactionTypes.find(eventName);
57+
if (it != interactionTypes.end()) {
58+
return it->second;
59+
}
60+
return "unknown";
61+
}
62+
63+
} // namespace facebook::react
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
#include <string_view>
11+
#include <unordered_map>
12+
13+
namespace facebook::react {
14+
15+
using InteractionTypesMap =
16+
std::unordered_map<std::string_view, std::string_view>;
17+
18+
const InteractionTypesMap& getInteractionTypes();
19+
20+
const std::string_view getInteractionTypeForEvent(std::string_view eventName);
21+
22+
} // namespace facebook::react

packages/react-native/ReactCommon/react/performance/cdpmetrics/CdpMetricsReporter.cpp

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include "CdpMetricsReporter.h"
9+
#include "CdpInteractionTypes.h"
910

1011
#include <folly/dynamic.h>
1112
#include <folly/json.h>
@@ -31,15 +32,32 @@ void CdpMetricsReporter::onEventTimingEntry(
3132
return;
3233
}
3334

35+
auto inputDelay = entry.processingStart - entry.startTime;
36+
auto processingDuration = entry.processingEnd - entry.processingStart;
37+
auto nextPaintTime = entry.startTime + entry.duration;
38+
auto presentationDelay = nextPaintTime - entry.processingEnd;
39+
3440
folly::dynamic jsonPayload = folly::dynamic::object;
35-
jsonPayload["eventName"] = entry.name;
36-
jsonPayload["durationMs"] =
41+
jsonPayload["name"] = "InteractionEntry";
42+
jsonPayload["duration"] =
3743
static_cast<int>(entry.duration.toDOMHighResTimeStamp());
44+
jsonPayload["phases"] = folly::dynamic::object(
45+
"inputDelay", static_cast<int>(inputDelay.toDOMHighResTimeStamp()))(
46+
"processingDuration",
47+
static_cast<int>(processingDuration.toDOMHighResTimeStamp()))(
48+
"presentationDelay",
49+
static_cast<int>(presentationDelay.toDOMHighResTimeStamp()));
3850
jsonPayload["startTime"] =
3951
static_cast<int>(entry.startTime.toDOMHighResTimeStamp());
52+
jsonPayload["nextPaintTime"] =
53+
static_cast<int>(nextPaintTime.toDOMHighResTimeStamp());
54+
jsonPayload["interactionType"] =
55+
std::string(getInteractionTypeForEvent(entry.name));
56+
jsonPayload["eventName"] = std::string(entry.name);
57+
jsonPayload["longAnimationFrameEntries"] = folly::dynamic::array();
58+
4059
auto jsonString = folly::toJson(jsonPayload);
4160
auto jsiString = jsi::String::createFromUtf8(runtime, jsonString);
42-
4361
auto metricsReporter =
4462
global.getPropertyAsFunction(runtime, metricsReporterName.data());
4563
metricsReporter.call(runtime, jsiString);

0 commit comments

Comments
 (0)