Skip to main content
Version: 1.0.0

Track Function Calls in iOS

Function tracking allows you to monitor code-level individual functions during runtime for potential errors, delays, and unexpected return values. By using the Ax.start() and Ax.end() APIs within your function definitions, Appxiom can monitor and report runtime issues with detailed data points to the dashboard.

  • Track function execution time, nil/false/invalid return values, and exceptions.
  • Customize monitoring with Observe fields (e.g., expectedExecutionTime, severity, expectNull).
  • Use in both Objective-C and Swift projects.

Regular Function Call Example

[self getUserNameFromDb:@"123-sd-12"];

-(NSString *) getUserNameFromDb:(NSString *) userId {
NSString *userName = [[User findById:userId] name];
return userName;
}

Using Ax.start() and Ax.end() APIs

Once Ax.start() and Ax.end() APIs are added to a function definition, errors like nil return value, wrong return values, and function execution delays will be captured and reported to the dashboard.

#import <AppxiomCore/Observer.h>
#import <AppxiomCore/Ax.h>

[self getUserNameFromDb:@"123-sd-12"];

-(NSString *) getUserNameFromDb:(NSString *) userId {
Observer *observer = [Ax observeWithCurrentFunctionSignature:@selector(getUserNameFromDb:) inClass:[self class]];
[Ax start:observer withParams:[NSArray arrayWithObjects:userId]]; //Ax.start

NSString *userName = [[User findById:userId] name];

[Ax end:observer withReturnValue:userName]; //Ax.end
return userName;
}

Things to Note

  1. In case of swift functions, the function must be marked with @objc to ensure compatibility with Objective-C runtime.
  2. Always call both Ax.start() and Ax.end() at the start and end of your function definition.
  3. The first parameter of Ax.start() and Ax.end() should be the same Observer object. See the Observe fields section for details.
  4. By default, the framework monitors for nil return value, false return value (for Boolean), and if the function takes more than 1000 ms to execute.
  5. Exceptions thrown during function invocation are automatically reported.
  6. Function parameters passed to Ax.start() will be tagged with issues reported in the Appxiom dashboard.
  7. If there is no return value, just call Ax.end() with an the observer object at the end of the function definition.

Observe Fields

You can use expectedExecutionTime, severity, expectNull, and other fields in the Observer parameter of the start API to control issue reports from a function. This allows customization in how issues are reported during tracked function execution.

Expected Execution Time

Type: 5 | Default Severity: Major (see severity)

By default, if a tracked function takes more than 1000 ms to execute, an issue report will be sent to the dashboard. Set a custom expected execution time using the expectedExecutionTime field in the Observer object.

#import <AppxiomCore/Observer.h>
#import <AppxiomCore/Ax.h>

Observer *observer = [Ax observeWithCurrentFunctionSignature:@selector(`functionSelector`) inClass:[self class]];
[observer expectedExecutionTime:3000]; // Pass observer to Ax.start API

Once this field is set, if the function execution takes more than the set amount of time, an issue report will be sent to the dashboard.

Expect Nil

Type: 2 | Default Severity: Major (see severity)

By default, if a tracked function returns nil, an issue report will be sent to the dashboard. Set the field expectNull to true to prevent the framework from reporting NULL issues.

Expected Boolean Value

Type: 4 | Default Severity: Major (see severity)

By default, if a tracked function with return type Boolean returns false, an issue report will be sent to the dashboard. If you want an issue to be raised when the return value is true, set the field expectedBooleanValue to false.

Set Range Check of Return Value

Type: 3 | Default Severity: Major (see severity)

If the tracked function returns a number (e.g., Integer, Double, Float), use min, max, minDecimal, maxDecimal fields to set expected upper and lower limits. If the function returns a value outside these limits, an issue report will be raised.

Severity

By default, issues raised from a tracked function will have the default severity level: MAJOR. Use the severity field to change the value. Available severity levels are MINOR, MAJOR, FATAL.

Frequently Asked Questions (FAQ)

Q: What is function tracking in Appxiom?
A: Function tracking allows you to monitor, capture, and report errors, delays, and unexpected return values from code-level functions in your iOS app.

Q: What types of issues can be detected?
A: Appxiom can detect nil/false/invalid return values, execution delays, exceptions, and out-of-range results.

Q: How do I enable function tracking?
A: Add Ax.start() at the beginning and Ax.end() at the end of your function definition along with an Observer object as parameter.

Q: Can I customize what is tracked?
A: Yes, use Observe fields like expectedExecutionTime, expectNull, expectedBooleanValue, min, max, and severity to control reporting.

Q: Does function tracking impact app performance?
A: The overhead is minimal. Appxiom is designed to be lightweight and should not affect app performance.

Q: Should I track every function in my app?
A: Focus on tracking critical business logic, data access, and user-facing features for the most value.