File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,10 +13,11 @@ pub enum Verdict {
1313 IdleTimeLimitExceeded ,
1414}
1515
16+ #[ derive( Debug ) ]
1617pub struct Metrics {
1718 pub verdict : Verdict ,
1819 pub run_time : Duration ,
20+ pub memory_usage : Byte ,
1921 pub stdout : String ,
2022 pub stderr : String ,
21- pub memory : Byte ,
2223}
Original file line number Diff line number Diff line change 11use std:: time:: Duration ;
22
3- use cgroups_rs:: fs:: { Cgroup , cpu:: CpuController } ;
3+ use byte_unit:: Byte ;
4+ use cgroups_rs:: fs:: { Cgroup , cpu:: CpuController , memory:: MemController } ;
45
56const CPU_USAGE_PREFIX : & str = "usage_usec " ;
67
78pub trait CgroupExt {
89 fn get_cpu_time ( & self ) -> Duration ;
10+ fn get_memory_usage ( & self ) -> Byte ;
11+ fn get_memory_limit ( & self ) -> Byte ;
912}
1013
1114impl CgroupExt for Cgroup {
@@ -22,4 +25,20 @@ impl CgroupExt for Cgroup {
2225 let usage = usage. parse ( ) . unwrap ( ) ;
2326 Duration :: from_micros ( usage)
2427 }
28+
29+ fn get_memory_usage ( & self ) -> Byte {
30+ // SAFETY: there must be memory controller for cgroup v2
31+ let memory_controller: & MemController = self . controller_of ( ) . unwrap ( ) ;
32+ let stats = memory_controller. memory_stat ( ) ;
33+
34+ Byte :: from_u64 ( stats. usage_in_bytes )
35+ }
36+
37+ fn get_memory_limit ( & self ) -> Byte {
38+ // SAFETY: there must be memory controller for cgroup v2
39+ let memory_controller: & MemController = self . controller_of ( ) . unwrap ( ) ;
40+ let stats = memory_controller. memory_stat ( ) ;
41+
42+ Byte :: from_u64 ( stats. limit_in_bytes . max ( 0 ) as u64 )
43+ }
2544}
You can’t perform that action at this time.
0 commit comments