From 45597e432f9c683b91ed6f424ad70d96a537fb83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AB=8F=E8=A8=AA=E5=AD=90?= Date: Tue, 18 Jun 2024 14:44:12 +0900 Subject: =?UTF-8?q?Linux:=20CPU=E3=81=AE=E8=A1=A8=E7=A4=BA=E3=81=AE?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/cpu.c | 34 +++++++++++++++++++++++++++++++--- src/memory.c | 2 +- src/uptime.c | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/cpu.c b/src/cpu.c index 5cd9d3d..11eebc9 100644 --- a/src/cpu.c +++ b/src/cpu.c @@ -9,7 +9,7 @@ void run_cpu_command(const char *command) { FILE *p = popen(command, "r"); if (!p) { - fprintf(stderr, "ホストコマンドを実効に失敗: %s", command); + fprintf(stderr, "CPUコマンドを実効に失敗: %s", command); return; } @@ -24,12 +24,40 @@ void run_cpu_command(const char *command) { void display_cpu() { #if defined(__NetBSD__) run_cpu_command("sysctl -n machdep.cpu_brand | sed 's/(R)//' | " - "sed 's/(TM)//' | sed 's/CPU //'"); + "sed 's/(TM)//' | sed 's/CPU //' | sed 's/Processor//'"); run_cpu_command("echo \" (\" && sysctl -n hw.ncpu && echo \" core)\""); #elif defined(__FreeBSD__) || defined(__OpenBSD__) run_cpu_command("sysctl -n hw.model | sed 's/(R)//' | " - "sed 's/(TM)//' | sed 's/CPU //'"); + "sed 's/(TM)//' | sed 's/CPU //' | sed 's/Processor//'"); run_cpu_command("echo \" (\" && sysctl -n hw.ncpu && echo \" core)\""); #elif defined(__linux__) + run_cpu_command("cat /proc/cpuinfo | awk -F '\\\\s*: | @' " + "'/model name|Hardware|Processor|^cpu model|chip type|^cpu type/ { " + "cpu=$2; if ($1 == \"Hardware\") exit } END { print cpu }' | " + "sed 's/(R)//' | sed 's/(TM)//' | sed 's/CPU //' | sed 's/ Processor//' | " + "sed 's/ [0-9]-Core//'"); + printf(" @ "); + + char buf[20]; + long int val; + double fmt; + FILE *fp = fopen("/sys/devices/system/cpu/cpu0/cpufreq/bios_limit", "r"); + if (fp == NULL) { + perror("失敗"); + return; + } + + if (fgets(buf, sizeof(buf), fp) != NULL) { + val = strtol(buf, NULL, 10); + fmt = val / 1000000.0; + printf("%.2f", fmt); + } else { + perror("失敗"); + fclose(fp); + return; + } + + fclose(fp); + run_cpu_command("echo \"GHz (\" && nproc && echo \" core)\""); #endif } diff --git a/src/memory.c b/src/memory.c index 6589da1..7fa55be 100644 --- a/src/memory.c +++ b/src/memory.c @@ -10,7 +10,7 @@ long long int run_mem_command(const char *command) { FILE *p = popen(command, "r"); if (!p) { - fprintf(stderr, "ホストコマンドを実効に失敗: %s", command); + fprintf(stderr, "メモリコマンドを実効に失敗: %s", command); return 0; } diff --git a/src/uptime.c b/src/uptime.c index 8198669..c9f1c8e 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -9,7 +9,7 @@ void run_uptime_command(const char *command) { FILE *p = popen(command, "r"); if (!p) { - fprintf(stderr, "ホストコマンドを実効に失敗: %s", command); + fprintf(stderr, "起動時間コマンドを実効に失敗: %s", command); return; } -- cgit v1.2.3