1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
use std::io;
use std::num::ParseIntError;

use Pid;


quick_error! {
    #[derive(Debug)]
    /// Error reading or parsing /proc/uptime
    pub enum UptimeError {
        Io(err: io::Error) {
            description("IO error")
            display("{}", err)
            from()
        }
        ParseInt(e: ParseIntError) {
            description("error parsing int")
            display("error parsing int: {}", e)
            from()
        }
        BadFormat {
            description("bad format")
        }
    }
}

quick_error! {
    #[derive(Debug)]
    /// Error reading or parsing /proc/self/stat or /proc/self/task/<TID>/stat
    pub enum StatError {
        Io(err: io::Error) {
            description("IO error")
            display("{}", err)
            from()
        }
        ParseInt(e: ParseIntError) {
            description("error parsing int")
            display("error parsing int: {}", e)
            from()
        }
        BadFormat {
            description("bad format")
        }
    }
}

quick_error! {
    #[derive(Debug)]
    /// Error reading or parsing /proc/self/io
    pub enum IoStatError {
        Io(err: io::Error) {
            description("IO error")
            display("{}", err)
            from()
        }
        ParseInt(e: ParseIntError) {
            description("error parsing int")
            display("error parsing int: {}", e)
            from()
        }
    }
}

quick_error! {
    #[derive(Debug)]
    /// Error reading or parsing /proc/self/status
    pub enum StatusError {
        Io(err: io::Error) {
            description("IO error")
            display("{}", err)
            from()
        }
        ParseInt(e: ParseIntError) {
            description("error parsing int")
            display("error parsing int: {}", e)
            from()
        }
        BadUnit {
            description("bad unit in memory data")
        }
        BadFormat {
            description("bad format")
        }
    }
}


quick_error! {
    #[derive(Debug)]
    /// Error scanning process info in /proc
    pub enum Error {
        Cpu(err: io::Error) {
            description("Error reading /sys/devices/system/cpu")
            display("Error reading /sys/devices/system/cpu: {}", err)
            from()
        }
        Uptime(err: UptimeError) {
            description("Error reading /proc/uptime")
            display("Error reading /proc/uptime: {}", err)
            from()
        }
        Status(err: StatusError) {
            description("Error reading /proc/self/status")
            display("Error reading /proc/self/status: {}", err)
            from()
        }
        Stat(err: StatError) {
            description("Error reading /proc/self/stat")
            display("Error reading /proc/self/stat: {}", err)
        }
        ThreadStat(tid: Pid, err: StatError) {
            description("Error reading /proc/self/task/<TID>/stat")
            display("Error reading /proc/self/task/{}/stat: {}", tid, err)
        }
        IoStat(err: IoStatError) {
            description("Error reading /proc/self/io")
            display("Error reading /proc/self/io: {}", err)
            from()
        }
    }
}