Is there a way to use OSSignPoster in .Net on MacOS

I am interested in adding signposts to an existing large application that was written in .NET compiled in VisualStudio for MacOS so that I can isolate portions of the application in instruments. It seems like it's straightforward to do this in C++ but I couldn't figure out how to do it, perhaps there is a way via dll invoke? Appreciate any suggestions.

Replies

I am on Sonoma 14.3.1, I believe I need to do something like the below but am having difficulty determining the correct dylib and APIs I can use in managed code.

    [DllImport("/usr/lib/libSystem.dylib", EntryPoint = "os_log_create")]
    private static extern IntPtr os_log_create(string subsystem, string category);

    [DllImport("libSystem.dylib")]
    private static extern int getpid();

OSSignposter is a Swift API for os_signpost which you probably won't be able to use from another language, but it sounds like you can use the C API declared in <os/signpost.h>.

Note that the C API is partially implemented using macros (for example, os_signpost_interval_begin()). You'll probably need to look through the <os/signpost.h> header to figure out which C functions the macros call and how they do so, replicating that in your code. Or you may be able to find a library which does this for you.

I believe the dylib which implements os_signpost is libsystem_trace.dylib.