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
/// Windows-specific extension to process [Memory] information.
///
/// Information here is provided by the [PROCESS_MEMORY_COUNTERS_EX] struct,
/// see its documentation for details.
///
/// [Memory]: ../../struct.Memory.html
/// [PROCESS_MEMORY_COUNTERS_EX]: https://docs.microsoft.com/en-us/windows/win32/api/psapi/ns-psapi-process_memory_counters_ex
pub trait MemoryExt {
    /// Returns the number of page faults.
    fn page_faults(&self) -> u32;

    /// Returns the the peak working set size.
    fn peak_working_set_size(&self) -> usize;

    /// Returns the current working set size.
    fn working_set_size(&self) -> usize;

    /// Returns the peak paged pool usage.
    fn quota_peak_paged_pool_usage(&self) -> usize;

    /// Returns the current paged pool usage.
    fn quota_paged_pool_usage(&self) -> usize;

    /// Returns the peak nonpaged pool usage.
    fn quota_peak_non_paged_pool_usage(&self) -> usize;

    /// Returns the current nonpaged pool usage.
    fn quota_non_paged_pool_usage(&self) -> usize;

    /// Returns the *Commit Charge* value in bytes.
    ///
    /// Commit Charge is the total amount of memory
    /// that the memory manager has committed for a running process.
    fn pagefile_usage(&self) -> usize;

    /// Returns the peak value in bytes of the *Commit Charge*
    /// during the lifetime of this process.
    fn peak_pagefile_usage(&self) -> usize;

    /// Same as [`pagefile_usage`](#tymethod.pagefile_usage).
    ///
    /// The *Commit Charge* value in bytes for this process.
    /// Commit Charge is the total amount of memory
    /// that the memory manager has committed for a running process.
    fn private_usage(&self) -> usize;
}

#[cfg(target_os = "windows")]
impl MemoryExt for crate::Memory {
    fn page_faults(&self) -> u32 {
        self.as_ref().page_faults()
    }

    fn peak_working_set_size(&self) -> usize {
        self.as_ref().peak_working_set_size()
    }

    fn working_set_size(&self) -> usize {
        self.as_ref().working_set_size()
    }

    fn quota_peak_paged_pool_usage(&self) -> usize {
        self.as_ref().quota_peak_paged_pool_usage()
    }

    fn quota_paged_pool_usage(&self) -> usize {
        self.as_ref().quota_paged_pool_usage()
    }

    fn quota_peak_non_paged_pool_usage(&self) -> usize {
        self.as_ref().quota_peak_non_paged_pool_usage()
    }

    fn quota_non_paged_pool_usage(&self) -> usize {
        self.as_ref().quota_non_paged_pool_usage()
    }

    fn pagefile_usage(&self) -> usize {
        self.as_ref().pagefile_usage()
    }

    fn peak_pagefile_usage(&self) -> usize {
        self.as_ref().peak_pagefile_usage()
    }

    fn private_usage(&self) -> usize {
        self.as_ref().private_usage()
    }
}