Debian Codegraph @

src/collection/temperature/linux.rs

raw symbols SCIP
1 //! Gets temperature sensor data for Linux platforms.
2
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
4 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/,
5 pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/::{Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#, PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#},
6 };
7
8 use anyhowrust-analyzer cargo anyhow 1.0.104 crate/::Resultrust-analyzer cargo anyhow 1.0.104 Result#;
9 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#};
10
11 use superrust-analyzer cargo bottom 0.14.9 collection/temperature/::TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#;
12 #[cfg(feature = "gpu")]
13 use craterust-analyzer cargo bottom 0.14.9 crate/::collectionrust-analyzer cargo bottom 0.14.9 collection/::amdrust-analyzer cargo bottom 0.14.9 collection/amd/::get_amd_namerust-analyzer cargo bottom 0.14.9 collection/amd/get_amd_name().;
14 use craterust-analyzer cargo bottom 0.14.9 crate/::{apprust-analyzer cargo bottom 0.14.9 app/::filterrust-analyzer cargo bottom 0.14.9 app/filter/::Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#, collectionrust-analyzer cargo bottom 0.14.9 collection/::linuxrust-analyzer cargo bottom 0.14.9 collection/linux/::utilsrust-analyzer cargo bottom 0.14.9 collection/linux/utils/::is_device_awakerust-analyzer cargo bottom 0.14.9 collection/linux/utils/is_device_awake().};
15
16 const EMPTY_NAMErust-analyzer cargo bottom 0.14.9 collection/temperature/linux/EMPTY_NAME.: &str = "Unknown";
17
18 /// Returned results from grabbing hwmon/coretemp temperature sensor
19 /// values or names.
20 struct HwmonResultsrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults# {
21 temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#temperatures.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#>,
22 num_hwmonrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#num_hwmon.: usize,
23 }
24
25 /// Parses and reads temperatures that were in millidegree Celsius, and if
26 /// successful, returns a temperature in Celsius.
27 fn parse_temprust-analyzer cargo bottom 0.14.9 collection/temperature/linux/parse_temp().(path: &Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<f32> {
28 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_to_stringrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_to_string().(path)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()..trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().().parserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]parse().::<f32>()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[f32][`Div<Self>`]div().1_000.0)
29 }
30
31 /// Get all candidates from hwmon and coretemp. It will also return the number
32 /// of entries from hwmon.
33 fn get_hwmon_candidatesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/get_hwmon_candidates().() -> (HashSetrust-analyzer cargo rustc-hash 2.1.3 FxHashSet#<PathBufrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/PathBuf#>, usize) {
34 let mut dirs = 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().();
35
36 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read_dir) = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/sys/class/hwmon").read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]read_dir().() {
37 for entry in read_dir.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
38 let mut path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
39
40 // hwmon includes many sensors, we only want ones with at least one temperature
41 // sensor Reading this file will wake the device, but we're only
42 // checking existence, so it should be fine.
43 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("temp1_input").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
44 // Note we also check for a `device` subdirectory (e.g.
45 // `/sys/class/hwmon/hwmon*/device/`). This is needed for
46 // CentOS, which adds this extra `/device` directory. See:
47 // - https://github.com/nicolargo/glances/issues/1060
48 // - https://github.com/giampaolo/psutil/issues/971
49 // - https://github.com/giampaolo/psutil/blob/642438375e685403b4cd60b0c0e25b80dd5a813d/psutil/_pslinux.py#L1316
50 //
51 // If it does match, then add the `device/` directory to the path.
52 if path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("device/temp1_input").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
53 path.pushrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[PathBuf]push().("device");
54 }
55 }
56
57 dirs.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(path);
58 }
59 }
60
61 let num_hwmon = dirs.lenrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]len().();
62
63 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read_dir) = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/sys/devices/platform").read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]read_dir().() {
64 for entry in read_dir.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
65 if entry.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().().starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("coretemp.")
66 && let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read_dir) = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().().joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("hwmon").read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]read_dir().()
67 {
68 for entry in read_dir.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
69 let path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
70
71 if path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("temp1_input").existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
72 // It's possible that there are dupes (represented by symlinks) - the
73 // easy way is to just substitute the parent
74 // directory and check if the hwmon
75 // variant exists already in a set.
76 //
77 // For more info, see https://github.com/giampaolo/psutil/pull/1822/files
78 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(child) = path.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().() {
79 let to_check_path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/sys/class/hwmon").joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(child);
80
81 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().dirs.containsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]contains().(&to_check_path) {
82 dirs.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/set/impl#[`HashSet<T, S, A>`]insert().(path);
83 }
84 }
85 }
86 }
87 }
88 }
89 }
90
91 (dirs, num_hwmon)
92 }
93
94 #[inline]
95 fn read_to_string_lossyrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/read_to_string_lossy().<P: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#>>(path: P) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
96 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::readrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read().(path)
97 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|v| Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_lossyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_lossy().(&v).trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
98 .okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()
99 }
100
101 #[inline]
102 fn humanize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/humanize_name().(name: &str, sensor_name: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
103 match sensor_name {
104 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ty) => formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{name} ({ty})"),
105 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => name.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
106 }
107 }
108
109 #[inline]
110 fn counted_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/counted_name().(seen_names: &mut HashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u32>, name: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
111 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(count) = seen_names.get_mutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get_mut().(&name) {
112 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[u32][`AddAssign<Self>`]add_assign().1;
113 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{name} ({count})")
114 } else {
115 seen_names.insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(name.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().(), 0);
116 name
117 }
118 }
119
120 fn uppercase_first_letterrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/uppercase_first_letter().(s: &mut str) {
121 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(r) = s.get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get_mut().(0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#1) {
122 r.make_ascii_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]make_ascii_uppercase().();
123 }
124 }
125
126 fn finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(
127 hwmon_name: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, sensor_label: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>,
128 fallback_sensor_name: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, seen_names: &mut HashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u32>,
129 ) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
130 let candidate_name = match (hwmon_name, sensor_label) {
131 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut label)) => match (name.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().(), label.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().()) {
132 (false, false) => {
133 uppercase_first_letterrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/uppercase_first_letter().(&mut label);
134 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{name}: {label}")
135 }
136 (true, false) => {
137 uppercase_first_letterrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/uppercase_first_letter().(&mut label);
138
139 // We assume label must not be empty.
140 match fallback_sensor_name {
141 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fallback) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fallback.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() => {
142 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{fallback}: {label}")
143 }
144 _ => label,
145 }
146 }
147 (false, true) => name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(),
148 (true, true) => EMPTY_NAMErust-analyzer cargo bottom 0.14.9 collection/temperature/linux/EMPTY_NAME..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
149 },
150 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(mut label)) => match fallback_sensor_name {
151 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(fallback) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().fallback.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() => {
152 if label.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
153 fallback.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().()
154 } else {
155 uppercase_first_letterrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/uppercase_first_letter().(&mut label);
156 formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{fallback}: {label}")
157 }
158 }
159 _ => {
160 if label.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
161 EMPTY_NAMErust-analyzer cargo bottom 0.14.9 collection/temperature/linux/EMPTY_NAME..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
162 } else {
163 uppercase_first_letterrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/uppercase_first_letter().(&mut label);
164 label
165 }
166 }
167 },
168 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => {
169 if name.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
170 EMPTY_NAMErust-analyzer cargo bottom 0.14.9 collection/temperature/linux/EMPTY_NAME..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
171 } else {
172 name
173 }
174 }
175 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#) => match fallback_sensor_name {
176 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(sensor_name) if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().sensor_name.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() => sensor_name.to_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[T][ToOwned]to_owned().(),
177 _ => EMPTY_NAMErust-analyzer cargo bottom 0.14.9 collection/temperature/linux/EMPTY_NAME..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
178 },
179 };
180
181 counted_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/counted_name().(seen_names, candidate_name)
182 }
183
184 /// Get temperature sensors from the linux sysfs interface `/sys/class/hwmon`
185 /// and `/sys/devices/platform/coretemp.*`. It returns all found temperature
186 /// sensors, and the number of checked hwmon directories (not coretemp
187 /// directories).
188 ///
189 /// For more details, see the relevant Linux kernel documentation:
190 /// - [`/sys/class/hwmon`](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-hwmon)
191 /// - [`/sys/devices/platform/coretemp.*`](https://www.kernel.org/doc/html/v5.14/hwmon/coretemp.html)
192 ///
193 /// This method will return `0` as the temperature for devices, such as GPUs,
194 /// that support power management features that have powered themselves off.
195 /// Specifically, in laptops with iGPUs and dGPUs, if the dGPU is capable of
196 /// entering ACPI D3cold, reading the temperature sensors will wake it,
197 /// and keep it awake, wasting power.
198 ///
199 /// For such devices, this method will only query the sensors *only* if
200 /// the device is already in ACPI D0. This has the notable issue that
201 /// once this happens, the device will be *kept* on through the sensor
202 /// reading, and not be able to re-enter ACPI D3cold.
203 fn hwmon_temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/hwmon_temperatures().(filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>, graph_filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>) -> HwmonResultsrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults# {
204 let mut temperatures: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#> = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![];
205 let mut seen_names: HashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u32> = 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().();
206
207 let (dirs, num_hwmon) = get_hwmon_candidatesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/get_hwmon_candidates().();
208
209 // Note that none of this is async if we ever go back to it, but sysfs is in
210 // memory, so in theory none of this should block if we're slightly careful.
211 // Of note is that reading the temperature sensors of a device that has
212 // `/sys/class/hwmon/hwmon*/device/power_state` == `D3cold` will
213 // wake the device up, and will block until it initializes.
214 //
215 // Reading the `hwmon*/device/power_state` or `hwmon*/temp*_label` properties
216 // will not wake the device, and thus not block,
217 // and meaning no sensors have to be hidden depending on `power_state`
218 //
219 // It would probably be more ideal to use a proper async runtime; this would
220 // also allow easy cancellation/timeouts.
221 for file_path in dirs {
222 let sensor_name = read_to_string_lossyrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/read_to_string_lossy().(file_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("name"));
223 let device = file_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("device");
224
225 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_device_awakerust-analyzer cargo bottom 0.14.9 collection/linux/utils/is_device_awake().(&device) {
226 let name = finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &sensor_name, &mut seen_names);
227 temperatures.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData# {
228 namerust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#name.,
229 temperaturerust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#temperature.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
230 });
231
232 continue;
233 }
234
235 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(dir_entries) = file_path.read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]read_dir().() {
236 // Enumerate the devices temperature sensors
237 for file in dir_entries.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
238 let name = file.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().();
239 let name = name.to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().();
240
241 // We only want temperature sensors, skip others early
242 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(name.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("temp") && name.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().("input")) {
243 continue;
244 }
245
246 let temp_path = file.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
247 let sensor_label_path = file_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().(name.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().("input", "label"));
248 let sensor_label = read_to_string_lossyrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/read_to_string_lossy().(sensor_label_path);
249
250 // Do some messing around to get a more sensible name for sensors:
251 // - For GPUs, this will use the kernel device name, ex `card0`
252 // - For nvme drives, this will also use the kernel name, ex `nvme0`. This is
253 // found differently than for GPUs
254 // - For whatever acpitz is, on my machine this is now `thermal_zone0`.
255 // - For k10temp, this will still be k10temp, but it has to be handled special.
256 let hwmon_name = {
257 let device = file_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("device");
258
259 // This will exist for GPUs but not others, this is how we find their kernel
260 // name.
261 let drm = device.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("drm");
262 if drm.existsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]exists().() {
263 // This should never actually be empty. If it is though, we'll fall back to
264 // the sensor name later on.
265
266 #[cfg(feature = "gpu")]
267 {
268 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(amd_gpu_name) = get_amd_namerust-analyzer cargo bottom 0.14.9 collection/amd/get_amd_name().(&device) {
269 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(amd_gpu_name)
270 } else if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(cards) = drm.read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]read_dir().() {
271 cards.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().().find_maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#find_map().(|card| {
272 card.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().().to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|name| {
273 name.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("card").thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core bool/impl#[bool]then().(|| {
274 humanize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/humanize_name().(name.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().(), sensor_name.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().())
275 })
276 })
277 })
278 } else {
279 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
280 }
281 }
282
283 #[cfg(not(feature = "gpu"))]
284 {
285 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(cards) = drm.read_dir() {
286 cards.flatten().find_map(|card| {
287 card.file_name().to_str().and_then(|name| {
288 name.starts_with("card").then(|| {
289 humanize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/humanize_name().(name.trim(), sensor_name.as_ref())
290 })
291 })
292 })
293 } else {
294 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
295 }
296 }
297 } else {
298 // This little mess is to account for stuff like k10temp. This is needed
299 // because the `device` symlink points to `nvme*`
300 // for nvme drives, but to PCI buses for anything
301 // else. If the first character is alphabetic, it's an actual name like
302 // k10temp or nvme0, not a PCI bus.
303 fsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/::read_linkrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/read_link().(device).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|link| {
304 let link = link.file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]file_name().().and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|f| f.to_strrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_str().()).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|s| s.trimrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim().());
305
306 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(link) = &link
307 && let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first_char) = link.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().().firstrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]first().()
308 && first_char.is_ascii_alphabeticrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_alphabetic().()
309 {
310 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(humanize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/humanize_name().(link, sensor_name.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()))
311 } else {
312 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
313 }
314 })
315 }
316 };
317
318 let name = finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(hwmon_name, sensor_label, &sensor_name, &mut seen_names);
319
320 // TODO: It's possible we may want to move the filter check further up to avoid
321 // probing hwmon if not needed?
322 if (Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#::optional_should_keeprust-analyzer cargo bottom 0.14.9 app/filter/impl#[Filter]optional_should_keep().(filter, &name)
323 || Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#::optional_should_keeprust-analyzer cargo bottom 0.14.9 app/filter/impl#[Filter]optional_should_keep().(graph_filter, &name))
324 && let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(temp_celsius) = parse_temprust-analyzer cargo bottom 0.14.9 collection/temperature/linux/parse_temp().(&temp_path)
325 {
326 temperatures.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData# {
327 namerust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#name.,
328 temperaturerust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#temperature.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(temp_celsius),
329 });
330 }
331 }
332 }
333 }
334
335 HwmonResultsrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults# {
336 temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#temperatures.,
337 num_hwmonrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#num_hwmon.,
338 }
339 }
340
341 /// Gets data from `/sys/class/thermal/thermal_zone*`. This should only be used
342 /// if [`hwmon_temperatures`] doesn't return anything to avoid duplicate sensor
343 /// results.
344 ///
345 /// See [the Linux kernel documentation](https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-thermal)
346 /// for more details.
347 fn add_thermal_zone_temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/add_thermal_zone_temperatures().(
348 temperatures: &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#>, filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>, graph_filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>,
349 ) {
350 let path = Pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/Path#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]new().("/sys/class/thermal");
351 let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(read_dir) = path.read_dirrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]read_dir().() else {
352 return;
353 };
354
355 let mut seen_names: HashMaprust-analyzer cargo rustc-hash 2.1.3 FxHashMap#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, u32> = 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().();
356
357 for entry in read_dir.flattenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#flatten().() {
358 if entry
359 .file_namerust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]file_name().()
360 .to_string_lossyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/os_str/impl#[OsStr]to_string_lossy().()
361 .starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("thermal_zone")
362 {
363 let file_path = entry.pathrust-analyzer cargo std https://github.com/rust-lang/rust/library/std fs/impl#[DirEntry]path().();
364 let name_path = file_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("type");
365
366 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(name) = read_to_string_lossyrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/read_to_string_lossy().(name_path) {
367 let name = if name.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]is_empty().() {
368 EMPTY_NAMErust-analyzer cargo bottom 0.14.9 collection/temperature/linux/EMPTY_NAME..to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()
369 } else {
370 name
371 };
372
373 if Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#::optional_should_keeprust-analyzer cargo bottom 0.14.9 app/filter/impl#[Filter]optional_should_keep().(filter, &name)
374 || Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#::optional_should_keeprust-analyzer cargo bottom 0.14.9 app/filter/impl#[Filter]optional_should_keep().(graph_filter, &name)
375 {
376 let temp_path = file_path.joinrust-analyzer cargo std https://github.com/rust-lang/rust/library/std path/impl#[Path]join().("temp");
377 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(temp_celsius) = parse_temprust-analyzer cargo bottom 0.14.9 collection/temperature/linux/parse_temp().(&temp_path) {
378 let name = counted_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/counted_name().(&mut seen_names, name);
379
380 temperatures.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData# {
381 namerust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#name.,
382 temperaturerust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#temperature.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(temp_celsius),
383 });
384 }
385 }
386 }
387 }
388 }
389 }
390
391 /// Gets temperature sensors and data.
392 pub fn get_temperature_datarust-analyzer cargo bottom 0.14.9 collection/temperature/linux/get_temperature_data().(
393 filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>, graph_filter: &Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Filterrust-analyzer cargo bottom 0.14.9 app/filter/Filter#>,
394 ) -> Resultrust-analyzer cargo anyhow 1.0.104 Result#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<TempSensorDatarust-analyzer cargo bottom 0.14.9 collection/temperature/TempSensorData#>>> {
395 let mut results = hwmon_temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/hwmon_temperatures().(filter, graph_filter);
396
397 if results.num_hwmonrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#num_hwmon. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
398 add_thermal_zone_temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/add_thermal_zone_temperatures().(&mut results.temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#temperatures., filter, graph_filter);
399 }
400
401 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(results.temperaturesrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/HwmonResults#temperatures.))
402 }
403
404 #[cfg(test)]
405 mod testsrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/tests/ {
406 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#;
407
408 use superrust-analyzer cargo bottom 0.14.9 collection/temperature/linux/::finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().;
409
410 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
411 fn test_finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/tests/test_finalize_name().() {
412 let mut seen_names = 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().();
413
414 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
415 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(
416 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("hwmon".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
417 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sensor".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
418 &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
419 &mut seen_names
420 ),
421 "hwmon: Sensor"
422 );
423
424 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
425 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(
426 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("hwmon".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
427 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
428 &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
429 &mut seen_names
430 ),
431 "hwmon"
432 );
433
434 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
435 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(
436 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
437 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sensor".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
438 &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
439 &mut seen_names
440 ),
441 "test: Sensor"
442 );
443
444 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
445 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(
446 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("hwmon".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
447 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("sensor".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
448 &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()),
449 &mut seen_names
450 ),
451 "hwmon: Sensor (1)"
452 );
453
454 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
455 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), &mut seen_names),
456 "test"
457 );
458
459 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &mut seen_names), "Unknown");
460
461 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
462 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#("test".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), &mut seen_names),
463 "test (1)"
464 );
465
466 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
467 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &mut seen_names),
468 "Unknown (1)"
469 );
470
471 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
472 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Default]default().()), Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &mut seen_names),
473 "Unknown (2)"
474 );
475
476 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
477 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Default]default().()), &Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &mut seen_names),
478 "Unknown (3)"
479 );
480
481 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(
482 finalize_namerust-analyzer cargo bottom 0.14.9 collection/temperature/linux/finalize_name().(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, &Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::defaultrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Default]default().()), &mut seen_names),
483 "Unknown (4)"
484 );
485 }
486 }