Reputation: 703
I watched Getting started with Instruments and there they show the usage of Signposts. The example is written in Swift but I'd like to use them with my Objective-C project.
In these example the signpost start and end are set inside the function which means they will be triggered accordingly. My project is a plugin and its structured differently where I only have a "main" function that gets called once and then I use a series of methods from a custom class to load and parse different kind of data. As it is all sequential ... can I have only one os_log_t
and os_signpost_id_t
and reutilize it over and over again with os_signpost_interval_begin
+ os_signpost_interval_end
? Or is this not safe as the method could return after the end
was triggered? Or could they have conflicts if they get called meny times so quickly?
Thanks.
#include <os/log.h>
#include <os/signpost.h>
// Initialize
os_log_t log = os_log_create("com.example.plugin", OS_LOG_CATEGORY_POINTS_OF_INTEREST);
os_signpost_id_t spid = os_signpost_id_generate(log);
// Measurement 1
os_signpost_interval_begin(log, spid, "testMethodA started");
[MyClass testMethodA:arg1 withOptions:arg2];
os_signpost_interval_end(log, spid, "testMethodA finished");
// Measurement 2
os_signpost_interval_begin(log, spid, "testMethodB started");
[MyClass testMethodB:arg1 withOptions:arg2];
os_signpost_interval_end(log, spid, "testMethodB finished");
[...]
Upvotes: 7
Views: 1606
Reputation: 703
Ok I found the problem. I was using a different name
for the os_signpost_interval_begin
and os_signpost_interval_end
and therefore it was not being ended and just started.
The code should look like this:
// Measurement 1
os_signpost_interval_begin(log, spid, "testMethodA");
[MyClass testMethodA:arg1 withOptions:arg2];
os_signpost_interval_end(log, spid, "testMethodA");
Upvotes: 9