66#include "modules/cpu/cpu.h"
77#include "util/stringUtils.h"
88
9- #define FF_CPU_NUM_FORMAT_ARGS 10
9+ #define FF_CPU_NUM_FORMAT_ARGS 11
1010
1111static int sortCores (const FFCPUCore * a , const FFCPUCore * b )
1212{
@@ -17,13 +17,13 @@ void ffPrintCPU(FFCPUOptions* options)
1717{
1818 FFCPUResult cpu = {
1919 .temperature = FF_CPU_TEMP_UNSET ,
20- .frequencyMin = 0.0 / 0.0 ,
21- .frequencyMax = 0.0 / 0.0 ,
22- .frequencyBase = 0.0 / 0.0 ,
23- .frequencyBiosLimit = 0.0 / 0.0 ,
20+ .frequencyMin = 0.0 / 0.0 ,
21+ .frequencyMax = 0.0 / 0.0 ,
22+ .frequencyBase = 0.0 / 0.0 ,
23+ .frequencyBiosLimit = 0.0 / 0.0 ,
2424 .name = ffStrbufCreate (),
2525 .vendor = ffStrbufCreate (),
26- };
26+ . coresUtilizationRate = FF_CPU_UTILIZATION_RATE_UNSET };
2727
2828 const char * error = ffDetectCPU (options , & cpu );
2929
@@ -86,6 +86,12 @@ void ffPrintCPU(FFCPUOptions* options)
8686 ffTempsAppendNum (cpu .temperature , & str , options -> tempConfig , & options -> moduleArgs );
8787 }
8888
89+ if (cpu .coresUtilizationRate != FF_CPU_UTILIZATION_RATE_UNSET )
90+ {
91+ ffStrbufAppendS (& str , " - " );
92+ ffPercentAppendNum (& str , cpu .coresUtilizationRate , options -> percent , true, & options -> moduleArgs );
93+ }
94+
8995 ffStrbufPutTo (& str , stdout );
9096 }
9197 else
@@ -107,17 +113,18 @@ void ffPrintCPU(FFCPUOptions* options)
107113 FF_STRBUF_AUTO_DESTROY tempStr = ffStrbufCreate ();
108114 ffTempsAppendNum (cpu .temperature , & tempStr , options -> tempConfig , & options -> moduleArgs );
109115 FF_PRINT_FORMAT_CHECKED (FF_CPU_MODULE_NAME , 0 , & options -> moduleArgs , FF_PRINT_TYPE_DEFAULT , FF_CPU_NUM_FORMAT_ARGS , ((FFformatarg []){
110- {FF_FORMAT_ARG_TYPE_STRBUF , & cpu .name , "name" },
111- {FF_FORMAT_ARG_TYPE_STRBUF , & cpu .vendor , "vendor" },
112- {FF_FORMAT_ARG_TYPE_UINT16 , & cpu .coresPhysical , "cores-physical" },
113- {FF_FORMAT_ARG_TYPE_UINT16 , & cpu .coresLogical , "cores-logical" },
114- {FF_FORMAT_ARG_TYPE_UINT16 , & cpu .coresOnline , "cores-online" },
115- {FF_FORMAT_ARG_TYPE_STRING , freqBase , "freq-base" },
116- {FF_FORMAT_ARG_TYPE_STRING , freqMax , "freq-max" },
117- {FF_FORMAT_ARG_TYPE_STRBUF , & tempStr , "temperature" },
118- {FF_FORMAT_ARG_TYPE_STRBUF , & coreTypes , "core-types" },
119- {FF_FORMAT_ARG_TYPE_STRING , freqBioslimit , "freq-bios-limit" },
120- }));
116+ {FF_FORMAT_ARG_TYPE_STRBUF , & cpu .name , "name" },
117+ {FF_FORMAT_ARG_TYPE_STRBUF , & cpu .vendor , "vendor" },
118+ {FF_FORMAT_ARG_TYPE_UINT16 , & cpu .coresPhysical , "cores-physical" },
119+ {FF_FORMAT_ARG_TYPE_UINT16 , & cpu .coresLogical , "cores-logical" },
120+ {FF_FORMAT_ARG_TYPE_UINT16 , & cpu .coresOnline , "cores-online" },
121+ {FF_FORMAT_ARG_TYPE_DOUBLE , & cpu .coresUtilizationRate , "cores-utilization-rate" },
122+ {FF_FORMAT_ARG_TYPE_STRING , freqBase , "freq-base" },
123+ {FF_FORMAT_ARG_TYPE_STRING , freqMax , "freq-max" },
124+ {FF_FORMAT_ARG_TYPE_STRBUF , & tempStr , "temperature" },
125+ {FF_FORMAT_ARG_TYPE_STRBUF , & coreTypes , "core-types" },
126+ {FF_FORMAT_ARG_TYPE_STRING , freqBioslimit , "freq-bios-limit" },
127+ }));
121128 }
122129 }
123130
@@ -230,6 +237,7 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
230237 yyjson_mut_obj_add_uint (doc , cores , "physical" , cpu .coresPhysical );
231238 yyjson_mut_obj_add_uint (doc , cores , "logical" , cpu .coresLogical );
232239 yyjson_mut_obj_add_uint (doc , cores , "online" , cpu .coresOnline );
240+ yyjson_mut_obj_add_real (doc , cores , "utilizationRate" , cpu .coresUtilizationRate );
233241
234242 yyjson_mut_val * frequency = yyjson_mut_obj_add_obj (doc , obj , "frequency" );
235243 yyjson_mut_obj_add_real (doc , frequency , "base" , cpu .frequencyBase );
@@ -254,18 +262,19 @@ void ffGenerateCPUJsonResult(FFCPUOptions* options, yyjson_mut_doc* doc, yyjson_
254262
255263void ffPrintCPUHelpFormat (void )
256264{
257- FF_PRINT_MODULE_FORMAT_HELP_CHECKED (FF_CPU_MODULE_NAME , "{1} ({5}) @ {7} GHz" , FF_CPU_NUM_FORMAT_ARGS , ((const char * []) {
258- "Name - name" ,
259- "Vendor - vendor" ,
260- "Physical core count - cores-physical" ,
261- "Logical core count - cores-logical" ,
262- "Online core count - cores-online" ,
263- "Base frequency - freq-base" ,
264- "Max frequency - freq-max" ,
265- "Temperature (formatted) - temperature" ,
266- "Logical core count grouped by frequency - core-types" ,
267- "Bios limited frequency - freq-bios-limit" ,
268- }));
265+ FF_PRINT_MODULE_FORMAT_HELP_CHECKED (FF_CPU_MODULE_NAME , "{1} ({5}) @ {7} GHz" , FF_CPU_NUM_FORMAT_ARGS , ((const char * []){
266+ "Name - name" ,
267+ "Vendor - vendor" ,
268+ "Physical core count - cores-physical" ,
269+ "Logical core count - cores-logical" ,
270+ "Online core count - cores-online" ,
271+ "Utilization rate - cores-utilization-rate" ,
272+ "Base frequency - freq-base" ,
273+ "Max frequency - freq-max" ,
274+ "Temperature (formatted) - temperature" ,
275+ "Logical core count grouped by frequency - core-types" ,
276+ "Bios limited frequency - freq-bios-limit" ,
277+ }));
269278}
270279
271280void ffInitCPUOptions (FFCPUOptions * options )
0 commit comments