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

Trace block macro c #32

Merged
merged 2 commits into from
Jul 18, 2019
Merged

Trace block macro c #32

merged 2 commits into from
Jul 18, 2019

Conversation

hfink-daqri
Copy link
Contributor

This PR ports the GPUVIS_TRACE_BLOCK(F) to C, with the help of some GNU extensions. I am using this in our project (which is mostly C), thought it might be useful to others. You can find details in the commit messages.

I tested this on Linux with C and C++, GCC 8 and Clang 8, also with GPUVIS_TRACE_UTILS_DISABLE=1. Looking forward to your feedback!

Heinrich added 2 commits July 16, 2019 12:17
This commit ports the GPUVIS_TRACE_BLOCK / GPUVIS_TRACE_BLOCKF macros
that already existed for C++ to C (with GNU extensions). That allows
pure C programs on Linux to have a simple way of quickly tracing the
execution duration of a specific scope.

This is how it's implemented:

First, we generalize the C++ class to a struct. In C++, we add the
constructors/destructors to the struct, which makes it functionally the
same as before, but have the ctors/dtors call into _begin/_end
C functions. That way we can share the setup/finalize code between C and
C++ (even though it's very simple).

In C, the same struct is used. For construction, a GNU statement-expression
macro is used to initialize the struct in-line. For destruction, the
`cleanup` GNU attribute is used to execute a function that finalizes the
block.
@mikesart mikesart merged commit 95520be into mikesart:master Jul 18, 2019
@mikesart
Copy link
Owner

Awesome - thanks Heinrich!

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

Successfully merging this pull request may close these issues.

2 participants