@@ -13,9 +13,9 @@ use crate::private::try_get_api;
1313/// identifier of the code, usually be the name of the method. None of the substrings should
1414/// contain `::`.
1515///
16- /// To create a `Signature` in the correct form, see `Signature::new` or `profile_sig!`. To
17- /// create a `Signature` from an existing `CStr` or `CString`, see `Signature::from_raw` and
18- /// `Signature::from_raw_owned` .
16+ /// To create a `Signature` in the correct form, see [ `Signature::new()`] or [ `profile_sig!`] . To
17+ /// create a `Signature` from an existing `CStr` or `CString`, see [ `Signature::from_raw()`] and
18+ /// [ `Signature::from_raw_owned()`] .
1919#[ derive( Clone , Eq , PartialEq , Hash , Debug ) ]
2020pub struct Signature < ' a > {
2121 sig : Cow < ' a , CStr > ,
@@ -54,7 +54,7 @@ impl<'a> Signature<'a> {
5454 Self :: from_raw ( sig)
5555 }
5656
57- /// Create a borrowed version of `self` for repeated use with `add_data` or `profile` .
57+ /// Create a borrowed version of `self` for repeated use with [ `add_data()`][Self::add_data()] or [ `profile()`][Self::add_data()] .
5858 #[ inline( always) ]
5959 pub fn borrow ( & self ) -> Signature < ' _ > {
6060 Signature {
@@ -64,7 +64,7 @@ impl<'a> Signature<'a> {
6464
6565 /// Add a data point to Godot's built-in profiler using this signature.
6666 ///
67- /// See the free function `gdnative::nativescript::profiling:: add_data` .
67+ /// See the free function [`profiler:: add_data()`][add_data()] .
6868 #[ inline]
6969 pub fn add_data ( & self , time : Duration ) {
7070 add_data ( self . borrow ( ) , time)
@@ -73,7 +73,7 @@ impl<'a> Signature<'a> {
7373 /// Times a closure and adds the measured time to Godot's built-in profiler with this
7474 /// signature, and then returns it's return value.
7575 ///
76- /// See the free function `gdnative::nativescript::profiling:: profile` .
76+ /// See the free function [`profiler:: profile()`][profile()] .
7777 #[ inline]
7878 pub fn profile < F , R > ( & self , f : F ) -> R
7979 where
@@ -155,3 +155,30 @@ where
155155 add_data ( signature, Instant :: now ( ) - start) ;
156156 ret
157157}
158+
159+ /// Convenience macro to create a profiling signature with a given tag.
160+ ///
161+ /// The expanded code will panic at runtime if the file name or `tag` contains `::` or
162+ /// any NUL-bytes.
163+ ///
164+ /// See [`Signature`] for more information.
165+ ///
166+ /// # Examples
167+ ///
168+ /// ```rust
169+ /// # fn main() {
170+ /// use gdnative::nativescript::profiler::{profile, profile_sig};
171+ ///
172+ /// let answer = profile(profile_sig!("foo"), || 42);
173+ /// assert_eq!(answer, 42);
174+ /// # }
175+ /// ```
176+ #[ macro_export]
177+ macro_rules! _profile_sig {
178+ ( $tag: expr) => {
179+ $crate:: nativescript:: profiler:: Signature :: new( file!( ) , line!( ) , $tag)
180+ } ;
181+ }
182+
183+ // Export macro in this module
184+ pub use _profile_sig as profile_sig;
0 commit comments