Commit 2c50a61e authored by Petr Štětka's avatar Petr Štětka
Browse files

*Added custom cpu graph

*Added custom cpu table
parent 1bdf3a82
......@@ -22,6 +22,8 @@ vala_binary: src/gnome-usage
*vala_check_package: x11
c_library: gtop-2.0 ${CMAKE_SOURCE_DIR}/external/rg/librg.a ${CMAKE_SOURCE_DIR}/external/egg/libegg-private.a
*vala_source: application.vala
*vala_source: cpu-graph-table.vala
*vala_source: cpu-graph.vala
*vala_source: cpu-sub-view.vala
*vala_source: data-view.vala
*vala_source: gnome-usage.vala
......@@ -40,18 +42,20 @@ h_folder: /usr/include/libgtop-2.0
*po: po
*translate: vala src/cpu-graph.vala
*translate: vala src/header-bar.vala
*translate: vala src/view.vala
*translate: vala src/storage-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/power-view.vala
*translate: vala src/process-list.vala
*translate: vala src/cpu-sub-view.vala
*translate: vala src/ram-sub-view.vala
*translate: vala src/data-view.vala
*translate: vala src/application.vala
*translate: vala src/data-view.vala
*translate: vala src/cpu-graph-table.vala
*translate: vala src/performance-view.vala
*translate: vala src/window.vala
*translate: vala src/system-monitor.vala
*translate: vala src/cpu-sub-view.vala
*translate: vala src/gnome-usage.vala
*data: data/local
......
src/application.vala
src/cpu-graph-table.vala
src/cpu-graph.vala
src/cpu-sub-view.vala
src/data-view.vala
src/gnome-usage.vala
......
......@@ -36,6 +36,8 @@ set (VALA_PACKAGES ${VALA_PACKAGES} x11)
set (APP_SOURCES ${APP_SOURCES} ${CMAKE_CURRENT_BINARY_DIR}/Config.vala)
set (APP_SOURCES ${APP_SOURCES} application.vala)
set (APP_SOURCES ${APP_SOURCES} cpu-graph-table.vala)
set (APP_SOURCES ${APP_SOURCES} cpu-graph.vala)
set (APP_SOURCES ${APP_SOURCES} cpu-sub-view.vala)
set (APP_SOURCES ${APP_SOURCES} data-view.vala)
set (APP_SOURCES ${APP_SOURCES} gnome-usage.vala)
......
......@@ -10,7 +10,7 @@ namespace Usage
public Application ()
{
application_id = "org.gnome.usage";
monitor = new SystemMonitor();
monitor = new SystemMonitor(1000);
}
public override void activate()
......
using Rg;
namespace Usage {
public class CpuGraphTable : Rg.Table
{
public CpuGraphTable (uint timespan, uint max_samples)
{
set_timespan (timespan * 1000);
set_max_samples (max_samples);
for (int i = 0; i < get_num_processors(); i++)
{
var column = new Rg.Column("CPU: " + i.to_string(), Type.from_name("gdouble"));
add_column(column);
}
(GLib.Application.get_default() as Application).monitor.set_update_graph_interval(timespan / (max_samples - 1)); //TODO move to settings!! Here is problem, that this will set all table ant it is problem.
Timeout.add(timespan / (max_samples - 1), update_data);
}
bool update_data()
{
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
for (int i = 0; i < get_num_processors(); i++)
iter.set (i, (GLib.Application.get_default() as Application).monitor.x_cpu_load_graph[i], -1);
return true;
}
}
}
using Rg;
namespace Usage {
public class CpuGraph : Rg.Graph {
static string[] colors = {
"#73d216",
"#f57900",
"#3465a4",
"#ef2929",
"#75507b",
"#ce5c00",
"#c17d11",
"#ce5c00",
};
private static CpuGraphTable table;
public CpuGraph (int64 timespan, int64 max_samples)
{
if(table == null)
{
table = new CpuGraphTable(30000, 60);
set_table(table);
}
else
set_table(table);
for(int i = 0; i < get_num_processors(); i++)
{
LineRenderer renderer = new LineRenderer();
renderer.column = i;
renderer.stroke_color = colors [i % colors.length];
add_renderer(renderer);
}
}
}
}
......@@ -27,7 +27,7 @@ namespace Usage
process_list_box = new ProcessList();
var cpu_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var cpu_graph = (Rg.CpuGraph) GLib.Object.new(typeof(Rg.CpuGraph), timespan: 30000000, max_samples: 60);
var cpu_graph = new CpuGraph(30000000, 60);
var cpu_graph_frame = new Gtk.Frame(null);
cpu_graph_frame.height_request = 200;
cpu_graph_frame.margin_start = margin_side;
......@@ -107,7 +107,7 @@ namespace Usage
all.toggled.connect(() => {
show_active_process = false;
monitor.set_process_mode(SystemMonitor.ProcessMode.ALL);
monitor.update();
monitor.update_data();
update_process();
});
......@@ -116,7 +116,7 @@ namespace Usage
my.toggled.connect(() => {
show_active_process = false;
monitor.set_process_mode(SystemMonitor.ProcessMode.USER);
monitor.update();
monitor.update_data();
update_process();
});
......
......@@ -94,7 +94,7 @@ namespace Usage
all.toggled.connect(() => {
show_active_process = false;
monitor.set_process_mode(SystemMonitor.ProcessMode.ALL);
monitor.update();
monitor.update_data();
update_process();
});
......@@ -103,7 +103,7 @@ namespace Usage
my.toggled.connect(() => {
show_active_process = false;
monitor.set_process_mode(SystemMonitor.ProcessMode.USER);
monitor.update();
monitor.update_data();
update_process();
});
......
......@@ -17,13 +17,29 @@ namespace Usage
public class SystemMonitor
{
public double cpu_load { get; private set; }
public double cpu_load_graph { get; private set; }
public double[] x_cpu_load { get; private set; }
public double[] x_cpu_load_graph { get; private set; }
public double mem_usage { get; private set; }
public double mem_usage_graph { get; private set; }
public double swap_usage { get; private set; }
public double swap_usage_graph { get; private set; }
//TODO update interval setter and getter for non graph
uint update_graph_interval = 0;
uint64 cpu_last_used = 0;
uint64 cpu_last_used_graph = 0;
uint64 cpu_last_total = 0;
uint64 cpu_last_total_graph = 0;
uint64[] x_cpu_last_used;
uint64[] x_cpu_last_used_graph;
uint64[] x_cpu_last_total;
uint64[] x_cpu_last_total_graph;
bool continue_graph_timeout = true;
const int UPDATE_INTERVAL = 1000;
HashTable<uint, Process> process_table;
private int process_mode = GTop.KERN_PROC_ALL;
......@@ -51,7 +67,7 @@ namespace Usage
}
}
public bool update()
public bool update_data()
{
/* CPU */
GTop.Cpu cpu_data;
......@@ -59,6 +75,15 @@ namespace Usage
var used = cpu_data.user + cpu_data.nice + cpu_data.sys;
cpu_load = (((double) (used - cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100;
var x_cpu_used = new uint64[get_num_processors()];
for (int i = 0; i < x_cpu_load.length; i++)
{
x_cpu_used[i] = cpu_data.xcpu_user[i] + cpu_data.xcpu_nice[i] + cpu_data.xcpu_sys[i];
x_cpu_load[i] = (((double) (x_cpu_used[i] - x_cpu_last_used[i])) / (cpu_data.xcpu_total[i] - x_cpu_last_total[i])) * 100;
GLib.stdout.printf("cpu[" + i.to_string() + "]" + ((int) x_cpu_load[i]).to_string() + "\t");
}
GLib.stdout.printf("\n");
/* Memory */
GTop.Mem mem;
GTop.get_mem (out mem);
......@@ -116,19 +141,78 @@ namespace Usage
cpu_last_used = used;
cpu_last_total = cpu_data.total;
x_cpu_last_used = x_cpu_used;
x_cpu_last_total = cpu_data.xcpu_total;
return true;
}
public bool update_graph_data()
{
/* CPU */
GTop.Cpu cpu_data;
GTop.get_cpu (out cpu_data);
var used = cpu_data.user + cpu_data.nice + cpu_data.sys;
cpu_load_graph = (((double) (used - cpu_last_used_graph)) / (cpu_data.total - cpu_last_total_graph)) * 100;
var x_cpu_used = new uint64[get_num_processors()];
for (int i = 0; i < x_cpu_load_graph.length; i++)
{
x_cpu_used[i] = cpu_data.xcpu_user[i] + cpu_data.xcpu_nice[i] + cpu_data.xcpu_sys[i];
x_cpu_load_graph[i] = (((double) (x_cpu_used[i] - x_cpu_last_used_graph[i])) / (cpu_data.xcpu_total[i] - x_cpu_last_total_graph[i])) * 100;
}
/* Memory */
GTop.Mem mem;
GTop.get_mem (out mem);
mem_usage_graph = (((double) (mem.used - mem.buffer - mem.cached)) / mem.total) * 100;
/* Swap */
GTop.Swap swap;
GTop.get_swap (out swap);
swap_usage_graph = (double) swap.used / swap.total;
cpu_last_used_graph = used;
cpu_last_total_graph = cpu_data.total;
x_cpu_last_used_graph = x_cpu_used;
x_cpu_last_total_graph = cpu_data.xcpu_total;
if(continue_graph_timeout == false)
Timeout.add(update_graph_interval, update_graph_data);
return continue_graph_timeout;
}
public void set_update_graph_interval(uint miliseconds)
{
update_graph_interval = miliseconds;
Timeout.add(update_graph_interval, update_graph_data);
}
public uint get_update_graph_interval()
{
return update_graph_interval;
}
public List<unowned Process> get_processes()
{
return process_table.get_values();
}
public SystemMonitor()
public SystemMonitor(int update_interval/*, int update_graph_interval*/)
{
GTop.init();
//this.update_interval = update_interval;
//this.update_graph_interval = update_graph_interval;
x_cpu_load = new double[get_num_processors()];
x_cpu_load_graph = new double[get_num_processors()];
x_cpu_last_used = new uint64[get_num_processors()];
x_cpu_last_used_graph = new uint64[get_num_processors()];
x_cpu_last_total = new uint64[get_num_processors()];
x_cpu_last_total_graph = new uint64[get_num_processors()];
process_table = new HashTable<uint, Process>(direct_hash, direct_equal);
Timeout.add(UPDATE_INTERVAL, update);
Timeout.add(update_interval, update_data);
}
}
}
......@@ -94,6 +94,8 @@ namespace Rg {
public weak void*[] data;
public int64 get_timestamp ();
public void get_value (uint column, GLib.Value value);
public void get (int first_column, ...);
public void set (int first_column, ...);
public bool next ();
}
[CCode (cheader_filename = "realtime-graphs.h", cname = "_RgColumnClass", has_type_id = false)]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment