@react-native-firebase/perf 26.4.0 → 27.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/RNFBPerf.podspec +6 -1
- package/android/build.gradle +3 -0
- package/android/src/main/java/io/invertase/firebase/perf/RNFBPerfHandleRegistry.kt +71 -0
- package/android/src/test/java/io/invertase/firebase/perf/RNFBPerfHandleRegistryTest.java +30 -0
- package/dist/module/version.js +1 -1
- package/dist/typescript/lib/index.d.ts +1 -1
- package/dist/typescript/lib/version.d.ts +1 -1
- package/ios/RNFBPerf/RNFBPerfHandleRegistry.m +28 -9
- package/ios/RNFBPerf/RNFBPerfHandleRegistryStorage.swift +58 -0
- package/ios/RNFBPerf/RNFBPerfHelper.h +71 -0
- package/ios/RNFBPerf/RNFBPerfHelper.m +219 -0
- package/ios/RNFBPerf/RNFBPerfHttpMethodMapper.swift +86 -0
- package/ios/RNFBPerf/RNFBPerfHttpMetricStopApplier.swift +87 -0
- package/ios/RNFBPerf/RNFBPerfModule.mm +35 -172
- package/ios/RNFBPerf/RNFBPerfTraceStopApplier.swift +68 -0
- package/ios/RNFBPerf.xcodeproj/project.pbxproj +32 -0
- package/ios/RNFBPerfUnitTests/HostStubs/Firebase/FIRPerformanceHostStub.m +170 -0
- package/ios/RNFBPerfUnitTests/HostStubs/Firebase/Firebase.h +75 -0
- package/ios/RNFBPerfUnitTests/HostStubs/RNFBApp/RNFBSharedUtils.h +12 -0
- package/ios/RNFBPerfUnitTests/HostStubs/RNFBApp/RNFBSharedUtilsHostStub.m +18 -0
- package/ios/RNFBPerfUnitTests/HostStubs/React/RCTBridgeModule.h +10 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfHandleRegistryTests.m +46 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfHelperHostStubTests.m +200 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfHttpMethodMapperFacadeTests.m +52 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfHttpMethodMapperTests.swift +92 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfHttpMetricStopApplierFacadeTests.m +105 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfHttpMetricStopApplierTests.swift +201 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfTraceStopApplierFacadeTests.m +75 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfTraceStopApplierTests.swift +142 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfUnitTests.xcodeproj/project.pbxproj +70 -0
- package/lib/version.ts +1 -1
- package/package.json +4 -4
- package/android/src/main/java/io/invertase/firebase/perf/RNFBPerfHandleRegistry.java +0 -72
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* HTTP method string → `FIRHTTPMethod` raw-value mapping previously inline in
|
|
21
|
+
* `-[RNFBPerfModule startHttpMetric:url:httpMethod:]`.
|
|
22
|
+
*
|
|
23
|
+
* Mirrors pre-port (case-insensitive `compare:`; successive ifs; default GET).
|
|
24
|
+
* Raw ints from Firebase Performance `FIRHTTPMethod` (`FIRHTTPMetric.h`):
|
|
25
|
+
* - GET = 0, PUT = 1, POST = 2, DELETE = 3, HEAD = 4
|
|
26
|
+
* - PATCH = 5, OPTIONS = 6, TRACE = 7, CONNECT = 8
|
|
27
|
+
*
|
|
28
|
+
* Unknown / empty / nil / `"get"` → GET (no explicit GET branch).
|
|
29
|
+
*/
|
|
30
|
+
@objc(RNFBPerfHttpMethodMapper)
|
|
31
|
+
public final class RNFBPerfHttpMethodMapper: NSObject {
|
|
32
|
+
/// `FIRHTTPMethodGET`
|
|
33
|
+
private static let getMethod = 0
|
|
34
|
+
/// `FIRHTTPMethodPUT`
|
|
35
|
+
private static let putMethod = 1
|
|
36
|
+
/// `FIRHTTPMethodPOST`
|
|
37
|
+
private static let postMethod = 2
|
|
38
|
+
/// `FIRHTTPMethodDELETE`
|
|
39
|
+
private static let deleteMethod = 3
|
|
40
|
+
/// `FIRHTTPMethodHEAD`
|
|
41
|
+
private static let headMethod = 4
|
|
42
|
+
/// `FIRHTTPMethodPATCH`
|
|
43
|
+
private static let patchMethod = 5
|
|
44
|
+
/// `FIRHTTPMethodOPTIONS`
|
|
45
|
+
private static let optionsMethod = 6
|
|
46
|
+
/// `FIRHTTPMethodTRACE`
|
|
47
|
+
private static let traceMethod = 7
|
|
48
|
+
/// `FIRHTTPMethodCONNECT`
|
|
49
|
+
private static let connectMethod = 8
|
|
50
|
+
|
|
51
|
+
@objc(httpMethodRawValueForString:)
|
|
52
|
+
public static func httpMethodRawValue(forString httpMethod: String?) -> Int {
|
|
53
|
+
var method = getMethod
|
|
54
|
+
guard let httpMethod else {
|
|
55
|
+
return method
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Successive case-insensitive compares (not else-if) — same outcome for
|
|
59
|
+
// single method strings; preserves pre-port control flow.
|
|
60
|
+
if httpMethod.caseInsensitiveCompare("put") == .orderedSame {
|
|
61
|
+
method = putMethod
|
|
62
|
+
}
|
|
63
|
+
if httpMethod.caseInsensitiveCompare("post") == .orderedSame {
|
|
64
|
+
method = postMethod
|
|
65
|
+
}
|
|
66
|
+
if httpMethod.caseInsensitiveCompare("head") == .orderedSame {
|
|
67
|
+
method = headMethod
|
|
68
|
+
}
|
|
69
|
+
if httpMethod.caseInsensitiveCompare("trace") == .orderedSame {
|
|
70
|
+
method = traceMethod
|
|
71
|
+
}
|
|
72
|
+
if httpMethod.caseInsensitiveCompare("patch") == .orderedSame {
|
|
73
|
+
method = patchMethod
|
|
74
|
+
}
|
|
75
|
+
if httpMethod.caseInsensitiveCompare("delete") == .orderedSame {
|
|
76
|
+
method = deleteMethod
|
|
77
|
+
}
|
|
78
|
+
if httpMethod.caseInsensitiveCompare("options") == .orderedSame {
|
|
79
|
+
method = optionsMethod
|
|
80
|
+
}
|
|
81
|
+
if httpMethod.caseInsensitiveCompare("connect") == .orderedSame {
|
|
82
|
+
method = connectMethod
|
|
83
|
+
}
|
|
84
|
+
return method
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Subset of `FIRHTTPMetric` setters used by
|
|
21
|
+
* `-[RNFBPerfModule stopHttpMetric:metricData:]`. Protocol-shaped so unit tests
|
|
22
|
+
* can stub without linking FirebasePerformance.
|
|
23
|
+
*/
|
|
24
|
+
@objc public protocol RNFBPerfHttpMetricApplying: AnyObject {
|
|
25
|
+
@objc(setValue:forAttribute:)
|
|
26
|
+
func setValue(_ value: String, forAttribute attributeName: String)
|
|
27
|
+
|
|
28
|
+
@objc(setResponseCode:)
|
|
29
|
+
func setResponseCode(_ responseCode: Int)
|
|
30
|
+
|
|
31
|
+
@objc(setRequestPayloadSize:)
|
|
32
|
+
func setRequestPayloadSize(_ bytes: Int)
|
|
33
|
+
|
|
34
|
+
@objc(setResponsePayloadSize:)
|
|
35
|
+
func setResponsePayloadSize(_ bytes: Int)
|
|
36
|
+
|
|
37
|
+
@objc(setResponseContentType:)
|
|
38
|
+
func setResponseContentType(_ contentType: String)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Applies HTTP metric stop fields previously set inline in
|
|
43
|
+
* `-[RNFBPerfModule stopHttpMetric:metricData:]`.
|
|
44
|
+
*
|
|
45
|
+
* Pre-port contracts:
|
|
46
|
+
* - attributes first (`setValue:forAttribute:`), then optional responseCode,
|
|
47
|
+
* requestPayloadSize, responsePayloadSize, responseContentType
|
|
48
|
+
* - missing optionals (nil NSNumber / nil content type) skipped
|
|
49
|
+
* - nil attributes dict → no crash
|
|
50
|
+
*/
|
|
51
|
+
@objc(RNFBPerfHttpMetricStopApplier)
|
|
52
|
+
public final class RNFBPerfHttpMetricStopApplier: NSObject {
|
|
53
|
+
@objc(applyAttributes:httpResponseCode:requestPayloadSize:responsePayloadSize:responseContentType:to:)
|
|
54
|
+
public static func apply(
|
|
55
|
+
attributes: NSDictionary?,
|
|
56
|
+
httpResponseCode: NSNumber?,
|
|
57
|
+
requestPayloadSize: NSNumber?,
|
|
58
|
+
responsePayloadSize: NSNumber?,
|
|
59
|
+
responseContentType: String?,
|
|
60
|
+
to metric: RNFBPerfHttpMetricApplying
|
|
61
|
+
) {
|
|
62
|
+
if let attributes {
|
|
63
|
+
attributes.enumerateKeysAndObjects { key, value, _ in
|
|
64
|
+
guard let attributeName = key as? String, let stringValue = value as? String else {
|
|
65
|
+
return
|
|
66
|
+
}
|
|
67
|
+
metric.setValue(stringValue, forAttribute: attributeName)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if let httpResponseCode {
|
|
72
|
+
metric.setResponseCode(httpResponseCode.intValue)
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if let requestPayloadSize {
|
|
76
|
+
metric.setRequestPayloadSize(requestPayloadSize.intValue)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if let responsePayloadSize {
|
|
80
|
+
metric.setResponsePayloadSize(responsePayloadSize.intValue)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if let responseContentType {
|
|
84
|
+
metric.setResponseContentType(responseContentType)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
@@ -15,28 +15,14 @@
|
|
|
15
15
|
*
|
|
16
16
|
*/
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
#define RNFB_PERF_SDK_AVAILABLE 1
|
|
24
|
-
#elif __has_include(<FirebasePerformance/FirebasePerformance.h>)
|
|
25
|
-
#import <FirebaseCore/FirebaseCore.h>
|
|
26
|
-
#import <FirebasePerformance/FirebasePerformance.h>
|
|
27
|
-
#define RNFB_PERF_SDK_AVAILABLE 1
|
|
28
|
-
#else
|
|
29
|
-
// Product headers absent (typical Mac Catalyst + SPM). Upstream Package.swift
|
|
30
|
-
// omits .macCatalyst from FirebasePerformanceTarget; CocoaPods historically
|
|
31
|
-
// masked this via the Firebase umbrella. Temporary stubs pending
|
|
32
|
-
// https://github.com/firebase/firebase-ios-sdk/pull/16468 (or permanent if
|
|
33
|
-
// upstream declines). Never fall through to @import in this .mm — that
|
|
34
|
-
// requires -fcxx-modules and breaks RN C++/JSI.
|
|
35
|
-
#define RNFB_PERF_SDK_AVAILABLE 0
|
|
36
|
-
#endif
|
|
37
|
-
#import "RNFBApp/RNFBSharedUtils.h"
|
|
38
|
-
#import "RNFBPerfHandleRegistry.h"
|
|
18
|
+
// This module intentionally has no Firebase imports and no `*-Swift.h` —
|
|
19
|
+
// see RNFBPerfHelper.h. Every Firebase Performance touch (and the Swift
|
|
20
|
+
// stop appliers / HTTP method mapper) is routed through the plain
|
|
21
|
+
// Objective-C RNFBPerfHelper class instead, which can safely import Firebase
|
|
22
|
+
// and the generated Swift interface because it compiles as ObjC, not ObjC++.
|
|
39
23
|
#import "RNFBPerfModule.h"
|
|
24
|
+
#import "RNFBPerfHandleRegistry.h"
|
|
25
|
+
#import "RNFBPerfHelper.h"
|
|
40
26
|
|
|
41
27
|
static RNFBPerfHandleRegistry *traces;
|
|
42
28
|
static RNFBPerfHandleRegistry *httpMetrics;
|
|
@@ -66,29 +52,8 @@ RCT_EXPORT_MODULE(NativeRNFBTurboPerf)
|
|
|
66
52
|
[httpMetrics takeAll];
|
|
67
53
|
}
|
|
68
54
|
|
|
69
|
-
#if !RNFB_PERF_SDK_AVAILABLE
|
|
70
|
-
- (void)rejectUnavailable:(RCTPromiseRejectBlock)reject {
|
|
71
|
-
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
72
|
-
userInfo:(NSMutableDictionary *)@{
|
|
73
|
-
@"code" : @"unsupported",
|
|
74
|
-
@"message" : @"Firebase Performance is not available on "
|
|
75
|
-
@"this platform or dependency configuration.",
|
|
76
|
-
}];
|
|
77
|
-
}
|
|
78
|
-
#endif
|
|
79
|
-
|
|
80
55
|
- (NSDictionary *)perfConstantsDictionary {
|
|
81
|
-
|
|
82
|
-
#if RNFB_PERF_SDK_AVAILABLE
|
|
83
|
-
constants[@"isPerformanceCollectionEnabled"] =
|
|
84
|
-
@([RCTConvert BOOL:@([FIRPerformance sharedInstance].dataCollectionEnabled)]);
|
|
85
|
-
constants[@"isInstrumentationEnabled"] =
|
|
86
|
-
@([RCTConvert BOOL:@([FIRPerformance sharedInstance].instrumentationEnabled)]);
|
|
87
|
-
#else
|
|
88
|
-
constants[@"isPerformanceCollectionEnabled"] = @(NO);
|
|
89
|
-
constants[@"isInstrumentationEnabled"] = @(NO);
|
|
90
|
-
#endif
|
|
91
|
-
return constants;
|
|
56
|
+
return [RNFBPerfHelper constantsDictionary];
|
|
92
57
|
}
|
|
93
58
|
|
|
94
59
|
- (facebook::react::ModuleConstants<JS::NativeRNFBTurboPerf::Constants>)constantsToExport {
|
|
@@ -107,76 +72,26 @@ RCT_EXPORT_MODULE(NativeRNFBTurboPerf)
|
|
|
107
72
|
- (void)setPerformanceCollectionEnabled:(BOOL)enabled
|
|
108
73
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
109
74
|
reject:(RCTPromiseRejectBlock)reject {
|
|
110
|
-
|
|
111
|
-
[FIRPerformance sharedInstance].dataCollectionEnabled = (BOOL)enabled;
|
|
112
|
-
resolve([NSNull null]);
|
|
113
|
-
#else
|
|
114
|
-
(void)enabled;
|
|
115
|
-
(void)resolve;
|
|
116
|
-
[self rejectUnavailable:reject];
|
|
117
|
-
#endif
|
|
75
|
+
[RNFBPerfHelper setPerformanceCollectionEnabled:enabled resolve:resolve reject:reject];
|
|
118
76
|
}
|
|
119
77
|
|
|
120
78
|
- (void)instrumentationEnabled:(BOOL)enabled
|
|
121
79
|
resolve:(RCTPromiseResolveBlock)resolve
|
|
122
80
|
reject:(RCTPromiseRejectBlock)reject {
|
|
123
|
-
|
|
124
|
-
[FIRPerformance sharedInstance].instrumentationEnabled = (BOOL)enabled;
|
|
125
|
-
resolve([NSNull null]);
|
|
126
|
-
#else
|
|
127
|
-
(void)enabled;
|
|
128
|
-
(void)resolve;
|
|
129
|
-
[self rejectUnavailable:reject];
|
|
130
|
-
#endif
|
|
81
|
+
[RNFBPerfHelper setInstrumentationEnabled:enabled resolve:resolve reject:reject];
|
|
131
82
|
}
|
|
132
83
|
|
|
133
84
|
- (void)startTrace:(double)id identifier:(NSString *)identifier {
|
|
134
|
-
|
|
135
|
-
FIRTrace *trace = [[FIRPerformance sharedInstance] traceWithName:identifier];
|
|
136
|
-
[trace start];
|
|
137
|
-
|
|
138
|
-
FIRTrace *displaced = [traces putReplacing:@((int)id) value:trace];
|
|
139
|
-
if (displaced != nil) {
|
|
140
|
-
[displaced stop];
|
|
141
|
-
}
|
|
142
|
-
#else
|
|
143
|
-
(void)id;
|
|
144
|
-
(void)identifier;
|
|
145
|
-
#endif
|
|
85
|
+
[RNFBPerfHelper startTraceWithId:@((int)id) identifier:identifier inRegistry:traces];
|
|
146
86
|
}
|
|
147
87
|
|
|
148
88
|
- (void)stopTrace:(double)id traceData:(JS::NativeRNFBTurboPerf::TraceData &)traceData {
|
|
149
|
-
#if RNFB_PERF_SDK_AVAILABLE
|
|
150
|
-
NSNumber *traceId = @((int)id);
|
|
151
|
-
FIRTrace *trace = [traces get:traceId];
|
|
152
|
-
if (trace == nil) {
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
|
|
156
89
|
NSDictionary *metrics = (NSDictionary *)traceData.metrics();
|
|
157
90
|
NSDictionary *attributes = (NSDictionary *)traceData.attributes();
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
[attributes
|
|
164
|
-
enumerateKeysAndObjectsUsingBlock:^(NSString *attributeName, NSString *value, BOOL *stop) {
|
|
165
|
-
[trace setValue:value forAttribute:attributeName];
|
|
166
|
-
}];
|
|
167
|
-
|
|
168
|
-
FIRTrace *expected = trace;
|
|
169
|
-
trace = [traces takeIf:traceId
|
|
170
|
-
when:^BOOL(NSObject *value) {
|
|
171
|
-
return value == expected;
|
|
172
|
-
}];
|
|
173
|
-
if (trace != nil) {
|
|
174
|
-
[trace stop];
|
|
175
|
-
}
|
|
176
|
-
#else
|
|
177
|
-
(void)id;
|
|
178
|
-
(void)traceData;
|
|
179
|
-
#endif
|
|
91
|
+
[RNFBPerfHelper stopTraceWithId:@((int)id)
|
|
92
|
+
metrics:metrics
|
|
93
|
+
attributes:attributes
|
|
94
|
+
inRegistry:traces];
|
|
180
95
|
}
|
|
181
96
|
|
|
182
97
|
- (void)startScreenTrace:(double)id identifier:(NSString *)identifier {
|
|
@@ -191,82 +106,30 @@ RCT_EXPORT_MODULE(NativeRNFBTurboPerf)
|
|
|
191
106
|
}
|
|
192
107
|
|
|
193
108
|
- (void)startHttpMetric:(double)id url:(NSString *)url httpMethod:(NSString *)httpMethod {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
method = FIRHTTPMethodPUT;
|
|
199
|
-
if ([httpMethod compare:@"post" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
200
|
-
method = FIRHTTPMethodPOST;
|
|
201
|
-
if ([httpMethod compare:@"head" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
202
|
-
method = FIRHTTPMethodHEAD;
|
|
203
|
-
if ([httpMethod compare:@"trace" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
204
|
-
method = FIRHTTPMethodTRACE;
|
|
205
|
-
if ([httpMethod compare:@"patch" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
206
|
-
method = FIRHTTPMethodPATCH;
|
|
207
|
-
if ([httpMethod compare:@"delete" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
208
|
-
method = FIRHTTPMethodDELETE;
|
|
209
|
-
if ([httpMethod compare:@"options" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
210
|
-
method = FIRHTTPMethodOPTIONS;
|
|
211
|
-
if ([httpMethod compare:@"connect" options:NSCaseInsensitiveSearch] == NSOrderedSame)
|
|
212
|
-
method = FIRHTTPMethodCONNECT;
|
|
213
|
-
|
|
214
|
-
FIRHTTPMetric *httpMetric = [[FIRHTTPMetric alloc] initWithURL:toNSURL HTTPMethod:method];
|
|
215
|
-
[httpMetric start];
|
|
216
|
-
|
|
217
|
-
FIRHTTPMetric *displaced = [httpMetrics putReplacing:@((int)id) value:httpMetric];
|
|
218
|
-
if (displaced != nil) {
|
|
219
|
-
[displaced stop];
|
|
220
|
-
}
|
|
221
|
-
#else
|
|
222
|
-
(void)id;
|
|
223
|
-
(void)url;
|
|
224
|
-
(void)httpMethod;
|
|
225
|
-
#endif
|
|
109
|
+
[RNFBPerfHelper startHttpMetricWithId:@((int)id)
|
|
110
|
+
url:url
|
|
111
|
+
httpMethod:httpMethod
|
|
112
|
+
inRegistry:httpMetrics];
|
|
226
113
|
}
|
|
227
114
|
|
|
228
115
|
- (void)stopHttpMetric:(double)id metricData:(JS::NativeRNFBTurboPerf::HttpMetricData &)metricData {
|
|
229
|
-
#if RNFB_PERF_SDK_AVAILABLE
|
|
230
|
-
NSNumber *metricId = @((int)id);
|
|
231
|
-
FIRHTTPMetric *httpMetric = [httpMetrics get:metricId];
|
|
232
|
-
if (httpMetric == nil) {
|
|
233
|
-
return;
|
|
234
|
-
}
|
|
235
|
-
|
|
236
116
|
NSDictionary *attributes = (NSDictionary *)metricData.attributes();
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
if (metricData.responseContentType() != nil) {
|
|
255
|
-
[httpMetric setResponseContentType:metricData.responseContentType()];
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
FIRHTTPMetric *expected = httpMetric;
|
|
259
|
-
httpMetric = [httpMetrics takeIf:metricId
|
|
260
|
-
when:^BOOL(NSObject *value) {
|
|
261
|
-
return value == expected;
|
|
262
|
-
}];
|
|
263
|
-
if (httpMetric != nil) {
|
|
264
|
-
[httpMetric stop];
|
|
265
|
-
}
|
|
266
|
-
#else
|
|
267
|
-
(void)id;
|
|
268
|
-
(void)metricData;
|
|
269
|
-
#endif
|
|
117
|
+
NSNumber *httpResponseCode = metricData.httpResponseCode().has_value()
|
|
118
|
+
? @((NSInteger)metricData.httpResponseCode().value())
|
|
119
|
+
: nil;
|
|
120
|
+
NSNumber *requestPayloadSize = metricData.requestPayloadSize().has_value()
|
|
121
|
+
? @((NSInteger)metricData.requestPayloadSize().value())
|
|
122
|
+
: nil;
|
|
123
|
+
NSNumber *responsePayloadSize = metricData.responsePayloadSize().has_value()
|
|
124
|
+
? @((NSInteger)metricData.responsePayloadSize().value())
|
|
125
|
+
: nil;
|
|
126
|
+
[RNFBPerfHelper stopHttpMetricWithId:@((int)id)
|
|
127
|
+
attributes:attributes
|
|
128
|
+
httpResponseCode:httpResponseCode
|
|
129
|
+
requestPayloadSize:requestPayloadSize
|
|
130
|
+
responsePayloadSize:responsePayloadSize
|
|
131
|
+
responseContentType:metricData.responseContentType()
|
|
132
|
+
inRegistry:httpMetrics];
|
|
270
133
|
}
|
|
271
134
|
|
|
272
135
|
@end
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2016-present Invertase Limited & Contributors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this library except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import Foundation
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Subset of `FIRTrace` metric/attribute setters used by
|
|
21
|
+
* `-[RNFBPerfModule stopTrace:traceData:]`. Protocol-shaped so unit tests can
|
|
22
|
+
* stub without linking FirebasePerformance.
|
|
23
|
+
*/
|
|
24
|
+
@objc public protocol RNFBPerfTraceApplying: AnyObject {
|
|
25
|
+
@objc(setIntValue:forMetric:)
|
|
26
|
+
func setIntValue(_ value: Int64, forMetric metricName: String)
|
|
27
|
+
|
|
28
|
+
@objc(setValue:forAttribute:)
|
|
29
|
+
func setValue(_ value: String, forAttribute attributeName: String)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Applies `metrics` then `attributes` dictionaries previously enumerated inline
|
|
34
|
+
* in `-[RNFBPerfModule stopTrace:traceData:]`.
|
|
35
|
+
*
|
|
36
|
+
* Pre-port contracts:
|
|
37
|
+
* - metrics: `[trace setIntValue:[value longLongValue] forMetric:metricName]`
|
|
38
|
+
* - attributes: `[trace setValue:value forAttribute:attributeName]`
|
|
39
|
+
* - nil / missing dictionaries → empty (no crash)
|
|
40
|
+
* - order: metrics first, then attributes
|
|
41
|
+
*/
|
|
42
|
+
@objc(RNFBPerfTraceStopApplier)
|
|
43
|
+
public final class RNFBPerfTraceStopApplier: NSObject {
|
|
44
|
+
@objc(applyMetrics:attributes:to:)
|
|
45
|
+
public static func apply(
|
|
46
|
+
metrics: NSDictionary?,
|
|
47
|
+
attributes: NSDictionary?,
|
|
48
|
+
to trace: RNFBPerfTraceApplying
|
|
49
|
+
) {
|
|
50
|
+
if let metrics {
|
|
51
|
+
metrics.enumerateKeysAndObjects { key, value, _ in
|
|
52
|
+
guard let metricName = key as? String, let number = value as? NSNumber else {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
trace.setIntValue(number.int64Value, forMetric: metricName)
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if let attributes {
|
|
60
|
+
attributes.enumerateKeysAndObjects { key, value, _ in
|
|
61
|
+
guard let attributeName = key as? String, let stringValue = value as? String else {
|
|
62
|
+
return
|
|
63
|
+
}
|
|
64
|
+
trace.setValue(stringValue, forAttribute: attributeName)
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
@@ -8,6 +8,12 @@
|
|
|
8
8
|
|
|
9
9
|
/* Begin PBXBuildFile section */
|
|
10
10
|
2744B98621F45429004F8E3F /* RNFBPerfModule.mm in Sources */ = {isa = PBXBuildFile; fileRef = 2744B98521F45429004F8E3F /* RNFBPerfModule.mm */; };
|
|
11
|
+
RNFBPERF0000000000000001 /* RNFBPerfHandleRegistry.m in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000002 /* RNFBPerfHandleRegistry.m */; };
|
|
12
|
+
RNFBPERF0000000000000003 /* RNFBPerfHandleRegistryStorage.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000004 /* RNFBPerfHandleRegistryStorage.swift */; };
|
|
13
|
+
RNFBPERF0000000000000006 /* RNFBPerfHttpMethodMapper.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000007 /* RNFBPerfHttpMethodMapper.swift */; };
|
|
14
|
+
RNFBPERF0000000000000008 /* RNFBPerfTraceStopApplier.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF0000000000000009 /* RNFBPerfTraceStopApplier.swift */; };
|
|
15
|
+
RNFBPERF000000000000000A /* RNFBPerfHttpMetricStopApplier.swift in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF000000000000000B /* RNFBPerfHttpMetricStopApplier.swift */; };
|
|
16
|
+
RNFBPERF000000000000000C /* RNFBPerfHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = RNFBPERF000000000000000D /* RNFBPerfHelper.m */; };
|
|
11
17
|
/* End PBXBuildFile section */
|
|
12
18
|
|
|
13
19
|
/* Begin PBXCopyFilesBuildPhase section */
|
|
@@ -26,6 +32,14 @@
|
|
|
26
32
|
2744B98221F45429004F8E3F /* libRNFBPerf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNFBPerf.a; sourceTree = BUILT_PRODUCTS_DIR; };
|
|
27
33
|
2744B98421F45429004F8E3F /* RNFBPerfModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFBPerfModule.h; path = RNFBPerf/RNFBPerfModule.h; sourceTree = SOURCE_ROOT; };
|
|
28
34
|
2744B98521F45429004F8E3F /* RNFBPerfModule.mm */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFBPerfModule.mm; path = RNFBPerf/RNFBPerfModule.mm; sourceTree = SOURCE_ROOT; };
|
|
35
|
+
RNFBPERF0000000000000005 /* RNFBPerfHandleRegistry.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFBPerfHandleRegistry.h; path = RNFBPerf/RNFBPerfHandleRegistry.h; sourceTree = SOURCE_ROOT; };
|
|
36
|
+
RNFBPERF0000000000000002 /* RNFBPerfHandleRegistry.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFBPerfHandleRegistry.m; path = RNFBPerf/RNFBPerfHandleRegistry.m; sourceTree = SOURCE_ROOT; };
|
|
37
|
+
RNFBPERF0000000000000004 /* RNFBPerfHandleRegistryStorage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfHandleRegistryStorage.swift; path = RNFBPerf/RNFBPerfHandleRegistryStorage.swift; sourceTree = SOURCE_ROOT; };
|
|
38
|
+
RNFBPERF0000000000000007 /* RNFBPerfHttpMethodMapper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfHttpMethodMapper.swift; path = RNFBPerf/RNFBPerfHttpMethodMapper.swift; sourceTree = SOURCE_ROOT; };
|
|
39
|
+
RNFBPERF0000000000000009 /* RNFBPerfTraceStopApplier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfTraceStopApplier.swift; path = RNFBPerf/RNFBPerfTraceStopApplier.swift; sourceTree = SOURCE_ROOT; };
|
|
40
|
+
RNFBPERF000000000000000B /* RNFBPerfHttpMetricStopApplier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = RNFBPerfHttpMetricStopApplier.swift; path = RNFBPerf/RNFBPerfHttpMetricStopApplier.swift; sourceTree = SOURCE_ROOT; };
|
|
41
|
+
RNFBPERF000000000000000E /* RNFBPerfHelper.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = RNFBPerfHelper.h; path = RNFBPerf/RNFBPerfHelper.h; sourceTree = SOURCE_ROOT; };
|
|
42
|
+
RNFBPERF000000000000000D /* RNFBPerfHelper.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = RNFBPerfHelper.m; path = RNFBPerf/RNFBPerfHelper.m; sourceTree = SOURCE_ROOT; };
|
|
29
43
|
/* End PBXFileReference section */
|
|
30
44
|
|
|
31
45
|
/* Begin PBXFrameworksBuildPhase section */
|
|
@@ -52,6 +66,14 @@
|
|
|
52
66
|
children = (
|
|
53
67
|
2744B9A121F48736004F8E3F /* converters */,
|
|
54
68
|
2744B98C21F45C64004F8E3F /* common */,
|
|
69
|
+
RNFBPERF0000000000000005 /* RNFBPerfHandleRegistry.h */,
|
|
70
|
+
RNFBPERF0000000000000002 /* RNFBPerfHandleRegistry.m */,
|
|
71
|
+
RNFBPERF0000000000000004 /* RNFBPerfHandleRegistryStorage.swift */,
|
|
72
|
+
RNFBPERF0000000000000007 /* RNFBPerfHttpMethodMapper.swift */,
|
|
73
|
+
RNFBPERF0000000000000009 /* RNFBPerfTraceStopApplier.swift */,
|
|
74
|
+
RNFBPERF000000000000000B /* RNFBPerfHttpMetricStopApplier.swift */,
|
|
75
|
+
RNFBPERF000000000000000E /* RNFBPerfHelper.h */,
|
|
76
|
+
RNFBPERF000000000000000D /* RNFBPerfHelper.m */,
|
|
55
77
|
2744B98421F45429004F8E3F /* RNFBPerfModule.h */,
|
|
56
78
|
2744B98521F45429004F8E3F /* RNFBPerfModule.mm */,
|
|
57
79
|
);
|
|
@@ -124,6 +146,12 @@
|
|
|
124
146
|
isa = PBXSourcesBuildPhase;
|
|
125
147
|
buildActionMask = 2147483647;
|
|
126
148
|
files = (
|
|
149
|
+
RNFBPERF0000000000000003 /* RNFBPerfHandleRegistryStorage.swift in Sources */,
|
|
150
|
+
RNFBPERF0000000000000006 /* RNFBPerfHttpMethodMapper.swift in Sources */,
|
|
151
|
+
RNFBPERF0000000000000008 /* RNFBPerfTraceStopApplier.swift in Sources */,
|
|
152
|
+
RNFBPERF000000000000000A /* RNFBPerfHttpMetricStopApplier.swift in Sources */,
|
|
153
|
+
RNFBPERF0000000000000001 /* RNFBPerfHandleRegistry.m in Sources */,
|
|
154
|
+
RNFBPERF000000000000000C /* RNFBPerfHelper.m in Sources */,
|
|
127
155
|
2744B98621F45429004F8E3F /* RNFBPerfModule.mm in Sources */,
|
|
128
156
|
);
|
|
129
157
|
runOnlyForDeploymentPostprocessing = 0;
|
|
@@ -150,6 +178,7 @@
|
|
|
150
178
|
CODE_SIGN_STYLE = Automatic;
|
|
151
179
|
COPY_PHASE_STRIP = NO;
|
|
152
180
|
DEBUG_INFORMATION_FORMAT = dwarf;
|
|
181
|
+
DEFINES_MODULE = YES;
|
|
153
182
|
GCC_C_LANGUAGE_STANDARD = gnu11;
|
|
154
183
|
GCC_DYNAMIC_NO_PIC = NO;
|
|
155
184
|
GCC_OPTIMIZATION_LEVEL = 0;
|
|
@@ -166,6 +195,7 @@
|
|
|
166
195
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
167
196
|
SDKROOT = iphoneos;
|
|
168
197
|
SKIP_INSTALL = YES;
|
|
198
|
+
SWIFT_VERSION = 5.10;
|
|
169
199
|
TARGETED_DEVICE_FAMILY = "1,2";
|
|
170
200
|
};
|
|
171
201
|
name = Debug;
|
|
@@ -189,6 +219,7 @@
|
|
|
189
219
|
CODE_SIGN_STYLE = Automatic;
|
|
190
220
|
COPY_PHASE_STRIP = NO;
|
|
191
221
|
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
|
|
222
|
+
DEFINES_MODULE = YES;
|
|
192
223
|
ENABLE_NS_ASSERTIONS = NO;
|
|
193
224
|
GCC_C_LANGUAGE_STANDARD = gnu11;
|
|
194
225
|
GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR;
|
|
@@ -200,6 +231,7 @@
|
|
|
200
231
|
PRODUCT_NAME = "$(TARGET_NAME)";
|
|
201
232
|
SDKROOT = iphoneos;
|
|
202
233
|
SKIP_INSTALL = YES;
|
|
234
|
+
SWIFT_VERSION = 5.10;
|
|
203
235
|
TARGETED_DEVICE_FAMILY = "1,2";
|
|
204
236
|
VALIDATE_PRODUCT = YES;
|
|
205
237
|
};
|