mirror of
https://github.com/facebook/react-native.git
synced 2026-11-18 20:19:07 +00:00
Support additional PerformanceResourceTiming fields (#53815)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/53815 Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D82561777 fbshipit-source-id: f387c4bca2112111e736433af90ada16efd14e8b
This commit is contained in:
1 parent
e97ef8f1fb
commit
5b8827939d
10 files changed
+73
-13
No files matched your search
+3
@@ -75,6 +75,9 @@ NativePerformanceEntry toNativePerformanceEntry(const PerformanceEntry& entry) {
|
||||
nativeEntry.responseStart = resourceEntry.responseStart;
|
||||
nativeEntry.responseEnd = resourceEntry.responseEnd;
|
||||
nativeEntry.responseStatus = resourceEntry.responseStatus;
|
||||
nativeEntry.contentType = resourceEntry.contentType;
|
||||
nativeEntry.encodedBodySize = resourceEntry.encodedBodySize;
|
||||
nativeEntry.decodedBodySize = resourceEntry.decodedBodySize;
|
||||
}
|
||||
|
||||
return nativeEntry;
|
||||
|
||||
+3
@@ -68,6 +68,9 @@ struct NativePerformanceEntry {
|
||||
std::optional<HighResTimeStamp> responseStart;
|
||||
std::optional<HighResTimeStamp> responseEnd;
|
||||
std::optional<int> responseStatus;
|
||||
std::optional<std::string> contentType;
|
||||
std::optional<int> encodedBodySize;
|
||||
std::optional<int> decodedBodySize;
|
||||
};
|
||||
|
||||
template <>
|
||||
|
||||
@@ -9,10 +9,10 @@
|
||||
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
#include <jsinspector-modern/network/CdpNetwork.h>
|
||||
#include <jsinspector-modern/network/HttpUtils.h>
|
||||
#include <jsinspector-modern/network/NetworkHandler.h>
|
||||
#include <jsinspector-modern/tracing/PerformanceTracer.h>
|
||||
#endif
|
||||
#include <jsinspector-modern/network/HttpUtils.h>
|
||||
#include <react/featureflags/ReactNativeFeatureFlags.h>
|
||||
#include <react/performance/timeline/PerformanceEntryReporter.h>
|
||||
|
||||
@@ -110,6 +110,7 @@ void NetworkReporter::reportResponseStart(
|
||||
const ResponseInfo& responseInfo,
|
||||
int encodedDataLength) {
|
||||
auto now = HighResTimeStamp::now();
|
||||
auto headers = responseInfo.headers.value_or(Headers{});
|
||||
|
||||
if (ReactNativeFeatureFlags::enableResourceTimingAPI()) {
|
||||
// All builds: Annotate PerformanceResourceTiming metadata
|
||||
@@ -117,16 +118,18 @@ void NetworkReporter::reportResponseStart(
|
||||
std::lock_guard<std::mutex> lock(perfTimingsMutex_);
|
||||
auto it = perfTimingsBuffer_.find(requestId);
|
||||
if (it != perfTimingsBuffer_.end()) {
|
||||
auto contentType = jsinspector_modern::mimeTypeFromHeaders(headers);
|
||||
it->second.connectEnd = now;
|
||||
it->second.responseStart = now;
|
||||
it->second.responseStatus = responseInfo.statusCode;
|
||||
it->second.contentType = contentType;
|
||||
it->second.encodedBodySize = encodedDataLength;
|
||||
it->second.decodedBodySize = encodedDataLength;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
|
||||
auto headers = responseInfo.headers.value_or(Headers{});
|
||||
|
||||
// Debugger enabled: CDP event handling
|
||||
jsinspector_modern::NetworkHandler::getInstance().onResponseReceived(
|
||||
requestId,
|
||||
@@ -174,7 +177,10 @@ void NetworkReporter::reportResponseEnd(
|
||||
eventData.connectEnd.value_or(now),
|
||||
eventData.responseStart.value_or(now),
|
||||
now,
|
||||
eventData.responseStatus);
|
||||
eventData.responseStatus,
|
||||
eventData.contentType,
|
||||
eventData.encodedBodySize,
|
||||
eventData.decodedBodySize);
|
||||
perfTimingsBuffer_.erase(requestId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,10 @@ struct ResourceTimingData {
|
||||
std::optional<HighResTimeStamp> connectStart;
|
||||
std::optional<HighResTimeStamp> connectEnd;
|
||||
std::optional<HighResTimeStamp> responseStart;
|
||||
std::optional<int> responseStatus;
|
||||
int responseStatus = 0;
|
||||
std::string contentType;
|
||||
int encodedBodySize = 0;
|
||||
int decodedBodySize = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -69,7 +69,10 @@ struct PerformanceResourceTiming : AbstractPerformanceEntry {
|
||||
std::optional<HighResTimeStamp> responseStart;
|
||||
/** Aligns with `duration`. */
|
||||
std::optional<HighResTimeStamp> responseEnd;
|
||||
std::optional<int> responseStatus;
|
||||
int responseStatus;
|
||||
std::string contentType;
|
||||
int encodedBodySize;
|
||||
int decodedBodySize;
|
||||
};
|
||||
|
||||
using PerformanceEntry = std::variant<
|
||||
|
||||
+7
-1
@@ -307,7 +307,10 @@ void PerformanceEntryReporter::reportResourceTiming(
|
||||
std::optional<HighResTimeStamp> connectEnd,
|
||||
HighResTimeStamp responseStart,
|
||||
HighResTimeStamp responseEnd,
|
||||
const std::optional<int>& responseStatus) {
|
||||
int responseStatus,
|
||||
const std::string& contentType,
|
||||
int encodedBodySize,
|
||||
int decodedBodySize) {
|
||||
const auto entry = PerformanceResourceTiming{
|
||||
{.name = url, .startTime = fetchStart},
|
||||
fetchStart,
|
||||
@@ -317,6 +320,9 @@ void PerformanceEntryReporter::reportResourceTiming(
|
||||
responseStart,
|
||||
responseEnd,
|
||||
responseStatus,
|
||||
contentType,
|
||||
encodedBodySize,
|
||||
decodedBodySize,
|
||||
};
|
||||
|
||||
// Add to buffers & notify observers
|
||||
|
||||
+4
-1
@@ -118,7 +118,10 @@ class PerformanceEntryReporter {
|
||||
std::optional<HighResTimeStamp> connectEnd,
|
||||
HighResTimeStamp responseStart,
|
||||
HighResTimeStamp responseEnd,
|
||||
const std::optional<int>& responseStatus);
|
||||
int responseStatus,
|
||||
const std::string& contentType,
|
||||
int encodedBodySize,
|
||||
int decodedBodySize);
|
||||
|
||||
private:
|
||||
std::unique_ptr<PerformanceObserverRegistry> observerRegistry_;
|
||||
|
||||
@@ -25,7 +25,10 @@ export type PerformanceResourceTimingJSON = {
|
||||
connectEnd: DOMHighResTimeStamp,
|
||||
responseStart: DOMHighResTimeStamp,
|
||||
responseEnd: DOMHighResTimeStamp,
|
||||
responseStatus: ?number,
|
||||
responseStatus: number,
|
||||
contentType: string,
|
||||
encodedBodySize: number,
|
||||
decodedBodySize: number,
|
||||
...
|
||||
};
|
||||
|
||||
@@ -39,7 +42,10 @@ export interface PerformanceResourceTimingInit {
|
||||
+connectEnd: DOMHighResTimeStamp;
|
||||
+responseStart: DOMHighResTimeStamp;
|
||||
+responseEnd: DOMHighResTimeStamp;
|
||||
+responseStatus?: number;
|
||||
+responseStatus: number;
|
||||
+contentType: string;
|
||||
+encodedBodySize: number;
|
||||
+decodedBodySize: number;
|
||||
}
|
||||
|
||||
export class PerformanceResourceTiming extends PerformanceEntry {
|
||||
@@ -49,7 +55,10 @@ export class PerformanceResourceTiming extends PerformanceEntry {
|
||||
#connectEnd: DOMHighResTimeStamp;
|
||||
#responseStart: DOMHighResTimeStamp;
|
||||
#responseEnd: DOMHighResTimeStamp;
|
||||
#responseStatus: ?number;
|
||||
#responseStatus: number;
|
||||
#contentType: string;
|
||||
#encodedBodySize: number;
|
||||
#decodedBodySize: number;
|
||||
|
||||
constructor(init: PerformanceResourceTimingInit) {
|
||||
super('resource', init);
|
||||
@@ -61,6 +70,9 @@ export class PerformanceResourceTiming extends PerformanceEntry {
|
||||
this.#responseStart = init.responseStart;
|
||||
this.#responseEnd = init.responseEnd;
|
||||
this.#responseStatus = init.responseStatus;
|
||||
this.#contentType = init.contentType;
|
||||
this.#encodedBodySize = init.encodedBodySize;
|
||||
this.#decodedBodySize = init.decodedBodySize;
|
||||
}
|
||||
|
||||
get fetchStart(): DOMHighResTimeStamp {
|
||||
@@ -87,10 +99,22 @@ export class PerformanceResourceTiming extends PerformanceEntry {
|
||||
return this.#responseEnd;
|
||||
}
|
||||
|
||||
get responseStatus(): ?number {
|
||||
get responseStatus(): number {
|
||||
return this.#responseStatus;
|
||||
}
|
||||
|
||||
get contentType(): string {
|
||||
return this.#contentType;
|
||||
}
|
||||
|
||||
get encodedBodySize(): number {
|
||||
return this.#encodedBodySize;
|
||||
}
|
||||
|
||||
get decodedBodySize(): number {
|
||||
return this.#decodedBodySize;
|
||||
}
|
||||
|
||||
toJSON(): PerformanceResourceTimingJSON {
|
||||
return {
|
||||
...super.toJSON(),
|
||||
@@ -101,6 +125,9 @@ export class PerformanceResourceTiming extends PerformanceEntry {
|
||||
responseStart: this.#responseStart,
|
||||
responseEnd: this.#responseEnd,
|
||||
responseStatus: this.#responseStatus,
|
||||
contentType: this.contentType,
|
||||
encodedBodySize: this.encodedBodySize,
|
||||
decodedBodySize: this.decodedBodySize,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -68,7 +68,10 @@ export function rawToPerformanceEntry(
|
||||
connectEnd: entry.connectEnd ?? 0,
|
||||
responseStart: entry.responseStart ?? 0,
|
||||
responseEnd: entry.responseEnd ?? 0,
|
||||
responseStatus: entry.responseStatus,
|
||||
responseStatus: entry.responseStatus ?? 0,
|
||||
contentType: entry.contentType ?? '',
|
||||
encodedBodySize: entry.encodedBodySize ?? 0,
|
||||
decodedBodySize: entry.decodedBodySize ?? 0,
|
||||
});
|
||||
default:
|
||||
return new PerformanceEntry(rawToPerformanceEntryType(entry.entryType), {
|
||||
|
||||
+3
@@ -37,6 +37,9 @@ export type RawPerformanceEntry = {
|
||||
responseStart?: number,
|
||||
responseEnd?: number,
|
||||
responseStatus?: number,
|
||||
contentType?: string,
|
||||
encodedBodySize?: number,
|
||||
decodedBodySize?: number,
|
||||
};
|
||||
|
||||
export opaque type OpaqueNativeObserverHandle = mixed;
|
||||
|
||||
Reference in new issue
Block a user