ittapi/
domain.rs

1use crate::util::access_sys_fn;
2use std::ffi::CString;
3
4/// A domain enables tagging trace data for different modules or libraries in a program. See the
5/// [Domain API] documentation for more information.
6///
7/// [Domain API]:
8///     https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top/api-support/instrumentation-and-tracing-technology-apis/instrumentation-tracing-technology-api-reference/domain-api.html
9pub struct Domain(*mut ittapi_sys::__itt_domain);
10impl Domain {
11    /// Create a new domain. Note that, if the `ittnotify` library is not initialized, this call
12    /// will succeed but the domain will be invalid; see discussion TODO.
13    ///
14    /// ```
15    /// # use ittapi::Domain;
16    /// let domain = Domain::new("test-domain");
17    /// ```
18    #[must_use]
19    pub fn new(name: &str) -> Self {
20        #[cfg(unix)]
21        let create_fn = access_sys_fn!(__itt_domain_create_ptr__3_0);
22        #[cfg(windows)]
23        let create_fn = access_sys_fn!(__itt_domain_createA_ptr__3_0);
24        let c_string =
25            CString::new(name).expect("unable to create a CString; does it contain a 0 byte?");
26        let domain = unsafe { create_fn(c_string.as_ptr()) };
27        Self(domain)
28    }
29
30    /// Use the `__itt_domain` pointer internally.
31    pub(crate) fn as_ptr(&self) -> *const ittapi_sys::__itt_domain {
32        self.0 as *const _
33    }
34}
35
36/// As discussed in the [ITT documentation], the `__itt_domain` structure is accessible by any
37/// thread in the process.
38///
39/// [ITT documentation]:
40///     https://www.intel.com/content/www/us/en/develop/documentation/vtune-help/top/api-support/instrumentation-and-tracing-technology-apis/instrumentation-tracing-technology-api-reference/domain-api.html
41unsafe impl Sync for Domain {}