Skip to content

Commit

Permalink
print the error; fixes #60
Browse files Browse the repository at this point in the history
  • Loading branch information
bast committed Jul 27, 2023
1 parent 9d2d16b commit 3bcb1e1
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
11 changes: 9 additions & 2 deletions src/batchless.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,20 @@ impl BatchlessJobManager {
}

impl BatchlessJobManager {
fn lookup(&mut self, processes: &[process::Process], want_pid: usize) -> Option<(usize, usize)> {
fn lookup(
&mut self,
processes: &[process::Process],
want_pid: usize,
) -> Option<(usize, usize)> {
let probe = self.cache.get(&want_pid);
if probe.is_some() {
return probe.copied();
}

for process::Process { pid, ppid, session, .. } in processes {
for process::Process {
pid, ppid, session, ..
} in processes
{
if *pid == want_pid {
let entry = (*session, *ppid);
self.cache.insert(want_pid, entry);
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ fn main() {
}
}

fn log(msg: &str) {
fn log_cmderror(msg: &str) {
// TODO (issue 52): Implement some sensible logging maybe
eprintln!("SONAR ERROR: {:?}", msg);
}
5 changes: 2 additions & 3 deletions src/process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn get_process_information(jobs: &mut dyn jobs::JobManager) -> Result<Vec<Pr
TIMEOUT_SECONDS,
) {
Ok(out) => Ok(parse_ps_output(&out, need_process_tree)),
Err(e) => Err(e)
Err(e) => Err(e),
}
}

Expand Down Expand Up @@ -110,8 +110,7 @@ pub fn parsed_full_test_output() -> Vec<Process> {
// Generated by PS_COMMAND_COMPLETE on lth's laptop, slightly edited to orphan #80199
//"ps -e --no-header -o pid,user:22,pcpu,pmem,size,ppid,sess,comm"
// pid user pcpu pmen size ppid sess command
let text =
" 1 root 0.0 0.0 21516 0 1 systemd
let text = " 1 root 0.0 0.0 21516 0 1 systemd
2 root 0.0 0.0 0 0 0 kthreadd
3 root 0.0 0.0 0 2 0 rcu_gp
4 root 0.0 0.0 0 2 0 rcu_par_gp
Expand Down
8 changes: 4 additions & 4 deletions src/ps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use crate::amd;
use crate::command::CmdError;
use crate::jobs;
use crate::log;
use crate::log_cmderror;
use crate::nvidia;
use crate::process;
use crate::util::{three_places, time_iso8601};
Expand Down Expand Up @@ -171,7 +171,7 @@ fn add_gpu_info(
}
}
Err(_) => {
log("GPU process listing failed");
log_cmderror("GPU process listing failed");
}
}
}
Expand Down Expand Up @@ -221,8 +221,8 @@ pub fn create_snapshot(
let mut user_by_pid: HashMap<usize, String> = HashMap::new();

match process::get_process_information(jobs) {
Err(_e) => {
log("CPU process listing failed");
Err(_) => {
log_cmderror("CPU process listing failed");
return;
}
Ok(ps_output) => {
Expand Down

0 comments on commit 3bcb1e1

Please sign in to comment.