@@ -38,18 +38,16 @@ void NetworkReporter::reportRequestStart(
38
38
const std::optional<ResponseInfo>& redirectResponse) {
39
39
auto now = HighResTimeStamp::now ();
40
40
41
- if (ReactNativeFeatureFlags::enableResourceTimingAPI ()) {
42
- // All builds: Annotate PerformanceResourceTiming metadata
43
- {
44
- std::lock_guard<std::mutex> lock (perfTimingsMutex_);
45
- perfTimingsBuffer_.emplace (
46
- requestId,
47
- ResourceTimingData{
48
- .url = requestInfo.url ,
49
- .fetchStart = now,
50
- .requestStart = now,
51
- });
52
- }
41
+ // All builds: Annotate PerformanceResourceTiming metadata
42
+ {
43
+ std::lock_guard<std::mutex> lock (perfTimingsMutex_);
44
+ perfTimingsBuffer_.emplace (
45
+ requestId,
46
+ ResourceTimingData{
47
+ .url = requestInfo.url ,
48
+ .fetchStart = now,
49
+ .requestStart = now,
50
+ });
53
51
}
54
52
55
53
#ifdef REACT_NATIVE_DEBUGGER_ENABLED
@@ -76,7 +74,6 @@ void NetworkReporter::reportRequestStart(
76
74
// Debugger enabled: Add trace events to Performance timeline
77
75
auto & performanceTracer =
78
76
jsinspector_modern::tracing::PerformanceTracer::getInstance ();
79
- performanceTracer.reportResourceWillSendRequest (requestId, now);
80
77
performanceTracer.reportResourceSendRequest (
81
78
requestId, now, requestInfo.url , requestInfo.httpMethod , headers);
82
79
#endif
@@ -87,14 +84,12 @@ void NetworkReporter::reportConnectionTiming(
87
84
const std::optional<Headers>& headers) {
88
85
auto now = HighResTimeStamp::now ();
89
86
90
- if (ReactNativeFeatureFlags::enableResourceTimingAPI ()) {
91
- // All builds: Annotate PerformanceResourceTiming metadata
92
- {
93
- std::lock_guard<std::mutex> lock (perfTimingsMutex_);
94
- auto it = perfTimingsBuffer_.find (requestId);
95
- if (it != perfTimingsBuffer_.end ()) {
96
- it->second .connectStart = now;
97
- }
87
+ // All builds: Annotate PerformanceResourceTiming metadata
88
+ {
89
+ std::lock_guard<std::mutex> lock (perfTimingsMutex_);
90
+ auto it = perfTimingsBuffer_.find (requestId);
91
+ if (it != perfTimingsBuffer_.end ()) {
92
+ it->second .connectStart = now;
98
93
}
99
94
}
100
95
@@ -112,20 +107,18 @@ void NetworkReporter::reportResponseStart(
112
107
auto now = HighResTimeStamp::now ();
113
108
auto headers = responseInfo.headers .value_or (Headers{});
114
109
115
- if (ReactNativeFeatureFlags::enableResourceTimingAPI ()) {
116
- // All builds: Annotate PerformanceResourceTiming metadata
117
- {
118
- std::lock_guard<std::mutex> lock (perfTimingsMutex_);
119
- auto it = perfTimingsBuffer_.find (requestId);
120
- if (it != perfTimingsBuffer_.end ()) {
121
- auto contentType = jsinspector_modern::mimeTypeFromHeaders (headers);
122
- it->second .connectEnd = now;
123
- it->second .responseStart = now;
124
- it->second .responseStatus = responseInfo.statusCode ;
125
- it->second .contentType = contentType;
126
- it->second .encodedBodySize = encodedDataLength;
127
- it->second .decodedBodySize = encodedDataLength;
128
- }
110
+ // All builds: Annotate PerformanceResourceTiming metadata
111
+ {
112
+ std::lock_guard<std::mutex> lock (perfTimingsMutex_);
113
+ auto it = perfTimingsBuffer_.find (requestId);
114
+ if (it != perfTimingsBuffer_.end ()) {
115
+ auto contentType = jsinspector_modern::mimeTypeFromHeaders (headers);
116
+ it->second .connectEnd = now;
117
+ it->second .responseStart = now;
118
+ it->second .responseStatus = responseInfo.statusCode ;
119
+ it->second .contentType = contentType;
120
+ it->second .encodedBodySize = encodedDataLength;
121
+ it->second .decodedBodySize = encodedDataLength;
129
122
}
130
123
}
131
124
@@ -140,9 +133,34 @@ void NetworkReporter::reportResponseStart(
140
133
encodedDataLength));
141
134
142
135
// Debugger enabled: Add trace event to Performance timeline
143
- jsinspector_modern::tracing::PerformanceTracer::getInstance ()
144
- .reportResourceReceiveResponse (
145
- requestId, now, responseInfo.statusCode , headers, encodedDataLength);
136
+ {
137
+ folly::dynamic timingData = folly::dynamic::object ();
138
+
139
+ std::lock_guard<std::mutex> lock (perfTimingsMutex_);
140
+ auto it = perfTimingsBuffer_.find (requestId);
141
+ if (it != perfTimingsBuffer_.end ()) {
142
+ // TODO(T238364329): All relative values in timingData should be based on
143
+ // fetchStart, once implemented.
144
+ auto requestStart = it->second .requestStart ;
145
+ timingData[" requestTime" ] = requestStart.toDOMHighResTimeStamp () / 1000 ;
146
+ timingData[" sendStart" ] = 0 ;
147
+ timingData[" sendEnd" ] =
148
+ (*it->second .connectStart - requestStart).toDOMHighResTimeStamp ();
149
+ timingData[" receiveHeadersStart" ] =
150
+ (*it->second .connectStart - requestStart).toDOMHighResTimeStamp ();
151
+ timingData[" receiveHeadersEnd" ] =
152
+ (now - requestStart).toDOMHighResTimeStamp ();
153
+ }
154
+
155
+ jsinspector_modern::tracing::PerformanceTracer::getInstance ()
156
+ .reportResourceReceiveResponse (
157
+ requestId,
158
+ now,
159
+ responseInfo.statusCode ,
160
+ headers,
161
+ encodedDataLength,
162
+ std::move (timingData));
163
+ }
146
164
#endif
147
165
}
148
166
@@ -192,8 +210,20 @@ void NetworkReporter::reportResponseEnd(
192
210
requestId, encodedDataLength);
193
211
194
212
// Debugger enabled: Add trace event to Performance timeline
195
- jsinspector_modern::tracing::PerformanceTracer::getInstance ()
196
- .reportResourceFinish (requestId, now);
213
+ {
214
+ int decodedBodyLength = 0 ;
215
+
216
+ std::lock_guard<std::mutex> lock (perfTimingsMutex_);
217
+ auto it = perfTimingsBuffer_.find (requestId);
218
+ if (it != perfTimingsBuffer_.end () &&
219
+ it->second .contentType .starts_with (" image/" )) {
220
+ decodedBodyLength = it->second .decodedBodySize ;
221
+ }
222
+
223
+ jsinspector_modern::tracing::PerformanceTracer::getInstance ()
224
+ .reportResourceFinish (
225
+ requestId, now, encodedDataLength, decodedBodyLength);
226
+ }
197
227
#endif
198
228
}
199
229
0 commit comments