-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an xtask for listing all USDT probes in Omicron (#5895)
- Loading branch information
1 parent
1a1ed33
commit 42fe148
Showing
4 changed files
with
101 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
//! Xtask for printing USDT probes. | ||
use crate::load_workspace; | ||
use tabled::settings::Style; | ||
use tabled::Table; | ||
use tabled::Tabled; | ||
|
||
#[derive(Tabled)] | ||
#[tabled(rename_all = "SCREAMING_SNAKE_CASE")] | ||
struct Probe { | ||
binary: String, | ||
provider: String, | ||
probe: String, | ||
arguments: String, | ||
} | ||
|
||
pub(crate) fn print_probes(filter: Option<String>) -> anyhow::Result<()> { | ||
const SKIP_ME: &[&str] = &["bootstrap", "xtask"]; | ||
const PATHS: &[&str] = &["release", "debug"]; | ||
let workspace = load_workspace()?; | ||
|
||
// Find all local packages and any binaries they contain, and attemp to find | ||
// contained DTrace probes in the object files. | ||
let mut entries = Vec::new(); | ||
for bin_target in | ||
workspace.workspace_packages().iter().flat_map(|package| { | ||
package.targets.iter().filter(|target| { | ||
target.is_bin() | ||
&& !SKIP_ME.contains(&target.name.as_str()) | ||
&& filter | ||
.as_ref() | ||
.map(|filt| target.name.contains(filt)) | ||
.unwrap_or(true) | ||
}) | ||
}) | ||
{ | ||
let maybe_path = PATHS | ||
.iter() | ||
.filter_map(|p| { | ||
let path = | ||
workspace.target_directory.join(p).join(&bin_target.name); | ||
if path.exists() { | ||
Some(path) | ||
} else { | ||
None | ||
} | ||
}) | ||
.next(); | ||
let Some(path) = maybe_path else { | ||
continue; | ||
}; | ||
match usdt::probe_records(&path) { | ||
Ok(sections) => { | ||
let all_providers = sections | ||
.into_iter() | ||
.flat_map(|section| section.providers.into_values()); | ||
for provider in all_providers { | ||
for probe in provider.probes.into_values() { | ||
let arguments = | ||
format!("[{}]", probe.arguments.join(",")); | ||
entries.push(Probe { | ||
binary: bin_target.name.clone(), | ||
provider: provider.name.clone(), | ||
probe: probe.name, | ||
arguments, | ||
}); | ||
} | ||
} | ||
} | ||
Err(e) => { | ||
eprintln!( | ||
"Failed to extract DTrace probes from '{path}': \ | ||
{e}, or it may have zero probes" | ||
); | ||
} | ||
} | ||
} | ||
println!("{}", Table::new(entries).with(Style::empty())); | ||
Ok(()) | ||
} |