From 14bae13f8187b055579f8a1694f0dd31f2f31cc4 Mon Sep 17 00:00:00 2001 From: Gene Carlson Date: Sat, 24 Dec 2022 15:18:44 +0900 Subject: [PATCH] FreeBSD: Additional memory reporting variables. --- AUTHORS | 5 +++++ doc/variables.yaml | 8 ++++++++ src/common.cc | 6 +++++- src/common.h | 4 ++++ src/conky.h | 3 ++- src/core.cc | 14 ++++++++++++++ src/freebsd.cc | 27 +++++++++++++++++++++++++-- 7 files changed, 63 insertions(+), 4 deletions(-) diff --git a/AUTHORS b/AUTHORS index eba35e53..cb4774e3 100644 --- a/AUTHORS +++ b/AUTHORS @@ -175,6 +175,11 @@ J Some cleaning and commenting apparently :) SIGHUP config file reload +K. Eugene Carlson + Additional Linux memory reporting variables + Linux CPU frequency governor reporting + Additional FreeBSD memory reporting variables + Kapil Hari Paranjape ibm_volume patch kFreeBSD support patch diff --git a/doc/variables.yaml b/doc/variables.yaml index 910aaf86..2c9dce20 100644 --- a/doc/variables.yaml +++ b/doc/variables.yaml @@ -1195,6 +1195,8 @@ values: - mbox - name: mem desc: Amount of memory in use. + - name: memactive + desc: Amount of active memory. FreeBSD only. - name: memavail desc: Amount of available memory as recorded in /proc/meminfo. Linux 3.14+ only. - name: membar @@ -1226,10 +1228,16 @@ values: - (scale) - (-t) - (-l) + - name: meminactive + desc: Amount of inactive memory. FreeBSD only. + - name: memlaundry + desc: Amount of memory in laundry. FreeBSD only. - name: memmax desc: Total amount of memory. - name: memperc desc: Percentage of memory in use. + - name: memwired + desc: Amount of wired memory. FreeBSD only. - name: memwithbuffers desc: |- Amount of memory in use, including that used by system diff --git a/src/common.cc b/src/common.cc index 410d300f..33ac3821 100644 --- a/src/common.cc +++ b/src/common.cc @@ -396,11 +396,15 @@ PRINT_HR_GENERATOR(mem) PRINT_HR_GENERATOR(memwithbuffers) PRINT_HR_GENERATOR(memeasyfree) PRINT_HR_GENERATOR(legacymem) +PRINT_HR_GENERATOR(memactive) +PRINT_HR_GENERATOR(meminactive) PRINT_HR_GENERATOR(memfree) PRINT_HR_GENERATOR(memmax) PRINT_HR_GENERATOR(memdirty) PRINT_HR_GENERATOR(shmem) PRINT_HR_GENERATOR(memavail) +PRINT_HR_GENERATOR(memwired) +PRINT_HR_GENERATOR(memlaundry) PRINT_HR_GENERATOR(swap) PRINT_HR_GENERATOR(swapfree) PRINT_HR_GENERATOR(swapmax) @@ -640,7 +644,7 @@ void print_battery_time(struct text_object *obj, char *p, } void battery_power_draw(struct text_object *obj, char *p, - unsigned int p_max_size) { + unsigned int p_max_size) { get_battery_power_draw(p, p_max_size, obj->data.s); } diff --git a/src/common.h b/src/common.h index 4d42702c..5b511f2a 100644 --- a/src/common.h +++ b/src/common.h @@ -109,6 +109,10 @@ void print_memeasyfree(struct text_object *, char *, unsigned int); void print_legacymem(struct text_object *, char *, unsigned int); void print_memfree(struct text_object *, char *, unsigned int); void print_memmax(struct text_object *, char *, unsigned int); +void print_memactive(struct text_object *, char *, unsigned int); +void print_meminactive(struct text_object *, char *, unsigned int); +void print_memwired(struct text_object *, char *, unsigned int); +void print_memlaundry(struct text_object *, char *, unsigned int); void print_memdirty(struct text_object *, char *, unsigned int); void print_shmem(struct text_object *, char *, unsigned int); void print_memavail(struct text_object *, char *, unsigned int); diff --git a/src/conky.h b/src/conky.h index 17c03da2..decc0262 100644 --- a/src/conky.h +++ b/src/conky.h @@ -166,7 +166,8 @@ struct information { /* memory information in kilobytes */ unsigned long long mem, memwithbuffers, memavail, memeasyfree, memfree, - memmax, memdirty, shmem, legacymem; + memmax, memdirty, shmem, legacymem, memactive, meminactive, memwired, + memlaundry; unsigned long long swap, swapfree, swapmax; unsigned long long bufmem, buffers, cached, free_bufcache; diff --git a/src/core.cc b/src/core.cc index 1b9a655a..7e3d1db7 100644 --- a/src/core.cc +++ b/src/core.cc @@ -1226,6 +1226,20 @@ struct text_object *construct_text_object(char *s, const char *arg, long line, obj->callbacks.print = &print_free_bufcache; obj->callbacks.free = &gen_free_opaque; #endif /* __linux__ */ +#ifdef __FreeBSD__ + END OBJ(memactive, &update_meminfo) obj->data.s = STRNDUP_ARG; + obj->callbacks.print = &print_memactive; + obj->callbacks.free = &gen_free_opaque; + END OBJ(meminactive, &update_meminfo) obj->data.s = STRNDUP_ARG; + obj->callbacks.print = &print_meminactive; + obj->callbacks.free = &gen_free_opaque; + END OBJ(memwired, &update_meminfo) obj->data.s = STRNDUP_ARG; + obj->callbacks.print = &print_memwired; + obj->callbacks.free = &gen_free_opaque; + END OBJ(memlaundry, &update_meminfo) obj->data.s = STRNDUP_ARG; + obj->callbacks.print = &print_memlaundry; + obj->callbacks.free = &gen_free_opaque; +#endif /* __FreeBSD__ */ #ifdef BUILD_GUI END OBJ(memgauge, &update_meminfo) scan_gauge(obj, arg, 1); obj->callbacks.gaugeval = &mem_barval; diff --git a/src/freebsd.cc b/src/freebsd.cc index 89bc60f0..8f6175e0 100644 --- a/src/freebsd.cc +++ b/src/freebsd.cc @@ -149,7 +149,8 @@ int check_mount(struct text_object *obj) { } int update_meminfo(void) { - u_int total_pages, inactive_pages, free_pages; + u_int total_pages, inactive_pages, free_pages, wire_pages, active_pages, + bufferspace, laundry_pages; unsigned long swap_avail, swap_free; int pagesize = getpagesize(); @@ -166,11 +167,33 @@ int update_meminfo(void) { fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_inactive_count\"\n"); } + if (GETSYSCTL("vm.stats.vm.v_wire_count", wire_pages)) { + fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_wire_count\"\n"); + } + + if (GETSYSCTL("vm.stats.vm.v_active_count", active_pages)) { + fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_active_count\"\n"); + } + + if (GETSYSCTL("vfs.bufspace", bufferspace)) { + fprintf(stderr, "Cannot read sysctl \"vfs.bufspace\"\n"); + } + + if (GETSYSCTL("vm.stats.vm.v_laundry_count", laundry_pages)) { + fprintf(stderr, "Cannot read sysctl \"vm.stats.vm.v_laundry_count\"\n"); + } + info.memmax = total_pages * (pagesize >> 10); info.mem = (total_pages - free_pages - inactive_pages) * (pagesize >> 10); info.memwithbuffers = info.mem; - info.memeasyfree = info.memfree = info.memmax - info.mem; + info.memeasyfree = info.memmax - info.mem; + info.memfree = free_pages * (pagesize >> 10); info.legacymem = info.mem; + info.memwired = wire_pages * (pagesize >> 10); + info.memactive = active_pages * (pagesize >> 10); + info.meminactive = inactive_pages * (pagesize >> 10); + info.memlaundry = laundry_pages * (pagesize >> 10); + info.buffers = bufferspace / 1024; if ((swapmode(&swap_avail, &swap_free)) >= 0) { info.swapmax = swap_avail;