use macros from config.h to calculate megabyes

instead of using hard coded divisions to calculate ram stats it's better to use
macros defined in config.h. BSD port was doing this already, using macros
defined in it's common.h header. I pulled those macros out and applied them to
all platforms.
File version.h.in got renamed into config.h.in since it doesn't caontain only
the version anymore.
This commit is contained in:
Pawel "l0ner" Soltys 2015-01-18 17:21:19 +01:00
parent b2084ea3b3
commit d3eb9e3187
8 changed files with 16 additions and 16 deletions

@ -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

@ -27,11 +27,6 @@
#include <sys/sysctl.h>
#include <sys/types.h>
// 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

@ -26,6 +26,7 @@
#include "common.h"
#include "memory.h"
#include "../luts.h"
#include "../config.h"
std::string mem_string( bool use_colors = false )
{

@ -29,6 +29,7 @@
#include "common.h"
#include "memory.h"
#include "../luts.h"
#include "../config.h"
std::string mem_string( bool use_colors = false )
{

@ -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)

@ -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 )
{

@ -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 )
{

@ -23,7 +23,7 @@
#include <cstdlib> // EXIT_SUCCESS
#include "argParse/argParse.h"
#include "version.h"
#include "config.h"
#include "graph.h"
// Tmux color lookup tables for the different metrics.