aboutsummaryrefslogtreecommitdiffstats
path: root/stat.h
diff options
context:
space:
mode:
authorverdant <im@verdant.ee>2026-07-22 14:44:38 +0800
committerverdant <im@verdant.ee>2026-07-22 14:44:38 +0800
commita6d136f0c34f6bb3de6b86ce7fe3ab608bd61283 (patch)
treec011fd99ad64aaec04bc18401c51f6ca590a2ddb /stat.h
parent80eeedf25b8f6f0c5797c0eca5c3b6f5fcffe96e (diff)
downloadsf-a6d136f0c34f6bb3de6b86ce7fe3ab608bd61283.tar.gz
sf-a6d136f0c34f6bb3de6b86ce7fe3ab608bd61283.zip
Implement Exponential Moving Average algorithm
For solving that CPU status updating is so fast, use EMA to calc a smooth value
Diffstat (limited to 'stat.h')
-rw-r--r--stat.h70
1 files changed, 35 insertions, 35 deletions
diff --git a/stat.h b/stat.h
index 81d84cc..5b14226 100644
--- a/stat.h
+++ b/stat.h
@@ -12,46 +12,46 @@
#define STAT_BAR_HEIGHT 1
typedef struct {
- char name[16];
- unsigned int user; /* User mode */
- unsigned int nice; /* Low-priority user mode */
- unsigned int system; /* Kernel mode */
- unsigned int idle; /* Free time of CPU */
+ char name[16];
+ unsigned int user; /* User mode */
+ unsigned int nice; /* Low-priority user mode */
+ unsigned int system; /* Kernel mode */
+ unsigned int idle; /* Free time of CPU */
+ unsigned long long iowait;
+ unsigned long long irq;
+ unsigned long long softirq;
+
+ unsigned long long prev_total;
+ unsigned long long prev_idle;
+ double cpu;
+ double smooth_cpu;
} cpu_occupy;
typedef struct {
- char sysver[30];
- struct {
- unsigned long mem_total;
- unsigned long mem_available;
- } meminfo;
- struct {
- unsigned long long disk_total;
- unsigned long long disk_available;
- } diskinfo;
- struct {
- char name[16];
- unsigned long long user; /* User mode */
- unsigned long long nice; /* Low-priority user mode */
- unsigned long long system; /* Kernel mode */
- unsigned long long idle; /* Free time of CPU */
- double cpu;
- } cpu_occupy;
+ char sysver[30];
+ struct {
+ unsigned long mem_total;
+ unsigned long mem_available;
+ } meminfo;
+ struct {
+ unsigned long long disk_total;
+ unsigned long long disk_available;
+ } diskinfo;
+ cpu_occupy *cpu_occ;
} stat;
-void stat_get_sysver(stat* s);
-stat* stat_init();
-void stat_print_info(WINDOW* w, int y, int maxx, const char* label,
- unsigned long total, unsigned long ava);
-void stat_print_cpu_info(WINDOW* w, int y, int maxx, stat* s);
-void stat_draw_bar(WINDOW* w, const char* label, int maxx, int y, int x,
- unsigned long total, unsigned long ava);
-void stat_draw_cpu_bar(WINDOW* w, int maxx, int y, int x, stat* s);
-void stat_get_meminfo(stat* s);
-void stat_get_diskinfo(stat* s);
-void stat_get_cpuinfo(stat* s);
-void stat_calc_cpuocc(stat* s);
+void stat_get_sysver(stat *s);
+stat *stat_init();
+void stat_print_info(WINDOW *w, int y, int maxx, const char *label,
+ unsigned long total, unsigned long ava);
+void stat_print_cpu_info(WINDOW *w, int y, int maxx, stat *s);
+void stat_draw_bar(WINDOW *w, const char *label, int maxx, int y, int x,
+ unsigned long total, unsigned long ava);
+void stat_draw_cpu_bar(WINDOW *w, int maxx, int y, int x, stat *s);
+void stat_get_meminfo(stat *s);
+void stat_get_diskinfo(stat *s);
+void stat_get_cpuinfo(stat *s);
int stat_get_bar_ticks(int maxx, unsigned long long total,
- unsigned long long ava);
+ unsigned long long ava);
#endif /* SF_STAT_H */