From 88938b24c369d293bfac34479181a4004c8e3304 Mon Sep 17 00:00:00 2001 From: "Matt McCormick (thewtex)" Date: Wed, 24 Feb 2010 23:37:21 -0600 Subject: [PATCH] Calculate used memory. --- tmux-mem-cpu-load.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/tmux-mem-cpu-load.cpp b/tmux-mem-cpu-load.cpp index 27ec42e..d12ef9c 100644 --- a/tmux-mem-cpu-load.cpp +++ b/tmux-mem-cpu-load.cpp @@ -94,7 +94,9 @@ string cpu_string() string mem_string() { - int total_mem; + unsigned int total_mem; + unsigned int used_mem; + unsigned int unused_mem; size_t line_start_pos; size_t line_end_pos; istringstream iss; @@ -109,12 +111,23 @@ string mem_string() iss.str( mem_line.substr( line_start_pos, line_end_pos - line_start_pos ) ); iss >> total_mem; - oss << "MEM: "; - oss << total_mem / 1024; + used_mem = total_mem; - + for( unsigned int i = 0; i < 3; i++ ) + { + getline( meminfo_file, mem_line ); + line_start_pos = mem_line.find_first_of( ':' ); + line_start_pos++; + line_end_pos = mem_line.find_first_of( 'k' ); + iss.str( mem_line.substr( line_start_pos, line_end_pos - line_start_pos ) ); + iss >> unused_mem; + used_mem -= unused_mem; + } meminfo_file.close(); + oss << "Mem: "; + oss << used_mem / 1024 << '/' << total_mem / 1024; + return oss.str(); }