initial
This commit is contained in:
parent
d67e39f3f7
commit
58ef6d327f
1725 changed files with 129819 additions and 0 deletions
40
dot_tmux/plugins/tmux-mem-cpu-load/common/conversions.h
Normal file
40
dot_tmux/plugins/tmux-mem-cpu-load/common/conversions.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CONVERSIONS_H_
|
||||
#define CONVERSIONS_H_
|
||||
|
||||
enum BYTE_UNITS
|
||||
{
|
||||
BYTES = 0,
|
||||
KILOBYTES = 1,
|
||||
MEGABYTES = 2,
|
||||
GIGABYTES = 3
|
||||
};
|
||||
|
||||
template <class T>
|
||||
inline T convert_unit( T num, int to, int from = BYTES)
|
||||
{
|
||||
for( ; from < to; from++)
|
||||
{
|
||||
num /= 1024;
|
||||
}
|
||||
return num;
|
||||
}
|
||||
|
||||
#endif
|
||||
67
dot_tmux/plugins/tmux-mem-cpu-load/common/cpu.h
Normal file
67
dot_tmux/plugins/tmux-mem-cpu-load/common/cpu.h
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef CPU_H_
|
||||
#define CPU_H_
|
||||
|
||||
#include <cstdint>
|
||||
#include <sys/types.h>
|
||||
|
||||
#if defined(__APPLE__) && defined(__MACH__)
|
||||
#define CP_USER 0
|
||||
#define CP_SYS 1
|
||||
#define CP_IDLE 2
|
||||
#define CP_NICE 3
|
||||
#define CP_STATES 4
|
||||
#elif defined(__OpenBSD__)
|
||||
#include <sys/sched.h>
|
||||
#define CP_STATES CPUSTATES
|
||||
#else
|
||||
#define CP_USER 0
|
||||
#define CP_NICE 1
|
||||
#define CP_SYS 2
|
||||
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__)
|
||||
// *BSD or OSX
|
||||
#define CP_INTR 3
|
||||
#define CP_IDLE 4
|
||||
#define CP_STATES 5
|
||||
#else
|
||||
//linux
|
||||
#define CP_IDLE 3
|
||||
#define CP_STATES 4
|
||||
#endif
|
||||
#endif
|
||||
|
||||
float cpu_percentage( unsigned );
|
||||
uint32_t get_cpu_count();
|
||||
|
||||
/** CPU percentage output mode.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* CPU_MODE_DEFAULT: 100%
|
||||
* CPU_MODE_THREADS: 800% (8 cores, fully loaded)
|
||||
*/
|
||||
enum CPU_MODE
|
||||
{
|
||||
CPU_MODE_DEFAULT,
|
||||
CPU_MODE_THREADS
|
||||
};
|
||||
|
||||
#endif
|
||||
37
dot_tmux/plugins/tmux-mem-cpu-load/common/error.h
Normal file
37
dot_tmux/plugins/tmux-mem-cpu-load/common/error.h
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef BSD_ERROR_H_
|
||||
#define BSD_ERROR_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <sys/errno.h>
|
||||
#include <cerrno>
|
||||
#include <cstring> // strerror
|
||||
#include <cstdlib> // exit()
|
||||
|
||||
inline void error( const char * error )
|
||||
{
|
||||
using std::cerr;
|
||||
using std::endl;
|
||||
|
||||
cerr << error << ": " << strerror( errno ) << endl;
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
"""Create the color code lookup table header."""
|
||||
|
||||
import matplotlib.cm
|
||||
|
||||
def write_table(fp, colormap_name, stat_name, first_half_foreground, second_half_foreground):
|
||||
fp.write('static const char ')
|
||||
fp.write(stat_name)
|
||||
fp.write('_lut[][32] = {\n')
|
||||
colormap = matplotlib.cm.get_cmap(colormap_name)
|
||||
for ii in range(101):
|
||||
fp.write('"#[fg=')
|
||||
if ii < 50:
|
||||
fp.write(first_half_foreground)
|
||||
else:
|
||||
fp.write(second_half_foreground)
|
||||
fp.write(',bg=colour')
|
||||
rgba = colormap(ii * 0.01)
|
||||
red = int(round(rgba[0] * 5))
|
||||
green = int(round(rgba[1] * 5))
|
||||
blue = int(round(rgba[2] * 5))
|
||||
color = 16 + 36*red + 6*green + blue;
|
||||
fp.write(str(color))
|
||||
fp.write(']"')
|
||||
if ii != 100:
|
||||
fp.write(',')
|
||||
fp.write('\n')
|
||||
fp.write('}; // end ')
|
||||
fp.write(stat_name)
|
||||
fp.write('_lut\n\n')
|
||||
|
||||
with open('luts.h', 'w') as fp:
|
||||
fp.write('#ifndef _luts_h\n')
|
||||
fp.write('#define _luts_h\n\n')
|
||||
|
||||
# hot colormap with white fg for the first half
|
||||
# and black fg for the second half
|
||||
write_table(fp, 'hot', 'cpu_percentage', 'brightwhite', 'black')
|
||||
write_table(fp, 'gist_earth', 'mem', 'brightwhite', 'black')
|
||||
write_table(fp, 'bone', 'load', 'brightwhite', 'black')
|
||||
|
||||
fp.write('#endif\n')
|
||||
53
dot_tmux/plugins/tmux-mem-cpu-load/common/getsysctl.h
Normal file
53
dot_tmux/plugins/tmux-mem-cpu-load/common/getsysctl.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2013 Justin Crawford <Justasic@gmail.com>
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Based on: github.com/freebsd/freebsd/blob/master/usr.bin/top/machine.c
|
||||
// Based on: Apple.cpp for load_string/mem_string and apple's documentation
|
||||
|
||||
#ifndef BSD_METER_COMMON_H_
|
||||
#define BSD_METER_COMMON_H_
|
||||
|
||||
#include <iostream>
|
||||
#include <cerrno>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/types.h>
|
||||
#include <cstdlib> //exit()
|
||||
#include <string.h> //strerror()
|
||||
|
||||
#define GETSYSCTL(name, var) getsysctl(name, &(var), sizeof(var))
|
||||
static inline void getsysctl( const char *name, void *ptr, size_t len )
|
||||
{
|
||||
size_t nlen = len;
|
||||
|
||||
if( sysctlbyname( name, ptr, &nlen, NULL, 0 ) == -1 )
|
||||
{
|
||||
std::cerr << "sysctl(" << name << "...) failed: " << strerror( errno )
|
||||
<< std::endl;
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
if( nlen != len )
|
||||
{
|
||||
std::cerr << "sysctl(" << name << "...) expected "
|
||||
<< static_cast<unsigned long>( len ) << " bytes, got "
|
||||
<< static_cast<unsigned long>( nlen ) << " bytes\n";
|
||||
//exit( 23 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
80
dot_tmux/plugins/tmux-mem-cpu-load/common/graph.cc
Normal file
80
dot_tmux/plugins/tmux-mem-cpu-load/common/graph.cc
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <map>
|
||||
|
||||
#include "graph.h"
|
||||
|
||||
std::string get_graph_by_percentage( unsigned value, unsigned len )
|
||||
{
|
||||
unsigned step = 0;
|
||||
std::string bars;
|
||||
|
||||
unsigned bar_count = ( static_cast<float>(value) / 99.9 * len );
|
||||
|
||||
for( ; step < bar_count; step++ )
|
||||
{
|
||||
bars.append( "|" );
|
||||
}
|
||||
for( ; step < len; step++ )
|
||||
{
|
||||
bars.append( " " );
|
||||
}
|
||||
|
||||
return bars;
|
||||
}
|
||||
|
||||
|
||||
std::string get_graph_by_value( unsigned value, unsigned max, unsigned len )
|
||||
{
|
||||
unsigned step = 0;
|
||||
std::string bars;
|
||||
|
||||
unsigned bar_count = ( static_cast<float>( value / ( max - 0.1 ) ) * len );
|
||||
|
||||
for( ; step < bar_count; step++ )
|
||||
{
|
||||
bars.append( "|" );
|
||||
}
|
||||
for( ; step < len; step++ )
|
||||
{
|
||||
bars.append( " " );
|
||||
}
|
||||
|
||||
return bars;
|
||||
}
|
||||
|
||||
std::string get_graph_vert( unsigned value )
|
||||
{
|
||||
static const std::map<unsigned, std::string> graph_chars = {
|
||||
{ 0, " " }, { 10, "▁" }, { 20, "▂" }, { 30, "▃" }, { 40, "▄" },
|
||||
{ 50, "▅" }, { 60, "▆" }, { 70, "▇" }, { 80, "█" }, { 90, "▲" }
|
||||
};
|
||||
|
||||
for( auto it = graph_chars.rbegin(); it != graph_chars.rend(); ++it )
|
||||
{
|
||||
if( value >= it->first )
|
||||
{
|
||||
return it->second;
|
||||
}
|
||||
}
|
||||
|
||||
return " "; // default return in case value doesn't match map options
|
||||
}
|
||||
28
dot_tmux/plugins/tmux-mem-cpu-load/common/graph.h
Normal file
28
dot_tmux/plugins/tmux-mem-cpu-load/common/graph.h
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef GRAPH_H_
|
||||
#define GRAPH_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string get_graph_by_percentage( unsigned, unsigned len = 10 );
|
||||
std::string get_graph_by_value( unsigned, unsigned, unsigned len = 10 );
|
||||
std::string get_graph_vert( unsigned );
|
||||
|
||||
#endif
|
||||
124
dot_tmux/plugins/tmux-mem-cpu-load/common/load.cc
Normal file
124
dot_tmux/plugins/tmux-mem-cpu-load/common/load.cc
Normal file
|
|
@ -0,0 +1,124 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2013 Justin Crawford <Justasic@gmail.com>
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
* Copyright 2016 Compilenix
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// Based on: github.com/freebsd/freebsd/blob/master/usr.bin/top/machine.c
|
||||
// Based on: Apple.cpp for load_string/mem_string and apple's documentation
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <stdlib.h> // getloadavg()
|
||||
#include <cmath> // floorf()
|
||||
#include <sys/types.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cpu.h"
|
||||
#include "load.h"
|
||||
#include "luts.h"
|
||||
|
||||
#include "powerline.h"
|
||||
|
||||
// Load Averages
|
||||
std::string load_string( bool use_colors,
|
||||
bool use_powerline_left, bool use_powerline_right, short num_averages,
|
||||
bool segments_to_right, short right_color )
|
||||
{
|
||||
std::ostringstream ss;
|
||||
ss.setf( std::ios::fixed, std::ios::floatfield );
|
||||
ss.precision( 2 );
|
||||
double averages[num_averages];
|
||||
// based on: opensource.apple.com/source/Libc/Libc-262/gen/getloadavg.c
|
||||
|
||||
if( num_averages <= 0 || num_averages > 3)
|
||||
{
|
||||
ss << (char) 0;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
if( getloadavg( averages, num_averages ) < 0 )
|
||||
{
|
||||
ss << " 0.00 0.00 0.00"; // couldn't get averages.
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned load_percent = static_cast<unsigned int>( averages[0] /
|
||||
get_cpu_count() * 0.5f * 100.0f );
|
||||
|
||||
if( load_percent > 100 )
|
||||
{
|
||||
load_percent = 100;
|
||||
}
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_right )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_RIGHT );
|
||||
}
|
||||
else if( use_powerline_left )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_LEFT );
|
||||
}
|
||||
else
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], NONE );
|
||||
}
|
||||
}
|
||||
|
||||
ss << ' ';
|
||||
for( int i = 0; i < num_averages; ++i )
|
||||
{
|
||||
// Round to nearest, make sure this is only a 0.00 value not a 0.0000
|
||||
float avg = floorf( static_cast<float>( averages[i] ) * 100 + 0.5 ) / 100;
|
||||
// Don't print trailing whitespace for last element
|
||||
if ( i == num_averages-1 )
|
||||
{
|
||||
ss << avg;
|
||||
}
|
||||
else
|
||||
{
|
||||
ss << avg << " ";
|
||||
}
|
||||
}
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_left && segments_to_right )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_LEFT, true );
|
||||
powerline_char( ss, load_lut[load_percent], right_color, POWERLINE_LEFT, true );
|
||||
}
|
||||
else if( use_powerline_left && !segments_to_right )
|
||||
{
|
||||
powerline( ss, load_lut[load_percent], POWERLINE_LEFT, true );
|
||||
powerline( ss, "#[fg=default,bg=default]", POWERLINE_LEFT );
|
||||
}
|
||||
else if( !use_powerline_right )
|
||||
{
|
||||
ss << "#[fg=default,bg=default]";
|
||||
}
|
||||
else if ( segments_to_right && use_powerline_right )
|
||||
{
|
||||
powerline_char( ss, load_lut[load_percent], right_color, POWERLINE_RIGHT, true );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
30
dot_tmux/plugins/tmux-mem-cpu-load/common/load.h
Normal file
30
dot_tmux/plugins/tmux-mem-cpu-load/common/load.h
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
* Copyright 2016 Compilenix
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef LOAD_H_
|
||||
#define LOAD_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
std::string load_string( bool use_colors = false,
|
||||
bool use_powerline_left = false, bool use_powerline_right = false,
|
||||
short num_averages = 3, bool segments_to_right = false,
|
||||
short right_color = 0 );
|
||||
|
||||
#endif
|
||||
316
dot_tmux/plugins/tmux-mem-cpu-load/common/luts.h
Normal file
316
dot_tmux/plugins/tmux-mem-cpu-load/common/luts.h
Normal file
|
|
@ -0,0 +1,316 @@
|
|||
#ifndef _luts_h
|
||||
#define _luts_h
|
||||
|
||||
static const char cpu_percentage_lut[][32] = {
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour19]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour20]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour21]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour57]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour56]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour55]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour54]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour53]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour52]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour88]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour124]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour160]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]",
|
||||
"#[fg=brightwhite,bg=colour196]"
|
||||
}; // end cpu_percentage_lut
|
||||
|
||||
static const char mem_lut[][32] = {
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour18]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour24]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour66]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour72]",
|
||||
"#[fg=brightwhite,bg=colour71]",
|
||||
"#[fg=brightwhite,bg=colour71]",
|
||||
"#[fg=brightwhite,bg=colour71]",
|
||||
"#[fg=brightwhite,bg=colour107]",
|
||||
"#[fg=brightwhite,bg=colour107]",
|
||||
"#[fg=black,bg=colour107]",
|
||||
"#[fg=black,bg=colour107]",
|
||||
"#[fg=black,bg=colour108]",
|
||||
"#[fg=black,bg=colour108]",
|
||||
"#[fg=black,bg=colour108]",
|
||||
"#[fg=black,bg=colour108]",
|
||||
"#[fg=black,bg=colour108]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour144]",
|
||||
"#[fg=black,bg=colour150]",
|
||||
"#[fg=black,bg=colour150]",
|
||||
"#[fg=black,bg=colour186]",
|
||||
"#[fg=black,bg=colour186]",
|
||||
"#[fg=black,bg=colour186]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour180]",
|
||||
"#[fg=black,bg=colour181]",
|
||||
"#[fg=black,bg=colour181]",
|
||||
"#[fg=black,bg=colour181]",
|
||||
"#[fg=black,bg=colour181]",
|
||||
"#[fg=black,bg=colour187]",
|
||||
"#[fg=black,bg=colour187]",
|
||||
"#[fg=black,bg=colour187]",
|
||||
"#[fg=black,bg=colour187]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour224]",
|
||||
"#[fg=black,bg=colour224]",
|
||||
"#[fg=black,bg=colour224]",
|
||||
"#[fg=black,bg=colour224]",
|
||||
"#[fg=black,bg=colour224]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]"
|
||||
}; // end mem_lut
|
||||
|
||||
static const char load_lut[][32] = {
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour16]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour17]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour59]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour60]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour102]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=brightwhite,bg=colour103]",
|
||||
"#[fg=black,bg=colour103]",
|
||||
"#[fg=black,bg=colour103]",
|
||||
"#[fg=black,bg=colour109]",
|
||||
"#[fg=black,bg=colour109]",
|
||||
"#[fg=black,bg=colour109]",
|
||||
"#[fg=black,bg=colour109]",
|
||||
"#[fg=black,bg=colour109]",
|
||||
"#[fg=black,bg=colour109]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour145]",
|
||||
"#[fg=black,bg=colour146]",
|
||||
"#[fg=black,bg=colour146]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour152]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour188]",
|
||||
"#[fg=black,bg=colour195]",
|
||||
"#[fg=black,bg=colour195]",
|
||||
"#[fg=black,bg=colour195]",
|
||||
"#[fg=black,bg=colour195]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]",
|
||||
"#[fg=black,bg=colour231]"
|
||||
}; // end load_lut
|
||||
|
||||
#endif
|
||||
302
dot_tmux/plugins/tmux-mem-cpu-load/common/main.cc
Normal file
302
dot_tmux/plugins/tmux-mem-cpu-load/common/main.cc
Normal file
|
|
@ -0,0 +1,302 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <cstdlib> // EXIT_SUCCESS, atoi()
|
||||
#include <getopt.h> // getopt_long
|
||||
|
||||
#include "version.h"
|
||||
#include "graph.h"
|
||||
|
||||
// Tmux color lookup tables for the different metrics.
|
||||
#include "luts.h"
|
||||
|
||||
#include "cpu.h"
|
||||
#include "memory.h"
|
||||
#include "load.h"
|
||||
|
||||
#include "powerline.h"
|
||||
|
||||
std::string cpu_string( CPU_MODE cpu_mode, unsigned int cpu_usage_delay, unsigned int graph_lines,
|
||||
bool use_colors = false,
|
||||
bool use_powerline_left = false, bool use_powerline_right = false, bool use_vert_graph = false)
|
||||
{
|
||||
|
||||
float percentage;
|
||||
float multiplier = 1.0f;
|
||||
|
||||
//output stuff
|
||||
std::ostringstream oss;
|
||||
oss.precision( 1 );
|
||||
oss.setf( std::ios::fixed | std::ios::right );
|
||||
|
||||
// get %
|
||||
percentage = cpu_percentage( cpu_usage_delay );
|
||||
|
||||
// set multiplier to number of threads ?
|
||||
if ( cpu_mode == CPU_MODE_THREADS )
|
||||
{
|
||||
multiplier = get_cpu_count();
|
||||
}
|
||||
|
||||
// if percentage*multiplier >= 100, remove decimal point to keep number short
|
||||
if ( percentage*multiplier >= 100.0f )
|
||||
{
|
||||
oss.precision( 0 );
|
||||
}
|
||||
|
||||
unsigned int percent = static_cast<unsigned int>( percentage );
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_right )
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], POWERLINE_RIGHT );
|
||||
}
|
||||
else if( use_powerline_left )
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], POWERLINE_LEFT );
|
||||
}
|
||||
else
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], NONE );
|
||||
}
|
||||
}
|
||||
|
||||
if( use_vert_graph )
|
||||
{
|
||||
oss << "▕";
|
||||
oss << get_graph_vert( unsigned( percentage ) );
|
||||
oss << "▏";
|
||||
}
|
||||
else if( graph_lines > 0)
|
||||
{
|
||||
oss << " [";
|
||||
oss << get_graph_by_percentage( unsigned( percentage ), graph_lines );
|
||||
oss << "]";
|
||||
}
|
||||
oss.width( 6 );
|
||||
oss.setf( std::ios::fixed, std::ios::floatfield );
|
||||
oss.precision( 1 );
|
||||
oss.fill( ' ' );
|
||||
oss << std::right << percentage * multiplier;
|
||||
oss << "%";
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_left )
|
||||
{
|
||||
powerline( oss, cpu_percentage_lut[percent], POWERLINE_LEFT, true );
|
||||
}
|
||||
else if( !use_powerline_right )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
void print_help()
|
||||
{
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
cout << "tmux-mem-cpu-load v" << tmux_mem_cpu_load_VERSION << endl
|
||||
<< "Usage: tmux-mem-cpu-load [OPTIONS]\n\n"
|
||||
<< "Available options:\n"
|
||||
<< "-h, --help\n"
|
||||
<< "\t Prints this help message\n"
|
||||
<< "-c, --colors\n"
|
||||
<< "\tUse tmux colors in output\n"
|
||||
<< "-p, --powerline-left\n"
|
||||
<< "\tUse powerline left symbols throughout the output, enables --colors\n"
|
||||
<< "-q, --powerline-right\n"
|
||||
<< "\tUse powerline right symbols throughout the output, enables --colors\n"
|
||||
<< "-v, --vertical-graph\n"
|
||||
<< "\tUse vertical bar chart for CPU graph\n"
|
||||
<< "-l <value>, --segments-left <value>\n"
|
||||
<< "\tEnable blending bg/fg color (depending on -p or -q use) with segment to left\n"
|
||||
<< "\tProvide color to be used depending on -p or -q option for seamless segment blending\n"
|
||||
<< "\tColor is an integer value which uses the standard tmux color palette values\n"
|
||||
<< "-r <value>, --segments-right <value>\n"
|
||||
<< "\tEnable blending bg/fg color (depending on -p or -q use) with segment to right\n"
|
||||
<< "\tProvide color to be used depending on -p or -q option for seamless segment blending\n"
|
||||
<< "\tColor is an integer value which uses the standard tmux color palette values\n"
|
||||
<< "-i <value>, --interval <value>\n"
|
||||
<< "\tSet tmux status refresh interval in seconds. Default: 1 second\n"
|
||||
<< "-g <value>, --graph-lines <value>\n"
|
||||
<< "\tSet how many lines should be drawn in a graph. Default: 10\n"
|
||||
<< "-m <value>, --mem-mode <value>\n"
|
||||
<< "\tSet memory display mode. 0: Default, 1: Free memory, 2: Usage percent.\n"
|
||||
<< "-t <value>, --cpu-mode <value>\n"
|
||||
<< "\tSet cpu % display mode. 0: Default max 100%, 1: Max 100% * number of threads. \n"
|
||||
<< "-a <value>, --averages-count <value>\n"
|
||||
<< "\tSet how many load-averages should be drawn. Default: 3\n"
|
||||
<< endl;
|
||||
}
|
||||
|
||||
int main( int argc, char** argv )
|
||||
{
|
||||
unsigned cpu_usage_delay = 990000;
|
||||
short averages_count = 3;
|
||||
short graph_lines = 10; // max 32767 should be enough
|
||||
short left_color = 0;
|
||||
short right_color = 0;
|
||||
bool use_colors = false;
|
||||
bool use_powerline_left = false;
|
||||
bool use_powerline_right = false;
|
||||
bool use_vert_graph = false;
|
||||
bool segments_to_left = false;
|
||||
bool segments_to_right= false;
|
||||
MEMORY_MODE mem_mode = MEMORY_MODE_DEFAULT;
|
||||
CPU_MODE cpu_mode = CPU_MODE_DEFAULT;
|
||||
|
||||
static struct option long_options[] =
|
||||
{
|
||||
// Struct is a s follows:
|
||||
// const char * name, int has_arg, int *flag, int val
|
||||
// if *flag is null, val is option identifier to use in switch()
|
||||
// otherwise it's a value to set the variable *flag points to
|
||||
{ "help", no_argument, NULL, 'h' },
|
||||
{ "colors", no_argument, NULL, 'c' },
|
||||
{ "powerline-left", no_argument, NULL, 'p' },
|
||||
{ "powerline-right", no_argument, NULL, 'q' },
|
||||
{ "vertical-graph", no_argument, NULL, 'v' },
|
||||
{ "interval", required_argument, NULL, 'i' },
|
||||
{ "graph-lines", required_argument, NULL, 'g' },
|
||||
{ "mem-mode", required_argument, NULL, 'm' },
|
||||
{ "cpu-mode", required_argument, NULL, 't' },
|
||||
{ "averages-count", required_argument, NULL, 'a' },
|
||||
{ "segments-left", required_argument, NULL, 'l' },
|
||||
{ "segments-right", required_argument, NULL, 'r' },
|
||||
{ 0, 0, 0, 0 } // used to handle unknown long options
|
||||
};
|
||||
|
||||
int c;
|
||||
// while c != -1
|
||||
while( (c = getopt_long( argc, argv, "hi:cpqvl:r:g:m:a:t:", long_options, NULL) ) != -1 )
|
||||
{
|
||||
switch( c )
|
||||
{
|
||||
case 'h': // --help, -h
|
||||
print_help();
|
||||
return EXIT_FAILURE;
|
||||
break;
|
||||
case 'c': // --colors
|
||||
use_colors = true;
|
||||
break;
|
||||
case 'p': // --powerline-left
|
||||
use_colors = true;
|
||||
use_powerline_left = true;
|
||||
break;
|
||||
case 'q': // --powerline-right
|
||||
use_colors = true;
|
||||
use_powerline_right = true;
|
||||
break;
|
||||
case 'v': // --vertical-graph
|
||||
use_vert_graph = true;
|
||||
break;
|
||||
case 'l': // --segments-left
|
||||
segments_to_left = true;
|
||||
if( atoi( optarg ) < 0 || atoi( optarg ) > 255 )
|
||||
{
|
||||
std::cerr << "Valid color vaues are from 0 to 255.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
left_color = atoi( optarg ) ;
|
||||
break;
|
||||
case 'r': // --segments-right
|
||||
segments_to_right= true;
|
||||
if( atoi( optarg ) < 0 || atoi( optarg ) > 255 )
|
||||
{
|
||||
std::cerr << "Valid color vaues are from 0 to 255.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
right_color = atoi( optarg ) ;
|
||||
break;
|
||||
case 'i': // --interval, -i
|
||||
if( atoi( optarg ) < 1 )
|
||||
{
|
||||
std::cerr << "Status interval argument must be one or greater.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cpu_usage_delay = atoi( optarg ) * 1000000 - 10000;
|
||||
break;
|
||||
case 'g': // --graph-lines, -g
|
||||
if( atoi( optarg ) < 0 )
|
||||
{
|
||||
std::cerr << "Graph lines argument must be zero or greater.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
graph_lines = atoi( optarg );
|
||||
break;
|
||||
case 'm': // --mem-mode, -m
|
||||
if( atoi( optarg ) < 0 )
|
||||
{
|
||||
std::cerr << "Memory mode argument must be zero or greater.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
mem_mode = static_cast< MEMORY_MODE >( atoi( optarg ) );
|
||||
break;
|
||||
case 't': // --cpu-mode, -t
|
||||
if( atoi( optarg ) < 0 )
|
||||
{
|
||||
std::cerr << "CPU mode argument must be zero or greater.\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
cpu_mode = static_cast< CPU_MODE >( atoi( optarg ) );
|
||||
break;
|
||||
case 'a': // --averages-count, -a
|
||||
if( atoi( optarg ) < 0 || atoi( optarg ) > 3 )
|
||||
{
|
||||
std::cerr << "Valid averages-count arguments are: 0, 1, 2, 3\n";
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
averages_count = atoi( optarg );
|
||||
break;
|
||||
case '?':
|
||||
// getopt_long prints error message automatically
|
||||
return EXIT_FAILURE;
|
||||
break;
|
||||
default:
|
||||
std::cerr << "?? getopt returned character code 0 " << c << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
}
|
||||
// Detect old option specification and return and error message.
|
||||
if( argc > optind )
|
||||
{
|
||||
std::cout <<
|
||||
"The interval and graph lines options are now specified with flags.\n\n";
|
||||
print_help();
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
MemoryStatus memory_status;
|
||||
mem_status( memory_status );
|
||||
std::cout << mem_string( memory_status, mem_mode, use_colors, use_powerline_left, use_powerline_right, segments_to_left, left_color )
|
||||
<< cpu_string( cpu_mode, cpu_usage_delay, graph_lines, use_colors, use_powerline_left, use_powerline_right, use_vert_graph )
|
||||
<< load_string( use_colors, use_powerline_left, use_powerline_right, averages_count, segments_to_right, right_color );
|
||||
|
||||
std::cout << std::endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
122
dot_tmux/plugins/tmux-mem-cpu-load/common/memory.cc
Normal file
122
dot_tmux/plugins/tmux-mem-cpu-load/common/memory.cc
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
#include "memory.h"
|
||||
#include "luts.h"
|
||||
#include "conversions.h"
|
||||
#include "powerline.h"
|
||||
|
||||
std::string mem_string( const MemoryStatus & mem_status,
|
||||
MEMORY_MODE mode,
|
||||
bool use_colors,
|
||||
bool use_powerline_left,
|
||||
bool use_powerline_right,
|
||||
bool segments_to_left,
|
||||
short left_color )
|
||||
{
|
||||
std::ostringstream oss;
|
||||
// Change the percision for floats, for a pretty output
|
||||
oss.precision( 2 );
|
||||
oss.setf( std::ios::fixed | std::ios::right );
|
||||
|
||||
unsigned int color = static_cast< unsigned int >((100 * mem_status.used_mem) / mem_status.total_mem);
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_right && segments_to_left )
|
||||
{
|
||||
powerline_char( oss, mem_lut[color], left_color, POWERLINE_RIGHT, false);
|
||||
oss << ' ';
|
||||
}
|
||||
else if( use_powerline_right && !segments_to_left )
|
||||
{
|
||||
oss << "#[bg=default]";
|
||||
powerline( oss, mem_lut[color], POWERLINE_RIGHT );
|
||||
oss << ' ';
|
||||
}
|
||||
else if( use_powerline_left && segments_to_left )
|
||||
{
|
||||
powerline_char( oss, mem_lut[color], left_color, POWERLINE_LEFT, false);
|
||||
oss << ' ';
|
||||
}
|
||||
else if( use_powerline_left )
|
||||
{
|
||||
//powerline( oss, mem_lut[color], POWERLINE_LEFT );
|
||||
// We do not know how to invert the default background color
|
||||
powerline( oss, mem_lut[color], NONE );
|
||||
oss << ' ';
|
||||
}
|
||||
else
|
||||
{
|
||||
powerline( oss, mem_lut[color], NONE );
|
||||
}
|
||||
}
|
||||
|
||||
switch( mode )
|
||||
{
|
||||
case MEMORY_MODE_FREE_MEMORY: // Show free memory in MB or GB
|
||||
{
|
||||
const float free_mem = mem_status.total_mem - mem_status.used_mem;
|
||||
const float free_mem_in_gigabytes = convert_unit( free_mem, GIGABYTES, MEGABYTES );
|
||||
|
||||
// if free memory is less than 1 GB, use MB instead
|
||||
if( free_mem_in_gigabytes < 1.0f )
|
||||
{
|
||||
oss << free_mem << "MB";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << free_mem_in_gigabytes << "GB";
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MEMORY_MODE_USAGE_PERCENTAGE:
|
||||
{
|
||||
// Calculate the percentage of used memory
|
||||
const float percentage_mem = mem_status.used_mem /
|
||||
static_cast<float>( mem_status.total_mem ) * 100.0;
|
||||
|
||||
oss << percentage_mem << '%';
|
||||
break;
|
||||
}
|
||||
default: // Default mode, just show the used/total memory in MB
|
||||
if(mem_status.used_mem>10000 && mem_status.total_mem>10000)
|
||||
oss<<static_cast<unsigned int>(mem_status.used_mem/1024)<<"/"<<static_cast<unsigned int>(mem_status.total_mem/1024)<<"GB";
|
||||
else if(mem_status.used_mem<10000 && mem_status.total_mem>10000)
|
||||
oss<<static_cast<unsigned int>(mem_status.used_mem)<<"MB/"<<static_cast<unsigned int>(mem_status.total_mem/1024)<<"GB";
|
||||
else
|
||||
oss<<static_cast<unsigned int>(mem_status.used_mem)<<"/"<<static_cast<unsigned int>(mem_status.total_mem)<<"MB";
|
||||
}
|
||||
|
||||
if( use_colors )
|
||||
{
|
||||
if( use_powerline_left )
|
||||
{
|
||||
powerline( oss, mem_lut[color], POWERLINE_LEFT, true );
|
||||
}
|
||||
else if( !use_powerline_right )
|
||||
{
|
||||
oss << "#[fg=default,bg=default]";
|
||||
}
|
||||
}
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
58
dot_tmux/plugins/tmux-mem-cpu-load/common/memory.h
Normal file
58
dot_tmux/plugins/tmux-mem-cpu-load/common/memory.h
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef MEMORY_H_
|
||||
#define MEMORY_H_
|
||||
|
||||
#include <string>
|
||||
|
||||
/** Memory status in megabytes */
|
||||
struct MemoryStatus
|
||||
{
|
||||
float used_mem;
|
||||
float total_mem;
|
||||
};
|
||||
|
||||
/** Get the current memory status */
|
||||
void mem_status( MemoryStatus & status );
|
||||
|
||||
|
||||
/** Memory status string output mode.
|
||||
*
|
||||
* Examples:
|
||||
*
|
||||
* MEMORY_MODE_DEFAULT: 11156/16003MB
|
||||
* MEMORY_MODE_FREE_MEMORY:
|
||||
* MEMORY_MODE_USAGE_PERCENTAGE:
|
||||
*/
|
||||
enum MEMORY_MODE
|
||||
{
|
||||
MEMORY_MODE_DEFAULT,
|
||||
MEMORY_MODE_FREE_MEMORY,
|
||||
MEMORY_MODE_USAGE_PERCENTAGE
|
||||
};
|
||||
|
||||
std::string mem_string( const MemoryStatus & mem_status,
|
||||
MEMORY_MODE mode = MEMORY_MODE_DEFAULT,
|
||||
bool use_colors = false,
|
||||
bool use_powerline_left = false,
|
||||
bool use_powerline_right = false,
|
||||
bool segments_to_left = false,
|
||||
short left_color = 0 );
|
||||
|
||||
#endif
|
||||
100
dot_tmux/plugins/tmux-mem-cpu-load/common/powerline.cc
Normal file
100
dot_tmux/plugins/tmux-mem-cpu-load/common/powerline.cc
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2016 Michał Goliński
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "powerline.h"
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <sstream>
|
||||
|
||||
#define PWL_LEFT_FILLED ""
|
||||
#define PWL_RIGHT_FILLED ""
|
||||
|
||||
const char * bg2fg( const char s[] )
|
||||
{
|
||||
static char buf[40] = {0};
|
||||
const char *substr = strchr(s, ',');
|
||||
buf[0] = '#';
|
||||
buf[1] = '[';
|
||||
buf[2] = 'f';
|
||||
strcpy(buf+3, substr+2);
|
||||
return buf;
|
||||
}
|
||||
|
||||
|
||||
void powerline( std::ostringstream & oss, const char color[],
|
||||
POWERLINE_DIRECTION direction, bool background_only )
|
||||
{
|
||||
switch( direction )
|
||||
{
|
||||
case NONE:
|
||||
oss << color;
|
||||
break;
|
||||
case POWERLINE_LEFT:
|
||||
if( background_only )
|
||||
{
|
||||
oss << ' ' << bg2fg( color );
|
||||
}
|
||||
else
|
||||
{
|
||||
std::string colorstr( color );
|
||||
oss << "#[" << colorstr.substr( colorstr.find( "," ) + 1 )
|
||||
<< PWL_LEFT_FILLED
|
||||
<< color;
|
||||
}
|
||||
break;
|
||||
case POWERLINE_RIGHT:
|
||||
oss << ' '
|
||||
<< bg2fg( color )
|
||||
<< PWL_RIGHT_FILLED
|
||||
<< color;
|
||||
break;
|
||||
};
|
||||
}
|
||||
|
||||
void powerline_char( std::ostringstream & oss, const char dynamic_color[],
|
||||
short static_color, POWERLINE_DIRECTION direction, bool eol )
|
||||
{
|
||||
char write_color[7];
|
||||
sprintf(write_color, "%d", static_color);
|
||||
switch( direction )
|
||||
{
|
||||
case POWERLINE_LEFT:
|
||||
if ( eol )
|
||||
{
|
||||
oss << bg2fg( dynamic_color ) << "#[bg=colour" << write_color << "]";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << dynamic_color << "#[fg=colour" << write_color << "]";
|
||||
}
|
||||
oss << PWL_LEFT_FILLED << dynamic_color;
|
||||
break;
|
||||
case POWERLINE_RIGHT:
|
||||
if ( eol )
|
||||
{
|
||||
oss << dynamic_color << "#[fg=colour" << write_color << "] ";
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << bg2fg(dynamic_color) << " #[bg=colour" << write_color << "]";
|
||||
}
|
||||
oss << PWL_RIGHT_FILLED << dynamic_color;
|
||||
break;
|
||||
}
|
||||
}
|
||||
40
dot_tmux/plugins/tmux-mem-cpu-load/common/powerline.h
Normal file
40
dot_tmux/plugins/tmux-mem-cpu-load/common/powerline.h
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2016 Michał Goliński
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef POWERLINE_H
|
||||
#define POWERLINE_H
|
||||
|
||||
#include <sstream>
|
||||
|
||||
enum POWERLINE_DIRECTION
|
||||
{
|
||||
NONE,
|
||||
POWERLINE_LEFT,
|
||||
POWERLINE_RIGHT
|
||||
};
|
||||
|
||||
/** Print out a powerline left character inverted version of the given
|
||||
* color. In the case of of using powerline left, the background color needs
|
||||
* to be inverted to the foreground before the powerline character is printed
|
||||
* in the next entr. */
|
||||
void powerline( std::ostringstream & oss, const char color[],
|
||||
POWERLINE_DIRECTION direction, bool background_only = false );
|
||||
void powerline_char( std::ostringstream & oss, const char dynamic_color[],
|
||||
short static_color, POWERLINE_DIRECTION direction, bool eol = false );
|
||||
|
||||
#endif // POWERLINE_H
|
||||
24
dot_tmux/plugins/tmux-mem-cpu-load/common/version.h.in
Normal file
24
dot_tmux/plugins/tmux-mem-cpu-load/common/version.h.in
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
/* vim: tabstop=2 shiftwidth=2 expandtab textwidth=80 linebreak wrap
|
||||
*
|
||||
* Copyright 2012 Matthew McCormick
|
||||
* Copyright 2015 Pawel 'l0ner' Soltys
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
// the configured options and settings for sysstat
|
||||
#define tmux_mem_cpu_load_VERSION_MAJOR @tmux-mem-cpu-load_VERSION_MAJOR@
|
||||
#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@"
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue