Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an event start timestamp field into RawEvent #46949

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ void EventDispatcher::dispatchEvent(RawEvent&& rawEvent) const {

auto eventLogger = eventLogger_.lock();
if (eventLogger != nullptr) {
rawEvent.loggingTag =
eventLogger->onEventStart(rawEvent.type, rawEvent.eventTarget);
rawEvent.loggingTag = eventLogger->onEventStart(
rawEvent.type, rawEvent.eventTarget, rawEvent.eventStartTimeStamp);
}
eventQueue_.enqueueEvent(std::move(rawEvent));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#pragma once

#include <react/renderer/core/EventTarget.h>
#include <react/timing/primitives.h>
#include <string_view>

namespace facebook::react {
Expand All @@ -30,7 +31,9 @@ class EventLogger {
*/
virtual EventTag onEventStart(
std::string_view name,
SharedEventTarget target) = 0;
SharedEventTarget target,
DOMHighResTimeStamp eventStartTimeStamp =
DOM_HIGH_RES_TIME_STAMP_UNSET) = 0;

/*
* Called when event starts getting dispatched (processed by the handlers, if
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <react/renderer/core/EventLogger.h>
#include <react/renderer/core/EventPayload.h>
#include <react/renderer/core/EventTarget.h>
#include <react/timing/primitives.h>

namespace facebook::react {

Expand Down Expand Up @@ -69,6 +70,11 @@ struct RawEvent {
SharedEventTarget eventTarget;
Category category;
EventTag loggingTag{0};

// The client may specify a platform-specific timestamp for the event start
// time, for example when MotionEvent was triggered on the Android native
// side.
DOMHighResTimeStamp eventStartTimeStamp{DOM_HIGH_RES_TIME_STAMP_UNSET};
};

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
namespace facebook::react {

class MockEventLogger : public EventLogger {
EventTag onEventStart(std::string_view /*name*/, SharedEventTarget /*target*/)
override {
EventTag onEventStart(
std::string_view /*name*/,
SharedEventTarget /*target*/,
DOMHighResTimeStamp /*eventStartTimeStamp*/) override {
return EMPTY_EVENT_TAG;
}
void onEventProcessingStart(EventTag /*tag*/) override {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ EventPerformanceLogger::EventPerformanceLogger(

EventTag EventPerformanceLogger::onEventStart(
std::string_view name,
SharedEventTarget target) {
SharedEventTarget target,
DOMHighResTimeStamp eventStartTimeStamp) {
auto performanceEntryReporter = performanceEntryReporter_.lock();
if (performanceEntryReporter == nullptr) {
return EMPTY_EVENT_TAG;
Expand All @@ -119,7 +120,11 @@ EventTag EventPerformanceLogger::onEventStart(

auto eventTag = createEventTag();

auto timeStamp = performanceEntryReporter->getCurrentTimeStamp();
// The event start timestamp may be provided by the caller in order to
// specify the platform specific event start time.
auto timeStamp = eventStartTimeStamp == DOM_HIGH_RES_TIME_STAMP_UNSET
? performanceEntryReporter->getCurrentTimeStamp()
: eventStartTimeStamp;
{
std::lock_guard lock(eventsInFlightMutex_);
eventsInFlight_.emplace(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ class EventPerformanceLogger : public EventLogger,

#pragma mark - EventLogger

EventTag onEventStart(std::string_view name, SharedEventTarget target)
override;
EventTag onEventStart(
std::string_view name,
SharedEventTarget target,
DOMHighResTimeStamp eventStartTimeStamp =
DOM_HIGH_RES_TIME_STAMP_UNSET) override;
void onEventProcessingStart(EventTag tag) override;
void onEventProcessingEnd(EventTag tag) override;

Expand Down
2 changes: 2 additions & 0 deletions packages/react-native/ReactCommon/react/timing/primitives.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ namespace facebook::react {
// not necessary in React Native.
using DOMHighResTimeStamp = double;

constexpr DOMHighResTimeStamp DOM_HIGH_RES_TIME_STAMP_UNSET = -1.0;

inline DOMHighResTimeStamp chronoToDOMHighResTimeStamp(
std::chrono::steady_clock::duration duration) {
return static_cast<std::chrono::duration<double, std::milli>>(duration)
Expand Down
Loading