CPUUsage / DiskIO / NetIO: add option waitTime

This commit is contained in:
李通洲
2024-10-22 11:08:44 +08:00
parent 40b8023ff9
commit c8521b55b9
12 changed files with 95 additions and 11 deletions
+18
View File
@@ -1181,6 +1181,12 @@
"description": "Display CPU usage per CPU logical core, instead of an average result",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). CPU usage = (inUseEnd - inUseStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1472,6 +1478,12 @@
"type": "boolean",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). Disk I/O = (totalBytesEnd - totalBytesStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
@@ -1841,6 +1853,12 @@
"type": "boolean",
"default": false
},
"waitTime": {
"type": "integer",
"description": "Wait time (in ms). Disk I/O = (totalBytesEnd - totalBytesStart) / waitTime",
"default": 200,
"minimum": 1
},
"key": {
"$ref": "#/$defs/key"
},
+24
View File
@@ -916,6 +916,14 @@
"type": "str"
}
},
{
"long": "diskio-wait-time",
"desc": "Set the wait time (in ms) when detecting disk usage",
"arg": {
"type": "num",
"default": 1000
}
},
{
"long": "physicaldisk-name-prefix",
"desc": "Show disks with given name prefix only",
@@ -1070,6 +1078,14 @@
"default": false
}
},
{
"long": "cpuusage-wait-time",
"desc": "Set the wait time (in ms) when detecting CPU usage",
"arg": {
"type": "num",
"default": 200
}
},
{
"long": "de-slow-version-detection",
"desc": "Set if DE version should be detected with slow operations",
@@ -1305,6 +1321,14 @@
"default": false
}
},
{
"long": "netio-wait-time",
"desc": "Set the wait time (in ms) when detecting network usage",
"arg": {
"type": "num",
"default": 1000
}
},
{
"long": "publicip-timeout",
"desc": "Time in milliseconds to wait for the public ip server to respond",
+3 -3
View File
@@ -13,7 +13,7 @@ void ffPrepareCPUUsage(void)
ffGetCpuUsageInfo(&cpuTimes1);
}
const char* ffGetCpuUsageResult(FFlist* result)
const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result)
{
const char* error = NULL;
if(cpuTimes1.elementSize == 0)
@@ -21,7 +21,7 @@ const char* ffGetCpuUsageResult(FFlist* result)
ffListInit(&cpuTimes1, sizeof(FFCpuUsageInfo));
error = ffGetCpuUsageInfo(&cpuTimes1);
if(error) return error;
ffTimeSleep(200);
ffTimeSleep(options->waitTime);
}
if(cpuTimes1.length == 0) return "No CPU cores found";
@@ -43,7 +43,7 @@ retry:
if (++retryCount <= 3)
{
ffListClear(&cpuTimes2);
ffTimeSleep(200);
ffTimeSleep(options->waitTime);
goto retry;
}
}
+1 -1
View File
@@ -8,4 +8,4 @@ typedef struct FFCpuUsageInfo {
} FFCpuUsageInfo;
const char* ffGetCpuUsageInfo(FFlist* cpuTimes);
const char* ffGetCpuUsageResult(FFlist* result); // list of double
const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result); // list of double
+2 -2
View File
@@ -41,9 +41,9 @@ const char* ffDetectDiskIO(FFlist* result, FFDiskIOOptions* options)
return "No physical disk found";
uint64_t time2 = ffTimeGetNow();
while (time2 - time1 < 1000)
while (time2 - time1 < options->waitTime)
{
ffTimeSleep((uint32_t) (1000 - (time2 - time1)));
ffTimeSleep((uint32_t) (options->waitTime - (time2 - time1)));
time2 = ffTimeGetNow();
}
+2 -2
View File
@@ -41,9 +41,9 @@ const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options)
return "No network interfaces found";
uint64_t time2 = ffTimeGetNow();
while (time2 - time1 < 1000)
while (time2 - time1 < options->waitTime)
{
ffTimeSleep((uint32_t) (1000 - (time2 - time1)));
ffTimeSleep((uint32_t) (options->waitTime - (time2 - time1)));
time2 = ffTimeGetNow();
}
+16 -3
View File
@@ -11,7 +11,7 @@
void ffPrintCPUUsage(FFCPUUsageOptions* options)
{
FF_LIST_AUTO_DESTROY percentages = ffListCreate(sizeof(double));
const char* error = ffGetCpuUsageResult(&percentages);
const char* error = ffGetCpuUsageResult(options, &percentages);
if(error)
{
@@ -111,6 +111,12 @@ bool ffParseCPUUsageCommandOptions(FFCPUUsageOptions* options, const char* key,
return true;
}
if (ffStrEqualsIgnCase(subKey, "wait-time"))
{
options->waitTime = ffOptionParseUInt32(key, value);
return true;
}
if (ffPercentParseCommandOptions(key, subKey, value, &options->percent))
return true;
@@ -136,6 +142,12 @@ void ffParseCPUUsageJsonObject(FFCPUUsageOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "waitTime"))
{
options->waitTime = (uint32_t) yyjson_get_uint(val);
continue;
}
if (ffPercentParseJsonObject(key, val, &options->percent))
continue;
@@ -156,10 +168,10 @@ void ffGenerateCPUUsageJsonConfig(FFCPUUsageOptions* options, yyjson_mut_doc* do
ffPercentGenerateJsonConfig(doc, module, defaultOptions.percent, options->percent);
}
void ffGenerateCPUUsageJsonResult(FF_MAYBE_UNUSED FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
void ffGenerateCPUUsageJsonResult(FFCPUUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY percentages = ffListCreate(sizeof(double));
const char* error = ffGetCpuUsageResult(&percentages);
const char* error = ffGetCpuUsageResult(options, &percentages);
if(error)
{
@@ -203,6 +215,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options)
ffOptionInitModuleArg(&options->moduleArgs, "󰓅");
options->separate = false;
options->percent = (FFColorRangeConfig) { 50, 80 };
options->waitTime = 200;
}
void ffDestroyCPUUsageOptions(FFCPUUsageOptions* options)
+1
View File
@@ -12,4 +12,5 @@ typedef struct FFCPUUsageOptions
bool separate;
FFColorRangeConfig percent;
uint32_t waitTime; // in ms
} FFCPUUsageOptions;
+13
View File
@@ -115,6 +115,12 @@ bool ffParseDiskIOCommandOptions(FFDiskIOOptions* options, const char* key, cons
return true;
}
if (ffStrEqualsIgnCase(subKey, "wait-time"))
{
options->waitTime = ffOptionParseUInt32(key, value);
return true;
}
return false;
}
@@ -143,6 +149,12 @@ void ffParseDiskIOJsonObject(FFDiskIOOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "waitTime"))
{
options->waitTime = (uint32_t) yyjson_get_uint(val);
continue;
}
ffPrintError(FF_DISKIO_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key);
}
}
@@ -222,6 +234,7 @@ void ffInitDiskIOOptions(FFDiskIOOptions* options)
ffStrbufInit(&options->namePrefix);
options->detectTotal = false;
options->waitTime = 1000;
}
void ffDestroyDiskIOOptions(FFDiskIOOptions* options)
+1
View File
@@ -10,5 +10,6 @@ typedef struct FFDiskIOOptions
FFModuleArgs moduleArgs;
FFstrbuf namePrefix;
uint32_t waitTime;
bool detectTotal;
} FFDiskIOOptions;
+13
View File
@@ -129,6 +129,12 @@ bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const
return true;
}
if (ffStrEqualsIgnCase(subKey, "wait-time"))
{
options->waitTime = ffOptionParseUInt32(key, value);
return true;
}
return false;
}
@@ -163,6 +169,12 @@ void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module)
continue;
}
if (ffStrEqualsIgnCase(key, "waitTime"))
{
options->waitTime = (uint32_t) yyjson_get_uint(val);
continue;
}
ffPrintError(FF_NETIO_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", key);
}
}
@@ -259,6 +271,7 @@ void ffInitNetIOOptions(FFNetIOOptions* options)
#endif
;
options->detectTotal = false;
options->waitTime = 1000;
}
void ffDestroyNetIOOptions(FFNetIOOptions* options)
+1
View File
@@ -10,6 +10,7 @@ typedef struct FFNetIOOptions
FFModuleArgs moduleArgs;
FFstrbuf namePrefix;
uint32_t waitTime;
bool defaultRouteOnly;
bool detectTotal;
} FFNetIOOptions;