Skip to content
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 an xtask for listing all USDT probes in Omicron #5895

Merged
merged 1 commit into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions dev-tools/xtask/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ cargo_metadata.workspace = true
clap.workspace = true
flate2.workspace = true
futures.workspace = true
fs-err.workspace = true
macaddr.workspace = true
md5 = "0.7.0"
reqwest = { workspace = true, features = [ "default-tls" ] }
Expand All @@ -25,8 +26,9 @@ slog-async.workspace = true
slog-bunyan.workspace = true
slog-term.workspace = true
strum.workspace = true
swrite.workspace = true
tabled.workspace = true
tar.workspace = true
tokio = { workspace = true, features = ["full"] }
toml.workspace = true
fs-err.workspace = true
swrite.workspace = true
usdt.workspace = true
11 changes: 11 additions & 0 deletions dev-tools/xtask/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ mod clippy;
mod download;
#[cfg_attr(not(target_os = "illumos"), allow(dead_code))]
mod external;
mod usdt;

#[cfg(target_os = "illumos")]
mod verify_libraries;
Expand Down Expand Up @@ -66,6 +67,15 @@ enum Cmds {
/// (this command is only available on illumos)
#[cfg(not(target_os = "illumos"))]
VirtualHardware,

/// Print USDT probes in Omicron binaries.
Probes {
/// An optional filter applied to binary names.
///
/// This is a simple substring match. Any binary with the filter as a
/// substring of its name will be examined for probes.
filter: Option<String>,
},
}

#[tokio::main]
Expand All @@ -91,6 +101,7 @@ async fn main() -> Result<()> {
Cmds::Releng | Cmds::VerifyLibraries | Cmds::VirtualHardware => {
anyhow::bail!("this command is only available on illumos");
}
Cmds::Probes { filter } => usdt::print_probes(filter),
}
}

Expand Down
84 changes: 84 additions & 0 deletions dev-tools/xtask/src/usdt.rs
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(())
}
Loading