@react-native-firebase/perf 26.3.3 → 27.0.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 +22 -0
- package/RNFBPerf.podspec +6 -1
- package/android/build.gradle +5 -0
- package/android/src/main/java/io/invertase/firebase/perf/RNFBPerfHandleRegistry.kt +71 -0
- package/android/src/main/java/io/invertase/firebase/perf/UniversalFirebasePerfModule.java +65 -28
- package/android/src/test/java/io/invertase/firebase/perf/RNFBPerfHandleRegistryTest.java +205 -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.h +41 -0
- package/ios/RNFBPerf/RNFBPerfHandleRegistry.m +87 -0
- 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 +41 -174
- 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 +169 -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 +321 -0
- package/ios/RNFBPerfUnitTests/RNFBPerfUnitTests.xcodeproj/xcshareddata/xcschemes/RNFBPerfUnitTests.xcscheme +69 -0
- package/lib/version.ts +1 -1
- package/package.json +5 -4
|
@@ -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
|
+
|
|
18
|
+
#import "RNFBPerfHandleRegistry.h"
|
|
19
|
+
|
|
20
|
+
#if __has_include("RNFBHandleMap.h")
|
|
21
|
+
#import "RNFBHandleMap.h"
|
|
22
|
+
#else
|
|
23
|
+
#import "RNFBApp/RNFBHandleMap.h"
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
#if __has_include(<RNFBPerf/RNFBPerf-Swift.h>)
|
|
27
|
+
#import <RNFBPerf/RNFBPerf-Swift.h>
|
|
28
|
+
#elif __has_include("RNFBPerf-Swift.h")
|
|
29
|
+
#import "RNFBPerf-Swift.h"
|
|
30
|
+
#elif __has_include("RNFBHandleMapStorage-Swift.inc")
|
|
31
|
+
#import "RNFBHandleMapStorage-Swift.inc"
|
|
32
|
+
#else
|
|
33
|
+
#error "RNFBPerfHandleRegistryStorage Swift interface not found"
|
|
34
|
+
#endif
|
|
35
|
+
|
|
36
|
+
@interface RNFBPerfHandleRegistry ()
|
|
37
|
+
@property(nonatomic, strong) RNFBPerfHandleRegistryStorage *storage;
|
|
38
|
+
@end
|
|
39
|
+
|
|
40
|
+
@implementation RNFBPerfHandleRegistry
|
|
41
|
+
|
|
42
|
+
- (instancetype)init {
|
|
43
|
+
self = [super init];
|
|
44
|
+
if (self) {
|
|
45
|
+
_storage = [[RNFBPerfHandleRegistryStorage alloc] init];
|
|
46
|
+
}
|
|
47
|
+
return self;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
- (BOOL)put:(id)key value:(id)value error:(NSError **)error {
|
|
51
|
+
if (![self.storage putOrDiscard:key value:value]) {
|
|
52
|
+
if (error != nil) {
|
|
53
|
+
NSString *message = [NSString stringWithFormat:@"Handle id already registered: %@", key];
|
|
54
|
+
*error = [NSError errorWithDomain:RNFBHandleMapErrorDomain
|
|
55
|
+
code:RNFBHandleMapErrorCollision
|
|
56
|
+
userInfo:@{NSLocalizedDescriptionKey : message}];
|
|
57
|
+
}
|
|
58
|
+
return NO;
|
|
59
|
+
}
|
|
60
|
+
return YES;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
- (BOOL)putOrDiscard:(id)key value:(id)value {
|
|
64
|
+
return [self.storage putOrDiscard:key value:value];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
- (id)putReplacing:(id)key value:(id)value {
|
|
68
|
+
return [self.storage putReplacing:key value:value];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
- (id)get:(id)key {
|
|
72
|
+
return [self.storage get:key];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
- (id)take:(id)key {
|
|
76
|
+
return [self.storage take:key];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
- (id)takeIf:(id)key when:(BOOL (^)(id))condition {
|
|
80
|
+
return [self.storage takeIf:key when:condition];
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (NSArray *)takeAll {
|
|
84
|
+
return [self.storage takeAll];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@end
|
|
@@ -0,0 +1,58 @@
|
|
|
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
|
+
#if canImport(RNFBApp)
|
|
20
|
+
import RNFBApp
|
|
21
|
+
#endif
|
|
22
|
+
|
|
23
|
+
/// Perf registry storage. Composes `RNFBHandleMapStorage`; `putOrDiscard` is first-wins
|
|
24
|
+
/// (`putIfAbsent`). Unique `put` collision errors stay on the ObjC façade.
|
|
25
|
+
@objc(RNFBPerfHandleRegistryStorage)
|
|
26
|
+
public final class RNFBPerfHandleRegistryStorage: NSObject {
|
|
27
|
+
private let storage = RNFBHandleMapStorage()
|
|
28
|
+
|
|
29
|
+
@objc(putOrDiscard:value:)
|
|
30
|
+
public func putOrDiscard(_ key: AnyObject, value: AnyObject) -> Bool {
|
|
31
|
+
storage.putIfAbsent(key, value: value)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
@objc(putReplacing:value:)
|
|
35
|
+
public func putReplacing(_ key: AnyObject, value: AnyObject) -> AnyObject? {
|
|
36
|
+
storage.putReplacing(key, value: value)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
@objc(get:)
|
|
40
|
+
public func get(_ key: AnyObject) -> AnyObject? {
|
|
41
|
+
storage.get(key)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@objc(take:)
|
|
45
|
+
public func take(_ key: AnyObject) -> AnyObject? {
|
|
46
|
+
storage.take(key)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
@objc(takeIf:when:)
|
|
50
|
+
public func takeIf(_ key: AnyObject, when condition: (AnyObject) -> Bool) -> AnyObject? {
|
|
51
|
+
storage.takeIf(key, when: condition)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@objc
|
|
55
|
+
public func takeAll() -> [AnyObject] {
|
|
56
|
+
storage.takeAll()
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
|
|
18
|
+
#import <Foundation/Foundation.h>
|
|
19
|
+
#import <React/RCTBridgeModule.h>
|
|
20
|
+
|
|
21
|
+
#import "RNFBPerfHandleRegistry.h"
|
|
22
|
+
|
|
23
|
+
NS_ASSUME_NONNULL_BEGIN
|
|
24
|
+
|
|
25
|
+
// Plain Objective-C helper (see docs/ios-spm.mdx and
|
|
26
|
+
// okf-bundle/ios-spm-native-imports.md) that owns every call touching
|
|
27
|
+
// Firebase Performance / metric types and the Swift stop appliers /
|
|
28
|
+
// HTTP method mapper for RNFBPerfModule. This keeps RNFBPerfModule.mm free
|
|
29
|
+
// of Firebase imports and `*-Swift.h`: under SPM an Objective-C++ (.mm)
|
|
30
|
+
// TurboModule cannot `@import` Firebase (or parse a Swift-generated header
|
|
31
|
+
// that uses module imports) when C++ modules are disabled (required by
|
|
32
|
+
// React Native's JSI headers). On Mac Catalyst + SPM the upstream wrap
|
|
33
|
+
// target omits the real module — see RNFBPerfHelper.m stubs and
|
|
34
|
+
// https://github.com/firebase/firebase-ios-sdk/pull/16468.
|
|
35
|
+
@interface RNFBPerfHelper : NSObject
|
|
36
|
+
|
|
37
|
+
+ (NSDictionary *)constantsDictionary;
|
|
38
|
+
|
|
39
|
+
+ (void)setPerformanceCollectionEnabled:(BOOL)enabled
|
|
40
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
41
|
+
reject:(RCTPromiseRejectBlock)reject;
|
|
42
|
+
|
|
43
|
+
+ (void)setInstrumentationEnabled:(BOOL)enabled
|
|
44
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
45
|
+
reject:(RCTPromiseRejectBlock)reject;
|
|
46
|
+
|
|
47
|
+
+ (void)startTraceWithId:(NSNumber *)traceId
|
|
48
|
+
identifier:(NSString *)identifier
|
|
49
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry;
|
|
50
|
+
|
|
51
|
+
+ (void)stopTraceWithId:(NSNumber *)traceId
|
|
52
|
+
metrics:(nullable NSDictionary *)metrics
|
|
53
|
+
attributes:(nullable NSDictionary *)attributes
|
|
54
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry;
|
|
55
|
+
|
|
56
|
+
+ (void)startHttpMetricWithId:(NSNumber *)metricId
|
|
57
|
+
url:(NSString *)url
|
|
58
|
+
httpMethod:(NSString *)httpMethod
|
|
59
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry;
|
|
60
|
+
|
|
61
|
+
+ (void)stopHttpMetricWithId:(NSNumber *)metricId
|
|
62
|
+
attributes:(nullable NSDictionary *)attributes
|
|
63
|
+
httpResponseCode:(nullable NSNumber *)httpResponseCode
|
|
64
|
+
requestPayloadSize:(nullable NSNumber *)requestPayloadSize
|
|
65
|
+
responsePayloadSize:(nullable NSNumber *)responsePayloadSize
|
|
66
|
+
responseContentType:(nullable NSString *)responseContentType
|
|
67
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry;
|
|
68
|
+
|
|
69
|
+
@end
|
|
70
|
+
|
|
71
|
+
NS_ASSUME_NONNULL_END
|
|
@@ -0,0 +1,219 @@
|
|
|
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
|
+
|
|
18
|
+
#if __has_include(<Firebase/Firebase.h>)
|
|
19
|
+
#import <Firebase/Firebase.h>
|
|
20
|
+
#define RNFB_PERF_SDK_AVAILABLE 1
|
|
21
|
+
#elif __has_include(<FirebasePerformance/FirebasePerformance.h>)
|
|
22
|
+
#import <FirebaseCore/FirebaseCore.h>
|
|
23
|
+
#import <FirebasePerformance/FirebasePerformance.h>
|
|
24
|
+
#define RNFB_PERF_SDK_AVAILABLE 1
|
|
25
|
+
#elif !TARGET_OS_MACCATALYST
|
|
26
|
+
// SPM on iOS/tvOS when product headers are not visible as includes: use
|
|
27
|
+
// @import in this plain .m (needs -fmodules only). Do not move @import into
|
|
28
|
+
// the .mm TurboModule (that would require -fcxx-modules).
|
|
29
|
+
@import FirebaseCore;
|
|
30
|
+
@import FirebasePerformance;
|
|
31
|
+
#define RNFB_PERF_SDK_AVAILABLE 1
|
|
32
|
+
#else
|
|
33
|
+
// Product headers/modules absent under Mac Catalyst + SPM. Upstream
|
|
34
|
+
// Package.swift omits .macCatalyst from FirebasePerformanceTarget; CocoaPods
|
|
35
|
+
// historically masked this via the Firebase umbrella. Temporary stubs pending
|
|
36
|
+
// https://github.com/firebase/firebase-ios-sdk/pull/16468 (or permanent if
|
|
37
|
+
// upstream declines). When that PR lands, drop the TARGET_OS_MACCATALYST
|
|
38
|
+
// gate and use the @import path on Catalyst too.
|
|
39
|
+
#define RNFB_PERF_SDK_AVAILABLE 0
|
|
40
|
+
#endif
|
|
41
|
+
|
|
42
|
+
#if __has_include(<RNFBPerf/RNFBPerf-Swift.h>)
|
|
43
|
+
#import <RNFBPerf/RNFBPerf-Swift.h>
|
|
44
|
+
#elif __has_include("RNFBPerf-Swift.h")
|
|
45
|
+
#import "RNFBPerf-Swift.h"
|
|
46
|
+
#elif __has_include("RNFBHandleMapStorage-Swift.inc")
|
|
47
|
+
#import "RNFBHandleMapStorage-Swift.inc"
|
|
48
|
+
#else
|
|
49
|
+
#error "RNFBPerf Swift interface not found"
|
|
50
|
+
#endif
|
|
51
|
+
|
|
52
|
+
#import "RNFBApp/RNFBSharedUtils.h"
|
|
53
|
+
#import "RNFBPerfHelper.h"
|
|
54
|
+
|
|
55
|
+
@implementation RNFBPerfHelper
|
|
56
|
+
|
|
57
|
+
#if !RNFB_PERF_SDK_AVAILABLE
|
|
58
|
+
+ (void)rejectUnavailable:(RCTPromiseRejectBlock)reject {
|
|
59
|
+
[RNFBSharedUtils rejectPromiseWithUserInfo:reject
|
|
60
|
+
userInfo:(NSMutableDictionary *)@{
|
|
61
|
+
@"code" : @"unsupported",
|
|
62
|
+
@"message" : @"Firebase Performance is not available on "
|
|
63
|
+
@"this platform or dependency configuration.",
|
|
64
|
+
}];
|
|
65
|
+
}
|
|
66
|
+
#endif
|
|
67
|
+
|
|
68
|
+
+ (NSDictionary *)constantsDictionary {
|
|
69
|
+
NSMutableDictionary *constants = [NSMutableDictionary new];
|
|
70
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
71
|
+
constants[@"isPerformanceCollectionEnabled"] =
|
|
72
|
+
@([FIRPerformance sharedInstance].dataCollectionEnabled);
|
|
73
|
+
constants[@"isInstrumentationEnabled"] =
|
|
74
|
+
@([FIRPerformance sharedInstance].instrumentationEnabled);
|
|
75
|
+
#else
|
|
76
|
+
constants[@"isPerformanceCollectionEnabled"] = @(NO);
|
|
77
|
+
constants[@"isInstrumentationEnabled"] = @(NO);
|
|
78
|
+
#endif
|
|
79
|
+
return constants;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
+ (void)setPerformanceCollectionEnabled:(BOOL)enabled
|
|
83
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
84
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
85
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
86
|
+
[FIRPerformance sharedInstance].dataCollectionEnabled = enabled;
|
|
87
|
+
resolve([NSNull null]);
|
|
88
|
+
#else
|
|
89
|
+
(void)enabled;
|
|
90
|
+
(void)resolve;
|
|
91
|
+
[self rejectUnavailable:reject];
|
|
92
|
+
#endif
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
+ (void)setInstrumentationEnabled:(BOOL)enabled
|
|
96
|
+
resolve:(RCTPromiseResolveBlock)resolve
|
|
97
|
+
reject:(RCTPromiseRejectBlock)reject {
|
|
98
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
99
|
+
[FIRPerformance sharedInstance].instrumentationEnabled = enabled;
|
|
100
|
+
resolve([NSNull null]);
|
|
101
|
+
#else
|
|
102
|
+
(void)enabled;
|
|
103
|
+
(void)resolve;
|
|
104
|
+
[self rejectUnavailable:reject];
|
|
105
|
+
#endif
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
+ (void)startTraceWithId:(NSNumber *)traceId
|
|
109
|
+
identifier:(NSString *)identifier
|
|
110
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry {
|
|
111
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
112
|
+
FIRTrace *trace = [[FIRPerformance sharedInstance] traceWithName:identifier];
|
|
113
|
+
[trace start];
|
|
114
|
+
|
|
115
|
+
FIRTrace *displaced = [registry putReplacing:traceId value:trace];
|
|
116
|
+
if (displaced != nil) {
|
|
117
|
+
[displaced stop];
|
|
118
|
+
}
|
|
119
|
+
#else
|
|
120
|
+
(void)traceId;
|
|
121
|
+
(void)identifier;
|
|
122
|
+
(void)registry;
|
|
123
|
+
#endif
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
+ (void)stopTraceWithId:(NSNumber *)traceId
|
|
127
|
+
metrics:(NSDictionary *)metrics
|
|
128
|
+
attributes:(NSDictionary *)attributes
|
|
129
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry {
|
|
130
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
131
|
+
FIRTrace *trace = [registry get:traceId];
|
|
132
|
+
if (trace == nil) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
id<RNFBPerfTraceApplying> traceTarget = (id<RNFBPerfTraceApplying>)trace;
|
|
137
|
+
[RNFBPerfTraceStopApplier applyMetrics:metrics attributes:attributes to:traceTarget];
|
|
138
|
+
|
|
139
|
+
FIRTrace *expected = trace;
|
|
140
|
+
trace = [registry takeIf:traceId
|
|
141
|
+
when:^BOOL(NSObject *value) {
|
|
142
|
+
return value == expected;
|
|
143
|
+
}];
|
|
144
|
+
if (trace != nil) {
|
|
145
|
+
[trace stop];
|
|
146
|
+
}
|
|
147
|
+
#else
|
|
148
|
+
(void)traceId;
|
|
149
|
+
(void)metrics;
|
|
150
|
+
(void)attributes;
|
|
151
|
+
(void)registry;
|
|
152
|
+
#endif
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
+ (void)startHttpMetricWithId:(NSNumber *)metricId
|
|
156
|
+
url:(NSString *)url
|
|
157
|
+
httpMethod:(NSString *)httpMethod
|
|
158
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry {
|
|
159
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
160
|
+
FIRHTTPMethod method =
|
|
161
|
+
(FIRHTTPMethod)[RNFBPerfHttpMethodMapper httpMethodRawValueForString:httpMethod];
|
|
162
|
+
NSURL *toNSURL = [NSURL URLWithString:url];
|
|
163
|
+
|
|
164
|
+
FIRHTTPMetric *httpMetric = [[FIRHTTPMetric alloc] initWithURL:toNSURL HTTPMethod:method];
|
|
165
|
+
[httpMetric start];
|
|
166
|
+
|
|
167
|
+
FIRHTTPMetric *displaced = [registry putReplacing:metricId value:httpMetric];
|
|
168
|
+
if (displaced != nil) {
|
|
169
|
+
[displaced stop];
|
|
170
|
+
}
|
|
171
|
+
#else
|
|
172
|
+
(void)metricId;
|
|
173
|
+
(void)url;
|
|
174
|
+
(void)httpMethod;
|
|
175
|
+
(void)registry;
|
|
176
|
+
#endif
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
+ (void)stopHttpMetricWithId:(NSNumber *)metricId
|
|
180
|
+
attributes:(NSDictionary *)attributes
|
|
181
|
+
httpResponseCode:(NSNumber *)httpResponseCode
|
|
182
|
+
requestPayloadSize:(NSNumber *)requestPayloadSize
|
|
183
|
+
responsePayloadSize:(NSNumber *)responsePayloadSize
|
|
184
|
+
responseContentType:(NSString *)responseContentType
|
|
185
|
+
inRegistry:(RNFBPerfHandleRegistry *)registry {
|
|
186
|
+
#if RNFB_PERF_SDK_AVAILABLE
|
|
187
|
+
FIRHTTPMetric *httpMetric = [registry get:metricId];
|
|
188
|
+
if (httpMetric == nil) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
id<RNFBPerfHttpMetricApplying> httpMetricTarget = (id<RNFBPerfHttpMetricApplying>)httpMetric;
|
|
193
|
+
[RNFBPerfHttpMetricStopApplier applyAttributes:attributes
|
|
194
|
+
httpResponseCode:httpResponseCode
|
|
195
|
+
requestPayloadSize:requestPayloadSize
|
|
196
|
+
responsePayloadSize:responsePayloadSize
|
|
197
|
+
responseContentType:responseContentType
|
|
198
|
+
to:httpMetricTarget];
|
|
199
|
+
|
|
200
|
+
FIRHTTPMetric *expected = httpMetric;
|
|
201
|
+
httpMetric = [registry takeIf:metricId
|
|
202
|
+
when:^BOOL(NSObject *value) {
|
|
203
|
+
return value == expected;
|
|
204
|
+
}];
|
|
205
|
+
if (httpMetric != nil) {
|
|
206
|
+
[httpMetric stop];
|
|
207
|
+
}
|
|
208
|
+
#else
|
|
209
|
+
(void)metricId;
|
|
210
|
+
(void)attributes;
|
|
211
|
+
(void)httpResponseCode;
|
|
212
|
+
(void)requestPayloadSize;
|
|
213
|
+
(void)responsePayloadSize;
|
|
214
|
+
(void)responseContentType;
|
|
215
|
+
(void)registry;
|
|
216
|
+
#endif
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@end
|
|
@@ -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
|
+
}
|