| 1 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#}; |
| 2 | |
| 3 | use craterust-analyzer cargo bottom 0.14.9 crate/::{ |
| 4 | collectionrust-analyzer cargo bottom 0.14.9 collection/::processesrust-analyzer cargo bottom 0.14.9 collection/processes/::{Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#, ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#}, |
| 5 | utilsrust-analyzer cargo bottom 0.14.9 utils/::int_hashrust-analyzer cargo bottom 0.14.9 utils/int_hash/::IntHashMaprust-analyzer cargo bottom 0.14.9 utils/int_hash/IntHashMap#, |
| 6 | }; |
| 7 | |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)] |
| 9 | pub struct ProcessDatarust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData# { |
| 10 | /// A PID to process data map. |
| 11 | pub process_harvestrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_harvest.: BTreeMaprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/BTreeMap#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#, ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#>, |
| 12 | |
| 13 | /// A mapping between a process PID to any children process PIDs. |
| 14 | pub process_parent_mappingrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_parent_mapping.: IntHashMaprust-analyzer cargo bottom 0.14.9 utils/int_hash/IntHashMap#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#, Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#>>, |
| 15 | |
| 16 | /// PIDs corresponding to processes that have no parents. |
| 17 | pub orphan_pidsrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#orphan_pids.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#>, |
| 18 | } |
| 19 | |
| 20 | impl ProcessDatarust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData# { |
| 21 | pub(superrust-analyzer cargo bottom 0.14.9 app/data/) fn ingestrust-analyzer cargo bottom 0.14.9 app/data/process/impl#[ProcessData]ingest().(&mut self, list_of_processes: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#>) { |
| 22 | self.process_parent_mappingrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_parent_mapping..clearrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]clear().(); |
| 23 | |
| 24 | // Reverse as otherwise the pid mappings are in the wrong order. |
| 25 | list_of_processes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#for_each().(|process_harvest| { |
| 26 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_pid) = process_harvest.parent_pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#parent_pid. { |
| 27 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(entry) = self.process_parent_mappingrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_parent_mapping..get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&parent_pid) { |
| 28 | entry.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(process_harvest.pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#pid.); |
| 29 | } else { |
| 30 | self.process_parent_mappingrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_parent_mapping. |
| 31 | .insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(parent_pid, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![process_harvest.pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#pid.]); |
| 32 | } |
| 33 | } |
| 34 | }); |
| 35 | |
| 36 | self.process_parent_mappingrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_parent_mapping..shrink_to_fitrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]shrink_to_fit().(); |
| 37 | |
| 38 | let process_pid_map = list_of_processes |
| 39 | .into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().() |
| 40 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|process| (process.pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#pid., process)) |
| 41 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 42 | self.process_harvestrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_harvest. = process_pid_map; |
| 43 | |
| 44 | // We collect all processes that either: |
| 45 | // - Do not have a parent PID (that is, they are orphan processes) |
| 46 | // - Have a parent PID but we don't have the parent (we promote them as orphans) |
| 47 | self.orphan_pidsrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#orphan_pids. = self |
| 48 | .process_harvestrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_harvest. |
| 49 | .iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]iter().() |
| 50 | .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|(pid, process_harvest)| match process_harvest.parent_pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#parent_pid. { |
| 51 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(parent_pid) if self.process_harvestrust-analyzer cargo bottom 0.14.9 app/data/process/ProcessData#process_harvest..contains_keyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc collections/btree/map/impl#[`BTreeMap<K, V, A>`]contains_key().(&parent_pid) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 52 | _ => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().pid), |
| 53 | }) |
| 54 | .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 55 | } |
| 56 | } |