mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
CpuUsage: optimise performance further
This commit is contained in:
@@ -8,29 +8,22 @@
|
||||
// We need to use uint64_t because sizeof(long) == 4 on Windows
|
||||
const char* ffGetCpuUsageInfo(uint64_t* inUseAll, uint64_t* totalAll);
|
||||
|
||||
static uint64_t inUseAll1, totalAll1, startTime;
|
||||
static uint64_t inUseAll1, totalAll1;
|
||||
|
||||
void ffPrepareCPUUsage()
|
||||
{
|
||||
startTime = ffTimeGetTick();
|
||||
ffGetCpuUsageInfo(&inUseAll1, &totalAll1);
|
||||
}
|
||||
|
||||
const char* ffGetCpuUsageResult(double* result)
|
||||
{
|
||||
const char* error = NULL;
|
||||
if(startTime == 0)
|
||||
if(inUseAll1 == 0 && totalAll1 == 0)
|
||||
{
|
||||
error = ffGetCpuUsageInfo(&inUseAll1, &totalAll1);
|
||||
if(error)
|
||||
return error;
|
||||
ffTimeSleep(250);
|
||||
}
|
||||
else
|
||||
{
|
||||
uint64_t duration = ffTimeGetTick() - startTime;
|
||||
if(duration < 250)
|
||||
ffTimeSleep(250 - (uint32_t) duration);
|
||||
ffTimeSleep(200);
|
||||
}
|
||||
|
||||
while(true)
|
||||
@@ -46,6 +39,6 @@ const char* ffGetCpuUsageResult(double* result)
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
ffTimeSleep(250);
|
||||
ffTimeSleep(200);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user