|
15 | 15 | use ruma::time::Instant;
|
16 | 16 | use tracing::{callsite::DefaultCallsite, Callsite as _};
|
17 | 17 |
|
18 |
| -/// A named RAII that will show on Drop how long its covered section took to |
| 18 | +/// A named RAII that will show on `Drop` how long its covered section took to |
19 | 19 | /// execute.
|
20 | 20 | pub struct TracingTimer {
|
21 | 21 | id: String,
|
@@ -72,11 +72,29 @@ impl TracingTimer {
|
72 | 72 | }
|
73 | 73 | }
|
74 | 74 |
|
75 |
| -/// Macro to create a RAII timer that will log a `tracing` event once it's |
76 |
| -/// dropped. |
| 75 | +/// Macro to create a RAII timer that will log on `Drop` how long its covered |
| 76 | +/// section took to execute. |
77 | 77 | ///
|
78 | 78 | /// The tracing level can be specified as a first argument, but it's optional.
|
79 | 79 | /// If it's missing, this will use the debug level.
|
| 80 | +/// |
| 81 | +/// ```rust,no_run |
| 82 | +/// # fn do_long_computation(_x: u32) {} |
| 83 | +/// # fn main() { |
| 84 | +/// use matrix_sdk_common::timer; |
| 85 | +/// |
| 86 | +/// // It's possible to specify the tracing level we want to be used for the log message on drop. |
| 87 | +/// { |
| 88 | +/// let _timer = timer!(tracing::Level::TRACE, "do long computation"); |
| 89 | +/// // But it's optional; by default it's set to `DEBUG`. |
| 90 | +/// let _debug_timer = timer!("do long computation but time it in DEBUG"); |
| 91 | +/// // The macro doesn't support formatting / structured events (yet?), but you can use |
| 92 | +/// // `format!()` for that. |
| 93 | +/// let other_timer = timer!(format!("do long computation for parameter = {}", 123)); |
| 94 | +/// do_long_computation(123); |
| 95 | +/// } // The log statements will happen here. |
| 96 | +/// # } |
| 97 | +/// ``` |
80 | 98 | #[macro_export]
|
81 | 99 | macro_rules! timer {
|
82 | 100 | ($level:expr, $string:expr) => {{
|
|
0 commit comments