Top: adds thread count detection

This commit is contained in:
李通洲
2026-08-31 20:27:22 +08:00
parent 6eef800ea2
commit 4ff931c06f
15 changed files with 113 additions and 33 deletions
+1
View File
@@ -9,6 +9,7 @@ typedef enum FFTopTypes: uint8_t {
FF_TOP_TYPE_DISK_READ = 1 << 2,
FF_TOP_TYPE_DISK_WRITE = 1 << 3,
FF_TOP_TYPE_START_TIME = 1 << 4,
FF_TOP_TYPE_THREADS = 1 << 5,
FF_TOP_TYPE_DISK = FF_TOP_TYPE_DISK_READ | FF_TOP_TYPE_DISK_WRITE,
} FFTopTypes;
+29 -14
View File
@@ -28,6 +28,9 @@ static void printTopResult(FFTopOptions* options, uint32_t index, uint32_t total
ffSizeAppendNum(process->bytesWritten, &output);
ffStrbufAppendS(&output, "/s");
}
if (options->showTypes & FF_TOP_TYPE_THREADS) {
ffStrbufAppendF(&output, " - THR %u", process->threads);
}
}
ffStrbufPutTo(&output, stdout);
} else {
@@ -44,17 +47,18 @@ static void printTopResult(FFTopOptions* options, uint32_t index, uint32_t total
ffSizeAppendNum(process->bytesWritten, &diskWriteFormatted);
ffStrbufAppendS(&diskWriteFormatted, "/s");
FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(Top), total == 1 ? 0 : (uint8_t) (index + 1), &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]){
FF_ARG(process->name, "name"),
FF_ARG(process->pid, "pid"),
FF_ARG(process->cpuPercent, "cpu"),
FF_ARG(process->memBytes, "mem"),
FF_ARG(process->bytesRead, "disk-read"),
FF_ARG(process->bytesWritten, "disk-write"),
FF_ARG(cpuFormatted, "cpu-percentage"),
FF_ARG(memFormatted, "mem-formatted"),
FF_ARG(diskReadFormatted, "disk-read-formatted"),
FF_ARG(diskWriteFormatted, "disk-write-formatted"),
}));
FF_ARG(process->name, "name"),
FF_ARG(process->pid, "pid"),
FF_ARG(process->cpuPercent, "cpu"),
FF_ARG(process->memBytes, "mem"),
FF_ARG(process->bytesRead, "disk-read"),
FF_ARG(process->bytesWritten, "disk-write"),
FF_ARG(process->threads, "threads"),
FF_ARG(cpuFormatted, "cpu-percentage"),
FF_ARG(memFormatted, "mem-formatted"),
FF_ARG(diskReadFormatted, "disk-read-formatted"),
FF_ARG(diskWriteFormatted, "disk-write-formatted"),
}));
}
}
@@ -121,6 +125,7 @@ void ffParseTopJsonObject(FFTopOptions* options, yyjson_val* module) {
{ "cpu", FF_TOP_TYPE_CPU },
{ "memory", FF_TOP_TYPE_MEMORY },
{ "disk", FF_TOP_TYPE_DISK },
{ "threads", FF_TOP_TYPE_THREADS },
{},
});
if (error == nullptr) {
@@ -138,6 +143,7 @@ void ffParseTopJsonObject(FFTopOptions* options, yyjson_val* module) {
{ "cpu", FF_TOP_TYPE_CPU },
{ "memory", FF_TOP_TYPE_MEMORY },
{ "disk", FF_TOP_TYPE_DISK },
{ "threads", FF_TOP_TYPE_THREADS },
{},
});
if (error == nullptr) {
@@ -175,6 +181,9 @@ void ffGenerateTopJsonConfig(FFTopOptions* options, yyjson_mut_doc* doc, yyjson_
if (options->showTypes & FF_TOP_TYPE_DISK) {
yyjson_mut_arr_add_str(doc, showTypes, "disk");
}
if (options->showTypes & FF_TOP_TYPE_THREADS) {
yyjson_mut_arr_add_str(doc, showTypes, "threads");
}
yyjson_mut_obj_add_val(doc, module, "showTypes", showTypes);
if (options->sort == FF_TOP_TYPE_CPU) {
yyjson_mut_obj_add_str(doc, module, "sort", "cpu");
@@ -186,6 +195,8 @@ void ffGenerateTopJsonConfig(FFTopOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_obj_add_str(doc, module, "sort", "disk-write");
} else if (options->sort == FF_TOP_TYPE_START_TIME) {
yyjson_mut_obj_add_str(doc, module, "sort", "start-time");
} else if (options->sort == FF_TOP_TYPE_THREADS) {
yyjson_mut_obj_add_str(doc, module, "sort", "threads");
}
yyjson_mut_obj_add_uint(doc, module, "processes", options->nProcesses);
yyjson_mut_obj_add_uint(doc, module, "waitTime", options->waitTime);
@@ -215,6 +226,9 @@ bool ffGenerateTopJsonResult(FFTopOptions* options, yyjson_mut_doc* doc, yyjson_
yyjson_mut_obj_add_uint(doc, item, "bytesRead", process->bytesRead);
yyjson_mut_obj_add_uint(doc, item, "bytesWritten", process->bytesWritten);
}
if (options->showTypes & FF_TOP_TYPE_THREADS) {
yyjson_mut_obj_add_uint(doc, item, "threads", process->threads);
}
yyjson_mut_obj_add_uint(doc, item, "startTime", process->startTime);
}
@@ -228,10 +242,10 @@ void ffInitTopOptions(FFTopOptions* options) {
ffOptionInitModuleArg(&options->moduleArgs, "󰍛");
options->sort = FF_TOP_TYPE_CPU;
options->showTypes = FF_TOP_TYPE_CPU | FF_TOP_TYPE_MEMORY
#if !__GNU__ && !__HAIKU__
#if !__GNU__ && !__HAIKU__
| FF_TOP_TYPE_DISK
#endif
;
#endif
;
options->nProcesses = 5;
options->waitTime = 500;
options->compact = false;
@@ -280,6 +294,7 @@ FFModuleBaseInfo ffTopModuleInfo = {
{ "Memory usage (RSS) in bytes", "mem" },
{ "Disk read bytes per second (0 if unsupported)", "disk-read" },
{ "Disk write bytes per second (0 if unsupported)", "disk-write" },
{ "Number of threads", "threads" },
{ "CPU usage percentage", "cpu-percentage" },
{ "Memory usage (RSS) formatted", "mem-formatted" },
{ "Disk read formatted", "disk-read-formatted" },