I'm trying to use the os_trace family of functions in my Mac OS X application. I wrote a simple test tool that uses os_trace in a simple background dispatch_async while the main thread rus dispatch_main, but I almost never see any results in either ostraceutil, lldb or crash reports. Every once in a while it works, but I cannot figure out what the randomness is.
Usually I see messages like this in syslog: 8/23/15 9:39:56.530 PM diagnosticd[22663]: error evaluating process info - pid: 23561, punique: 23561
I've made sure the build is signed, it's a release build, and I have an Info.plist embedded in the executable. codesign -vv reports the binary is signed and satisfies the designated requirement. ostraceutil -watch -process <pid> doesn't ever show anything, and ostraceutil -diagnostic -process <pid> only reports basic image information until I should start seeing trace messages--once trace messags should appear, ostraceutil -diagnostic shows nothing, not even image info.
I can't see what else I may be missing. This is all on 10.10.5. The code is below.
__attribute__((noinline)) static void DoSomething (size_t index)
{
os_activity_t activity = os_activity_start ("Parse parameters", OS_ACTIVITY_FLAG_DEFAULT);
os_trace ("Doing something %lld", index);
for (int i = 0; i < 2000; i++)
{
int something = arc4random_uniform (50);
if (something == 1)
{
printf ("trace\n");
os_trace ("trace: %d", something);
}
else if (something == 2)
{
printf ("error\n");
os_trace_error ("error %d", something);
}
else if (something == 3)
abort();
else
usleep (something);
}
os_activity_end (activity);
}
int main(int argc, const char * argv[])
{
printf("I'm prisoner %d!\n", getpid());
dispatch_after (dispatch_time (DISPATCH_TIME_NOW, 5 * NSEC_PER_SEC), dispatch_get_main_queue(),
^{
DoSomething (arc4random());
});
dispatch_main();
return 0;
}