mirror of
https://github.com/xzeldon/htop.git
synced 2024-12-24 15:15:44 +00:00
CPU Temperature and Frequency meter for Linux platform
This commit is contained in:
parent
611ea4606f
commit
36260b5814
34
CRT.h
34
CRT.h
@ -15,8 +15,8 @@ in the source distribution for its full text.
|
||||
#include "ProvideCurses.h"
|
||||
#include "Settings.h"
|
||||
|
||||
|
||||
typedef enum TreeStr_ {
|
||||
typedef enum TreeStr_
|
||||
{
|
||||
TREE_STR_VERT,
|
||||
TREE_STR_RTEE,
|
||||
TREE_STR_BEND,
|
||||
@ -28,7 +28,8 @@ typedef enum TreeStr_ {
|
||||
LAST_TREE_STR
|
||||
} TreeStr;
|
||||
|
||||
typedef enum ColorScheme_ {
|
||||
typedef enum ColorScheme_
|
||||
{
|
||||
COLORSCHEME_DEFAULT,
|
||||
COLORSCHEME_MONOCHROME,
|
||||
COLORSCHEME_BLACKONWHITE,
|
||||
@ -39,7 +40,8 @@ typedef enum ColorScheme_ {
|
||||
LAST_COLORSCHEME
|
||||
} ColorScheme;
|
||||
|
||||
typedef enum ColorElements_ {
|
||||
typedef enum ColorElements_
|
||||
{
|
||||
RESET_COLOR,
|
||||
DEFAULT_COLOR,
|
||||
FUNCTION_BAR,
|
||||
@ -64,6 +66,8 @@ typedef enum ColorElements_ {
|
||||
METER_VALUE_WARN,
|
||||
LED_COLOR,
|
||||
UPTIME,
|
||||
TEMP,
|
||||
FREQ,
|
||||
BATTERY,
|
||||
TASKS_RUNNING,
|
||||
SWAP,
|
||||
@ -148,24 +152,24 @@ typedef enum ColorElements_ {
|
||||
LAST_COLORELEMENT
|
||||
} ColorElements;
|
||||
|
||||
void CRT_fatalError(const char* note) ATTR_NORETURN;
|
||||
void CRT_fatalError(const char *note) ATTR_NORETURN;
|
||||
|
||||
#ifdef NDEBUG
|
||||
# define CRT_debug(...)
|
||||
#define CRT_debug(...)
|
||||
#else
|
||||
void CRT_debug_impl(const char* file, size_t lineno, const char* func, const char* fmt, ...) ATTR_FORMAT(printf, 4, 5);
|
||||
# define CRT_debug(...) CRT_debug_impl(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
void CRT_debug_impl(const char *file, size_t lineno, const char *func, const char *fmt, ...) ATTR_FORMAT(printf, 4, 5);
|
||||
#define CRT_debug(...) CRT_debug_impl(__FILE__, __LINE__, __func__, __VA_ARGS__)
|
||||
#endif
|
||||
|
||||
void CRT_handleSIGSEGV(int signal) ATTR_NORETURN;
|
||||
|
||||
#define KEY_WHEELUP KEY_F(30)
|
||||
#define KEY_WHEELUP KEY_F(30)
|
||||
#define KEY_WHEELDOWN KEY_F(31)
|
||||
#define KEY_RECLICK KEY_F(32)
|
||||
#define KEY_RECLICK KEY_F(32)
|
||||
#define KEY_SHIFT_TAB KEY_F(33)
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A'))
|
||||
#define KEY_ALT(x) (KEY_F(64 - 26) + ((x) - 'A'))
|
||||
|
||||
extern const char* CRT_degreeSign;
|
||||
extern const char *CRT_degreeSign;
|
||||
|
||||
#ifdef HAVE_LIBNCURSESW
|
||||
|
||||
@ -173,9 +177,9 @@ extern bool CRT_utf8;
|
||||
|
||||
#endif
|
||||
|
||||
extern const char* const* CRT_treeStr;
|
||||
extern const char *const *CRT_treeStr;
|
||||
|
||||
extern const int* CRT_colors;
|
||||
extern const int *CRT_colors;
|
||||
|
||||
extern int CRT_cursorX;
|
||||
|
||||
@ -187,7 +191,7 @@ extern ColorScheme CRT_colorScheme;
|
||||
|
||||
void CRT_setMouse(bool enabled);
|
||||
|
||||
void CRT_init(const Settings* settings, bool allowUnicode);
|
||||
void CRT_init(const Settings *settings, bool allowUnicode);
|
||||
|
||||
void CRT_done(void);
|
||||
|
||||
|
29
FreqMeter.c
Normal file
29
FreqMeter.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "FreqMeter.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "Object.h"
|
||||
#include "Platform.h"
|
||||
#include "XUtils.h"
|
||||
|
||||
static const int FreqMeter_attributes[] = {
|
||||
FREQ};
|
||||
|
||||
static void FreqMeter_updateValues(Meter *this)
|
||||
{
|
||||
float freq = Platform_getFreq();
|
||||
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.1lf GHz", freq);
|
||||
}
|
||||
|
||||
const MeterClass FreqMeter_class = {
|
||||
.super = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete},
|
||||
.updateValues = FreqMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = FreqMeter_attributes,
|
||||
.name = "Freq",
|
||||
.uiName = "Freq",
|
||||
.caption = "CPU/Frequency: "};
|
8
FreqMeter.h
Normal file
8
FreqMeter.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef HEADER_FreqMeter
|
||||
#define HEADER_FreqMeter
|
||||
|
||||
#include "Meter.h"
|
||||
|
||||
extern const MeterClass FreqMeter_class;
|
||||
|
||||
#endif
|
@ -82,6 +82,8 @@ myhtopsources = \
|
||||
TasksMeter.c \
|
||||
TraceScreen.c \
|
||||
UptimeMeter.c \
|
||||
FreqMeter.c \
|
||||
TempMeter.c \
|
||||
UsersTable.c \
|
||||
Vector.c \
|
||||
XUtils.c
|
||||
@ -144,6 +146,8 @@ myhtopheaders = \
|
||||
TasksMeter.h \
|
||||
TraceScreen.h \
|
||||
UptimeMeter.h \
|
||||
FreqMeter.h \
|
||||
TempMeter.h \
|
||||
UsersTable.h \
|
||||
Vector.h \
|
||||
XUtils.h
|
||||
|
720
Settings.c
720
Settings.c
File diff suppressed because it is too large
Load Diff
29
TempMeter.c
Normal file
29
TempMeter.c
Normal file
@ -0,0 +1,29 @@
|
||||
#include "TempMeter.h"
|
||||
|
||||
#include "CRT.h"
|
||||
#include "Object.h"
|
||||
#include "Platform.h"
|
||||
#include "XUtils.h"
|
||||
|
||||
static const int TempMeter_attributes[] = {
|
||||
TEMP};
|
||||
|
||||
static void TempMeter_updateValues(Meter *this)
|
||||
{
|
||||
float temp_c = Platform_getTemp();
|
||||
|
||||
xSnprintf(this->txtBuffer, sizeof(this->txtBuffer), "%.1lf °C", temp_c);
|
||||
}
|
||||
|
||||
const MeterClass TempMeter_class = {
|
||||
.super = {
|
||||
.extends = Class(Meter),
|
||||
.delete = Meter_delete},
|
||||
.updateValues = TempMeter_updateValues,
|
||||
.defaultMode = TEXT_METERMODE,
|
||||
.maxItems = 1,
|
||||
.total = 100.0,
|
||||
.attributes = TempMeter_attributes,
|
||||
.name = "Temp",
|
||||
.uiName = "Temp",
|
||||
.caption = "CPU/Temperature: "};
|
8
TempMeter.h
Normal file
8
TempMeter.h
Normal file
@ -0,0 +1,8 @@
|
||||
#ifndef HEADER_TempMeter
|
||||
#define HEADER_TempMeter
|
||||
|
||||
#include "Meter.h"
|
||||
|
||||
extern const MeterClass TempMeter_class;
|
||||
|
||||
#endif
|
47
XUtils.h
47
XUtils.h
@ -17,60 +17,61 @@ in the source distribution for its full text.
|
||||
#include "Compat.h"
|
||||
#include "Macros.h"
|
||||
|
||||
|
||||
void fail(void) ATTR_NORETURN;
|
||||
|
||||
void* xMalloc(size_t size) ATTR_ALLOC_SIZE1(1) ATTR_MALLOC;
|
||||
void *xMalloc(size_t size) ATTR_ALLOC_SIZE1(1) ATTR_MALLOC;
|
||||
|
||||
void* xMallocArray(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC;
|
||||
void *xMallocArray(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC;
|
||||
|
||||
void* xCalloc(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC;
|
||||
void *xCalloc(size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(1, 2) ATTR_MALLOC;
|
||||
|
||||
void* xRealloc(void* ptr, size_t size) ATTR_ALLOC_SIZE1(2);
|
||||
void *xRealloc(void *ptr, size_t size) ATTR_ALLOC_SIZE1(2);
|
||||
|
||||
void* xReallocArray(void* ptr, size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(2, 3);
|
||||
void *xReallocArray(void *ptr, size_t nmemb, size_t size) ATTR_ALLOC_SIZE2(2, 3);
|
||||
|
||||
void* xReallocArrayZero(void* ptr, size_t prevmemb, size_t newmemb, size_t size) ATTR_ALLOC_SIZE2(3, 4);
|
||||
void *xReallocArrayZero(void *ptr, size_t prevmemb, size_t newmemb, size_t size) ATTR_ALLOC_SIZE2(3, 4);
|
||||
|
||||
/*
|
||||
* String_startsWith gives better performance if strlen(match) can be computed
|
||||
* at compile time (e.g. when they are immutable string literals). :)
|
||||
*/
|
||||
static inline bool String_startsWith(const char* s, const char* match) {
|
||||
static inline bool String_startsWith(const char *s, const char *match)
|
||||
{
|
||||
return strncmp(s, match, strlen(match)) == 0;
|
||||
}
|
||||
|
||||
bool String_contains_i(const char* s1, const char* s2, bool multi);
|
||||
bool String_contains_i(const char *s1, const char *s2, bool multi);
|
||||
|
||||
static inline bool String_eq(const char* s1, const char* s2) {
|
||||
static inline bool String_eq(const char *s1, const char *s2)
|
||||
{
|
||||
return strcmp(s1, s2) == 0;
|
||||
}
|
||||
|
||||
char* String_cat(const char* s1, const char* s2) ATTR_MALLOC;
|
||||
char *String_cat(const char *s1, const char *s2) ATTR_MALLOC;
|
||||
|
||||
char* String_trim(const char* in) ATTR_MALLOC;
|
||||
char *String_trim(const char *in) ATTR_MALLOC;
|
||||
|
||||
char** String_split(const char* s, char sep, size_t* n);
|
||||
char **String_split(const char *s, char sep, size_t *n);
|
||||
|
||||
void String_freeArray(char** s);
|
||||
void String_freeArray(char **s);
|
||||
|
||||
char* String_readLine(FILE* fd) ATTR_MALLOC;
|
||||
char *String_readLine(FILE *fd) ATTR_MALLOC;
|
||||
|
||||
/* Always null-terminates dest. Caller must pass a strictly positive size. */
|
||||
size_t String_safeStrncpy(char* restrict dest, const char* restrict src, size_t size);
|
||||
size_t String_safeStrncpy(char *restrict dest, const char *restrict src, size_t size);
|
||||
|
||||
ATTR_FORMAT(printf, 2, 3)
|
||||
int xAsprintf(char** strp, const char* fmt, ...);
|
||||
int xAsprintf(char **strp, const char *fmt, ...);
|
||||
|
||||
ATTR_FORMAT(printf, 3, 4)
|
||||
int xSnprintf(char* buf, size_t len, const char* fmt, ...);
|
||||
int xSnprintf(char *buf, size_t len, const char *fmt, ...);
|
||||
|
||||
char* xStrdup(const char* str) ATTR_NONNULL ATTR_MALLOC;
|
||||
void free_and_xStrdup(char** ptr, const char* str);
|
||||
char *xStrdup(const char *str) ATTR_NONNULL ATTR_MALLOC;
|
||||
void free_and_xStrdup(char **ptr, const char *str);
|
||||
|
||||
char* xStrndup(const char* str, size_t len) ATTR_NONNULL ATTR_MALLOC;
|
||||
char *xStrndup(const char *str, size_t len) ATTR_NONNULL ATTR_MALLOC;
|
||||
|
||||
ssize_t xReadfile(const char* pathname, void* buffer, size_t count);
|
||||
ssize_t xReadfileat(openat_arg_t dirfd, const char* pathname, void* buffer, size_t count);
|
||||
ssize_t xReadfile(const char *pathname, void *buffer, size_t count);
|
||||
ssize_t xReadfileat(openat_arg_t dirfd, const char *pathname, void *buffer, size_t count);
|
||||
|
||||
#endif
|
||||
|
742
linux/Platform.c
742
linux/Platform.c
File diff suppressed because it is too large
Load Diff
@ -34,10 +34,9 @@ in the source distribution for its full text.
|
||||
|
||||
/* GNU/Hurd does not have PATH_MAX in limits.h */
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 4096
|
||||
#define PATH_MAX 4096
|
||||
#endif
|
||||
|
||||
|
||||
extern const ScreenDefaults Platform_defaultScreens[];
|
||||
|
||||
extern const unsigned int Platform_numberOfDefaultScreens;
|
||||
@ -46,90 +45,98 @@ extern const SignalItem Platform_signals[];
|
||||
|
||||
extern const unsigned int Platform_numberOfSignals;
|
||||
|
||||
extern const MeterClass* const Platform_meterTypes[];
|
||||
extern const MeterClass *const Platform_meterTypes[];
|
||||
|
||||
bool Platform_init(void);
|
||||
void Platform_done(void);
|
||||
|
||||
extern bool Running_containerized;
|
||||
|
||||
void Platform_setBindings(Htop_Action* keys);
|
||||
void Platform_setBindings(Htop_Action *keys);
|
||||
|
||||
int Platform_getUptime(void);
|
||||
|
||||
void Platform_getLoadAverage(double* one, double* five, double* fifteen);
|
||||
float Platform_getTemp(void);
|
||||
|
||||
float Platform_getFreq(void);
|
||||
|
||||
void Platform_getLoadAverage(double *one, double *five, double *fifteen);
|
||||
|
||||
int Platform_getMaxPid(void);
|
||||
|
||||
double Platform_setCPUValues(Meter* this, unsigned int cpu);
|
||||
double Platform_setCPUValues(Meter *this, unsigned int cpu);
|
||||
|
||||
void Platform_setMemoryValues(Meter* this);
|
||||
void Platform_setMemoryValues(Meter *this);
|
||||
|
||||
void Platform_setSwapValues(Meter* this);
|
||||
void Platform_setSwapValues(Meter *this);
|
||||
|
||||
void Platform_setZramValues(Meter* this);
|
||||
void Platform_setZramValues(Meter *this);
|
||||
|
||||
void Platform_setZfsArcValues(Meter* this);
|
||||
void Platform_setZfsArcValues(Meter *this);
|
||||
|
||||
void Platform_setZfsCompressedArcValues(Meter* this);
|
||||
void Platform_setZfsCompressedArcValues(Meter *this);
|
||||
|
||||
char* Platform_getProcessEnv(pid_t pid);
|
||||
char *Platform_getProcessEnv(pid_t pid);
|
||||
|
||||
char* Platform_getInodeFilename(pid_t pid, ino_t inode);
|
||||
char *Platform_getInodeFilename(pid_t pid, ino_t inode);
|
||||
|
||||
FileLocks_ProcessData* Platform_getProcessLocks(pid_t pid);
|
||||
FileLocks_ProcessData *Platform_getProcessLocks(pid_t pid);
|
||||
|
||||
void Platform_getPressureStall(const char* file, bool some, double* ten, double* sixty, double* threehundred);
|
||||
void Platform_getPressureStall(const char *file, bool some, double *ten, double *sixty, double *threehundred);
|
||||
|
||||
bool Platform_getDiskIO(DiskIOData* data);
|
||||
bool Platform_getDiskIO(DiskIOData *data);
|
||||
|
||||
bool Platform_getNetworkIO(NetworkIOData* data);
|
||||
bool Platform_getNetworkIO(NetworkIOData *data);
|
||||
|
||||
void Platform_getBattery(double* percent, ACPresence* isOnAC);
|
||||
void Platform_getBattery(double *percent, ACPresence *isOnAC);
|
||||
|
||||
static inline void Platform_getHostname(char* buffer, size_t size) {
|
||||
static inline void Platform_getHostname(char *buffer, size_t size)
|
||||
{
|
||||
Generic_hostname(buffer, size);
|
||||
}
|
||||
|
||||
static inline void Platform_getRelease(char** string) {
|
||||
static inline void Platform_getRelease(char **string)
|
||||
{
|
||||
*string = Generic_uname();
|
||||
}
|
||||
|
||||
#ifdef HAVE_LIBCAP
|
||||
#define PLATFORM_LONG_OPTIONS \
|
||||
{"drop-capabilities", optional_argument, 0, 160},
|
||||
#define PLATFORM_LONG_OPTIONS \
|
||||
{"drop-capabilities", optional_argument, 0, 160},
|
||||
#else
|
||||
#define PLATFORM_LONG_OPTIONS
|
||||
#define PLATFORM_LONG_OPTIONS
|
||||
#endif
|
||||
|
||||
void Platform_longOptionsUsage(const char* name);
|
||||
void Platform_longOptionsUsage(const char *name);
|
||||
|
||||
CommandLineStatus Platform_getLongOption(int opt, int argc, char** argv);
|
||||
CommandLineStatus Platform_getLongOption(int opt, int argc, char **argv);
|
||||
|
||||
static inline void Platform_gettime_realtime(struct timeval* tv, uint64_t* msec) {
|
||||
static inline void Platform_gettime_realtime(struct timeval *tv, uint64_t *msec)
|
||||
{
|
||||
Generic_gettime_realtime(tv, msec);
|
||||
}
|
||||
|
||||
static inline void Platform_gettime_monotonic(uint64_t* msec) {
|
||||
static inline void Platform_gettime_monotonic(uint64_t *msec)
|
||||
{
|
||||
Generic_gettime_monotonic(msec);
|
||||
}
|
||||
|
||||
static inline Hashtable* Platform_dynamicMeters(void) { return NULL; }
|
||||
static inline Hashtable *Platform_dynamicMeters(void) { return NULL; }
|
||||
|
||||
static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable* table) { }
|
||||
static inline void Platform_dynamicMetersDone(ATTR_UNUSED Hashtable *table) {}
|
||||
|
||||
static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter* meter) { }
|
||||
static inline void Platform_dynamicMeterInit(ATTR_UNUSED Meter *meter) {}
|
||||
|
||||
static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter* meter) { }
|
||||
static inline void Platform_dynamicMeterUpdateValues(ATTR_UNUSED Meter *meter) {}
|
||||
|
||||
static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter* meter, ATTR_UNUSED RichString* out) { }
|
||||
static inline void Platform_dynamicMeterDisplay(ATTR_UNUSED const Meter *meter, ATTR_UNUSED RichString *out) {}
|
||||
|
||||
static inline Hashtable* Platform_dynamicColumns(void) { return NULL; }
|
||||
static inline Hashtable *Platform_dynamicColumns(void) { return NULL; }
|
||||
|
||||
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable* table) { }
|
||||
static inline void Platform_dynamicColumnsDone(ATTR_UNUSED Hashtable *table) {}
|
||||
|
||||
static inline const char* Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { return NULL; }
|
||||
static inline const char *Platform_dynamicColumnInit(ATTR_UNUSED unsigned int key) { return NULL; }
|
||||
|
||||
static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process* proc, ATTR_UNUSED RichString* str, ATTR_UNUSED unsigned int key) { return false; }
|
||||
static inline bool Platform_dynamicColumnWriteField(ATTR_UNUSED const Process *proc, ATTR_UNUSED RichString *str, ATTR_UNUSED unsigned int key) { return false; }
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user