From 2040736dd67496449b228d08c71b32f8f4e21951 Mon Sep 17 00:00:00 2001 From: l0ner Date: Sat, 19 Apr 2014 22:36:59 +0000 Subject: [PATCH] CPU usage graph generation by getGraphByPercentage function. --- CMakeLists.txt | 2 +- tmux-mem-cpu-load.cpp | 25 +++++++++++-------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e47058..645b162 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,7 @@ SET( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}" ) # add binary tree so we find version.h include_directories("${PROJECT_BINARY_DIR}" ${Boost_INCLUDE_DIRS}) -add_executable(tmux-mem-cpu-load tmux-mem-cpu-load.cpp ${METER_SOURCES}) +add_executable(tmux-mem-cpu-load tmux-mem-cpu-load.cpp graph.cc ${METER_SOURCES}) target_link_libraries(tmux-mem-cpu-load ${Boost_LIBRARIES}) install(TARGETS tmux-mem-cpu-load RUNTIME DESTINATION bin diff --git a/tmux-mem-cpu-load.cpp b/tmux-mem-cpu-load.cpp index f618450..c0cea93 100644 --- a/tmux-mem-cpu-load.cpp +++ b/tmux-mem-cpu-load.cpp @@ -44,6 +44,8 @@ #include "linux/load.h" #endif +#include "graph.h" + // Function declarations. // TODO: those should stay in separate headers // LINUX: DONE/partial @@ -52,28 +54,23 @@ std::string cpu_string( unsigned int cpu_usage_delay, unsigned int graph_lines, bool use_colors = false ) { - std::string meter( graph_lines + 2, ' ' ); - meter[0] = '['; - meter[meter.length() - 1] = ']'; - int meter_count = 0; - float percentage; + + float percentage; + + //output stuff std::ostringstream oss; oss.precision( 1 ); oss.setf( std::ios::fixed | std::ios::right ); + // get % percentage = cpu_percentage( cpu_usage_delay ); - float meter_step = 99.9 / graph_lines; - meter_count = 1; - - while(meter_count*meter_step < percentage) { - meter[meter_count] = '|'; - meter_count++; - } if( use_colors ) oss << cpu_percentage_lut[static_cast( percentage )]; - - oss << meter; + + oss << "["; + oss << getGraphByPercentage( unsigned(percentage), graph_lines ); + oss << "]"; oss.width( 5 ); oss << percentage; oss << "%";