File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ vm-fdt = "0.2.0"
30
30
vm-superio = " 0.7.0"
31
31
tracing = { version = " 0.1.37" , features = [" attributes" ] }
32
32
tracing-subscriber = " 0.3.17"
33
+ tracing-flame = " 0.2.0"
33
34
log = { version = " 0.4.17" , features = [" serde" ] }
34
35
35
36
dumbo = { path = " ../dumbo" }
Original file line number Diff line number Diff line change @@ -190,9 +190,10 @@ pub struct LoggerConfig {
190
190
pub show_level : Option < bool > ,
191
191
/// When enabled, the logger will append the origin of the log entry.
192
192
pub show_log_origin : Option < bool > ,
193
+ /// The profile file to output.
194
+ pub profile_file : Option < std:: path:: PathBuf > ,
193
195
}
194
196
195
-
196
197
impl LoggerConfig {
197
198
/// Initializes the logger.
198
199
pub fn init ( & self ) {
@@ -229,7 +230,20 @@ impl LoggerConfig {
229
230
230
231
let fmt_layer = fmt_layer. with_writer ( writer. with_max_level ( level) ) ;
231
232
232
- tracing_subscriber:: registry ( ) . with ( fmt_layer) . init ( ) ;
233
+ if let Some ( profile_file) = & self . profile_file {
234
+ // We can discard the flush guard as
235
+ // > This type is only needed when using
236
+ // > `tracing::subscriber::set_global_default`, which prevents the drop
237
+ // > implementation of layers from running when the program exits.
238
+ // See https://docs.rs/tracing-flame/0.2.0/tracing_flame/struct.FlushGuard.html
239
+ let ( flame_layer, _guard) = tracing_flame:: FlameLayer :: with_file ( profile_file) . unwrap ( ) ;
240
+ tracing_subscriber:: registry ( )
241
+ . with ( fmt_layer)
242
+ . with ( flame_layer)
243
+ . init ( ) ;
244
+ } else {
245
+ tracing_subscriber:: registry ( ) . with ( fmt_layer) . init ( ) ;
246
+ }
233
247
}
234
248
}
235
249
You can’t perform that action at this time.
0 commit comments