Rust: add verbosity and flamegraph as extractor options

This commit is contained in:
Arthur Baars
2025-02-12 11:49:10 +01:00
parent 64f0908d0d
commit 18cf39d063
3 changed files with 35 additions and 5 deletions

View File

@@ -54,3 +54,27 @@ options:
Comma-separated list of cfg settings to enable, or disable if prefixed with `-`.
Can be repeated.
type: array
logging:
title: Options pertaining to logging.
type: object
properties:
verbosity:
title: Extractor logging verbosity level.
description: >
Controls the level of verbosity of the extractor.
The supported levels are (in order of increasing verbosity):
- off
- errors
- warnings
- info or progress
- debug or progress+
- trace or progress++
- progress+++
type: string
pattern: "^(off|errors|warnings|(info|progress)|(debug|progress\\+)|(trace|progress\\+\\+)|progress\\+\\+\\+)$"
flamegraph:
title: "[Experimental] File path for write flame graph log"
description: >
Collect flame graph data using the `tracing-flame` crate. To render a flame graph
or chart, run the `inferno-flamegraph` command. See also: https://crates.io/crates/tracing-flame
type: string

View File

@@ -50,8 +50,8 @@ pub struct Config {
pub cargo_target: Option<String>,
pub cargo_features: Vec<String>,
pub cargo_cfg_overrides: Vec<String>,
pub flame_log: Option<PathBuf>,
pub verbosity: Option<String>,
pub logging_flamegraph: Option<PathBuf>,
pub logging_verbosity: Option<String>,
pub compression: Compression,
pub inputs: Vec<PathBuf>,
pub qltest: bool,
@@ -65,7 +65,13 @@ impl Config {
.context("expanding parameter files")?;
let cli_args = CliConfig::parse_from(args);
let mut figment = Figment::new()
.merge(Env::prefixed("CODEQL_"))
.merge(Env::raw().filter_map(|f| {
if f.eq("CODEQL_VERBOSITY") {
Some("LOGGING_VERBOSITY".into())
} else {
None
}
}))
.merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_"))
.merge(Env::prefixed("CODEQL_EXTRACTOR_RUST_OPTION_"))
.merge(Serialized::defaults(cli_args));

View File

@@ -186,7 +186,7 @@ fn main() -> anyhow::Result<()> {
qltest::prepare(&mut cfg)?;
}
let start = Instant::now();
let (flame_layer, _flush_guard) = if let Some(path) = &cfg.flame_log {
let (flame_layer, _flush_guard) = if let Some(path) = &cfg.logging_flamegraph {
tracing_flame::FlameLayer::with_file(path)
.ok()
.map(|(a, b)| (Some(a), Some(b)))
@@ -198,7 +198,7 @@ fn main() -> anyhow::Result<()> {
tracing_subscriber::registry()
.with(codeql_extractor::extractor::default_subscriber_with_level(
"single_arch",
&cfg.verbosity,
&cfg.logging_verbosity,
))
.with(flame_layer)
.init();