-
Notifications
You must be signed in to change notification settings - Fork 105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add some performance instrumentation to our code #1972
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,6 +117,9 @@ impl KaniSession { | |
|
||
if self.args.debug { | ||
flags.push("--log-level=debug".into()); | ||
} else if self.args.verbose { | ||
// Print the symtab command being invoked. | ||
flags.push("--log-level=info".into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was removed in #1730 is the underlying issue fixed there? |
||
} else { | ||
flags.push("--log-level=warn".into()); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ use std::io::Write; | |
use std::path::{Path, PathBuf}; | ||
use std::process::{Child, Command, ExitStatus, Stdio}; | ||
use std::sync::Mutex; | ||
use std::time::Instant; | ||
use tracing::level_filters::LevelFilter; | ||
use tracing_subscriber::{layer::SubscriberExt, EnvFilter, Registry}; | ||
use tracing_tree::HierarchicalLayer; | ||
|
||
/// Environment variable used to control this session log tracing. | ||
/// This is the same variable used to control `kani-compiler` logs. Note that you can still control | ||
/// the driver logs separately, by using the logger directives to select the kani-driver crate. | ||
|
@@ -129,9 +129,14 @@ impl KaniSession { | |
if self.args.verbose { | ||
println!("[Kani] Running: `{}`", render_command(&cmd).to_string_lossy()); | ||
} | ||
let result = cmd | ||
.status() | ||
.context(format!("Failed to invoke {}", cmd.get_program().to_string_lossy()))?; | ||
let program = cmd.get_program().to_string_lossy().to_string(); | ||
let result = self.with_timer( | ||
|| { | ||
cmd.status() | ||
.context(format!("Failed to invoke {}", cmd.get_program().to_string_lossy())) | ||
}, | ||
&program, | ||
)?; | ||
if !result.success() { | ||
bail!("{} exited with status {}", cmd.get_program().to_string_lossy(), result); | ||
} | ||
|
@@ -171,7 +176,14 @@ impl KaniSession { | |
let output_file = std::fs::File::create(&stdout)?; | ||
cmd.stdout(output_file); | ||
|
||
cmd.status().context(format!("Failed to invoke {}", cmd.get_program().to_string_lossy())) | ||
let program = cmd.get_program().to_string_lossy().to_string(); | ||
self.with_timer( | ||
|| { | ||
cmd.status() | ||
.context(format!("Failed to invoke {}", cmd.get_program().to_string_lossy())) | ||
}, | ||
&program, | ||
) | ||
} | ||
|
||
/// Run a job and pipe its output to this process. | ||
|
@@ -191,6 +203,21 @@ impl KaniSession { | |
|
||
Ok(Some(process)) | ||
} | ||
|
||
/// Execute the provided function and measure the clock time it took for its execution. | ||
/// Print the time with the given description if we are on verbose or debug mode. | ||
pub fn with_timer<T, F>(&self, func: F, description: &str) -> T | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth creating a "common" or "utils" crate at some point that includes this function (and similar ones) to avoid duplication. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I totally agree. Not sure it's worth it in this PR though |
||
where | ||
F: FnOnce() -> T, | ||
{ | ||
let start = Instant::now(); | ||
let ret = func(); | ||
if self.args.verbose || self.args.debug { | ||
let elapsed = start.elapsed(); | ||
println!("Finished {description} in {}s", elapsed.as_secs_f32()) | ||
} | ||
ret | ||
} | ||
} | ||
|
||
/// Return the path for the folder where the current executable is located. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add documentation