Skip to content

Commit

Permalink
Show cached memory as in free (Linux only)
Browse files Browse the repository at this point in the history
  • Loading branch information
pghvlaans authored and brndnmtthws committed Jan 14, 2024
1 parent 5e6db91 commit 0af1939
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions doc/variables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,8 @@ values:
- (interval)
- name: free_bufcache
desc: Amount of memory cached or buffered, as reported by free. Linux only.
- name: free_cached
desc: Amount of memory cached, as reported by free. Linux only.
- name: freq
desc: |-
Returns CPU #n's frequency in MHz. CPUs are counted from 1.
Expand Down
6 changes: 6 additions & 0 deletions src/common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,12 @@ void print_free_bufcache(struct text_object *obj, char *p,
p_max_size);
}

void print_free_cached(struct text_object *obj, char *p,
unsigned int p_max_size) {
human_readable(apply_base_multiplier(obj->data.s, info.free_cached), p,
p_max_size);
}

void print_evaluate(struct text_object *obj, char *p, unsigned int p_max_size) {
std::vector<char> buf(text_buffer_size.get(*state));
evaluate(obj->data.s, &buf[0], buf.size());
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ void print_threads(struct text_object *, char *, unsigned int);
void print_buffers(struct text_object *, char *, unsigned int);
void print_cached(struct text_object *, char *, unsigned int);
void print_free_bufcache(struct text_object *, char *, unsigned int);
void print_free_cached(struct text_object *, char *, unsigned int);

void print_evaluate(struct text_object *, char *, unsigned int);

Expand Down
2 changes: 1 addition & 1 deletion src/conky.h
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ struct information {
memmax, memdirty, shmem, legacymem, memactive, meminactive, memwired,
memlaundry;
unsigned long long swap, swapfree, swapmax;
unsigned long long bufmem, buffers, cached, free_bufcache;
unsigned long long bufmem, buffers, cached, free_bufcache, free_cached;

unsigned short procs;
unsigned short run_procs;
Expand Down
3 changes: 3 additions & 0 deletions src/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,9 @@ struct text_object *construct_text_object(char *s, const char *arg, long line,
END OBJ(free_bufcache, &update_meminfo) obj->data.s = STRNDUP_ARG;
obj->callbacks.print = &print_free_bufcache;
obj->callbacks.free = &gen_free_opaque;
END OBJ(free_cached, &update_meminfo) obj->data.s = STRNDUP_ARG;
obj->callbacks.print = &print_free_cached;
obj->callbacks.free = &gen_free_opaque;
#endif /* __linux__ */
#ifdef __FreeBSD__
END OBJ(memactive, &update_meminfo) obj->data.s = STRNDUP_ARG;
Expand Down
5 changes: 3 additions & 2 deletions src/linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ int update_meminfo(void) {
info.memmax = info.memdirty = info.swap = info.swapfree = info.swapmax =
info.memwithbuffers = info.buffers = info.cached = info.memfree =
info.memeasyfree = info.legacymem = info.shmem = info.memavail =
info.free_bufcache = 0;
info.free_bufcache = info.free_cached = 0;

if (!(meminfo_fp = open_file("/proc/meminfo", &reported))) { return 0; }

Expand Down Expand Up @@ -261,7 +261,8 @@ int update_meminfo(void) {
info.memeasyfree = cureasyfree;
info.legacymem =
info.memmax - (info.memfree + info.buffers + info.cached + sreclaimable);
info.free_bufcache = info.cached + info.buffers + sreclaimable;
info.free_cached = info.cached + sreclaimable;
info.free_bufcache = info.free_cached + info.buffers;

fclose(meminfo_fp);
return 0;
Expand Down

0 comments on commit 0af1939

Please sign in to comment.