Skip to content

Commit

Permalink
chore: log formatter time taken (#200)
Browse files Browse the repository at this point in the history
Log time taken by each formatter (TRACE).
  • Loading branch information
hougesen authored Apr 24, 2024
1 parent 5ce4a90 commit 8732b1d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ pub struct FormatCommandArguments {

#[derive(clap::ValueEnum, Clone, Copy, PartialEq, Eq, Default, Debug)]
pub enum LogLevel {
#[default]
Trace,
#[default]
Debug,
Info,
Warn,
Expand Down
9 changes: 8 additions & 1 deletion src/languages/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use schemars::JsonSchema;
use crate::{
error::MdsfError,
formatters::MdsfFormatter,
terminal::{print_binary_not_in_path, print_error_formatting, print_formatter_info},
terminal::{
print_binary_not_in_path, print_error_formatting, print_formatter_info,
print_formatter_time,
},
LineInfo,
};

Expand Down Expand Up @@ -465,8 +468,12 @@ where

print_formatter_info(&formatter_name, info);

let time = std::time::Instant::now();

let r = f.format_snippet(snippet_path);

print_formatter_time(&formatter_name, info, time.elapsed());

if let Err(e) = &r {
if let MdsfError::MissingBinary(binary) = e {
print_binary_not_in_path(
Expand Down
14 changes: 13 additions & 1 deletion src/terminal/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use console::style;
use log::{debug, error, info, warn};
use log::{debug, error, info, trace, warn};

use crate::{error::MdsfError, runners::JavaScriptRuntime, LineInfo};

Expand All @@ -21,6 +21,18 @@ pub fn print_formatter_info(formatter: &str, info: &LineInfo) {
);
}

#[inline]
pub fn print_formatter_time(formatter: &str, info: &LineInfo, duration: core::time::Duration) {
trace!(
"{}:{} to :{} {} took {}ms to format using {formatter}",
info.filename.display(),
info.start,
info.end,
info.language,
duration.as_millis()
);
}

#[inline]
pub fn print_unchanged_file(path: &std::path::Path, dur: core::time::Duration) {
info!(
Expand Down

0 comments on commit 8732b1d

Please sign in to comment.