bugsnag / bugsnag-cocoa-performance

Monitor the start-up, screen loading and network requests of your iOS app and see the results in your BugSnag dashboard.
https://docs.bugsnag.com/performance/integration-guides/ios
MIT License
11 stars 8 forks source link

[PLAT-12123] Add cross-talk API #263

Closed kstenerud closed 1 month ago

kstenerud commented 2 months ago

Goal

Add a cross-talk API. This API can be connected to by another native library (and is being added to bugsnag-cocoa here: https://github.com/bugsnag/bugsnag-cocoa/pull/1649 )

Design

The cross-talk API is a well-known, uniquely named class (BugsnagPerformanceCrossTalkAPI) that can be loaded by name from native code in another library using NSClassFromString().

The calling code can then request that a named API be mapped to a particular selector using mapAPINamed:toSelector:. All methods are mapped onto BugsnagPerformanceCrossTalkAPI itself.

The mapping request includes a string representing the method the caller wants, and the selector they are expecting to use.

[cls mapAPINamed:@"getCurrentTraceAndSpanIdV1" toSelector:@selector(getCurrentTraceAndSpanId)];

If we're not willing to map that method, we map instead to a "null implementation" that does nothing and returns nil. This allows us to version any exposed API, and also deprecate them later without breaking any clients.

BugsnagPerformanceCrossTalkAPI is implemented as a singleton to ensure that only one instance ever exists across all libraries using it (including this library when it configures the object). Exposed functions are designed to work even while unconfigured (whereby they return nil).

Testing

Added unit tests, and also tested in a test app with bugsnag-cocoa.

github-actions[bot] commented 2 months ago

BugsnagPerformance.framework binary size increased by 3,232 bytes from 456,232 to 459,464

    FILE SIZE        VM SIZE    
 --------------  -------------- 
  [ = ]       0  +521% +12.8Ki    [__LINKEDIT]
  +2.3% +2.27Ki  +2.3% +2.27Ki    __TEXT,__text
  +1.6% +1.72Ki  +1.6% +1.72Ki    String Table
  +1.5% +1.30Ki  +1.5% +1.30Ki    Symbol Table
  +9.2%    +505  +9.2%    +505    __TEXT,__cstring
  +3.5%    +416  +3.5%    +416    __DATA,__objc_const
  +5.4%    +384  +5.4%    +384    __DATA_CONST,__cfstring
   +12%    +320   +12%    +320    __TEXT,__objc_methtype
  +2.3%    +263  +2.3%    +263    __TEXT,__objc_methname
  +2.2%    +204  +2.2%    +204    __TEXT,__gcc_except_tab
  +1.6%    +139  +1.8%    +155    [10 Others]
  +1.0%     +96  +1.0%     +96    __TEXT,__objc_stubs
  +2.4%     +80  +2.4%     +80    Lazy Binding Info
  +6.7%     +80  +6.7%     +80    __DATA,__objc_data
  +1.1%     +48  +1.1%     +48    __TEXT,__unwind_info
  +1.6%     +40  +1.6%     +40    __DATA,__objc_selrefs
  +2.4%     +36  +2.4%     +36    __TEXT,__stub_helper
  +2.4%     +36  +2.4%     +36    __TEXT,__stubs
 -10.4%    -392 -10.4%    -392    [__DATA_CONST]
  -3.8%    -572  -3.9%    -588    [__DATA]
  -9.4% -3.77Ki  -9.4% -3.77Ki    [__TEXT]
  +0.7% +3.16Ki  +3.6% +16.0Ki    TOTAL

Generated by :no_entry_sign: Danger