os_trace doesn't ever show output

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;
}

You should read my posts in this thread in the old DevForums, where I gave multiple sets of precise steps for testing

os_trace
.

Alas, I don’t have time to repeat those tests today, so stuff might have changed, but it will at least give you a baseline.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Quinn,


The steps in your original post work for me on 10.10.5, so nothing seems to have changed in the OS. But perhaps the difference in your app and mine is that I'm trying this from a command line tool, not an AppKit double-clickable application. I used the Xcode template "Command line tool" under OS X -> Application, and in my main() I all dispatch_async with a 5 second delay to setup an os_activity, and then call dispatch_main (see full source above). I ran it from one Terminal window, and in another Terminal window I tried using ostraceutil to view the messages.


Is there something special that AppKit NSApplicationMain() does that sets up the tracing? I would think dispatch_main would do the same. I tried switching to CFRunLoopRun() and still got nothing in my ostraceutil and Crash Reporter logs. The real use for this in my could eventually is a system daemon running from launchd, so it's no use to us if it only works in AppKit code.


Thanks for the help.

Is there something special that AppKit NSApplicationMain() does that sets up the tracing?

Not that I’m aware of, but certainly Crash Reporter understands the difference between apps and tools and might behave differently in each case.

I would think dispatch_main would do the same.

dispatch_main
is nothing like
NSApplicationMain
. Specifically, it actually terminates the main thread, leaving your process in a state where it has no main thread! It does, however, have a main queue, which acts more like a standard dispatch queue rather than the way the main queue works in a run loop based process.

I tried switching to CFRunLoopRun() …

OTOH,

CFRunLoopRun
is much closer to
NSApplicationMain
.

If you get totally stuck I recommend you open a DTS tech support incident and we can dig into this in more detail.

Share and Enjoy

Quinn "The Eskimo!"
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
os_trace doesn't ever show output
 
 
Q