diff --git a/CMakeLists.txt b/CMakeLists.txt index 9a229c2..4e42569 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,7 +46,7 @@ endif() # generate header file to handle version configure_file( - "${PROJECT_SOURCE_DIR}/version.h.in" "${PROJECT_SOURCE_DIR}/version.h" + "${PROJECT_SOURCE_DIR}/config.h.in" "${PROJECT_SOURCE_DIR}/config.h" ) # set buold type diff --git a/bsd/common.h b/bsd/common.h index fb0ff7f..58f6860 100644 --- a/bsd/common.h +++ b/bsd/common.h @@ -27,11 +27,6 @@ #include #include -// Memory Sizes -#define KILOBYTES(x) ((x)/1024) -#define MEGABYTES(x) (KILOBYTES((x))/1024) -#define GIGABYTES(x) (MEGABYTES((x))/1024) - // CPU percentages stuff #define CP_USER 0 #define CP_NICE 1 diff --git a/bsd/memory_freebsd.cc b/bsd/memory_freebsd.cc index 50d3e11..d37f8b4 100644 --- a/bsd/memory_freebsd.cc +++ b/bsd/memory_freebsd.cc @@ -26,6 +26,7 @@ #include "common.h" #include "memory.h" #include "../luts.h" +#include "../config.h" std::string mem_string( bool use_colors = false ) { diff --git a/bsd/memory_openbsd.cc b/bsd/memory_openbsd.cc index 84e29b8..ba00c6b 100644 --- a/bsd/memory_openbsd.cc +++ b/bsd/memory_openbsd.cc @@ -29,6 +29,7 @@ #include "common.h" #include "memory.h" #include "../luts.h" +#include "../config.h" std::string mem_string( bool use_colors = false ) { diff --git a/version.h.in b/config.h.in similarity index 88% rename from version.h.in rename to config.h.in index c46dd04..10a77b9 100644 --- a/version.h.in +++ b/config.h.in @@ -21,3 +21,8 @@ #define tmux_mem_cpu_load_VERSION_MINOR @tmux-mem-cpu-load_VERSION_MINOR@ #define tmux_mem_cpu_load_VERSION_PATCH @tmux-mem-cpu-load_VERSION_PATCH@ #define tmux_mem_cpu_load_VERSION "@tmux-mem-cpu-load_VERSION@" + +// Memory Sizes +#define KILOBYTES(x) ((x)/1024) +#define MEGABYTES(x) (KILOBYTES((x))/1024) +#define GIGABYTES(x) (MEGABYTES((x))/1024) diff --git a/linux/memory.cc b/linux/memory.cc index 42580a5..7254c5b 100644 --- a/linux/memory.cc +++ b/linux/memory.cc @@ -21,6 +21,7 @@ #include "memory.h" #include "../luts.h" +#include "../config.h" std::string mem_string( bool use_colors = false ) { @@ -29,17 +30,17 @@ std::string mem_string( bool use_colors = false ) struct sysinfo sinfo; sysinfo(&sinfo); - unsigned int total_mem = sinfo.totalram / 1014; - unsigned int used_mem = total_mem - sinfo.freeram / 1024; + unsigned int total_mem = MEGABYTES(sinfo.totalram); + unsigned int used_mem = total_mem - MEGABYTES(sinfo.freeram); // we don't need this for now - //unsigned int unused_mem = sinfo.freeram / 1024; + //unsigned int unused_mem = MEGABYTES(sinfo.freeram); if( use_colors ) { oss << mem_lut[(100 * used_mem) / total_mem]; } - oss << used_mem / 1024 << '/' << total_mem / 1024 << "MB"; + oss << used_mem << '/' << total_mem << "MB"; if( use_colors ) { diff --git a/osx/memory.cc b/osx/memory.cc index d83e5be..f9ac677 100644 --- a/osx/memory.cc +++ b/osx/memory.cc @@ -23,6 +23,7 @@ #include "memory.h" #include "../luts.h" +#include "../config.h" std::string mem_string( bool use_colors ) { @@ -58,16 +59,12 @@ std::string mem_string( bool use_colors ) ) * ( int64_t )page_size; } - // To kilobytes - used_mem /= 1024; - total_mem /= 1024; - if( use_colors ) { oss << mem_lut[( 100 * used_mem ) / total_mem]; } - oss << used_mem / 1024 << '/' << total_mem / 1024 << "MB"; + oss << MEGABYTES(used_mem) << '/' << MEGABYTES(total_mem) << "MB"; if( use_colors ) { diff --git a/tmux-mem-cpu-load.cpp b/tmux-mem-cpu-load.cpp index 15d090f..7f8f312 100644 --- a/tmux-mem-cpu-load.cpp +++ b/tmux-mem-cpu-load.cpp @@ -23,7 +23,7 @@ #include // EXIT_SUCCESS #include "argParse/argParse.h" -#include "version.h" +#include "config.h" #include "graph.h" // Tmux color lookup tables for the different metrics.