Commit 74fd0f82 authored by Petr Štětka's avatar Petr Štětka
Browse files

Fixed bug with samples in graph.

parent 5fd3d393
......@@ -2,9 +2,9 @@ using Rg;
namespace Usage {
public class CpuGraphTable : Rg.Table
public class CpuGraphTableSingle : Rg.Table
{
public CpuGraphTable (uint timespan, uint max_samples)
public CpuGraphTableSingle (uint timespan, uint max_samples)
{
set_timespan (timespan * 1000);
set_max_samples (max_samples);
......@@ -12,25 +12,9 @@ namespace Usage {
var column = new Rg.Column("TOTAL CPU", Type.from_name("gdouble"));
add_column(column);
(GLib.Application.get_default() as Application).monitor.set_update_graph_interval(timespan / (max_samples - 1));
Timeout.add(timespan / (max_samples - 1), update_data);
}
public CpuGraphTable.multi (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));
Timeout.add(timespan / (max_samples - 1), update_data_multi);
}
bool update_data()
{
Rg.TableIter iter;
......@@ -39,16 +23,34 @@ namespace Usage {
return true;
}
bool update_data_multi()
{
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;
}
}
public class CpuGraphTableMulti : Rg.Table
{
public CpuGraphTableMulti (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));
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 {
namespace Usage
{
public class CpuGraphSingle : Rg.Graph
{
private static CpuGraphTableSingle table;
public class CpuGraph : Rg.Graph {
public CpuGraphSingle (uint timespan, uint max_samples)
{
if(table == null)
{
table = new CpuGraphTableSingle(timespan, max_samples);
set_table(table);
}
else
set_table(table);
LineRenderer renderer = new LineRenderer();
renderer.stroke_color = "#ef2929";
renderer.line_width = 2;
add_renderer(renderer);
}
}
static string[] colors = {
public class CpuGraphMulti : Rg.Graph
{
static string[] colors =
{
"#73d216",
"#ef2929",
"#3465a4",
......@@ -15,35 +37,18 @@ namespace Usage {
"#ce5c00",
};
private static CpuGraphTable table;
private static CpuGraphTable table_multi;
private static CpuGraphTableMulti table;
public CpuGraph (uint timespan, uint max_samples)
public CpuGraphMulti (uint timespan, uint max_samples)
{
if(table == null)
{
table = new CpuGraphTable(timespan, max_samples);
table = new CpuGraphTableMulti(timespan, max_samples);
set_table(table);
}
else
set_table(table);
LineRenderer renderer = new LineRenderer();
renderer.stroke_color = colors [1];
renderer.line_width = 2;
add_renderer(renderer);
}
public CpuGraph.multi (uint timespan, uint max_samples)
{
if(table_multi == null)
{
table_multi = new CpuGraphTable.multi(timespan, max_samples);
set_table(table_multi);
}
else
set_table(table_multi);
for(int i = 0; i < get_num_processors(); i++)
{
LineRenderer renderer = new LineRenderer();
......
......@@ -27,7 +27,7 @@ namespace Usage
process_list_box = new ProcessList();
var cpu_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
var cpu_graph = new CpuGraph.multi(30000, 60);
var cpu_graph = new CpuGraphMulti(30000, 60);
var cpu_graph_frame = new Gtk.Frame(null);
cpu_graph_frame.height_request = 200;
cpu_graph_frame.margin_start = margin_side;
......
......@@ -4,28 +4,28 @@ namespace Usage
{
public GraphSwitcherButton.processor(string label)
{
Rg.Graph processor_graph = new CpuGraph(30000, 60);
Rg.Graph processor_graph = new CpuGraphSingle(30000, 30);
child = createContent(processor_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
public GraphSwitcherButton.memory(string label)
{
Rg.Graph memory_graph = new CpuGraph(30000, 10);
Rg.Graph memory_graph = new CpuGraphSingle(30000, 30);
child = createContent(memory_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
public GraphSwitcherButton.disk(string label)
{
Rg.Graph disk_graph = new CpuGraph(30000, 5);
Rg.Graph disk_graph = new CpuGraphSingle(30000, 30);
child = createContent(disk_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
public GraphSwitcherButton.network(string label)
{
Rg.Graph network_graph = new CpuGraph(30000, 1);
Rg.Graph network_graph = new CpuGraphSingle(30000, 30);
child = createContent(network_graph, label);
relief = Gtk.ReliefStyle.NONE;
}
......@@ -34,9 +34,9 @@ namespace Usage
{
var graph_frame = new Gtk.Frame(null);
graph_frame.height_request = 80;
graph_frame.margin_top = 14;
graph_frame.margin_start = 9;
graph_frame.margin_end = 9;
graph_frame.margin_top = 12;
graph_frame.margin_start = 8;
graph_frame.margin_end = 8;
graph_frame.add(graph);
var label = new Gtk.Label(label_text);
......
......@@ -9,7 +9,7 @@ namespace Usage
{
GLib.Object(application : application);
this.set_default_size(950, 600);
this.set_default_size(950, 520);
this.window_position = Gtk.WindowPosition.CENTER;
stack = new Gtk.Stack();
......
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