/// Read information from the filesystem and create a new `Stat`
Read information from the filesystem and create a new `Stat`
Read information from the filesystem and create a new ` Stat `
pub fn load() -> Result<Stat, io::Error> {
                    let contents = read_file("/sys/fs/cgroup/memory/memory.stat")?;
                    let mut fields: HashMap<String, usize> = HashMap::new();
                    let needed: HashSet<_> = ["cache", "rss", "rss_huge", "swap"]
                        .iter()
                        .cloned()
                        .collect();
                    let mut found = 0;
                    for line in contents.lines() {
                        let mut parts = line.split(' ');
                        let field = parts.next().unwrap();
                        let val = parts.next().unwrap();
                        if needed.contains(&field) {
                            fields.insert(field.to_owned(), val.parse().unwrap());
                            found += 1;
                            if found >= 4 {
                                break;
                            }
                        }
                    }
                    Ok(Stat {
                        cache: *fields.get("cache").unwrap(),
                        rss: *fields.get("rss").unwrap(),
                        rss_huge: *fields.get("rss_huge").unwrap(),
                        swap: *fields.get("swap").unwrap(),
                    })
                }
pub fn load ( ) -> Result < Stat , io :: Error > { let contents = read_file ( " " ) ? ; let mut fields : HashMap < String , usize > = HashMap :: new ( ) ; let needed : HashSet < _ > = [ " " , " " , " " , " " ] . iter ( ) . cloned ( ) . collect ( ) ; let mut found = 0 ; for line in contents . lines ( ) { let mut parts = line . split ( ' ' ) ; let field = parts . next ( ) . unwrap ( ) ; let val = parts . next ( ) . unwrap ( ) ; if needed . contains ( & field ) { fields . insert ( field . to_owned ( ) , val . parse ( ) . unwrap ( ) ) ; found += 1 ; if found >= 4 { break ; } } } Ok ( Stat { cache : * fields . get ( " " ) . unwrap ( ) , rss : * fields . get ( " " ) . unwrap ( ) , rss_huge : * fields . get ( " " ) . unwrap ( ) , swap : * fields . get ( " " ) . unwrap ( ) , } ) }
Read information from the filesystem and create a new `Stat`
Read information from the filesystem and create a new ` Stat `