Debian Codegraph @

src/collection/processes/linux/mod.rs

raw symbols SCIP
1 //! Process data collection for Linux.
2
3 mod processrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/;
4
5 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
6 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/, Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#},
7 iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{BufReadrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#, BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#},
8 timerust-analyzer cargo std https://github.com/rust-lang/rust/library/std time/::Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#,
9 };
10
11 use concat_stringrust-analyzer cargo concat-string 1.0.1 crate/::concat_stringrust-analyzer cargo concat-string 1.0.1 concat_string!;
12 use processrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/::*;
13 use rustc_hashrust-analyzer cargo rustc-hash 2.1.3 crate/::{FxHashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap# as HashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap#, FxHashSetrust-analyzer cargo rustc-hash 2.1.3 FxHashSet# as HashSetrust-analyzer cargo rustc-hash 2.1.3 FxHashSet#};
14 use sysinforust-analyzer cargo sysinfo 0.39.6 crate/::ProcessStatusrust-analyzer cargo sysinfo 0.39.6 common/system/ProcessStatus#;
15
16 use superrust-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#, UserTablerust-analyzer cargo bottom 0.14.9 collection/processes/unix/user_table/UserTable#, process_status_strrust-analyzer cargo bottom 0.14.9 collection/processes/process_status_str().};
17 use craterust-analyzer cargo bottom 0.14.9 crate/::collectionrust-analyzer cargo bottom 0.14.9 collection/::{DataCollectorrust-analyzer cargo bottom 0.14.9 collection/DataCollector#, errorrust-analyzer cargo bottom 0.14.9 collection/error/::CollectionResultrust-analyzer cargo bottom 0.14.9 collection/error/CollectionResult#, processesrust-analyzer cargo bottom 0.14.9 collection/processes/::ProcessTyperust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#};
18
19 /// Maximum character length of a `/proc/<PID>/stat` process name (the length is
20 /// 16, but this includes a null terminator).
21 ///
22 /// If it's equal or greater, then we instead refer to the command for the name.
23 const MAX_STAT_NAME_LENrust-analyzer cargo bottom 0.14.9 collection/processes/linux/MAX_STAT_NAME_LEN.: usize = 15;
24
25 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
26 pub struct PrevProcDetailsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails# {
27 total_read_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_read_bytes.: u64,
28 total_write_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_write_bytes.: u64,
29 cpu_timerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#cpu_time.: u64,
30 }
31
32 /// Given `/proc/stat` file contents, determine the idle and non-idle values of
33 /// the CPU used to calculate CPU usage.
34 fn fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().(line: &str) -> (f64, f64) {
35 /// Converts a `Option<&str>` value to an f64. If it fails to parse or is
36 /// `None`, it will return `0_f64`.
37 fn str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&str>) -> f64 {
38 val.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|v| v.parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<f64>().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0_f64)
39 }
40
41 let mut val = line.split_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_whitespace().();
42 let user = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
43 let nice: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
44 let system: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
45 let idle: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
46 let iowait: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
47 let irq: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
48 let softirq: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
49 let steal: f64 = str_to_f64rust-analyzer cargo bottom 0.14.9 collection/processes/linux/str_to_f64().(val.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`SplitWhitespace<'a>`][Iterator]next().());
50
51 // Note we do not get guest/guest_nice, as they are calculated as part of
52 // user/nice respectively See https://github.com/htop-dev/htop/blob/main/linux/LinuxProcessList.c
53 let idle = idle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().iowait;
54 let non_idle = user rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().nice rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().system rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().irq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().softirq rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().steal;
55
56 (idle, non_idle)
57 }
58
59 struct CpuUsagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage# {
60 /// Difference between the total delta and the idle delta.
61 cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#cpu_usage.: f64,
62
63 /// Overall CPU usage as a fraction.
64 cpu_fractionrust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#cpu_fraction.: f64,
65 }
66
67 fn cpu_usage_calculationrust-analyzer cargo bottom 0.14.9 collection/processes/linux/cpu_usage_calculation().(
68 prev_idle: &mut f64, prev_non_idle: &mut f64,
69 ) -> CollectionResultrust-analyzer cargo bottom 0.14.9 collection/error/CollectionResult#<CpuUsagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#> {
70 let (idle, non_idle) = {
71 // From SO answer: https://stackoverflow.com/a/23376195
72 let first_line = {
73 // We just need a single line from this file. Read it and return it.
74 let mut reader = BufReaderrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/BufReader#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/buffered/bufreader/impl#[`BufReader<R>`]new().(Filerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/File#::openrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[File]open().("/proc/stat")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().);
75 let mut buffer = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
76 reader.read_linerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/BufRead#read_line().(&mut buffer)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
77
78 buffer
79 };
80
81 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().(&first_line)
82 };
83
84 let total = idle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().non_idle;
85 let prev_total = *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_idle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Add<Self>`]add().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_non_idle;
86
87 let total_delta = total rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().prev_total;
88 let idle_delta = idle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_idle;
89
90 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_idle = idle;
91 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().prev_non_idle = non_idle;
92
93 // TODO: Should these return errors instead?
94 let cpu_usage = if total_delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().idle_delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne().0.0 {
95 total_delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Sub<Self>`]sub().idle_delta
96 } else {
97 1.0
98 };
99
100 let cpu_fraction = if total_delta rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]ne().0.0 {
101 cpu_usage rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().total_delta
102 } else {
103 0.0
104 };
105
106 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(CpuUsagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage# {
107 cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#cpu_usage.,
108 cpu_fractionrust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#cpu_fraction.,
109 })
110 }
111
112 /// Returns the usage and a new set of process times.
113 ///
114 /// NB: cpu_fraction should be represented WITHOUT the x100 factor!
115 fn get_linux_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/get_linux_cpu_usage().(
116 stat: &Statrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#, cpu_usage: f64, cpu_fraction: f64, prev_proc_times: u64,
117 use_current_cpu_total: bool,
118 ) -> (f32, u64) {
119 // Based heavily on https://stackoverflow.com/a/23376195 and https://stackoverflow.com/a/1424556
120 let new_proc_times = stat.utimerust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#utime. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Add<Self>`]add().stat.stimerust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#stime.;
121 let diff = new_proc_times.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(prev_proc_times) as f64; // No try_from for u64 -> f64... oh well.
122
123 if cpu_usage rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[f64][`PartialEq<Self>`]eq().0.0 {
124 (0.0, new_proc_times)
125 } else if use_current_cpu_total {
126 (((diff rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().cpu_usage) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().100.0) as f32, new_proc_times)
127 } else {
128 (
129 ((diff rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().cpu_usage) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().100.0 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().cpu_fraction) as f32,
130 new_proc_times,
131 )
132 }
133 }
134
135 fn read_procrust-analyzer cargo bottom 0.14.9 collection/processes/linux/read_proc().(
136 prev_proc: &PrevProcDetailsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#, process: Processrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#, args: ReadProcArgsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#, user_table: &mut UserTablerust-analyzer cargo bottom 0.14.9 collection/processes/unix/user_table/UserTable#,
137 thread_parent: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#>,
138 ) -> CollectionResultrust-analyzer cargo bottom 0.14.9 collection/error/CollectionResult#<(ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#, u64)> {
139 let Processrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process# {
140 pidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#pid.: _pid,
141 uidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#uid.,
142 statrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#stat.,
143 iorust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#io.,
144 cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#cmdline.,
145 } = process;
146
147 let ReadProcArgsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs# {
148 use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#use_current_cpu_total.,
149 cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#cpu_usage.,
150 cpu_fractionrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#cpu_fraction.,
151 total_memoryrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#total_memory.,
152 time_difference_in_secsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#time_difference_in_secs.,
153 system_uptimerust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#system_uptime.,
154 get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#get_process_threads.: _,
155 } = args;
156
157 let process_state_char = stat.staterust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#state.;
158 let process_state = (
159 process_status_strrust-analyzer cargo bottom 0.14.9 collection/processes/process_status_str().(ProcessStatusrust-analyzer cargo sysinfo 0.39.6 common/system/ProcessStatus#::fromrust-analyzer cargo sysinfo 0.39.6 unix/linux/process/impl#[ProcessStatus][`From<char>`]from().(process_state_char)),
160 process_state_char,
161 );
162 let (cpu_usage_percent, new_process_times) = get_linux_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/get_linux_cpu_usage().(
163 &stat,
164 cpu_usage,
165 cpu_fraction,
166 prev_proc.cpu_timerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#cpu_time.,
167 use_current_cpu_total,
168 );
169
170 let (parent_pid, process_type) = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(thread_parent) = thread_parent {
171 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(thread_parent), ProcessTyperust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#::ProcessThreadrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#ProcessThread#)
172 } else if stat.is_kernel_threadrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#is_kernel_thread. {
173 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stat.ppidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#ppid.), ProcessTyperust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#::Kernelrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#Kernel#)
174 } else {
175 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(stat.ppidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#ppid.), ProcessTyperust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#::Regularrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessType#Regular#)
176 };
177
178 let mem_usage = stat.rss_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/impl#[Stat]rss_bytes().();
179 let mem_usage_percent = (mem_usage as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().total_memory as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().100.0) as f32;
180 let virtual_mem = stat.vsizerust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#vsize.;
181
182 // XXX: This can fail if permission is denied.
183 let (total_read, total_write, read_per_sec, write_per_sec) = if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(io) = io {
184 let total_read = io.read_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Io#read_bytes.;
185 let total_write = io.write_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Io#write_bytes.;
186 let prev_total_read = prev_proc.total_read_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_read_bytes.;
187 let prev_total_write = prev_proc.total_write_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_write_bytes.;
188
189 let read_per_sec = total_read
190 .saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(prev_total_read)
191 .checked_divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_div().(time_difference_in_secs)
192 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
193
194 let write_per_sec = total_write
195 .saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(prev_total_write)
196 .checked_divrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]checked_div().(time_difference_in_secs)
197 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0);
198
199 (total_read, total_write, read_per_sec, write_per_sec)
200 } else {
201 (0, 0, 0, 0)
202 };
203
204 let user = uid.and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|uid| user_table.uid_to_usernamerust-analyzer cargo bottom 0.14.9 collection/processes/unix/user_table/impl#[UserTable]uid_to_username().(uid).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().());
205
206 let time = if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ticks_per_sec) = u32::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[u32][`TryFrom<u64>`]try_from().(rustixrust-analyzer cargo rustix 1.1.4 crate/::paramrust-analyzer cargo rustix 1.1.4 param/::clock_ticks_per_secondrust-analyzer cargo rustix 1.1.4 param/auxv/clock_ticks_per_second().()) {
207 if ticks_per_sec rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u32][`PartialEq<Self>`]eq().0 {
208 Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.
209 } else {
210 Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::from_secsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]from_secs().(
211 system_uptime.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u64]saturating_sub().(stat.start_timerust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#start_time. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`Div<Self>`]div().ticks_per_sec as u64),
212 )
213 }
214 } else {
215 Durationrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/Duration#::ZEROrust-analyzer cargo core https://github.com/rust-lang/rust/library/core time/impl#[Duration]ZERO.
216 };
217
218 let (command, name) = {
219 let comm = stat.commrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#comm.;
220 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(cmdline) = cmdline {
221 if cmdline.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
222 (concat_stringrust-analyzer cargo concat-string 1.0.1 concat_string!!("[", comm, "]"), comm)
223 } else {
224 // If the comm fits then we'll default to whatever is set.
225 // If it doesn't, we need to do some magic to determine what it's
226 // supposed to be.
227
228 // TODO: We might want to re-evaluate if we want to do it like this,
229 // as it turns out I was dumb and sometimes comm != process name...
230 //
231 // What we should do is store:
232 // - basename (what we're kinda doing now, except we're gating on comm length)
233 // - command (full thing)
234 // - comm (as a separate thing)
235 //
236 // Stuff like htop also offers the option to "highlight" basename and comm in
237 // command. Might be neat?
238 let name = if comm.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().MAX_STAT_NAME_LENrust-analyzer cargo bottom 0.14.9 collection/processes/linux/MAX_STAT_NAME_LEN. {
239 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().(&cmdline)
240 } else {
241 comm
242 };
243
244 (cmdline, name)
245 }
246 } else {
247 (comm.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), comm)
248 }
249 };
250
251 // We have moved command processing here.
252 // SAFETY: We are only replacing a single char (NUL) with another single char
253 // (space).
254
255 let mut command = command;
256 let buf_mut = unsafe { command.as_mut_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_mut_vec().() };
257
258 for byte in buf_mut {
259 if *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 {
260 const SPACErust-analyzer cargo bottom 0.14.9 collection/processes/linux/SPACE.: u8 = ' '.to_ascii_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_ascii_lowercase().() as u8;
261 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().byte = SPACErust-analyzer cargo bottom 0.14.9 collection/processes/linux/SPACE.;
262 }
263 }
264
265 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((
266 ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest# {
267 pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#pid.: process.pidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#pid.,
268 parent_pidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#parent_pid.,
269 cpu_usage_percentrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#cpu_usage_percent.,
270 mem_usage_percentrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#mem_usage_percent.,
271 mem_usagerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#mem_usage.,
272 virtual_memrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#virtual_mem.,
273 namerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#name.,
274 commandrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#command.,
275 read_per_secrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#read_per_sec.,
276 write_per_secrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#write_per_sec.,
277 total_readrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#total_read.,
278 total_writerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#total_write.,
279 process_staterust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#process_state.,
280 uidrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#uid.,
281 userrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#user.,
282 timerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#time.,
283 #[cfg(feature = "gpu")]
284 gpu_memrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_mem.: 0,
285 #[cfg(feature = "gpu")]
286 gpu_mem_percentrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_mem_percent.: 0.0,
287 #[cfg(feature = "gpu")]
288 gpu_utilrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_util.: 0,
289 process_typerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#process_type.,
290 #[cfg(unix)]
291 nicerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#nice.: stat.nicerust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#nice.,
292 priorityrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#priority.: stat.priorityrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Stat#priority.,
293 },
294 new_process_times,
295 ))
296 }
297
298 /// We follow something similar to how htop does it to identify a valid name
299 /// based on the cmdline.
300 /// - https://github.com/htop-dev/htop/blob/bcb18ef82269c68d54a160290e5f8b2e939674ec/Process.c#L268
301 /// (kinda)
302 /// - https://github.com/htop-dev/htop/blob/bcb18ef82269c68d54a160290e5f8b2e939674ec/Process.c#L573
303 ///
304 /// Also note that cmdline is (for us) separated by \0.
305 fn binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().(cmdline: &str) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
306 // Normally `/proc/<pid>/cmdline` separates arguments with NUL bytes. Some
307 // processes rewrite it using spaces, though, so stop at the first option in
308 // that case. In particular, do this before looking for the final slash;
309 // otherwise a path in a later argument can be mistaken for the executable.
310 let argv0 = cmdline.split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().('\0').map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(cmdline, |(argv0, _)| argv0);
311 let executable = argv0
312 .split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(" -")
313 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(argv0, |(executable, _)| executable);
314 let executable = executable
315 .split_oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]split_once().(':')
316 .map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(executable, |(executable, _)| executable);
317
318 executable
319 .rsplitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rsplit().('/')
320 .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`RSplit<'a, P>`][Iterator]next().()
321 .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(executable)
322 .to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
323 }
324
325 pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct PrevProcrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#<'a> {
326 pub prev_idlerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#prev_idle.: &'a mut f64,
327 pub prev_non_idlerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#prev_non_idle.: &'a mut f64,
328 }
329
330 pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct ProcHarvestOptionsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions# {
331 pub use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#use_current_cpu_total.: bool,
332 pub unnormalized_cpurust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#unnormalized_cpu.: bool,
333 pub get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#get_process_threads.: bool,
334 }
335
336 fn is_str_numericrust-analyzer cargo bottom 0.14.9 collection/processes/linux/is_str_numeric().(s: &str) -> bool {
337 s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().allrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#all().(|c| c.is_ascii_digitrust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii_digit().())
338 }
339
340 /// General args to keep around for reading proc data.
341 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
342 pub(craterust-analyzer cargo bottom 0.14.9 crate/) struct ReadProcArgsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs# {
343 pub use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#use_current_cpu_total.: bool,
344 pub cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#cpu_usage.: f64,
345 pub cpu_fractionrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#cpu_fraction.: f64,
346 pub total_memoryrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#total_memory.: u64,
347 pub time_difference_in_secsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#time_difference_in_secs.: u64,
348 pub system_uptimerust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#system_uptime.: u64,
349 pub get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#get_process_threads.: bool,
350 }
351
352 pub(craterust-analyzer cargo bottom 0.14.9 crate/) fn linux_process_datarust-analyzer cargo bottom 0.14.9 collection/processes/linux/linux_process_data().(
353 collector: &mut DataCollectorrust-analyzer cargo bottom 0.14.9 collection/DataCollector#, time_difference_in_secs: u64,
354 ) -> CollectionResultrust-analyzer cargo bottom 0.14.9 collection/error/CollectionResult#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#>> {
355 let total_memory = collector.total_memoryrust-analyzer cargo bottom 0.14.9 collection/impl#[DataCollector]total_memory().();
356 let prev_proc = PrevProcrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc# {
357 prev_idlerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#prev_idle.: &mut collector.prev_idlerust-analyzer cargo bottom 0.14.9 collection/DataCollector#prev_idle.,
358 prev_non_idlerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#prev_non_idle.: &mut collector.prev_non_idlerust-analyzer cargo bottom 0.14.9 collection/DataCollector#prev_non_idle.,
359 };
360 let proc_harvest_options = ProcHarvestOptionsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions# {
361 use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#use_current_cpu_total.: collector.use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/DataCollector#use_current_cpu_total.,
362 unnormalized_cpurust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#unnormalized_cpu.: collector.unnormalized_cpurust-analyzer cargo bottom 0.14.9 collection/DataCollector#unnormalized_cpu.,
363 get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#get_process_threads.: collector.get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/DataCollector#get_process_threads.,
364 };
365 let prev_process_details = &mut collector.prev_process_detailsrust-analyzer cargo bottom 0.14.9 collection/DataCollector#prev_process_details.;
366 let user_table = &mut collector.user_tablerust-analyzer cargo bottom 0.14.9 collection/DataCollector#user_table.;
367
368 let ProcHarvestOptionsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions# {
369 use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#use_current_cpu_total.,
370 unnormalized_cpurust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#unnormalized_cpu.,
371 get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ProcHarvestOptions#get_process_threads.: get_threads,
372 } = proc_harvest_options;
373
374 let PrevProcrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc# {
375 prev_idlerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#prev_idle.,
376 prev_non_idlerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProc#prev_non_idle.,
377 } = prev_proc;
378
379 // TODO: [PROC THREADS] Add threads
380
381 let CpuUsagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage# {
382 mut cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#cpu_usage.,
383 cpu_fractionrust-analyzer cargo bottom 0.14.9 collection/processes/linux/CpuUsage#cpu_fraction.,
384 } = cpu_usage_calculationrust-analyzer cargo bottom 0.14.9 collection/processes/linux/cpu_usage_calculation().(prev_idle, prev_non_idle)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().;
385
386 if unnormalized_cpu {
387 let num_processors = collector
388 .cgroup_cpu_datarust-analyzer cargo bottom 0.14.9 collection/DataCollector#cgroup_cpu_data.
389 .cpu_quotarust-analyzer cargo bottom 0.14.9 collection/linux/cgroups/CgroupCpuCollector#cpu_quota.
390 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| collector.sysrust-analyzer cargo bottom 0.14.9 collection/DataCollector#sys..systemrust-analyzer cargo bottom 0.14.9 collection/SysinfoSource#system..cpusrust-analyzer cargo sysinfo 0.39.6 common/system/impl#[System]cpus().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() as f64);
391
392 // Note we *divide* here because the later calculation divides `cpu_usage` - in
393 // effect, multiplying over the number of cores.
394 cpu_usage rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign()./=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`DivAssign<Self>`]div_assign().num_processors;
395 }
396
397 // TODO: Could maybe use a double buffer hashmap to avoid allocating this each
398 // time? e.g. we swap which is prev and which is new.
399 let mut seen_pids: HashSetrust-analyzer cargo rustc-hash 2.1.3 FxHashSet#<Pidrust-analyzer cargo bottom 0.14.9 collection/processes/Pid#> = HashSetrust-analyzer cargo rustc-hash 2.1.3 FxHashSet#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S>`][Default]default().();
400
401 // Note this will only return PIDs of _processes_, not threads. You can get
402 // those from /proc/<PID>/task though.
403 let pids = fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_dir().("/proc")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().().filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|dir| {
404 // Need to filter out non-PID entries.
405 if is_str_numericrust-analyzer cargo bottom 0.14.9 collection/processes/linux/is_str_numeric().(dir.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().().to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().().trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().()) {
406 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(dir.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().())
407 } else {
408 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
409 }
410 });
411
412 let args = ReadProcArgsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs# {
413 use_current_cpu_totalrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#use_current_cpu_total.,
414 cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#cpu_usage.,
415 cpu_fractionrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#cpu_fraction.,
416 total_memoryrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#total_memory.,
417 time_difference_in_secsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#time_difference_in_secs.,
418 system_uptimerust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#system_uptime.: sysinforust-analyzer cargo sysinfo 0.39.6 crate/::Systemrust-analyzer cargo sysinfo 0.39.6 common/system/System#::uptimerust-analyzer cargo sysinfo 0.39.6 common/system/impl#[System]uptime().(),
419 get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#get_process_threads.: get_threads,
420 };
421
422 // TODO: Maybe pre-allocate these buffers in the future w/ routine cleanup.
423 let mut buffer = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
424 let mut process_threads_to_check = HashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap#::defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S>`][Default]default().();
425
426 let mut process_vector: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<ProcessHarvestrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#> = pids
427 .filter_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter_map().(|pid_path| {
428 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((process, threads)) =
429 Processrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#::from_pathrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/impl#[Process]from_path().(pid_path, &mut buffer, args.get_process_threadsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/ReadProcArgs#get_process_threads.)
430 {
431 let pid = process.pidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#pid.;
432 let prev_proc_details = prev_process_details.entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(pid).or_defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V>`]or_default().();
433
434 #[cfg_attr(not(feature = "gpu"), expect(unused_mut))]
435 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((mut process_harvest, new_process_times)) =
436 read_procrust-analyzer cargo bottom 0.14.9 collection/processes/linux/read_proc().(prev_proc_details, process, args, user_table, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#)
437 {
438 #[cfg(feature = "gpu")]
439 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(gpus) = &collector.gpu_pidsrust-analyzer cargo bottom 0.14.9 collection/DataCollector#gpu_pids. {
440 gpus.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().for_eachrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]for_each().(|gpu| {
441 // add mem/util for all gpus to pid
442 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((mem, util)) = gpu.getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&pid) {
443 process_harvest.gpu_memrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_mem. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<&u64>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<&u64>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u64][`AddAssign<&u64>`]add_assign().mem;
444 process_harvest.gpu_utilrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_util. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<&u32>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<&u32>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<&u32>`]add_assign().util;
445 }
446 });
447 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(gpu_total_mem) = &collector.gpus_total_memrust-analyzer cargo bottom 0.14.9 collection/DataCollector#gpus_total_mem. {
448 process_harvest.gpu_mem_percentrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_mem_percent. =
449 (process_harvest.gpu_memrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#gpu_mem. as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Div<Self>`]div().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().gpu_total_mem as f64 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f64][`Mul<Self>`]mul().100.0)
450 as f32;
451 }
452 }
453
454 prev_proc_details.cpu_timerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#cpu_time. = new_process_times;
455 prev_proc_details.total_read_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_read_bytes. = process_harvest.total_readrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#total_read.;
456 prev_proc_details.total_write_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_write_bytes. = process_harvest.total_writerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#total_write.;
457
458 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().threads.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() {
459 process_threads_to_check.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(pid, threads);
460 }
461
462 seen_pids.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(pid);
463 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(process_harvest);
464 }
465 }
466
467 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
468 })
469 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().();
470
471 // Get thread data.
472 for (pid, tid_paths) in process_threads_to_check {
473 for tid_path in tid_paths {
474 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((process, _)) = Processrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#::from_pathrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/impl#[Process]from_path().(tid_path, &mut buffer, false) {
475 let tid = process.pidrust-analyzer cargo bottom 0.14.9 collection/processes/linux/process/Process#pid.;
476 let prev_proc_details = prev_process_details.entryrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]entry().(tid).or_defaultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`Entry<'a, K, V>`]or_default().();
477
478 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((process_harvest, new_process_times)) =
479 read_procrust-analyzer cargo bottom 0.14.9 collection/processes/linux/read_proc().(prev_proc_details, process, args, user_table, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(pid))
480 {
481 prev_proc_details.cpu_timerust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#cpu_time. = new_process_times;
482 prev_proc_details.total_read_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_read_bytes. = process_harvest.total_readrust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#total_read.;
483 prev_proc_details.total_write_bytesrust-analyzer cargo bottom 0.14.9 collection/processes/linux/PrevProcDetails#total_write_bytes. = process_harvest.total_writerust-analyzer cargo bottom 0.14.9 collection/processes/ProcessHarvest#total_write.;
484
485 seen_pids.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(tid);
486 process_vector.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(process_harvest);
487 }
488 }
489 }
490 }
491
492 // Clean up values we don't care about anymore.
493 prev_process_details.retainrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]retain().(|pid, _| seen_pids.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(pid));
494
495 // Occasional garbage collection.
496 if collector.should_run_less_routine_tasksrust-analyzer cargo bottom 0.14.9 collection/DataCollector#should_run_less_routine_tasks. {
497 prev_process_details.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().();
498 }
499
500 // TODO: This might be more efficient to just separate threads into their own
501 // list, but for now this works so it fits with existing code.
502 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(process_vector)
503 }
504
505 #[cfg(test)]
506 mod testsrust-analyzer cargo bottom 0.14.9 collection/processes/linux/tests/ {
507 use superrust-analyzer cargo bottom 0.14.9 collection/processes/linux/::*;
508
509 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
510 fn test_proc_cpu_parserust-analyzer cargo bottom 0.14.9 collection/processes/linux/tests/test_proc_cpu_parse().() {
511 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
512 (100_f64, 200_f64),
513 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100"),
514 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 4 values"
515 );
516 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
517 (120_f64, 200_f64),
518 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100 20"),
519 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 5 values"
520 );
521 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
522 (120_f64, 230_f64),
523 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100 20 30"),
524 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 6 values"
525 );
526 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
527 (120_f64, 270_f64),
528 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100 20 30 40"),
529 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 7 values"
530 );
531 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
532 (120_f64, 320_f64),
533 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100 20 30 40 50"),
534 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 8 values"
535 );
536 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
537 (120_f64, 320_f64),
538 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100 20 30 40 50 100"),
539 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 9 values"
540 );
541 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
542 (120_f64, 320_f64),
543 fetch_cpu_usagerust-analyzer cargo bottom 0.14.9 collection/processes/linux/fetch_cpu_usage().("100 0 100 100 20 30 40 50 100 200"),
544 "Failed to properly calculate idle/non-idle for /proc/stat CPU with 10 values"
545 );
546 }
547
548 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
549 fn test_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/tests/test_name_from_cmdline().() {
550 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/btm"), "btm");
551 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
552 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/btm\0--asdf\0--asdf/gkj"),
553 "btm"
554 );
555 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/btm:"), "btm");
556 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/b tm"), "b tm");
557 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/b tm:"), "b tm");
558 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/b tm\0--test"), "b tm");
559 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/b tm:\0--test"), "b tm");
560 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
561 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/b t m:\0--\"test thing\""),
562 "b t m"
563 );
564 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
565 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("firefox -contentproc -isForBrowser -prefsHandle 0"),
566 "firefox"
567 );
568 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
569 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().(
570 "/nix/store/discord/opt/Discord/.Discord-wrapped --type=renderer \
571 --openh264-library-path=/home/user/libopenh264-2.5.1-linux64.7.so"
572 ),
573 ".Discord-wrapped"
574 );
575 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("こんにちは\0"), "こんにちは");
576 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
577 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("こんにちは -こんばんは"),
578 "こんにちは"
579 );
580 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
581 binary_name_from_cmdlinerust-analyzer cargo bottom 0.14.9 collection/processes/linux/binary_name_from_cmdline().("/usr/bin/こんにちは -こんばんは\0"),
582 "こんにちは"
583 );
584 }
585 }