-
Notifications
You must be signed in to change notification settings - Fork 46
Update file format of domain.rs and event.rs from crlf to lf #192
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,56 +1,56 @@ | ||
| use crate::util::access_sys_fn; | ||
| use std::ffi::CString; | ||
| /// A domain enables tagging trace data for different modules or libraries in a program. See the | ||
| /// [Domain API] documentation for more information. | ||
| /// | ||
| /// [Domain API]: | ||
| /// https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/current/domain-api.html | ||
| pub struct Domain(*mut ittapi_sys::__itt_domain); | ||
| impl Domain { | ||
| /// Create a new domain. Note that, if the `ittnotify` library is not initialized, this call | ||
| /// will succeed but the domain will be invalid; see discussion TODO. | ||
| /// | ||
| /// ``` | ||
| /// # use ittapi::Domain; | ||
| /// let domain = Domain::new("test-domain"); | ||
| /// ``` | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the domain name contains a `0` byte. | ||
| #[must_use] | ||
| pub fn new(name: &str) -> Self { | ||
| #[cfg(unix)] | ||
| let create_fn = access_sys_fn!(__itt_domain_create_ptr__3_0); | ||
| #[cfg(windows)] | ||
| let create_fn = access_sys_fn!(__itt_domain_createA_ptr__3_0); | ||
| let c_string = | ||
| CString::new(name).expect("unable to create a CString; does it contain a 0 byte?"); | ||
| let domain = unsafe { create_fn(c_string.as_ptr()) }; | ||
| Self(domain) | ||
| } | ||
| /// Use the `__itt_domain` pointer internally. | ||
| pub(crate) fn as_ptr(&self) -> *const ittapi_sys::__itt_domain { | ||
| self.0.cast_const() | ||
| } | ||
| } | ||
| /// As discussed in the [ITT documentation], the `__itt_domain` structure is accessible by any | ||
| /// thread in the process. | ||
| /// | ||
| /// [ITT documentation]: | ||
| /// https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/current/domain-api.html | ||
| unsafe impl Sync for Domain {} | ||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
| #[test] | ||
| #[should_panic(expected = "unable to create a CString; does it contain a 0 byte?")] | ||
| fn zero_byte() { | ||
| let _domain = Domain::new("zero\0byte\0name"); | ||
| } | ||
| } | ||
| use crate::util::access_sys_fn; | ||
| use std::ffi::CString; | ||
|
|
||
| /// A domain enables tagging trace data for different modules or libraries in a program. See the | ||
| /// [Domain API] documentation for more information. | ||
| /// | ||
| /// [Domain API]: | ||
| /// https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/current/domain-api.html | ||
| pub struct Domain(*mut ittapi_sys::__itt_domain); | ||
| impl Domain { | ||
| /// Create a new domain. Note that, if the `ittnotify` library is not initialized, this call | ||
| /// will succeed but the domain will be invalid; see discussion TODO. | ||
| /// | ||
| /// ``` | ||
| /// # use ittapi::Domain; | ||
| /// let domain = Domain::new("test-domain"); | ||
| /// ``` | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the domain name contains a `0` byte. | ||
| #[must_use] | ||
| pub fn new(name: &str) -> Self { | ||
| #[cfg(unix)] | ||
| let create_fn = access_sys_fn!(__itt_domain_create_ptr__3_0); | ||
| #[cfg(windows)] | ||
| let create_fn = access_sys_fn!(__itt_domain_createA_ptr__3_0); | ||
| let c_string = | ||
| CString::new(name).expect("unable to create a CString; does it contain a 0 byte?"); | ||
| let domain = unsafe { create_fn(c_string.as_ptr()) }; | ||
| Self(domain) | ||
| } | ||
|
|
||
| /// Use the `__itt_domain` pointer internally. | ||
| pub(crate) fn as_ptr(&self) -> *const ittapi_sys::__itt_domain { | ||
| self.0.cast_const() | ||
| } | ||
| } | ||
|
|
||
| /// As discussed in the [ITT documentation], the `__itt_domain` structure is accessible by any | ||
| /// thread in the process. | ||
| /// | ||
| /// [ITT documentation]: | ||
| /// https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/current/domain-api.html | ||
| unsafe impl Sync for Domain {} | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| #[should_panic(expected = "unable to create a CString; does it contain a 0 byte?")] | ||
| fn zero_byte() { | ||
| let _domain = Domain::new("zero\0byte\0name"); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,94 +1,94 @@ | ||
| use std::{ffi::CString, marker::PhantomData}; | ||
|
|
||
| /// See the [Event API] documentation. | ||
| /// | ||
| /// [Event API]: https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/current/event-api.html | ||
| /// | ||
| /// ``` | ||
| /// let event = ittapi::Event::new("foo"); | ||
| /// { | ||
| /// let span = event.start(); | ||
| /// // do some work... | ||
| /// // ...the event is stopped when `span` is dropped | ||
| /// } | ||
| /// ``` | ||
| pub struct Event(ittapi_sys::__itt_event); | ||
| impl Event { | ||
| /// Create the event. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the name contains a `0` byte or if its size will not fit in a 32-bit | ||
| /// representation. | ||
| #[must_use] | ||
| pub fn new(name: &str) -> Self { | ||
| #[cfg(unix)] | ||
| let create_fn = unsafe { ittapi_sys::__itt_event_create_ptr__3_0 }; | ||
| #[cfg(windows)] | ||
| let create_fn = unsafe { ittapi_sys::__itt_event_createA_ptr__3_0 }; | ||
| if let Some(create_fn) = create_fn { | ||
| let c_string = | ||
| CString::new(name).expect("unable to create a CString; does it contain a 0 byte?"); | ||
| let size = name | ||
| .len() | ||
| .try_into() | ||
| .expect("unable to fit the name length into an i32"); | ||
| let event = unsafe { create_fn(c_string.as_ptr(), size) }; | ||
| Self(event) | ||
| } else { | ||
| Self(-1) | ||
| } | ||
| } | ||
|
|
||
| /// Start the event. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// This will panic if the ITT library cannot start the event. | ||
| #[must_use] | ||
| pub fn start(&self) -> StartedEvent { | ||
| if let Some(start_fn) = unsafe { ittapi_sys::__itt_event_start_ptr__3_0 } { | ||
| let result = unsafe { start_fn(self.0) }; | ||
| assert!(result == 0, "unable to start event"); | ||
| } | ||
| StartedEvent { | ||
| event: self.0, | ||
| phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct StartedEvent<'a> { | ||
| event: ittapi_sys::__itt_event, | ||
| phantom: PhantomData<&'a mut ()>, | ||
| } | ||
|
|
||
| impl StartedEvent<'_> { | ||
| /// End the event. | ||
| #[allow(clippy::unused_self)] | ||
| pub fn end(self) { | ||
| // Do nothing; the `Drop` implementation does the work. See discussion at | ||
| // https://stackoverflow.com/questions/53254645. | ||
| } | ||
| } | ||
|
|
||
| impl Drop for StartedEvent<'_> { | ||
| fn drop(&mut self) { | ||
| if let Some(end_fn) = unsafe { ittapi_sys::__itt_event_end_ptr__3_0 } { | ||
| let result = unsafe { end_fn(self.event) }; | ||
| assert!(result == 0, "unable to stop event"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn sanity() { | ||
| let event = Event::new("test"); | ||
| let _started_event = event.start(); | ||
| // Dropping `started_event` ends the event. | ||
| } | ||
| } | ||
| use std::{ffi::CString, marker::PhantomData}; | ||
|
|
||
| /// See the [Event API] documentation. | ||
| /// | ||
| /// [Event API]: https://www.intel.com/content/www/us/en/docs/vtune-profiler/user-guide/current/event-api.html | ||
| /// | ||
| /// ``` | ||
| /// let event = ittapi::Event::new("foo"); | ||
| /// { | ||
| /// let span = event.start(); | ||
| /// // do some work... | ||
| /// // ...the event is stopped when `span` is dropped | ||
| /// } | ||
| /// ``` | ||
| pub struct Event(ittapi_sys::__itt_event); | ||
| impl Event { | ||
| /// Create the event. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// Panics if the name contains a `0` byte or if its size will not fit in a 32-bit | ||
| /// representation. | ||
| #[must_use] | ||
| pub fn new(name: &str) -> Self { | ||
| #[cfg(unix)] | ||
| let create_fn = unsafe { ittapi_sys::__itt_event_create_ptr__3_0 }; | ||
| #[cfg(windows)] | ||
| let create_fn = unsafe { ittapi_sys::__itt_event_createA_ptr__3_0 }; | ||
| if let Some(create_fn) = create_fn { | ||
| let c_string = | ||
| CString::new(name).expect("unable to create a CString; does it contain a 0 byte?"); | ||
| let size = name | ||
| .len() | ||
| .try_into() | ||
| .expect("unable to fit the name length into an i32"); | ||
| let event = unsafe { create_fn(c_string.as_ptr(), size) }; | ||
| Self(event) | ||
| } else { | ||
| Self(-1) | ||
| } | ||
| } | ||
|
|
||
| /// Start the event. | ||
| /// | ||
| /// # Panics | ||
| /// | ||
| /// This will panic if the ITT library cannot start the event. | ||
| #[must_use] | ||
| pub fn start(&self) -> StartedEvent { | ||
Check warningCode scanning / clippy hiding a lifetime that's elided elsewhere is confusing Warning
hiding a lifetime that's elided elsewhere is confusing
|
||
| if let Some(start_fn) = unsafe { ittapi_sys::__itt_event_start_ptr__3_0 } { | ||
| let result = unsafe { start_fn(self.0) }; | ||
| assert!(result == 0, "unable to start event"); | ||
| } | ||
| StartedEvent { | ||
| event: self.0, | ||
| phantom: PhantomData, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct StartedEvent<'a> { | ||
| event: ittapi_sys::__itt_event, | ||
| phantom: PhantomData<&'a mut ()>, | ||
| } | ||
|
|
||
| impl StartedEvent<'_> { | ||
| /// End the event. | ||
| #[allow(clippy::unused_self)] | ||
| pub fn end(self) { | ||
| // Do nothing; the `Drop` implementation does the work. See discussion at | ||
| // https://stackoverflow.com/questions/53254645. | ||
| } | ||
| } | ||
|
|
||
| impl Drop for StartedEvent<'_> { | ||
| fn drop(&mut self) { | ||
| if let Some(end_fn) = unsafe { ittapi_sys::__itt_event_end_ptr__3_0 } { | ||
| let result = unsafe { end_fn(self.event) }; | ||
| assert!(result == 0, "unable to stop event"); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[cfg(test)] | ||
| mod tests { | ||
| use super::*; | ||
|
|
||
| #[test] | ||
| fn sanity() { | ||
| let event = Event::new("test"); | ||
| let _started_event = event.start(); | ||
| // Dropping `started_event` ends the event. | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / clippy
hiding a lifetime that's elided elsewhere is confusing Warning