Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Librem5
gnome-usage
Commits
74fd0f82
Commit
74fd0f82
authored
Oct 18, 2016
by
Petr Štětka
Browse files
Fixed bug with samples in graph.
parent
5fd3d393
Changes
5
Hide whitespace changes
Inline
Side-by-side
src/cpu-graph-table.vala
View file @
74fd0f82
...
...
@@ -2,9 +2,9 @@ using Rg;
namespace
Usage
{
public
class
CpuGraphTable
:
Rg
.
Table
public
class
CpuGraphTable
Single
:
Rg
.
Table
{
public
CpuGraphTable
(
uint
timespan
,
uint
max_samples
)
public
CpuGraphTable
Single
(
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
;
}
}
}
src/cpu-graph.vala
View file @
74fd0f82
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
CpuGraph
Multi
(
uint
timespan
,
uint
max_samples
)
{
if
(
table
==
null
)
{
table
=
new
CpuGraphTable
(
timespan
,
max_samples
);
table
=
new
CpuGraphTable
Multi
(
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
();
...
...
src/cpu-sub-view.vala
View file @
74fd0f82
...
...
@@ -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
.
m
ulti
(
30000
,
60
);
var
cpu_graph
=
new
CpuGraph
M
ulti
(
30000
,
60
);
var
cpu_graph_frame
=
new
Gtk
.
Frame
(
null
);
cpu_graph_frame
.
height_request
=
200
;
cpu_graph_frame
.
margin_start
=
margin_side
;
...
...
src/graph-switcher-button.vala
View file @
74fd0f82
...
...
@@ -4,28 +4,28 @@ namespace Usage
{
public
GraphSwitcherButton
.
processor
(
string
label
)
{
Rg
.
Graph
processor_graph
=
new
CpuGraph
(
30000
,
6
0
);
Rg
.
Graph
processor_graph
=
new
CpuGraph
Single
(
30000
,
3
0
);
child
=
createContent
(
processor_graph
,
label
);
relief
=
Gtk
.
ReliefStyle
.
NONE
;
}
public
GraphSwitcherButton
.
memory
(
string
label
)
{
Rg
.
Graph
memory_graph
=
new
CpuGraph
(
30000
,
1
0
);
Rg
.
Graph
memory_graph
=
new
CpuGraph
Single
(
30000
,
3
0
);
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
CpuGraph
Single
(
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
CpuGraph
Single
(
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
=
1
4
;
graph_frame
.
margin_start
=
9
;
graph_frame
.
margin_end
=
9
;
graph_frame
.
margin_top
=
1
2
;
graph_frame
.
margin_start
=
8
;
graph_frame
.
margin_end
=
8
;
graph_frame
.
add
(
graph
);
var
label
=
new
Gtk
.
Label
(
label_text
);
...
...
src/window.vala
View file @
74fd0f82
...
...
@@ -9,7 +9,7 @@ namespace Usage
{
GLib
.
Object
(
application
:
application
);
this
.
set_default_size
(
950
,
60
0
);
this
.
set_default_size
(
950
,
52
0
);
this
.
window_position
=
Gtk
.
WindowPosition
.
CENTER
;
stack
=
new
Gtk
.
Stack
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment