fix: stabilize process targeting with search/pinning and fix targeted report data isolation
This commit is contained in:
@@ -409,22 +409,26 @@ fn generate_report(start_time: DateTime<Utc>, snapshots: Vec<Snapshot>, mode: Pr
|
||||
// Targeted mode: Return only the target root(s) and their hierarchy
|
||||
let mut targeted_roots = Vec::new();
|
||||
if let Some(tpid) = target_pid {
|
||||
// Find target or its closest surviving ancestor/child in the tree
|
||||
// Actually final_roots already contains the full tree.
|
||||
// We want only the root that contains our target PID.
|
||||
fn find_target_node(roots: &mut Vec<AggregatedProcess>, tpid: u32) -> Option<AggregatedProcess> {
|
||||
for i in 0..roots.len() {
|
||||
if roots[i].pid == tpid {
|
||||
return Some(roots.remove(i));
|
||||
fn extract_target(nodes: Vec<AggregatedProcess>, tpid: u32) -> (Vec<AggregatedProcess>, Option<AggregatedProcess>) {
|
||||
let mut remaining = Vec::new();
|
||||
let mut found = None;
|
||||
for mut node in nodes {
|
||||
if node.pid == tpid {
|
||||
found = Some(node);
|
||||
} else {
|
||||
let (new_children, sub_found) = extract_target(node.children, tpid);
|
||||
node.children = new_children;
|
||||
if let Some(f) = sub_found {
|
||||
found = Some(f);
|
||||
}
|
||||
if let Some(found) = find_target_node(&mut roots[i].children, tpid) {
|
||||
return Some(found);
|
||||
remaining.push(node);
|
||||
}
|
||||
}
|
||||
None
|
||||
(remaining, found)
|
||||
}
|
||||
if let Some(target_tree) = find_target_node(&mut final_roots, tpid) {
|
||||
targeted_roots.push(target_tree);
|
||||
let (_, target_node) = extract_target(final_roots, tpid);
|
||||
if let Some(t) = target_node {
|
||||
targeted_roots.push(t);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user