Skip to content

Commit

Permalink
Closes #15 by adding new public API methods; added support for select…
Browse files Browse the repository at this point in the history
…or with a SEL return value
  • Loading branch information
vittoriom committed Nov 8, 2013
1 parent 673bb40 commit 2a3ab1b
Show file tree
Hide file tree
Showing 3 changed files with 209 additions and 48 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,24 @@ You can trace the execution of a particular selector (this will log start - end

<code>[instrumenter traceSelector:@selector(doBar) forClass:[self class]];</code>

You can also trace the execution of a particular selector only if it's called on a specific instance by calling

<code>[instrumenter traceSelector:@selector(doBar) forObject:fooInstance];</code>

And you can instrument execution of a method by passing blocks of code to be executed before and after the execution of a particular selector by calling

<code>[instrumenter instrumentSelector:@selector(doBar) forClass:[self class] withBeforeBlock:^{
NSLog(@"Here I am!");
} afterBlock:nil];
</code>

As for tracing, you can instrument a selector called only on a specific instance with

<code>[instrumenter instrumentSelector:@selector(doBar) forObject:fooInstance withBeforeBlock:^{
NSLog(@"Here I am!");
} afterBlock:nil];
</code>

License:
--------------
This product is released under the BSD license.
Expand Down
39 changes: 39 additions & 0 deletions VMInstrumenter/VMDInstrumenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,20 @@ extern const NSString * VMDInstrumenterDefaultMethodExceptionReason;
*/
- (void) instrumentSelector:(SEL)selectorToInstrument forClass:(Class)classToInspect withBeforeBlock:(void(^)())beforeBlock afterBlock:(void(^)())afterBlock;

/**
This method instruments calls to a specified selector on a specified object
with beforeBlock and afterBlock parameters. Specifically, every time the selector is called on the instance,
beforeBlock is executed before the selector is, and afterBlock is executed after the selector is.
@param selectorToInstrument the selector that you'd like to instrument
@param objectInstance the instance that gets the selector called on
@param beforeBlock the block of code to execute before the call to the selector
@param afterBlock the block of code to execute after the call to the selector
@throws NSInternalInconsistencyException Just in case the selector cannot be found in the class of the specified object
*/
- (void) instrumentSelector:(SEL)selectorToInstrument forObject:(id)objectInstance withBeforeBlock:(void(^)())beforeBlock afterBlock:(void(^)())afterBlock;

/**
This method instruments calls to a specified selector of a specified class and just logs execution
Expand All @@ -80,6 +94,18 @@ extern const NSString * VMDInstrumenterDefaultMethodExceptionReason;
*/
- (void) traceSelector:(SEL)selectorToTrace forClass:(Class)classToInspect;

/**
This method instruments calls to a specified selector on a specified object
You can use more specific methods if you want particular tracing to be done
@param selectorToTrace the selector that you'd like to trace
@param objectInstance the instance that gets the selector called on
@throws NSInternalInconsistencyException Just in case the selector cannot be found in the class of the specified object
*/
- (void) traceSelector:(SEL)selectorToTrace forObject:(id)objectInstance;

/**
This method instruments calls to a specified selector of a specified class and just logs execution as the previous method
Moreover, if dumpStack is YES, it prints the stack trace after every execution
Expand All @@ -93,4 +119,17 @@ extern const NSString * VMDInstrumenterDefaultMethodExceptionReason;
*/
- (void) traceSelector:(SEL)selectorToTrace forClass:(Class)classToInspect dumpingStackTrace:(BOOL)dumpStack dumpingObject:(BOOL)dumpObject;

/**
This method instruments calls to a specified selector of a specified object and just logs execution as the previous method
Moreover, if dumpStack is YES, it prints the stack trace after every execution
@param selectorToTrace the selector that you'd like to trace
@param objectInstance the instance that gets the selector called on
@param dumpStack if you want to dump the stacktrace
@param dumpObject if you want to dump the internal of the object
@throws NSInternalInconsistencyException Just in case the selector cannot be found in the class of the specified object
*/
- (void) traceSelector:(SEL)selectorToTrace forObject:(id)objectInstance dumpingStackTrace:(BOOL)dumpStack dumpingObject:(BOOL)dumpObject;

@end
Loading

0 comments on commit 2a3ab1b

Please sign in to comment.