mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
API to report events
Summary: Extends the WebPerformance API with ability to report events, [according to the standard](https://www.w3.org/TR/event-timing/#sec-performance-event-timing). This is an API-only change, the actual reporting comes in a separate diff, to simplify reviewing. Changelog: [Internal] Reviewed By: christophpurrer Differential Revision: D42097695 fbshipit-source-id: d8b468ffed50c1c3d889151df5e8ca644d6e1a68
This commit is contained in:
committed by
Facebook GitHub Bot
parent
d09c5fd7a9
commit
4eecab3a76
@@ -17,6 +17,10 @@ static PerformanceEntryType stringToPerformanceEntryType(
|
||||
return PerformanceEntryType::MARK;
|
||||
} else if (entryType == "measure") {
|
||||
return PerformanceEntryType::MEASURE;
|
||||
} else if (entryType == "event") {
|
||||
return PerformanceEntryType::EVENT;
|
||||
} else if (entryType == "first-input") {
|
||||
return PerformanceEntryType::FIRST_INPUT;
|
||||
} else {
|
||||
return PerformanceEntryType::UNDEFINED;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ using RawPerformanceEntry = NativePerformanceObserverCxxBaseRawPerformanceEntry<
|
||||
// For "event" entries only:
|
||||
std::optional<double>,
|
||||
std::optional<double>,
|
||||
std::optional<double>>;
|
||||
std::optional<uint32_t>>;
|
||||
|
||||
template <>
|
||||
struct Bridging<RawPerformanceEntry>
|
||||
@@ -37,7 +37,7 @@ struct Bridging<RawPerformanceEntry>
|
||||
double,
|
||||
std::optional<double>,
|
||||
std::optional<double>,
|
||||
std::optional<double>> {};
|
||||
std::optional<uint32_t>> {};
|
||||
|
||||
using GetPendingEntriesResult =
|
||||
NativePerformanceObserverCxxBaseGetPendingEntriesResult<
|
||||
|
||||
@@ -16,6 +16,8 @@ export const RawPerformanceEntryTypeValues = {
|
||||
UNDEFINED: 0,
|
||||
MARK: 1,
|
||||
MEASURE: 2,
|
||||
EVENT: 3,
|
||||
FIRST_INPUT: 4,
|
||||
};
|
||||
|
||||
export type RawPerformanceEntryType = number;
|
||||
|
||||
@@ -167,6 +167,26 @@ double PerformanceEntryReporter::getMarkTime(
|
||||
}
|
||||
}
|
||||
|
||||
void PerformanceEntryReporter::event(
|
||||
const std::string &name,
|
||||
double startTime,
|
||||
double duration,
|
||||
bool isFirstInput,
|
||||
double processingStart,
|
||||
double processingEnd,
|
||||
uint32_t interactionId) {
|
||||
logEntry(
|
||||
{name,
|
||||
static_cast<int>(
|
||||
isFirstInput ? PerformanceEntryType::FIRST_INPUT
|
||||
: PerformanceEntryType::MEASURE),
|
||||
startTime,
|
||||
duration,
|
||||
processingStart,
|
||||
processingEnd,
|
||||
interactionId});
|
||||
}
|
||||
|
||||
void PerformanceEntryReporter::clearEntries(
|
||||
std::function<bool(const RawPerformanceEntry &)> predicate) {
|
||||
int lastPos = entries_.size() - 1;
|
||||
|
||||
@@ -45,7 +45,9 @@ enum class PerformanceEntryType {
|
||||
UNDEFINED = 0,
|
||||
MARK = 1,
|
||||
MEASURE = 2,
|
||||
_COUNT = 3,
|
||||
EVENT = 3,
|
||||
FIRST_INPUT = 4,
|
||||
_COUNT = 5,
|
||||
};
|
||||
|
||||
class PerformanceEntryReporter {
|
||||
@@ -88,6 +90,15 @@ class PerformanceEntryReporter {
|
||||
const std::optional<std::string> &endMark);
|
||||
void clearMeasures(const std::optional<std::string> &measureName);
|
||||
|
||||
void event(
|
||||
const std::string &name,
|
||||
double startTime,
|
||||
double duration,
|
||||
bool isFirstInput,
|
||||
double processingStart,
|
||||
double processingEnd,
|
||||
uint32_t interactionId);
|
||||
|
||||
private:
|
||||
PerformanceEntryReporter() {}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import NativePerformanceObserver, {
|
||||
} from './NativePerformanceObserver';
|
||||
|
||||
export type HighResTimeStamp = number;
|
||||
export type PerformanceEntryType = 'mark' | 'measure';
|
||||
export type PerformanceEntryType = 'mark' | 'measure' | 'event' | 'first-input';
|
||||
|
||||
export class PerformanceEntry {
|
||||
name: string;
|
||||
@@ -62,6 +62,10 @@ function rawToPerformanceEntryType(
|
||||
return 'mark';
|
||||
case RawPerformanceEntryTypeValues.MEASURE:
|
||||
return 'measure';
|
||||
case RawPerformanceEntryTypeValues.EVENT:
|
||||
return 'event';
|
||||
case RawPerformanceEntryTypeValues.FIRST_INPUT:
|
||||
return 'first-input';
|
||||
default:
|
||||
throw new TypeError(
|
||||
`unexpected performance entry type received: ${type}`,
|
||||
@@ -311,7 +315,7 @@ export default class PerformanceObserver {
|
||||
}
|
||||
|
||||
static supportedEntryTypes: $ReadOnlyArray<PerformanceEntryType> =
|
||||
Object.freeze(['mark', 'measure']);
|
||||
Object.freeze(['mark', 'measure', 'event', 'first-input']);
|
||||
}
|
||||
|
||||
function union<T>(a: $ReadOnlySet<T>, b: $ReadOnlySet<T>): Set<T> {
|
||||
|
||||
Reference in New Issue
Block a user