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
|
// Targeted mode: Return only the target root(s) and their hierarchy
|
||||||
let mut targeted_roots = Vec::new();
|
let mut targeted_roots = Vec::new();
|
||||||
if let Some(tpid) = target_pid {
|
if let Some(tpid) = target_pid {
|
||||||
// Find target or its closest surviving ancestor/child in the tree
|
fn extract_target(nodes: Vec<AggregatedProcess>, tpid: u32) -> (Vec<AggregatedProcess>, Option<AggregatedProcess>) {
|
||||||
// Actually final_roots already contains the full tree.
|
let mut remaining = Vec::new();
|
||||||
// We want only the root that contains our target PID.
|
let mut found = None;
|
||||||
fn find_target_node(roots: &mut Vec<AggregatedProcess>, tpid: u32) -> Option<AggregatedProcess> {
|
for mut node in nodes {
|
||||||
for i in 0..roots.len() {
|
if node.pid == tpid {
|
||||||
if roots[i].pid == tpid {
|
found = Some(node);
|
||||||
return Some(roots.remove(i));
|
} else {
|
||||||
}
|
let (new_children, sub_found) = extract_target(node.children, tpid);
|
||||||
if let Some(found) = find_target_node(&mut roots[i].children, tpid) {
|
node.children = new_children;
|
||||||
return Some(found);
|
if let Some(f) = sub_found {
|
||||||
|
found = Some(f);
|
||||||
|
}
|
||||||
|
remaining.push(node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None
|
(remaining, found)
|
||||||
}
|
}
|
||||||
if let Some(target_tree) = find_target_node(&mut final_roots, tpid) {
|
let (_, target_node) = extract_target(final_roots, tpid);
|
||||||
targeted_roots.push(target_tree);
|
if let Some(t) = target_node {
|
||||||
|
targeted_roots.push(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user