3 个不稳定版本
0.2.2 | 2023年5月15日 |
---|---|
0.2.1 | 2023年5月15日 |
0.1.0 | 2023年5月15日 |
#276 在 分析
每月32次 下载
4KB
性能标记
performance_mark
是一个属性宏,它为函数添加性能(时间)日志记录。默认情况下,它使用 println!
,但可以配置为使用自定义方法。
基本示例
use performance_mark_attribute::performance_mark;
#[performance_mark]
fn test_function_logged_using_stdout() {
println!("Hello!");
}
输出
(performance_mark) test_function_logged_using_stdout took 7.177µs
自定义日志方法
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);
}
自定义异步日志方法
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
}
依赖
~280–730KB
~17K SLoC