Commit 87d93506 authored by Petr Štětka's avatar Petr Štětka
Browse files

increased process update interval to 3 sec.

Updated CPU graph.
parent 9fbc9aae
......@@ -2,31 +2,88 @@ using Rg;
namespace Usage {
public class CpuGraphTable : Rg.Table
public class CpuGraphTableComplex : Rg.Table
{
bool multi;
public signal void big_process_usage (int column);
public signal void small_process_usage (int column);
private bool[] change_big_process_usage;
private bool[] change_small_process_usage;
public CpuGraphTable (bool multi = false)
public CpuGraphTableComplex ()
{
this.multi = multi;
var settings = (GLib.Application.get_default() as Application).settings;
set_timespan (settings.graph_timespan * 1000);
set_max_samples (settings.graph_max_samples);
if(multi)
var column_total = new Rg.Column("TOTAL CPU", Type.from_name("gdouble"));
add_column(column_total);
change_big_process_usage = new bool[get_num_processors()];
change_small_process_usage = new bool[get_num_processors()];
for (int i = 0; i < get_num_processors(); i++)
{
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);
}
var column_x_cpu = new Rg.Column("CPU: " + i.to_string(), Type.from_name("gdouble"));
add_column(column_x_cpu);
change_big_process_usage[i] = false;
change_small_process_usage[i] = true;
}
else
Timeout.add(settings.graph_update_interval, update_data);
}
bool update_data()
{
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
for (int i = 0; i < get_num_processors(); i++)
{
var column = new Rg.Column("TOTAL CPU", Type.from_name("gdouble"));
add_column(column);
iter.set (i, monitor.x_cpu_load_graph[i], -1);
if(monitor.x_cpu_load_graph[i] >= 90)
{
if(change_big_process_usage[i])
{
big_process_usage(i);
change_big_process_usage[i] = false;
change_small_process_usage[i] = true;
}
}
else
{
if(change_small_process_usage[i])
{
small_process_usage(i);
change_small_process_usage[i] = false;
change_big_process_usage[i] = true;
}
}
}
return true;
}
}
public class CpuGraphTableMostUsedCore : Rg.Table
{
public signal void big_process_usage ();
public signal void small_process_usage ();
private bool change_big_process_usage = false;
private bool change_small_process_usage = true;
public CpuGraphTableMostUsedCore ()
{
var settings = (GLib.Application.get_default() as Application).settings;
set_timespan (settings.graph_timespan * 1000);
set_max_samples (settings.graph_max_samples);
var column = new Rg.Column("MOST USED CORE", Type.from_name("gdouble"));
add_column(column);
Timeout.add(settings.graph_update_interval, update_data);
}
......@@ -35,13 +92,35 @@ namespace Usage {
Rg.TableIter iter;
push (out iter, get_monotonic_time ());
if(multi)
SystemMonitor monitor = (GLib.Application.get_default() as Application).monitor;
double most_used_core = monitor.x_cpu_load_graph[0];
for (int i = 1; i < get_num_processors(); i++)
{
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);
if(monitor.x_cpu_load_graph[i] > most_used_core)
most_used_core = monitor.x_cpu_load_graph[i];
}
iter.set (0, most_used_core, -1);
if(most_used_core >= 90)
{
if(change_big_process_usage)
{
big_process_usage();
change_big_process_usage = false;
change_small_process_usage = true;
}
}
else
iter.set (0, (GLib.Application.get_default() as Application).monitor.cpu_load_graph, -1);
{
if(change_small_process_usage)
{
small_process_usage();
change_small_process_usage = false;
change_big_process_usage = true;
}
}
return true;
}
......
......@@ -2,61 +2,77 @@ using Rg;
namespace Usage
{
public class CpuGraphSingle : Rg.Graph
private const string red_color = "#ee2222";
private const string blue_color = "#4a90d9";
/**
* Graph showing most used core
**/
public class CpuGraphMostUsed : Rg.Graph
{
private static CpuGraphTable table;
private static CpuGraphTableMostUsedCore table;
LineRenderer renderer;
public CpuGraphSingle ()
public CpuGraphMostUsed ()
{
if(table == null)
{
table = new CpuGraphTable(false);
table = new CpuGraphTableMostUsedCore();
set_table(table);
}
else
set_table(table);
LineRenderer renderer = new LineRenderer();
renderer.stroke_color = "#ef2929";
renderer.line_width = 2;
renderer = new LineRenderer();
renderer.stroke_color = blue_color;
renderer.line_width = 1.2;
add_renderer(renderer);
table.big_process_usage.connect (() => {
renderer.stroke_color = red_color;
});
table.small_process_usage.connect (() => {
renderer.stroke_color = blue_color;
});
}
}
public class CpuGraphMulti : Rg.Graph
/**
* Graph showing all processor cores.
**/
public class CpuGraphAllCores : Rg.Graph
{
static string[] colors =
{
"#73d216",
"#ef2929",
"#3465a4",
"#f57900",
"#75507b",
"#ce5c00",
"#c17d11",
"#ce5c00",
};
private static CpuGraphTable table;
public CpuGraphMulti ()
private static CpuGraphTableComplex table;
private LineRenderer[] renderers;
public CpuGraphAllCores ()
{
if(table == null)
{
table = new CpuGraphTable(true);
table = new CpuGraphTableComplex();
set_table(table);
}
else
set_table(table);
renderers = new LineRenderer[get_num_processors()];
for(int i = 0; i < get_num_processors(); i++)
{
LineRenderer renderer = new LineRenderer();
renderer.column = i;
renderer.stroke_color = colors [i % colors.length];
renderer.line_width = 2;
add_renderer(renderer);
renderers[i] = new LineRenderer();
renderers[i].column = i;
renderers[i].stroke_color = blue_color;
renderers[i].line_width = 2;
add_renderer(renderers[i]);
}
table.big_process_usage.connect ((column) => {
renderers[column].stroke_color = red_color;
});
table.small_process_usage.connect ((column) => {
renderers[column].stroke_color = blue_color;
});
}
}
}
......@@ -3,7 +3,6 @@ namespace Usage
public class ProcessorSubView : View
{
ProcessList process_list_box;
Gtk.Label cpu_load_label;
List<ProcessRow> process_row_list;
bool show_active_process = true;
......@@ -11,7 +10,6 @@ namespace Usage
{
name = "PROCESSOR";
cpu_load_label = new Gtk.Label(null);
var label = new Gtk.Label("<span font_desc=\"14.0\">" + _("Processor") + "</span>");
label.set_use_markup(true);
label.margin_top = 20;
......@@ -19,7 +17,7 @@ namespace Usage
process_list_box = new ProcessList();
var cpu_graph = new CpuGraphMulti();
var cpu_graph = new CpuGraphAllCores();
var cpu_graph_frame = new Gtk.Frame(null);
cpu_graph_frame.height_request = 225;
cpu_graph_frame.width_request = 600;
......@@ -56,7 +54,6 @@ namespace Usage
private bool update_process()
{
process_list_box.foreach((widget) => { widget.destroy(); });
cpu_load_label.set_text(((int) monitor.cpu_load).to_string() + " %");
process_row_list = new List<ProcessRow>();
foreach(unowned Process process in monitor.get_processes())
......@@ -123,7 +120,7 @@ namespace Usage
public override void update_header_bar()
{
header_bar.clear();
header_bar.show_menu_button();
//header_bar.show_menu_button();
header_bar.show_stack_switcher();
}
}
......
......@@ -4,7 +4,7 @@ namespace Usage
{
public GraphSwitcherButton.processor(string label)
{
Rg.Graph processor_graph = new CpuGraphSingle();
Rg.Graph processor_graph = new CpuGraphMostUsed();
child = createContent(processor_graph, label);
style_button();
}
......@@ -18,14 +18,14 @@ namespace Usage
public GraphSwitcherButton.disk(string label)
{
Rg.Graph disk_graph = new CpuGraphSingle();
Rg.Graph disk_graph = new MemoryGraph();
child = createContent(disk_graph, label);
style_button();
}
public GraphSwitcherButton.network(string label)
{
Rg.Graph network_graph = new CpuGraphSingle();
Rg.Graph network_graph = new MemoryGraph();
child = createContent(network_graph, label);
style_button();
}
......
......@@ -7,6 +7,6 @@ namespace Usage {
public uint graph_timespan { get; set; default = 30000;}
public uint graph_max_samples { get; set; default = 30; }
public uint graph_update_interval { get { return graph_timespan / (graph_max_samples - 1); }}
public uint list_update_interval { get; set; default = 1000; }
public uint list_update_interval { get; set; default = 3000; }
}
}
......@@ -117,7 +117,7 @@ namespace Usage
else
{
unowned Process process = process_table[pids[i]];
process.cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100;
process.cpu_load = (((double) (proc_time.rtime - process.cpu_last_used)) / (cpu_data.total - cpu_last_total)) * 100 * get_num_processors();
process.alive = true;
process.cpu_last_used = proc_time.rtime;
......
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