Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto generate names #46

Open
Scraft opened this issue Jun 24, 2015 · 1 comment
Open

Auto generate names #46

Scraft opened this issue Jun 24, 2015 · 1 comment

Comments

@Scraft
Copy link

Scraft commented Jun 24, 2015

I wanted to be able to just drop in a single macro in a bunch of functions, and have the API auto fill-in the function names for me, i.e.

void func1( ) {
    rmt_ScopedCPUSampleAutoName( );
}
void func2( ) {
    rmt_ScopedCPUSampleAutoName( );
}
int main( int argc, char ** argv ) {
    rmt_ScopedCPUSampleAutoName( );
    func1( );
    func2( );
    return 0;
}

I didn't want to have to manually pass in a name to each call. My solution:

#define rmt_BeginCPUSampleAutoName( ) \
    RMT_OPTIONAL(RMT_ENABLED, { \
        static rmtU32 rmt_sample_hash_##__LINE__ = 0;   \
        _rmt_BeginCPUSample(__FUNCTION__, &rmt_sample_hash_##__LINE__); \
    })

#define rmt_ScopedCPUSampleAutoName( ) \
    RMT_OPTIONAL(RMT_ENABLED, rmt_BeginCPUSampleAutoName( )); \
    RMT_OPTIONAL(RMT_ENABLED, rmt_EndCPUSampleOnScopeExit rmt_ScopedCPUSample##__LINE__);

This generates a call tree like:

celtoysautoname

Sorry this isn't a proper full request, but I hoped this might be something you'd consider implementing (either as is, or in a better way if you know of one).

@dwilliamson
Copy link
Collaborator

This is a very good idea.

I would love to add this right now but the public interface is very inflexible in terms of adding new permutations. I want:

  • CPU/D3D11/D3D12/CUDA/OpenCL sample types.
  • Different types of sample (e.g. cumulative).

So instead of adding a new named macro for different sample types it's added as a parameter, like:

rmt_BeginSample(CPU, Name)

Adding auto name would explode existing combinations even more. I should really solve this. In fact, once this is solved the only way I can think of adding the auto name feature is the same way you've done it. Unless you require names to be strings, which I'm not sure I want.

In terms of implementation, it's probably best to generate a unique symbol for the sample variable using the __COUNTER__ macro:

#define JOIN2(x, y) x ## y
#define JOIN(x, y) JOIN2(x, y)
#define UNIQUE(x) JOIN(x, __COUNTER__)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants