Skip to content

Add C++17 header-only wrapper for ITT API#226

Merged
eparshut merged 34 commits intointel:masterfrom
eparshut:cpp_wrapper
Apr 24, 2026
Merged

Add C++17 header-only wrapper for ITT API#226
eparshut merged 34 commits intointel:masterfrom
eparshut:cpp_wrapper

Conversation

@eparshut
Copy link
Copy Markdown
Contributor

Added a modern C++17 header-only wrapper over the ITT C API with RAII scope guards for tasks, regions, frames, and collection control.

What was added:

  • ScopedTask, ScopedRegion, ScopedFrame, ScopedPause — RAII classes that call the matching end/resume on destruction
  • Domain, StringHandle — lightweight value types wrapping __itt_domain* and __itt_string_handle*
  • task_begin()/task_end() manual API, __itt_id support for parent/child relationships
  • set_thread_name(), pause()/resume() free functions
  • CMake ittapi::cxx INTERFACE target (opt-in via -DITT_API_CPP_SUPPORT=ON)
  • buildall.py -cpp flag,
  • CI coverage on Linux and Windows
  • 8 tests

@eparshut eparshut requested a review from a team April 17, 2026 17:13
Copy link
Copy Markdown
Contributor

@alexey-kireev alexey-kireev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great!

Comment thread cpp/include/ittapi_task.hpp Outdated
: m_domain(domain)
, m_active(true)
{
__itt_string_handle* h = detail::create_string_handle(std::string(name).c_str());
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not create mutex contention problem when ScopedTasks are used from multiple threads and creating handles? Maybe consider thread local cache for handles?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, done!
It's great that you're helping us :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NP, I am still subscribed to the repo and my inbox is being bombarded by GitHub on every update. Since this is a header-only code the issues that may be in it will be very difficult to fix without full rebuild of customer code so it is better to exercise extra caution when making changes.
Also to explore as a further improvement idea, it may be good to have a constexpr hashing implementation for strings somewhere inbetween the cache and StringHandle so that lookups could be more effective. The strings fed to StringHandle are assumed to be constexpr anyway and can be hashed at compile-time as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. That's why I tried to make this wrapper code as simple as possible to have less potential problems as possible

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would this not create mutex contention problem when ScopedTasks are used from multiple threads and creating handles? Maybe consider thread local cache for handles?

Wow! Look who's here! :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am now worried if storing just a string_view is alright due to lifetime expectation of the original string. What if the original string passed by the user is somehow a temporary object and is destroyed upon returning from the initial call?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see a problem here since the implemented cache keys always point to the ittapi string copy: cache.emplace(h->strA, h);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see now. Nicely done! I only hope they won't invalidate on static to dynamic lib transition

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original (static) __itt_string_handles remain valid for the whole lifetime of the profiled process and are not freed on the transition phase

@eparshut eparshut merged commit 15fdfc1 into intel:master Apr 24, 2026
20 checks passed
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.

4 participants