get_gpuを最適化
このコミットが含まれているのは:
コミット
db01f3469c
14
config.h
14
config.h
|
@ -75,15 +75,25 @@
|
|||
REMOVE("Quad-Core"), \
|
||||
REMOVE("Six-Core"), \
|
||||
REMOVE("Eight-Core"), \
|
||||
REMOVE("Core"), \
|
||||
REMOVE("2-Core"), \
|
||||
REMOVE("3-Core"), \
|
||||
REMOVE("4-Core"), \
|
||||
REMOVE("6-Core"), \
|
||||
REMOVE("8-Core"), \
|
||||
REMOVE("12-Core"), \
|
||||
REMOVE("Processor"), \
|
||||
REMOVE("CPU"), \
|
||||
}
|
||||
|
||||
#define GPU_CONFIG \
|
||||
{ \
|
||||
REMOVE("Advanced Micro Devices, Inc. "), \
|
||||
REMOVE("Advanced Micro Devices, Inc."), \
|
||||
REPLACE(" [AMD/ATI]", "AMD/ATI"), \
|
||||
REMOVE("Corporation"), \
|
||||
REMOVE("Controller"), \
|
||||
REMOVE("Graphics"), \
|
||||
REMOVE("Integrated"), \
|
||||
REMOVE("Navi 14"), \
|
||||
REMOVE("["), \
|
||||
REMOVE("]"), \
|
||||
}
|
||||
|
|
83
paleofetch.c
83
paleofetch.c
|
@ -412,6 +412,8 @@ static void get_terminal_wayland(char *terminal) {
|
|||
return;
|
||||
}
|
||||
|
||||
printf("%s\n", terminal);
|
||||
|
||||
wl_display_disconnect(display);
|
||||
}
|
||||
|
||||
|
@ -474,49 +476,29 @@ static char *get_cpu() {
|
|||
}
|
||||
|
||||
char *cpu_model = malloc(BUF_SIZE / 2);
|
||||
char *line = NULL;
|
||||
size_t len;
|
||||
int num_cores = 0, cpu_freq, prec = 3;
|
||||
char *line = malloc(BUF_SIZE);
|
||||
size_t len = 0;
|
||||
int num_cores = 0, cpu_freq;
|
||||
double freq;
|
||||
char freq_unit[] = "GHz";
|
||||
int prec = 3;
|
||||
|
||||
while (getline(&line, &len, cpuinfo) != -1) {
|
||||
num_cores += sscanf(line, "model name : %[^\n@]", cpu_model);
|
||||
}
|
||||
free(line);
|
||||
fclose(cpuinfo);
|
||||
|
||||
FILE *cpufreq = fopen("/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq", "r");
|
||||
line = NULL;
|
||||
fseek(cpuinfo, 0, SEEK_SET);
|
||||
|
||||
if (cpufreq != NULL) {
|
||||
if (getline(&line, &len, cpufreq) != -1) {
|
||||
sscanf(line, "%d", &cpu_freq);
|
||||
cpu_freq /= 1000;
|
||||
} else {
|
||||
fclose(cpufreq);
|
||||
free(line);
|
||||
goto cpufreq_fallback;
|
||||
while (getline(&line, &len, cpuinfo) != -1) {
|
||||
if (sscanf(line, "cpuMHz : %lf", &freq) > 0) {
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
cpufreq_fallback:
|
||||
cpufreq = fopen("/proc/cpuinfo", "r");
|
||||
if (cpufreq == NULL) {
|
||||
status = -1;
|
||||
halt_and_catch_fire("Unable to open cpuinfo");
|
||||
}
|
||||
|
||||
while (getline(&line, &len, cpufreq) != -1) {
|
||||
if (sscanf(line, "cpu MHz : %lf", &freq) > 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cpu_freq = (int) freq;
|
||||
}
|
||||
|
||||
fclose(cpuinfo);
|
||||
free(line);
|
||||
fclose(cpufreq);
|
||||
|
||||
cpu_freq = (int) freq;
|
||||
|
||||
if (cpu_freq < 1000) {
|
||||
freq = (double) cpu_freq;
|
||||
|
@ -552,53 +534,52 @@ cpufreq_fallback:
|
|||
if (num_cores == 0) {
|
||||
*cpu = '\0';
|
||||
}
|
||||
|
||||
return cpu;
|
||||
}
|
||||
|
||||
static char *find_gpu(int index) {
|
||||
char buffer[BUF_SIZE], *device_class, *gpu = malloc(BUF_SIZE);
|
||||
char buffer[BUF_SIZE], *device_class;
|
||||
struct pci_access *pacc;
|
||||
struct pci_dev *dev;
|
||||
int gpu_index = 0;
|
||||
bool found = false;
|
||||
char *gpu = malloc(BUF_SIZE);
|
||||
|
||||
pacc = pci_alloc();
|
||||
pci_init(pacc);
|
||||
pci_scan_bus(pacc);
|
||||
dev = pacc->devices;
|
||||
|
||||
while (dev != NULL) {
|
||||
for (dev = pacc->devices; dev != NULL; dev = dev->next) {
|
||||
pci_fill_info(dev, PCI_FILL_IDENT | PCI_FILL_BASES | PCI_FILL_CLASS);
|
||||
device_class = pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_CLASS, dev->device_class);
|
||||
if (strcmp("VGA compatible controller", device_class) == 0 || strcmp("3D controller", device_class) == 0) {
|
||||
strncpy(gpu, pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_DEVICE | PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id), BUF_SIZE - 1);
|
||||
|
||||
if (!strcmp("VGA compatible controller", device_class) || !strcmp("3D controller", device_class)) {
|
||||
snprintf(gpu, BUF_SIZE, "%s", pci_lookup_name(pacc, buffer, sizeof(buffer), PCI_LOOKUP_DEVICE | PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id));
|
||||
|
||||
if (gpu_index == index) {
|
||||
found = true;
|
||||
break;
|
||||
} else {
|
||||
gpu_index++;
|
||||
}
|
||||
gpu_index++;
|
||||
}
|
||||
|
||||
dev = dev->next;
|
||||
}
|
||||
|
||||
if (found == false) {
|
||||
*gpu = '\0';
|
||||
}
|
||||
|
||||
pci_cleanup(pacc);
|
||||
|
||||
for (int i = 0; i < COUNT(gpu_config); ++i) {
|
||||
if (gpu_config[i].repl_str == NULL) {
|
||||
remove_substring(gpu, gpu_config[i].substring, gpu_config[i].length);
|
||||
} else {
|
||||
replace_substring(gpu, gpu_config[i].substring, gpu_config[i].repl_str, gpu_config[i].length, gpu_config[i].repl_len);
|
||||
if (!found) {
|
||||
*gpu = '\0';
|
||||
} else {
|
||||
for (int i = 0; i < COUNT(gpu_config); ++i) {
|
||||
if (gpu_config[i].repl_str == NULL) {
|
||||
remove_substring(gpu, gpu_config[i].substring, gpu_config[i].length);
|
||||
} else {
|
||||
replace_substring(gpu, gpu_config[i].substring, gpu_config[i].repl_str, gpu_config[i].length, gpu_config[i].repl_len);
|
||||
}
|
||||
}
|
||||
truncate_spaces(gpu);
|
||||
}
|
||||
|
||||
truncate_spaces(gpu);
|
||||
|
||||
return gpu;
|
||||
}
|
||||
|
||||
|
|
読み込み中…
新しいイシューから参照