Can I set signposts before and after a call in objective-c?
Asked Answered
C

1

7

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.

// 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");

[...]
Chelsea answered 1/7, 2020 at 0:26 Comment(0)
C
9

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");
Chelsea answered 2/7, 2020 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.