@@ -32,8 +32,9 @@ use std::fs::File;
3232use std:: io:: { BufRead , BufReader } ;
3333use std:: ops:: Sub ;
3434use std:: path:: { Path , PathBuf } ;
35+ use utoipa:: ToSchema ;
3536
36- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
37+ #[ derive( Debug , Clone , Serialize , Deserialize , ToSchema ) ]
3738pub enum CpuSetCGroup {
3839 V1 ( CpuSetCGroupV1 ) ,
3940 V2 ( CpuSetCGroupV2 ) ,
@@ -89,7 +90,7 @@ pub fn new_cpuset_cgroup(
8990 }
9091}
9192
92- #[ derive( Debug , Clone , Serialize , Deserialize , Default ) ]
93+ #[ derive( Debug , Clone , Serialize , Deserialize , Default , ToSchema ) ]
9394pub struct CpuSetCGroupV2 {
9495 full_path : PathBuf ,
9596 pub ( crate ) mems : NodeVec ,
@@ -154,7 +155,7 @@ impl CpuSetCGroupV2 {
154155 }
155156}
156157
157- #[ derive( Debug , Clone , Serialize , Deserialize , Default ) ]
158+ #[ derive( Debug , Clone , Serialize , Deserialize , Default , ToSchema ) ]
158159pub struct CpuSetCGroupV1 {
159160 full_path : PathBuf ,
160161 pub ( crate ) mems : NodeVec ,
@@ -222,7 +223,7 @@ impl CpuSetCGroupV1 {
222223 }
223224}
224225
225- #[ derive( Clone , Debug , Copy , Eq , PartialEq , Deserialize , Serialize ) ]
226+ #[ derive( Clone , Debug , Copy , Eq , PartialEq , Deserialize , Serialize , ToSchema ) ]
226227pub struct CpuCGroupBasicInfo {
227228 cpu_usage : u64 , // unit: ns
228229 cpu_user_time : u64 , // unit: ns
@@ -266,7 +267,7 @@ impl Sub for CpuCGroupBasicInfo {
266267 }
267268}
268269
269- #[ derive( Debug , Clone , Serialize , Deserialize ) ]
270+ #[ derive( Debug , Clone , Serialize , Deserialize , ToSchema ) ]
270271pub enum CpuCGroup {
271272 V1 ( CpuCGroupV1 ) ,
272273 V2 ( CpuCGroupV2 ) ,
@@ -321,7 +322,7 @@ pub fn new_cpu_cgroup(mount_point: &str, user_path: &Path, cgroup_type: CGroupTy
321322 }
322323}
323324
324- #[ derive( Clone , Debug , Deserialize , Serialize , Default ) ]
325+ #[ derive( Clone , Debug , Deserialize , Serialize , Default , ToSchema ) ]
325326pub struct CpuCGroupV2 {
326327 full_path : PathBuf ,
327328 user_path : PathBuf ,
@@ -348,7 +349,7 @@ pub struct CpuCGroupV2 {
348349 imc_writes : u64 ,
349350}
350351
351- #[ derive( Debug , Clone , Serialize , Deserialize , Default , PartialEq , Eq ) ]
352+ #[ derive( Debug , Clone , Serialize , Deserialize , Default , PartialEq , Eq , ToSchema ) ]
352353pub struct CpuStatsV2 {
353354 usage_usec : u64 ,
354355 user_usec : u64 ,
@@ -559,7 +560,7 @@ impl CpuCGroupV2 {
559560 }
560561}
561562
562- #[ derive( Clone , Debug , Deserialize , Serialize , Default ) ]
563+ #[ derive( Clone , Debug , Deserialize , Serialize , Default , ToSchema ) ]
563564pub struct CpuCGroupV1 {
564565 full_path : PathBuf ,
565566 user_path : PathBuf ,
@@ -578,6 +579,8 @@ pub struct CpuCGroupV1 {
578579 cpu_user_usage_ratio : f32 ,
579580 cpu_sys_usage_ratio : f32 ,
580581
582+ percpu_usage : Vec < u64 > ,
583+
581584 cpu_nr_throttled : Option < u64 > ,
582585 cpu_nr_periods : Option < u64 > ,
583586 cpu_throttled_time : Option < u64 > ,
@@ -718,6 +721,18 @@ impl CpuCGroupV1 {
718721 Ok ( true )
719722 }
720723
724+ pub fn update_percpu_usage ( & mut self ) -> common:: Result < bool > {
725+ let mut path = PathBuf :: from ( & self . full_path ) ;
726+ path. push ( "cpuacct.usage_percpu" ) ;
727+ let contents = fs:: read_to_string ( & path) ?;
728+ self . percpu_usage = contents
729+ . split_whitespace ( )
730+ . map ( |x| x. parse :: < u64 > ( ) . unwrap ( ) )
731+ . collect ( ) ;
732+
733+ Ok ( true )
734+ }
735+
721736 pub fn update ( & mut self ) {
722737 if let Err ( e) = self . update_period_us ( ) {
723738 warn ! (
@@ -754,6 +769,13 @@ impl CpuCGroupV1 {
754769 self . full_path. display( )
755770 ) ;
756771 }
772+ if let Err ( e) = self . update_percpu_usage ( ) {
773+ warn ! (
774+ "[cpucg] update percpu usage error: {}, path= {}" ,
775+ e,
776+ self . full_path. display( )
777+ ) ;
778+ }
757779 self . update_time = get_secs_since_epoch ( )
758780 }
759781
0 commit comments