mirror of https://github.com/xzeldon/htop.git
[#480] SysArchMeter to view kernel/arch info
At start, SysArchMeter calls the uname function to obtain the kernel version and architecture. If available, the distro version is obtained by calling lsb_release. The obtained values are stored in static variables and used when updating the meter.
This commit is contained in:
parent
7bfa466abe
commit
51e79ddc07
|
@ -67,6 +67,7 @@ myhtopsources = \
|
||||||
Settings.c \
|
Settings.c \
|
||||||
SignalsPanel.c \
|
SignalsPanel.c \
|
||||||
SwapMeter.c \
|
SwapMeter.c \
|
||||||
|
SysArchMeter.c \
|
||||||
TasksMeter.c \
|
TasksMeter.c \
|
||||||
TraceScreen.c \
|
TraceScreen.c \
|
||||||
UptimeMeter.c \
|
UptimeMeter.c \
|
||||||
|
@ -121,6 +122,7 @@ myhtopheaders = \
|
||||||
Settings.h \
|
Settings.h \
|
||||||
SignalsPanel.h \
|
SignalsPanel.h \
|
||||||
SwapMeter.h \
|
SwapMeter.h \
|
||||||
|
SysArchMeter.h \
|
||||||
TasksMeter.h \
|
TasksMeter.h \
|
||||||
TraceScreen.h \
|
TraceScreen.h \
|
||||||
UptimeMeter.h \
|
UptimeMeter.h \
|
||||||
|
|
|
@ -0,0 +1,83 @@
|
||||||
|
/*
|
||||||
|
htop - SysArchMeter.c
|
||||||
|
(C) 2021 htop dev team
|
||||||
|
Released under the GNU GPLv2, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
#include "config.h" // IWYU pragma: keep
|
||||||
|
|
||||||
|
#include "SysArchMeter.h"
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <sys/utsname.h>
|
||||||
|
|
||||||
|
#include "XUtils.h"
|
||||||
|
|
||||||
|
|
||||||
|
static const int SysArchMeter_attributes[] = {HOSTNAME};
|
||||||
|
|
||||||
|
static void SysArchMeter_updateValues(Meter* this, char* buffer, size_t size) {
|
||||||
|
static struct utsname uname_info;
|
||||||
|
static int uname_result;
|
||||||
|
static char distro[3][64] = { {'\0'}, {'\0'}, {'\0'} };
|
||||||
|
static bool loaded_data = false;
|
||||||
|
|
||||||
|
(void)this;
|
||||||
|
|
||||||
|
if(!loaded_data) {
|
||||||
|
uname_result = uname(&uname_info);
|
||||||
|
FILE* fp = popen("lsb_release --id --release --codename", "r");
|
||||||
|
if(fp) {
|
||||||
|
char line[96] = {'\0'};
|
||||||
|
size_t n = 0;
|
||||||
|
|
||||||
|
while(fgets(line, sizeof(line), fp)) {
|
||||||
|
n = strcspn(line, ":");
|
||||||
|
if(n > 0 && (n + 1) < strlen(line)) {
|
||||||
|
char* value = String_trim(&line[n + 1]);
|
||||||
|
line[n] = '\0';
|
||||||
|
|
||||||
|
if(String_eq(line, "Distributor ID"))
|
||||||
|
snprintf(distro[0], sizeof(distro[0]), "%s", value);
|
||||||
|
else if(String_eq(line, "Release"))
|
||||||
|
snprintf(distro[1], sizeof(distro[1]), "%s", value);
|
||||||
|
else if(String_eq(line, "Codename"))
|
||||||
|
snprintf(distro[2], sizeof(distro[2]), "%s", value);
|
||||||
|
|
||||||
|
free(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!distro[0][0])
|
||||||
|
snprintf(distro[0], sizeof(distro[0]), "Unknown");
|
||||||
|
pclose(fp);
|
||||||
|
}
|
||||||
|
loaded_data = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(uname_result == 0) {
|
||||||
|
if (distro[1][0] && distro[2][0])
|
||||||
|
snprintf(buffer, size, "%s %s [%s] / %s %s (%s)", uname_info.sysname, uname_info.release, uname_info.machine, distro[0], distro[1], distro[2]);
|
||||||
|
else if(distro[1][0])
|
||||||
|
snprintf(buffer, size, "%s %s [%s] / %s %s", uname_info.sysname, uname_info.release, uname_info.machine, distro[0], distro[1]);
|
||||||
|
else
|
||||||
|
snprintf(buffer, size, "%s %s [%s]", uname_info.sysname, uname_info.release, uname_info.machine);
|
||||||
|
} else {
|
||||||
|
snprintf(buffer, size, "Unknown");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const MeterClass SysArchMeter_class = {
|
||||||
|
.super = {
|
||||||
|
.extends = Class(Meter),
|
||||||
|
.delete = Meter_delete
|
||||||
|
},
|
||||||
|
.updateValues = SysArchMeter_updateValues,
|
||||||
|
.defaultMode = TEXT_METERMODE,
|
||||||
|
.maxItems = 0,
|
||||||
|
.total = 100.0,
|
||||||
|
.attributes = SysArchMeter_attributes,
|
||||||
|
.name = "System",
|
||||||
|
.uiName = "System",
|
||||||
|
.caption = "System: ",
|
||||||
|
};
|
|
@ -0,0 +1,14 @@
|
||||||
|
#ifndef HEADER_SysArchMeter
|
||||||
|
#define HEADER_SysArchMeter
|
||||||
|
/*
|
||||||
|
htop - SysArchMeter.h
|
||||||
|
(C) 2021 htop dev team
|
||||||
|
Released under the GNU GPLv2, see the COPYING file
|
||||||
|
in the source distribution for its full text.
|
||||||
|
*/
|
||||||
|
#include "Meter.h"
|
||||||
|
|
||||||
|
|
||||||
|
extern const MeterClass SysArchMeter_class;
|
||||||
|
|
||||||
|
#endif
|
|
@ -31,6 +31,7 @@ in the source distribution for its full text.
|
||||||
#include "MemoryMeter.h"
|
#include "MemoryMeter.h"
|
||||||
#include "ProcessLocksScreen.h"
|
#include "ProcessLocksScreen.h"
|
||||||
#include "SwapMeter.h"
|
#include "SwapMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "TasksMeter.h"
|
#include "TasksMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
#include "zfs/ZfsArcMeter.h"
|
#include "zfs/ZfsArcMeter.h"
|
||||||
|
@ -93,6 +94,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&TasksMeter_class,
|
&TasksMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
|
|
|
@ -19,6 +19,7 @@ in the source distribution for its full text.
|
||||||
#include "DateMeter.h"
|
#include "DateMeter.h"
|
||||||
#include "DateTimeMeter.h"
|
#include "DateTimeMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "DragonFlyBSDProcess.h"
|
#include "DragonFlyBSDProcess.h"
|
||||||
#include "DragonFlyBSDProcessList.h"
|
#include "DragonFlyBSDProcessList.h"
|
||||||
|
|
||||||
|
@ -85,6 +86,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
&AllCPUs4Meter_class,
|
&AllCPUs4Meter_class,
|
||||||
|
|
|
@ -42,6 +42,7 @@ in the source distribution for its full text.
|
||||||
#include "ProcessList.h"
|
#include "ProcessList.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "SwapMeter.h"
|
#include "SwapMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "TasksMeter.h"
|
#include "TasksMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
#include "XUtils.h"
|
#include "XUtils.h"
|
||||||
|
@ -103,6 +104,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
&AllCPUs4Meter_class,
|
&AllCPUs4Meter_class,
|
||||||
|
|
|
@ -49,6 +49,7 @@ in the source distribution for its full text.
|
||||||
#include "SELinuxMeter.h"
|
#include "SELinuxMeter.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "SwapMeter.h"
|
#include "SwapMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "SystemdMeter.h"
|
#include "SystemdMeter.h"
|
||||||
#include "TasksMeter.h"
|
#include "TasksMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
|
@ -162,6 +163,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&LoadMeter_class,
|
&LoadMeter_class,
|
||||||
&MemoryMeter_class,
|
&MemoryMeter_class,
|
||||||
&SwapMeter_class,
|
&SwapMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&HugePageMeter_class,
|
&HugePageMeter_class,
|
||||||
&TasksMeter_class,
|
&TasksMeter_class,
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
|
|
|
@ -37,6 +37,7 @@ in the source distribution for its full text.
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "SignalsPanel.h"
|
#include "SignalsPanel.h"
|
||||||
#include "SwapMeter.h"
|
#include "SwapMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "TasksMeter.h"
|
#include "TasksMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
#include "XUtils.h"
|
#include "XUtils.h"
|
||||||
|
@ -99,6 +100,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
&AllCPUs4Meter_class,
|
&AllCPUs4Meter_class,
|
||||||
|
|
|
@ -19,6 +19,7 @@ in the source distribution for its full text.
|
||||||
#include "DateMeter.h"
|
#include "DateMeter.h"
|
||||||
#include "DateTimeMeter.h"
|
#include "DateTimeMeter.h"
|
||||||
#include "HostnameMeter.h"
|
#include "HostnameMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
#include "zfs/ZfsArcMeter.h"
|
#include "zfs/ZfsArcMeter.h"
|
||||||
#include "zfs/ZfsCompressedArcMeter.h"
|
#include "zfs/ZfsCompressedArcMeter.h"
|
||||||
|
@ -100,6 +101,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&TasksMeter_class,
|
&TasksMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
|
|
|
@ -21,6 +21,7 @@ in the source distribution for its full text.
|
||||||
#include "Macros.h"
|
#include "Macros.h"
|
||||||
#include "MemoryMeter.h"
|
#include "MemoryMeter.h"
|
||||||
#include "SwapMeter.h"
|
#include "SwapMeter.h"
|
||||||
|
#include "SysArchMeter.h"
|
||||||
#include "TasksMeter.h"
|
#include "TasksMeter.h"
|
||||||
#include "UptimeMeter.h"
|
#include "UptimeMeter.h"
|
||||||
|
|
||||||
|
@ -45,6 +46,7 @@ const MeterClass* const Platform_meterTypes[] = {
|
||||||
&TasksMeter_class,
|
&TasksMeter_class,
|
||||||
&BatteryMeter_class,
|
&BatteryMeter_class,
|
||||||
&HostnameMeter_class,
|
&HostnameMeter_class,
|
||||||
|
&SysArchMeter_class,
|
||||||
&UptimeMeter_class,
|
&UptimeMeter_class,
|
||||||
&AllCPUsMeter_class,
|
&AllCPUsMeter_class,
|
||||||
&AllCPUs2Meter_class,
|
&AllCPUs2Meter_class,
|
||||||
|
|
Loading…
Reference in New Issue