NetUsage: rename to NetIO

This commit is contained in:
李通洲
2023-09-27 00:05:37 +08:00
parent 3866f27448
commit 154657b455
26 changed files with 102 additions and 102 deletions
+2 -2
View File
@@ -60,8 +60,8 @@ void ffPrepareCommandOption(FFdata* data)
if(ffStrbufContainIgnCaseS(&data->structure, FF_CPUUSAGE_MODULE_NAME))
ffPrepareCPUUsage();
if(ffStrbufContainIgnCaseS(&data->structure, FF_NETUSAGE_MODULE_NAME))
ffPrepareNetUsage(&instance.config.netUsage);
if(ffStrbufContainIgnCaseS(&data->structure, FF_NETIO_MODULE_NAME))
ffPrepareNetIO(&instance.config.netIo);
if(instance.config.multithreading)
{
+2 -2
View File
@@ -106,7 +106,7 @@ static void defaultConfig(void)
ffInitMediaOptions(&instance.config.media);
ffInitMemoryOptions(&instance.config.memory);
ffInitMonitorOptions(&instance.config.monitor);
ffInitNetUsageOptions(&instance.config.netUsage);
ffInitNetIOOptions(&instance.config.netIo);
ffInitOSOptions(&instance.config.os);
ffInitOpenCLOptions(&instance.config.openCL);
ffInitOpenGLOptions(&instance.config.openGL);
@@ -320,7 +320,7 @@ static void destroyConfig(void)
ffDestroyMediaOptions(&instance.config.media);
ffDestroyMemoryOptions(&instance.config.memory);
ffDestroyMonitorOptions(&instance.config.monitor);
ffDestroyNetUsageOptions(&instance.config.netUsage);
ffDestroyNetIOOptions(&instance.config.netIo);
ffDestroyOSOptions(&instance.config.os);
ffDestroyOpenCLOptions(&instance.config.openCL);
ffDestroyOpenGLOptions(&instance.config.openGL);
+3 -3
View File
@@ -113,10 +113,10 @@ static void prepareModuleJsonObject(const char* type, yyjson_val* module)
break;
}
case 'n': case 'N': {
if (ffStrEqualsIgnCase(type, FF_NETUSAGE_MODULE_NAME))
if (ffStrEqualsIgnCase(type, FF_NETIO_MODULE_NAME))
{
if (module) ffParseNetUsageJsonObject(&cfg->netUsage, module);
ffPrepareNetUsage(&cfg->netUsage);
if (module) ffParseNetIOJsonObject(&cfg->netIo, module);
ffPrepareNetIO(&cfg->netIo);
}
break;
}
+1 -1
View File
@@ -82,7 +82,7 @@ static FFModuleBaseInfo* M[] = {
};
static FFModuleBaseInfo* N[] = {
(void*) &instance.config.netUsage,
(void*) &instance.config.netIo,
NULL,
};
+3 -3
View File
@@ -370,7 +370,7 @@
#--lm-key LM
#--locale-key Locale
#--localip-key Local IP ({1})
#--netusage-key Net Usage ({1})
#--netio-key Network IO ({1})
#--publicip-key Public IP
#--wifi-key Wifi
#--weather-key Weather
@@ -423,7 +423,7 @@
#--lm-format
#--locale-format
#--localip-format
#--netusage-format
#--netio-format
#--publicip-format
#--weather-format
#--monitor-format
@@ -473,7 +473,7 @@
#--lm-key-color
#--locale-key-color
#--localip-key-color
#--netusage-key-color
#--netio-key-color
#--publicip-key-color
#--weather-key-color
#--monitor-key-color
+2 -2
View File
@@ -150,8 +150,8 @@ Module specific options:
--localip-name-prefix <str>: Show interfaces with given interface name prefix only. Default is empty
--localip-default-route-only <?value>: Show the interface that is used for default routing only. Default is false
--localip-compact <?value>: Show all IPs in one line. Default is false
--netusage-name-prefix <str>: Show interfaces with given name prefix only. Default is empty
--netusage-default-route-only <?value>: Show the interfac that is used for default routing only. Default is false
--netio-name-prefix <str>: Show interfaces with given name prefix only. Default is empty
--netio-default-route-only <?value>: Show the interfac that is used for default routing only. Default is false
--publicip-timeout: Time in milliseconds to wait for the public ip server to respond. Default is disabled (0)
--publicip-url: The URL of public IP detection server to be used.
--weather-location: Set the location to be used. It must be URI encoded (eg a whitespace must be encoded as `+`).
+1 -1
View File
@@ -130,7 +130,7 @@ const char* ffDetectGamepad(FFlist* devices /* List of FFGamepadDevice */)
if (hHidFile && HidD_GetProductString(hHidFile, displayName, sizeof(wchar_t) * 126))
ffStrbufSetWS(&device->name, displayName);
else
ffStrbufSetF(&device->name, "Unknown gamepad %4X-%4X", rdi.hid.dwVendorId, rdi.hid.dwProductId);
ffStrbufSetF(&device->name, "Unknown gamepad %4X-%4X", (unsigned) rdi.hid.dwVendorId, (unsigned) rdi.hid.dwProductId);
}
}
@@ -1,26 +1,26 @@
#include "netusage.h"
#include "netio.h"
#include "common/time.h"
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options);
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options);
static FFlist ioCounters1;
static uint64_t time1;
void ffPrepareNetUsage(FFNetUsageOptions* options)
void ffPrepareNetIO(FFNetIOOptions* options)
{
ffListInit(&ioCounters1, sizeof(FFNetUsageIoCounters));
ffNetUsageGetIoCounters(&ioCounters1, options);
ffListInit(&ioCounters1, sizeof(FFNetIOResult));
ffNetIOGetIoCounters(&ioCounters1, options);
time1 = ffTimeGetNow();
}
const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options)
const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options)
{
const char* error = NULL;
if (time1 == 0)
{
ffListInit(&ioCounters1, sizeof(FFNetUsageIoCounters));
error = ffNetUsageGetIoCounters(&ioCounters1, options);
ffListInit(&ioCounters1, sizeof(FFNetIOResult));
error = ffNetIOGetIoCounters(&ioCounters1, options);
if (error)
return error;
time1 = ffTimeGetNow();
@@ -36,7 +36,7 @@ const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options)
time2 = ffTimeGetNow();
}
error = ffNetUsageGetIoCounters(result, options);
error = ffNetIOGetIoCounters(result, options);
if (error)
return error;
@@ -45,13 +45,13 @@ const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options)
for (uint32_t i = 0; i < result->length; ++i)
{
FFNetUsageIoCounters* icPrev = (FFNetUsageIoCounters*)ffListGet(&ioCounters1, i);
FFNetUsageIoCounters* icCurr = (FFNetUsageIoCounters*)ffListGet(result, i);
FFNetIOResult* icPrev = (FFNetIOResult*)ffListGet(&ioCounters1, i);
FFNetIOResult* icCurr = (FFNetIOResult*)ffListGet(result, i);
if (!ffStrbufEqual(&icPrev->name, &icCurr->name))
return "Network interface name changed";
static_assert(sizeof(FFNetUsageIoCounters) - offsetof(FFNetUsageIoCounters, txBytes) == sizeof(uint64_t) * 8, "Unexpected struct FFNetUsageIoCounters layout");
for (size_t off = offsetof(FFNetUsageIoCounters, txBytes); off < sizeof(FFNetUsageIoCounters); off += sizeof(uint64_t))
static_assert(sizeof(FFNetIOResult) - offsetof(FFNetIOResult, txBytes) == sizeof(uint64_t) * 8, "Unexpected struct FFNetIOResult layout");
for (size_t off = offsetof(FFNetIOResult, txBytes); off < sizeof(FFNetIOResult); off += sizeof(uint64_t))
{
uint64_t* prevValue = (uint64_t*) ((uint8_t*) icPrev + off);
uint64_t* currValue = (uint64_t*) ((uint8_t*) icCurr + off);
@@ -1,6 +1,6 @@
#include "fastfetch.h"
typedef struct FFNetUsageIoCounters
typedef struct FFNetIOResult
{
FFstrbuf name;
bool defaultRoute;
@@ -12,6 +12,6 @@ typedef struct FFNetUsageIoCounters
uint64_t txErrors;
uint64_t rxDrops;
uint64_t txDrops;
} FFNetUsageIoCounters;
} FFNetIOResult;
const char* ffDetectNetUsage(FFlist* result, FFNetUsageOptions* options);
const char* ffDetectNetIO(FFlist* result, FFNetIOOptions* options);
@@ -1,4 +1,4 @@
#include "netusage.h"
#include "netio.h"
#include "common/io/io.h"
#include "common/netif/netif.h"
@@ -12,7 +12,7 @@
#include <sys/sysctl.h>
#include <sys/socket.h>
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
size_t bufSize = 0;
if (sysctl((int[]) { CTL_NET, PF_ROUTE, 0, 0, NET_RT_IFLIST2, 0 }, 6, NULL, &bufSize, 0, 0) < 0)
@@ -43,8 +43,8 @@ const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
if (options->namePrefix.length && strncmp(sdl->sdl_data, options->namePrefix.chars, options->namePrefix.length) != 0)
continue;
FFNetUsageIoCounters* counters = (FFNetUsageIoCounters*) ffListAdd(result);
*counters = (FFNetUsageIoCounters) {
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
*counters = (FFNetIOResult) {
.name = ffStrbufCreateNS(sdl->sdl_nlen, sdl->sdl_data),
.txBytes = ifm->ifm_data.ifi_obytes,
.rxBytes = ifm->ifm_data.ifi_ibytes,
@@ -1,4 +1,4 @@
#include "netusage.h"
#include "netio.h"
#include "common/io/io.h"
#include "common/netif/netif.h"
@@ -6,7 +6,7 @@
#include <net/if.h>
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
FF_AUTO_CLOSE_DIR DIR* dirp = opendir("/sys/class/net");
if (!dirp) return "opendir(\"/sys/class/net\") == NULL";
@@ -33,7 +33,7 @@ const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
if(!ffReadFileBuffer(path.chars, &buffer) || !ffStrbufEqualS(&buffer, "up"))
continue;
FFNetUsageIoCounters* counters = (FFNetUsageIoCounters*) ffListAdd(result);
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
ffStrbufInitS(&counters->name, entry->d_name);
counters->defaultRoute = isDefaultRoute;
@@ -1,4 +1,4 @@
#include "netusage.h"
#include "netio.h"
#include "common/netif/netif.h"
#include "util/mallocHelper.h"
@@ -7,7 +7,7 @@
#include <ws2tcpip.h>
#include <iphlpapi.h>
const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
const char* ffNetIOGetIoCounters(FFlist* result, FFNetIOOptions* options)
{
IP_ADAPTER_ADDRESSES* FF_AUTO_FREE adapter_addresses = NULL;
@@ -54,8 +54,8 @@ const char* ffNetUsageGetIoCounters(FFlist* result, FFNetUsageOptions* options)
MIB_IF_ROW2 ifRow = { .InterfaceIndex = adapter->IfIndex };
if (GetIfEntry2(&ifRow) == NO_ERROR)
{
FFNetUsageIoCounters* counters = (FFNetUsageIoCounters*) ffListAdd(result);
*counters = (FFNetUsageIoCounters) {
FFNetIOResult* counters = (FFNetIOResult*) ffListAdd(result);
*counters = (FFNetIOResult) {
.name = ffStrbufCreateS(name),
.txBytes = ifRow.OutOctets,
.rxBytes = ifRow.InOctets,
+2 -2
View File
@@ -397,9 +397,9 @@ static inline void printCommandHelp(const char* command)
"Public IP address"
);
}
else if(ffStrEqualsIgnCase(command, "netusage-format"))
else if(ffStrEqualsIgnCase(command, "netio-format"))
{
constructAndPrintCommandHelpFormat("netusage", "{}", 3,
constructAndPrintCommandHelpFormat("netio", "{}", 3,
"Size of data received per second (formatted)",
"Size of data sent per second (formatted)",
"Interface name",
+1 -1
View File
@@ -112,7 +112,7 @@ typedef struct FFconfig
FFMediaOptions media;
FFMemoryOptions memory;
FFMonitorOptions monitor;
FFNetUsageOptions netUsage;
FFNetIOOptions netIo;
FFOSOptions os;
FFOpenCLOptions openCL;
FFOpenGLOptions openGL;
+1 -1
View File
@@ -31,7 +31,7 @@
#include "modules/media/media.h"
#include "modules/memory/memory.h"
#include "modules/monitor/monitor.h"
#include "modules/netusage/netusage.h"
#include "modules/netio/netio.h"
#include "modules/opengl/opengl.h"
#include "modules/opencl/opencl.h"
#include "modules/os/os.h"
@@ -1,26 +1,26 @@
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "common/parsing.h"
#include "detection/netusage/netusage.h"
#include "modules/netusage/netusage.h"
#include "detection/netio/netio.h"
#include "modules/netio/netio.h"
#include "util/stringUtils.h"
#define FF_NETUSAGE_DISPLAY_NAME "Net Usage"
#define FF_NETUSAGE_NUM_FORMAT_ARGS 12
#define FF_NETIO_DISPLAY_NAME "Network IO"
#define FF_NETIO_NUM_FORMAT_ARGS 12
static int sortInfs(const FFNetUsageIoCounters* left, const FFNetUsageIoCounters* right)
static int sortInfs(const FFNetIOResult* left, const FFNetIOResult* right)
{
return ffStrbufComp(&left->name, &right->name);
}
static void formatKey(const FFNetUsageOptions* options, FFNetUsageIoCounters* inf, uint32_t index, FFstrbuf* key)
static void formatKey(const FFNetIOOptions* options, FFNetIOResult* inf, uint32_t index, FFstrbuf* key)
{
if(options->moduleArgs.key.length == 0)
{
if(!inf->name.length)
ffStrbufSetF(&inf->name, "unknown %u", (unsigned) index);
ffStrbufSetF(key, FF_NETUSAGE_DISPLAY_NAME " (%s)", inf->name.chars);
ffStrbufSetF(key, FF_NETIO_DISPLAY_NAME " (%s)", inf->name.chars);
}
else
{
@@ -32,14 +32,14 @@ static void formatKey(const FFNetUsageOptions* options, FFNetUsageIoCounters* in
}
}
void ffPrintNetUsage(FFNetUsageOptions* options)
void ffPrintNetIO(FFNetIOOptions* options)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetUsageIoCounters));
const char* error = ffDetectNetUsage(&result, options);
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult));
const char* error = ffDetectNetIO(&result, options);
if(error)
{
ffPrintError(FF_NETUSAGE_DISPLAY_NAME, 0, &options->moduleArgs, "%s", error);
ffPrintError(FF_NETIO_DISPLAY_NAME, 0, &options->moduleArgs, "%s", error);
return;
}
@@ -50,7 +50,7 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
FF_STRBUF_AUTO_DESTROY buffer = ffStrbufCreate();
FF_STRBUF_AUTO_DESTROY buffer2 = ffStrbufCreate();
FF_LIST_FOR_EACH(FFNetUsageIoCounters, inf, result)
FF_LIST_FOR_EACH(FFNetIOResult, inf, result)
{
formatKey(options, inf, result.length == 1 ? 0 : index + 1, &key);
ffStrbufClear(&buffer);
@@ -60,9 +60,9 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
ffPrintLogoAndKey(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
ffParseSize(inf->rxBytes, &buffer);
ffStrbufAppendS(&buffer, "/s (in) - ");
ffStrbufAppendS(&buffer, "/s (IN) - ");
ffParseSize(inf->txBytes, &buffer);
ffStrbufAppendS(&buffer, "/s (out)");
ffStrbufAppendS(&buffer, "/s (OUT)");
if (!options->defaultRouteOnly && inf->defaultRoute)
ffStrbufAppendS(&buffer, " *");
ffStrbufPutTo(&buffer, stdout);
@@ -75,7 +75,7 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
ffParseSize(inf->txBytes, &buffer2);
ffStrbufAppendS(&buffer2, "/s");
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETUSAGE_NUM_FORMAT_ARGS, (FFformatarg[]){
ffPrintFormatString(key.chars, 0, &options->moduleArgs, FF_PRINT_TYPE_NO_CUSTOM_KEY, FF_NETIO_NUM_FORMAT_ARGS, (FFformatarg[]){
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer},
{FF_FORMAT_ARG_TYPE_STRBUF, &buffer2},
{FF_FORMAT_ARG_TYPE_STRBUF, &inf->name},
@@ -93,24 +93,24 @@ void ffPrintNetUsage(FFNetUsageOptions* options)
++index;
}
FF_LIST_FOR_EACH(FFNetUsageIoCounters, inf, result)
FF_LIST_FOR_EACH(FFNetIOResult, inf, result)
{
ffStrbufDestroy(&inf->name);
}
}
void ffInitNetUsageOptions(FFNetUsageOptions* options)
void ffInitNetIOOptions(FFNetIOOptions* options)
{
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETUSAGE_MODULE_NAME, ffParseNetUsageCommandOptions, ffParseNetUsageJsonObject, ffPrintNetUsage, ffGenerateNetUsageJson);
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_NETIO_MODULE_NAME, ffParseNetIOCommandOptions, ffParseNetIOJsonObject, ffPrintNetIO, ffGenerateNetIOJson);
ffOptionInitModuleArg(&options->moduleArgs);
ffStrbufInit(&options->namePrefix);
options->defaultRouteOnly = false;
}
bool ffParseNetUsageCommandOptions(FFNetUsageOptions* options, const char* key, const char* value)
bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const char* value)
{
const char* subKey = ffOptionTestPrefix(key, FF_NETUSAGE_MODULE_NAME);
const char* subKey = ffOptionTestPrefix(key, FF_NETIO_MODULE_NAME);
if (!subKey) return false;
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
return true;
@@ -130,13 +130,13 @@ bool ffParseNetUsageCommandOptions(FFNetUsageOptions* options, const char* key,
return false;
}
void ffDestroyNetUsageOptions(FFNetUsageOptions* options)
void ffDestroyNetIOOptions(FFNetIOOptions* options)
{
ffOptionDestroyModuleArg(&options->moduleArgs);
ffStrbufDestroy(&options->namePrefix);
}
void ffParseNetUsageJsonObject(FFNetUsageOptions* options, yyjson_val* module)
void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module)
{
yyjson_val *key_, *val;
size_t idx, max;
@@ -161,14 +161,14 @@ void ffParseNetUsageJsonObject(FFNetUsageOptions* options, yyjson_val* module)
continue;
}
ffPrintError(FF_NETUSAGE_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
ffPrintError(FF_NETIO_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
}
}
void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
void ffGenerateNetIOJson(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module)
{
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetUsageIoCounters));
const char* error = ffDetectNetUsage(&result, options);
FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNetIOResult));
const char* error = ffDetectNetIO(&result, options);
if(error)
{
@@ -177,7 +177,7 @@ void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyj
}
yyjson_mut_val* arr = yyjson_mut_obj_add_arr(doc, module, "result");
FF_LIST_FOR_EACH(FFNetUsageIoCounters, counter, result)
FF_LIST_FOR_EACH(FFNetIOResult, counter, result)
{
yyjson_mut_val* obj = yyjson_mut_arr_add_obj(doc, arr);
yyjson_mut_obj_add_strbuf(doc, obj, "name", &counter->name);
@@ -192,7 +192,7 @@ void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyj
yyjson_mut_obj_add_uint(doc, obj, "txDrops", counter->txDrops);
}
FF_LIST_FOR_EACH(FFNetUsageIoCounters, inf, result)
FF_LIST_FOR_EACH(FFNetIOResult, inf, result)
{
ffStrbufDestroy(&inf->name);
}
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include "fastfetch.h"
#define FF_NETIO_MODULE_NAME "NetIO"
void ffPrepareNetIO(FFNetIOOptions* options);
void ffPrintNetIO(FFNetIOOptions* options);
void ffInitNetIOOptions(FFNetIOOptions* options);
bool ffParseNetIOCommandOptions(FFNetIOOptions* options, const char* key, const char* value);
void ffDestroyNetIOOptions(FFNetIOOptions* options);
void ffParseNetIOJsonObject(FFNetIOOptions* options, yyjson_val* module);
void ffGenerateNetIOJson(FFNetIOOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
@@ -4,11 +4,11 @@
#include "common/option.h"
typedef struct FFNetUsageOptions
typedef struct FFNetIOOptions
{
FFModuleBaseInfo moduleInfo;
FFModuleArgs moduleArgs;
FFstrbuf namePrefix;
bool defaultRouteOnly;
} FFNetUsageOptions;
} FFNetIOOptions;
-14
View File
@@ -1,14 +0,0 @@
#pragma once
#include "fastfetch.h"
#define FF_NETUSAGE_MODULE_NAME "NetUsage"
void ffPrepareNetUsage(FFNetUsageOptions* options);
void ffPrintNetUsage(FFNetUsageOptions* options);
void ffInitNetUsageOptions(FFNetUsageOptions* options);
bool ffParseNetUsageCommandOptions(FFNetUsageOptions* options, const char* key, const char* value);
void ffDestroyNetUsageOptions(FFNetUsageOptions* options);
void ffParseNetUsageJsonObject(FFNetUsageOptions* options, yyjson_val* module);
void ffGenerateNetUsageJson(FFNetUsageOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);
+1 -1
View File
@@ -31,7 +31,7 @@
#include "modules/media/option.h"
#include "modules/memory/option.h"
#include "modules/monitor/option.h"
#include "modules/netusage/option.h"
#include "modules/netio/option.h"
#include "modules/opengl/option.h"
#include "modules/opencl/option.h"
#include "modules/os/option.h"