#performance #attributes #mark #time #performance-mark #logging #macro

macro performance-mark-macro

performance_mark is an attribute macro that adds performance (time) logging to methods. This crate is implementation detail, you should depend on performance-mark-attribute instead.

3 unstable releases

0.2.2 May 15, 2023
0.2.1 May 15, 2023
0.2.0 May 15, 2023
0.1.0 May 15, 2023

#35 in #mark


Used in performance-mark-attribut…

MIT license

11KB
148 lines

Performance Mark

performance_mark is an attribute macro that adds performance (time) logging to functions. By default, it uses println!, but can be configured to use a custom method.

Basic example:

use performance_mark_attribute::performance_mark;

#[performance_mark]
fn test_function_logged_using_stdout() {
   println!("Hello!");
}

Output:

(performance_mark) test_function_logged_using_stdout took 7.177µs

Custom Logging Method

use performance_mark_attribute::{performance_mark, LogContext}

#[performance_mark(log_with_this)]
fn test_function_logged_using_custom_function() {
   println!("Hello!");
}

fn log_with_this(ctx: LogContext) {
    println!("Function: {} , Time: {}ms", ctx.function, ctx.duration);
}

Custom Async Logging Method

use performance_mark_attribute::{performance_mark, LogContext}

#[performance_mark(async log_with_this)]
fn test_function_logged_using_custom_function() {
   println!("Hello!");
}

async fn log_with_this(ctx: LogContext) {
    // Log asynchronously
}

lib.rs:

This crate implements the macro for performance_mark and should not be used directly.

Dependencies

~300–750KB
~18K SLoC