Skip to content

[sled-diagnostics] chunk the number of pids for ptool commands #8167

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

Open
wants to merge 2 commits into
base: spr/papertigers/main.sled-diagnostics-chunk-the-number-of-pids-for-ptool-commands
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions sled-diagnostics/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ cfg-if.workspace = true
fs-err = { workspace = true, features = ["tokio"] }
futures.workspace = true
illumos-utils.workspace = true
itertools.workspace = true
libc.workspace = true
omicron-workspace-hack.workspace = true
once_cell.workspace = true
Expand Down
16 changes: 10 additions & 6 deletions sled-diagnostics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use std::sync::Arc;

use itertools::Itertools;
use slog::Logger;

#[macro_use]
Expand Down Expand Up @@ -34,6 +35,9 @@ use queries::*;
/// Max number of commands to run in parallel
const MAX_PARALLELISM: usize = 50;

/// Max number of pids to operate on when running ptool commands
const PID_CHUNK_SIZE: usize = 15;

struct MultipleCommands<T> {
semaphore: Arc<Semaphore>,
set: JoinSet<T>,
Expand Down Expand Up @@ -119,9 +123,9 @@ pub async fn pargs_oxide_processes(
};

let mut commands = MultipleCommands::new();
for pid in pids {
for pid_chunk in &pids.into_iter().chunks(PID_CHUNK_SIZE) {
commands.add_command(execute_command_with_timeout(
pargs_process(pid),
pargs_processes(pid_chunk),
DEFAULT_TIMEOUT,
));
}
Expand All @@ -140,9 +144,9 @@ pub async fn pstack_oxide_processes(
};

let mut commands = MultipleCommands::new();
for pid in pids {
for pid_chunk in &pids.into_iter().chunks(PID_CHUNK_SIZE) {
commands.add_command(execute_command_with_timeout(
pstack_process(pid),
pstack_processes(pid_chunk),
DEFAULT_TIMEOUT,
));
}
Expand All @@ -161,9 +165,9 @@ pub async fn pfiles_oxide_processes(
};

let mut commands = MultipleCommands::new();
for pid in pids {
for pid_chunk in &pids.into_iter().chunks(PID_CHUNK_SIZE) {
commands.add_command(execute_command_with_timeout(
pfiles_process(pid),
pfiles_processes(pid_chunk),
DEFAULT_TIMEOUT,
));
}
Expand Down
12 changes: 6 additions & 6 deletions sled-diagnostics/src/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,21 +248,21 @@ pub fn nvmeadm_list() -> Command {
cmd
}

pub fn pargs_process(pid: i32) -> Command {
pub fn pargs_processes(pids: impl Iterator<Item = i32>) -> Command {
let mut cmd = std::process::Command::new(PFEXEC);
cmd.env_clear().arg(PARGS).arg("-ae").arg(pid.to_string());
cmd.env_clear().arg(PARGS).arg("-ae").args(pids.map(|p| p.to_string()));
cmd
}

pub fn pstack_process(pid: i32) -> Command {
pub fn pstack_processes(pids: impl Iterator<Item = i32>) -> Command {
let mut cmd = std::process::Command::new(PFEXEC);
cmd.env_clear().arg(PSTACK).arg(pid.to_string());
cmd.env_clear().arg(PSTACK).args(pids.map(|p| p.to_string()));
cmd
}

pub fn pfiles_process(pid: i32) -> Command {
pub fn pfiles_processes(pids: impl Iterator<Item = i32>) -> Command {
let mut cmd = std::process::Command::new(PFEXEC);
cmd.env_clear().arg(PFILES).arg(pid.to_string());
cmd.env_clear().arg(PFILES).args(pids.map(|p| p.to_string()));
cmd
}

Expand Down
Loading