Global: refactor code of -h <module>-format

This commit is contained in:
李通洲
2024-12-11 10:47:02 +08:00
parent e45ff546ed
commit 9a36d63d18
78 changed files with 1454 additions and 1872 deletions
+22 -27
View File
@@ -6,7 +6,6 @@
#include "util/stringUtils.h"
#define FF_DISKIO_DISPLAY_NAME "Disk IO"
#define FF_DISKIO_NUM_FORMAT_ARGS 8
static int sortDevices(const FFDiskIOResult* left, const FFDiskIOResult* right)
{
@@ -22,7 +21,7 @@ static void formatKey(const FFDiskIOOptions* options, FFDiskIOResult* dev, uint3
else
{
ffStrbufClear(key);
FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, 4, ((FFformatarg[]){
FF_PARSE_FORMAT_STRING_CHECKED(key, &options->moduleArgs.key, ((FFformatarg[]){
FF_FORMAT_ARG(index, "index"),
FF_FORMAT_ARG(dev->name, "name"),
FF_FORMAT_ARG(dev->devPath, "dev-path"),
@@ -75,7 +74,7 @@ void ffPrintDiskIO(FFDiskIOOptions* options)
ffParseSize(dev->bytesWritten, &buffer2);
if (!options->detectTotal) ffStrbufAppendS(&buffer, "/s");
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_DISKIO_NUM_FORMAT_ARGS, ((FFformatarg[]){
FF_PRINT_FORMAT_CHECKED(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, ((FFformatarg[]){
FF_FORMAT_ARG(buffer, "size-read"),
FF_FORMAT_ARG(buffer2, "size-written"),
FF_FORMAT_ARG(dev->name, "name"),
@@ -203,33 +202,29 @@ void ffGenerateDiskIOJsonResult(FFDiskIOOptions* options, yyjson_mut_doc* doc, y
}
}
void ffPrintDiskIOHelpFormat(void)
{
FF_PRINT_MODULE_FORMAT_HELP_CHECKED(FF_DISKIO_MODULE_NAME, "{1} (R) - {2} (W)", FF_DISKIO_NUM_FORMAT_ARGS, ((const char* []) {
"Size of data read [per second] (formatted) - size-read",
"Size of data written [per second] (formatted) - size-written",
"Device name - name",
"Device raw file path - dev-path",
"Size of data read [per second] (in bytes) - bytes-read",
"Size of data written [per second] (in bytes) - bytes-written",
"Number of reads - read-count",
"Number of writes - write-count",
}));
}
static FFModuleBaseInfo ffModuleInfo = {
.name = FF_DISKIO_MODULE_NAME,
.description = "Print physical disk I/O throughput",
.parseCommandOptions = (void*) ffParseDiskIOCommandOptions,
.parseJsonObject = (void*) ffParseDiskIOJsonObject,
.printModule = (void*) ffPrintDiskIO,
.generateJsonResult = (void*) ffGenerateDiskIOJsonResult,
.generateJsonConfig = (void*) ffGenerateDiskIOJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{"Size of data read [per second] (formatted)", "size-read"},
{"Size of data written [per second] (formatted)", "size-written"},
{"Device name", "name"},
{"Device raw file path", "dev-path"},
{"Size of data read [per second] (in bytes)", "bytes-read"},
{"Size of data written [per second] (in bytes)", "bytes-written"},
{"Number of reads", "read-count"},
{"Number of writes", "write-count"},
}))
};
void ffInitDiskIOOptions(FFDiskIOOptions* options)
{
ffOptionInitModuleBaseInfo(
&options->moduleInfo,
FF_DISKIO_MODULE_NAME,
"Print physical disk I/O throughput",
ffParseDiskIOCommandOptions,
ffParseDiskIOJsonObject,
ffPrintDiskIO,
ffGenerateDiskIOJsonResult,
ffPrintDiskIOHelpFormat,
ffGenerateDiskIOJsonConfig
);
options->moduleInfo = ffModuleInfo;
ffOptionInitModuleArg(&options->moduleArgs, "󰓅");
ffStrbufInit(&options->namePrefix);