mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
Global: removes FFlist::elementSize
Improves performance of module Sound and PhysicalMemory
This commit is contained in:
@@ -8,19 +8,19 @@ static FFlist cpuTimes1;
|
||||
static uint64_t startTime;
|
||||
|
||||
void ffPrepareCPUUsage(void) {
|
||||
if (cpuTimes1.elementSize != 0) {
|
||||
if (startTime != 0) {
|
||||
return; // Already prepared
|
||||
}
|
||||
|
||||
ffListInit(&cpuTimes1, sizeof(FFCpuUsageInfo));
|
||||
ffListInit(&cpuTimes1);
|
||||
ffGetCpuUsageInfo(&cpuTimes1);
|
||||
startTime = ffTimeGetNow();
|
||||
}
|
||||
|
||||
const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result) {
|
||||
const char* error = NULL;
|
||||
if (cpuTimes1.elementSize == 0) {
|
||||
ffListInit(&cpuTimes1, sizeof(FFCpuUsageInfo));
|
||||
if (startTime == 0) {
|
||||
ffListInit(&cpuTimes1);
|
||||
error = ffGetCpuUsageInfo(&cpuTimes1);
|
||||
if (error) {
|
||||
return error;
|
||||
@@ -37,7 +37,7 @@ const char* ffGetCpuUsageResult(FFCPUUsageOptions* options, FFlist* result) {
|
||||
return "No CPU cores found";
|
||||
}
|
||||
|
||||
FF_LIST_AUTO_DESTROY cpuTimes2 = ffListCreate(sizeof(FFCpuUsageInfo));
|
||||
FF_LIST_AUTO_DESTROY cpuTimes2 = ffListCreate();
|
||||
uint32_t retryCount = 0;
|
||||
|
||||
retry:
|
||||
@@ -65,7 +65,7 @@ retry:
|
||||
for (uint32_t i = 0; i < cpuTimes1.length; ++i) {
|
||||
FFCpuUsageInfo* cpuTime1 = FF_LIST_GET(FFCpuUsageInfo, cpuTimes1, i);
|
||||
FFCpuUsageInfo* cpuTime2 = FF_LIST_GET(FFCpuUsageInfo, cpuTimes2, i);
|
||||
*(double*) ffListAdd(result) = (double) (cpuTime2->inUseAll - cpuTime1->inUseAll) / (double) (cpuTime2->totalAll - cpuTime1->totalAll) * 100;
|
||||
*FF_LIST_ADD(double, *result) = (double) (cpuTime2->inUseAll - cpuTime1->inUseAll) / (double) (cpuTime2->totalAll - cpuTime1->totalAll) * 100;
|
||||
cpuTime1->inUseAll = cpuTime2->inUseAll;
|
||||
cpuTime1->totalAll = cpuTime2->totalAll;
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
|
||||
integer_t inUse = cpuInfo[CPU_STATE_MAX * i + CPU_STATE_USER] + cpuInfo[CPU_STATE_MAX * i + CPU_STATE_SYSTEM] + cpuInfo[CPU_STATE_MAX * i + CPU_STATE_NICE];
|
||||
integer_t total = inUse + cpuInfo[CPU_STATE_MAX * i + CPU_STATE_IDLE];
|
||||
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
*info = (FFCpuUsageInfo) {
|
||||
.inUseAll = (uint64_t) inUse,
|
||||
.totalAll = (uint64_t) total,
|
||||
|
||||
@@ -47,7 +47,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
|
||||
uint64_t inUse = cpTime[CP_USER] + cpTime[CP_NICE] + cpTime[CP_SYS] + cpTime[CP_INTR];
|
||||
uint64_t total = inUse + cpTime[CP_IDLE];
|
||||
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
*info = (FFCpuUsageInfo) {
|
||||
.inUseAll = inUse,
|
||||
.totalAll = total,
|
||||
|
||||
@@ -18,7 +18,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
|
||||
uint64_t uptime = (uint64_t) system_time();
|
||||
|
||||
for (uint32_t i = 0; i < sysInfo.cpu_count; ++i) {
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
info->inUseAll = (uint64_t) cpuInfo[i].active_time;
|
||||
info->totalAll = uptime;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
|
||||
uint64_t inUse = user + nice + system + irq + softirq;
|
||||
uint64_t total = inUse + idle + iowait;
|
||||
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
*info = (FFCpuUsageInfo) {
|
||||
.inUseAll = inUse,
|
||||
.totalAll = total,
|
||||
|
||||
@@ -28,7 +28,7 @@ const char* ffGetCpuUsageInfo(FFlist* cpuTimes) {
|
||||
uint64_t inUse = cs.cpu_sysinfo.cpu[CPU_USER] + cs.cpu_sysinfo.cpu[CPU_KERNEL];
|
||||
uint64_t total = inUse + cs.cpu_sysinfo.cpu[CPU_IDLE] + cs.cpu_sysinfo.cpu[CPU_WAIT];
|
||||
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
*info = (FFCpuUsageInfo) {
|
||||
.inUseAll = inUse,
|
||||
.totalAll = total,
|
||||
|
||||
@@ -28,7 +28,7 @@ static const char* getInfoByNqsi(FFlist* cpuTimes) {
|
||||
uint64_t inUse = (uint64_t) (coreInfo->UserTime.QuadPart + coreInfo->KernelTime.QuadPart);
|
||||
uint64_t total = inUse + (uint64_t) coreInfo->IdleTime.QuadPart;
|
||||
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
*info = (FFCpuUsageInfo) {
|
||||
.inUseAll = inUse,
|
||||
.totalAll = total,
|
||||
@@ -138,7 +138,7 @@ static const char* getInfoByPerflib(FFlist* cpuTimes) {
|
||||
return "Counter \"% Processor Utility\" are not supported";
|
||||
}
|
||||
|
||||
FFCpuUsageInfo* info = (FFCpuUsageInfo*) ffListAdd(cpuTimes);
|
||||
FFCpuUsageInfo* info = FF_LIST_ADD(FFCpuUsageInfo, *cpuTimes);
|
||||
*info = (FFCpuUsageInfo) {
|
||||
.inUseAll = processorUtility,
|
||||
.totalAll = utilityBase,
|
||||
|
||||
Reference in New Issue
Block a user