SFInstrumentation Class Reference

Inherits from NSObject
Declared in SFInstrumentation.h

Overview

This class exposes API that allow to intercept method call and introspect the object being intercepted. It can be used to record timing & usage information for example.

  enabled

Enable or disable this instrumentation instance

@property (nonatomic) BOOL enabled

Declared In

SFInstrumentation.h

+ instrumentationForClass:

Returns an instrumentation instance for the specified class

+ (instancetype)instrumentationForClass:(Class)clazz

Parameters

clazz

The class to be instrumented

Declared In

SFInstrumentation.h

+ instrumentationForClassWithName:

Returns an instrumentation instance for the class with the specified name.

+ (instancetype)instrumentationForClassWithName:(NSString *)className

Parameters

className

The name of the class to be instrumented.

Declared In

SFInstrumentation.h

– interceptorForSelector:isInstanceSelector:

Returns the interceptor configured for the class with the given selector, or nil if an interceptor is not configured for the given selector.

- (nullable SFMethodInterceptor *)interceptorForSelector:(SEL)selector isInstanceSelector:(BOOL)isInstanceSelector

Parameters

selector

The selector to check

isInstanceSelector

Whether or not the selector is an instance selector.

Return Value

The configured SFMethodInterceptor instance, or nil if an interceptor is not configured.

Declared In

SFInstrumentation.h

– interceptInstanceMethod:beforeBlock:afterBlock:

Use this method to intercept the instance method specified by selector

- (void)interceptInstanceMethod:(SEL)selector beforeBlock:(nullable SFMethodInterceptorInvocationCallback)before afterBlock:(nullable SFMethodInterceptorInvocationAfterCallback)after

Parameters

selector

The selector to intercept

before

An optional block invoked before the selector is executed

after

An optional block invoked after the selector is executed

Declared In

SFInstrumentation.h

– interceptInstanceMethod:replaceWithInvocationBlock:

Use this method to intercept the instance method specified by selector and provide a block that will be invoked instead of the method. Note: the block contains a single argument which is the NSInvocation of the message.

- (void)interceptInstanceMethod:(SEL)selector replaceWithInvocationBlock:(nullable SFMethodInterceptorInvocationCallback)replace

Parameters

selector

The instance method to be intercepted

replace

The block to be invoked

Declared In

SFInstrumentation.h

– interceptClassMethod:beforeBlock:afterBlock:

Use this method to intercept the class method specified by selector

- (void)interceptClassMethod:(SEL)selector beforeBlock:(nullable SFMethodInterceptorInvocationCallback)before afterBlock:(nullable SFMethodInterceptorInvocationAfterCallback)after

Parameters

selector

The selector to intercept

before

An optional block invoked before the selector is executed

after

An optional block invoked after the selector is executed

Declared In

SFInstrumentation.h

– interceptClassMethod:replaceWithInvocationBlock:

Use this method to intercept the class method specified by selector and provide a block that will be invoked instead of the method. Note: the block contains a single argument which is the NSInvocation of the message.

- (void)interceptClassMethod:(SEL)selector replaceWithInvocationBlock:(SFMethodInterceptorInvocationCallback)replace

Parameters

selector

The instance method to be intercepted

replace

The block to be invoked

Declared In

SFInstrumentation.h

– instrumentForTiming:afterBlock:

Instrument some selectors of a the target class for performance timing.

- (void)instrumentForTiming:(SFInstrumentationSelectorFilter)selectorFilter afterBlock:(SFMethodInterceptorInvocationAfterCallback)after

Parameters

selectorFilter

A block invoked when to select selectors from the class to instrument

after

An optional block invoked after any selector is executed

Discussion

This method will only instrument selectors defined on or explicitly overridden in the class. To instrument inherited selectors, use the instrumentForTiming:inheritanceLevels:afterBlock: overload. Calling this method is the same as calling instrumentForTiming:inheritanceLevels:afterBlock: with an inheritance levels value of zero.

Declared In

SFInstrumentation.h

– instrumentForTiming:inheritanceLevels:afterBlock:

Instrument some selectors of the target class and its parent class(es) for performance timing.

- (void)instrumentForTiming:(SFInstrumentationSelectorFilter)selectorFilter inheritanceLevels:(NSUInteger)numInheritanceLevels afterBlock:(SFMethodInterceptorInvocationAfterCallback)after

Parameters

selectorFilter

A block invoked when to select selectors from the class to instrument

numInheritanceLevels

The number of inherited classes whose selectors will be made available.

after

An optional block invoked after any selector is executed

Declared In

SFInstrumentation.h

– loadInstructions:completion:

Loads the array of instructions execute them. The instructions usually comes from a JSON file.

- (void)loadInstructions:(NSArray *)instructions completion:(dispatch_block_t)completion

Parameters

instructions

The array of instructions

completion

Optional completion block

Declared In

SFInstrumentation.h

– startMeasure

Start the timing measurement

- (void)startMeasure

Declared In

SFInstrumentation.h

– stopMeasure

Stop the timing measurement

- (void)stopMeasure

Declared In

SFInstrumentation.h