@@ -13,9 +13,9 @@ use crate::private::try_get_api;
13
13
/// identifier of the code, usually be the name of the method. None of the substrings should
14
14
/// contain `::`.
15
15
///
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()`] .
19
19
#[ derive( Clone , Eq , PartialEq , Hash , Debug ) ]
20
20
pub struct Signature < ' a > {
21
21
sig : Cow < ' a , CStr > ,
@@ -54,7 +54,7 @@ impl<'a> Signature<'a> {
54
54
Self :: from_raw ( sig)
55
55
}
56
56
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()] .
58
58
#[ inline( always) ]
59
59
pub fn borrow ( & self ) -> Signature < ' _ > {
60
60
Signature {
@@ -64,7 +64,7 @@ impl<'a> Signature<'a> {
64
64
65
65
/// Add a data point to Godot's built-in profiler using this signature.
66
66
///
67
- /// See the free function `gdnative::nativescript::profiling:: add_data` .
67
+ /// See the free function [`profiler:: add_data()`][add_data()] .
68
68
#[ inline]
69
69
pub fn add_data ( & self , time : Duration ) {
70
70
add_data ( self . borrow ( ) , time)
@@ -73,7 +73,7 @@ impl<'a> Signature<'a> {
73
73
/// Times a closure and adds the measured time to Godot's built-in profiler with this
74
74
/// signature, and then returns it's return value.
75
75
///
76
- /// See the free function `gdnative::nativescript::profiling:: profile` .
76
+ /// See the free function [`profiler:: profile()`][profile()] .
77
77
#[ inline]
78
78
pub fn profile < F , R > ( & self , f : F ) -> R
79
79
where
@@ -155,3 +155,30 @@ where
155
155
add_data ( signature, Instant :: now ( ) - start) ;
156
156
ret
157
157
}
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