Skip to content

Commit

Permalink
review fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
aestriplex committed Feb 16, 2025
1 parent c9fa7bf commit 17bf46f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
6 changes: 3 additions & 3 deletions GPUMeter.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,18 @@ static int humanTimeUnit(char* buffer, size_t size, unsigned long long int value
}

static void GPUMeter_updateValues(Meter* this) {
const Machine* machine = this->host;
const Machine* host = this->host;
char* buffer = this->txtBuffer;
size_t size = sizeof(this->txtBuffer);

if (!isNonnegative(machine->totalGPUUsage)) {
if (!isNonnegative(host->totalGPUUsage)) {
this->values[0] = 0;
int written = xSnprintf(buffer, size, "N/A");
METER_BUFFER_CHECK(buffer, size, written);
return;
}

int written = xSnprintf(buffer, size, "%.1f", machine->totalGPUUsage);
int written = xSnprintf(buffer, size, "%.1f", host->totalGPUUsage);
METER_BUFFER_CHECK(buffer, size, written);
METER_BUFFER_APPEND_CHR(buffer, size, '%');
}
Expand Down
38 changes: 25 additions & 13 deletions darwin/DarwinMachine.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ static void DarwinMachine_getVMStats(DarwinMachine* this) {
#endif
}

static void DarwinMachine_setDeafultGPUValues(Machine* super) {
super->totalGPUUsage = (double)-1;
super->totalGPUTimeDiff = (unsigned long long int)-1;
}

void Machine_scan(Machine* super) {
DarwinMachine* host = (DarwinMachine*) super;

Expand Down Expand Up @@ -138,31 +143,38 @@ bool Machine_isCPUonline(const Machine* host, unsigned int id) {

void Machine_scanGPUUsage(Machine* super) {
DarwinMachine* dhost = (DarwinMachine *)super;
CFMutableDictionaryRef properties = NULL;
CFDictionaryRef perfStats;
CFNumberRef deviceUtil;
int device = 0, ret;


DarwinMachine_setDeafultGPUValues(super);

if (!dhost->GPUService) {
return;
}

ret = IORegistryEntryCreateCFProperties(dhost->GPUService, &properties, kCFAllocatorDefault, kNilOptions);

CFMutableDictionaryRef properties = NULL;
kern_return_t ret = IORegistryEntryCreateCFProperties(dhost->GPUService, &properties, kCFAllocatorDefault, kNilOptions);
if (ret != KERN_SUCCESS) {
return;
}

perfStats = CFDictionaryGetValue(properties, CFSTR("PerformanceStatistics"));

assert(perfStats && CFGetTypeID(perfStats) == CFDictionaryGetTypeID());

deviceUtil = CFDictionaryGetValue(perfStats, CFSTR("Device Utilization %"));
CFDictionaryRef perfStats = CFDictionaryGetValue(properties, CFSTR("PerformanceStatistics"));

if (!perfStats) {
CFRelease(properties);
return;
}

assert(CFGetTypeID(perfStats) == CFDictionaryGetTypeID());

CFNumberRef deviceUtil = CFDictionaryGetValue(perfStats, CFSTR("Device Utilization %"));
if (!deviceUtil) {
CFRelease(properties);
return;
}


int device = -1;
CFNumberGetValue(deviceUtil, kCFNumberIntType, &device);
CFRelease(properties);

super->totalGPUUsage = (double)device;
super->totalGPUTimeDiff = (unsigned long long int)-1;
}

0 comments on commit 17bf46f

Please sign in to comment.