/rust/registry/src/index.crates.io-1949cf8c6b5b557f/num_threads-0.1.7/src/linux.rs
Line | Count | Source |
1 | | use std::fs; |
2 | | use std::num::NonZeroUsize; |
3 | | |
4 | 0 | pub(crate) fn num_threads() -> Option<NonZeroUsize> { |
5 | 0 | fs::read_to_string("/proc/self/stat") |
6 | 0 | .ok() |
7 | 0 | .as_ref() |
8 | | // Skip past the pid and (process name) fields |
9 | 0 | .and_then(|stat| stat.rsplit(')').next()) |
10 | | // 20th field, less the two we skipped |
11 | 0 | .and_then(|rstat| rstat.split_whitespace().nth(17)) |
12 | 0 | .and_then(|num_threads| num_threads.parse::<usize>().ok()) |
13 | 0 | .and_then(NonZeroUsize::new) |
14 | 0 | } |