aclysma / profiling

Provides a very thin abstraction over instrumented profiling crates like puffin, optick, tracy, and superluminal-perf.
Apache License 2.0
319 stars 39 forks source link

Wrapping an extern "C" function #50

Closed ewpratten closed 7 months ago

ewpratten commented 1 year ago

I would like to be able to profile some extern "C" functions.

Currently, if I try to apply the #[profiling::function] macro to one of these functions, I get an error:

extern "C" {
    #[profiling::function]
    pub fn MyFunction(x: Data);
}
error: expected curly braces

Is there any way to do this without wrapping every external function in a Rust function first?

aclysma commented 1 year ago

The way the procmacro works is it appends a one-liner to the code in the body of the function. An extern function doesn't have a body, so we can't really inject new behavior into it. I suspect any solution for this would ultimately behind the scenes just wrap the call in a rust function.

I try to keep procmacros extremely straightforward and use them sparingly, and I think the cost/benefit ratio for this would be outside my comfort zone. (I'd keep an open mind if you wanted to give it a try though.)

ewpratten commented 1 year ago

Ah, I figured.

I'm going to try auto-wrapping the functions then.

aclysma commented 7 months ago

Since this has been idle for a while and I'm not optimistic a solution would be simple, going to close.