Commit 76a60244 authored by Petr Štětka's avatar Petr Štětka
Browse files

Implemented net usage, but it need some tweaks and fixes!

Tweak UI.
parent de9e29e8
......@@ -5,7 +5,8 @@ New GNOME Usage!
## Actual TODO:
- [x] Processor Usage
- [x] Memory usage
- [ ] Network usage - 20%
- [x] Network usage
- [ ] Tweak network usage
- [ ] RPM/DEB packages
- [ ] Storage view - 0%
- [ ] Power view (Design?)
......@@ -25,7 +26,7 @@ sudo setcap cap_net_raw,cap_net_admin=eip /usr/local/bin/gnome-usage
In terminal run ```gnome-usage``` command or run GNOME Usage application from app launcher.
##Version
Actual version is 0.2.8
Actual version is 0.3.0
##License
Code is under GNU GPLv3 license.
......
No preview for this file type
......@@ -175,6 +175,89 @@ rg_table_set_max_samples (RgTable *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MAX_SAMPLES]);
}
gdouble
rg_table_get_max_iter_value (RgTable *self,
guint column_index)
{
gdouble max_value = 0.0;
gdouble double_value = 0.0;
RgTableIter iter;
if (rg_table_get_iter_first (self, &iter))
{
GValue value = G_VALUE_INIT;
rg_table_iter_get_value(&iter, column_index, &value);
switch (G_VALUE_TYPE (&value))
{
case G_TYPE_DOUBLE:
double_value = g_value_get_double (&value);
break;
case G_TYPE_UINT:
double_value = g_value_get_uint (&value);
break;
case G_TYPE_UINT64:
double_value = g_value_get_uint64 (&value);
break;
case G_TYPE_INT:
double_value = g_value_get_int (&value);
break;
case G_TYPE_INT64:
double_value = g_value_get_int64 (&value);
break;
default:
double_value = 0.0;
break;
}
max_value = double_value;
while (rg_table_iter_next (&iter))
{
GValue value = G_VALUE_INIT;
rg_table_iter_get_value(&iter, column_index, &value);
switch (G_VALUE_TYPE (&value))
{
case G_TYPE_DOUBLE:
double_value = g_value_get_double (&value);
break;
case G_TYPE_UINT:
double_value = g_value_get_uint (&value);
break;
case G_TYPE_UINT64:
double_value = g_value_get_uint64 (&value);
break;
case G_TYPE_INT:
double_value = g_value_get_int (&value);
break;
case G_TYPE_INT64:
double_value = g_value_get_int64 (&value);
break;
default:
double_value = 0.0;
break;
}
if(double_value > max_value)
max_value = double_value;
}
}
return max_value;
}
/**
* rg_table_push:
* @self: Table to push to
......
......@@ -67,6 +67,8 @@ gint64 rg_table_iter_get_timestamp (RgTableIter *iter);
void rg_table_iter_set (RgTableIter *iter,
gint first_column,
...);
gdouble rg_table_get_max_iter_value(RgTable *self,
guint column);
G_END_DECLS
......
......@@ -5,7 +5,7 @@ project_name: gnome-usage
vala_binary: src/gnome-usage
*version: 0.2.8
*version: 0.3.0
*vala_vapi: vapis/better.vapi
*vala_vapi: vapis/egg.vapi
*vala_vapi: vapis/glibtop.vapi
......@@ -44,6 +44,8 @@ c_library: gmodule-2.0 m rt gtop-2.0 ${CMAKE_SOURCE_DIR}/external/netinfo/libnet
*vala_source: memory-graph.vala
*vala_source: memory-monitor.vala
*vala_source: memory-sub-view.vala
*vala_source: network-graph-table.vala
*vala_source: network-graph.vala
*vala_source: network-monitor.vala
*vala_source: network-sub-view.vala
*vala_source: performance-view.vala
......@@ -57,7 +59,6 @@ c_library: gmodule-2.0 m rt gtop-2.0 ${CMAKE_SOURCE_DIR}/external/netinfo/libnet
*vala_source: sub-process-list-box.vala
*vala_source: sub-process-sub-row.vala
*vala_source: system-monitor.vala
*vala_source: test-netinfo.vala
*vala_source: view.vala
*vala_source: window.vala
c_source: ../external/egg/egg-animation.c
......@@ -150,39 +151,40 @@ translate: c src/../external/rg/rg-table.c
*translate: vala src/cpu-graph-table.vala
*translate: vala src/cookie-graph.vala
*translate: vala src/cpu-graph.vala
*translate: vala src/application.vala
*translate: vala src/header-bar.vala
*translate: vala src/process-dialog.vala
*translate: vala src/network-graph-table.vala
*translate: vala src/cpu-monitor.vala
*translate: vala src/graph-block.vala
*translate: vala src/memory-graph.vala
*translate: vala src/process-row.vala
*translate: vala src/network-sub-view.vala
*translate: vala src/system-monitor.vala
*translate: vala src/process.vala
*translate: vala src/network-monitor.vala
*translate: vala src/performance-view.vala
*translate: vala src/process-list-box.vala
*translate: vala src/sub-process-sub-row.vala
*translate: vala src/memory-sub-view.vala
*translate: vala src/graph-box.vala
*translate: vala src/view.vala
*translate: vala src/disk-sub-view.vala
*translate: vala src/sub-process-sub-row.vala
*translate: vala src/system-monitor.vala
*translate: vala src/memory-graph-table.vala
*translate: vala src/window.vala
*translate: vala src/sub-process-list-box.vala
*translate: vala src/window.vala
*translate: vala src/process-list-box.vala
*translate: vala src/color-rectangle.vala
*translate: vala src/graph-stack-switcher.vala
*translate: vala src/storage-view.vala
*translate: vala src/settings.vala
*translate: vala src/power-view.vala
*translate: vala src/cpu-sub-view.vala
*translate: vala src/test-netinfo.vala
*translate: vala src/process-dialog.vala
*translate: vala src/graph-block-row.vala
*translate: vala src/graph-switcher-button.vala
*translate: vala src/process-row.vala
*translate: vala src/data-view.vala
*translate: vala src/network-monitor.vala
*translate: vala src/process.vala
*translate: vala src/application.vala
*translate: vala src/network-graph.vala
*translate: vala src/gnome-usage.vala
*translate: vala src/network-sub-view.vala
*translate: vala src/memory-monitor.vala
*translate: vala src/graph-switcher-button.vala
*translate: c src/better-box.c
*data: data/local
......
......@@ -18,6 +18,8 @@ src/memory-graph-table.vala
src/memory-graph.vala
src/memory-monitor.vala
src/memory-sub-view.vala
src/network-graph-table.vala
src/network-graph.vala
src/network-monitor.vala
src/network-sub-view.vala
src/performance-view.vala
......@@ -31,7 +33,6 @@ src/storage-view.vala
src/sub-process-list-box.vala
src/sub-process-sub-row.vala
src/system-monitor.vala
src/test-netinfo.vala
src/view.vala
src/window.vala
src/../external/egg/egg-animation.c
......
......@@ -7,13 +7,13 @@ set (GETTEXT_PACKAGE "gnome-usage")
set (RELEASE_NAME "gnome-usage")
set (CMAKE_C_FLAGS "")
set (PREFIX ${CMAKE_INSTALL_PREFIX})
set (VERSION "0.2.8")
set (VERSION "0.3.0")
set (TESTSRCDIR "${CMAKE_SOURCE_DIR}")
set (DOLLAR "$")
configure_file (${CMAKE_SOURCE_DIR}/src/Config.vala.cmake ${CMAKE_BINARY_DIR}/src/Config.vala)
add_definitions(-DGETTEXT_PACKAGE=\"${GETTEXT_PACKAGE}\")
set (VERSION "0.2.8")
set (VERSION "0.3.0")
add_definitions (${DEPS_CFLAGS})
link_libraries ( ${DEPS_LIBRARIES} )
link_directories ( ${DEPS_LIBRARY_DIRS} )
......@@ -56,6 +56,8 @@ set (APP_SOURCES ${APP_SOURCES} memory-graph-table.vala)
set (APP_SOURCES ${APP_SOURCES} memory-graph.vala)
set (APP_SOURCES ${APP_SOURCES} memory-monitor.vala)
set (APP_SOURCES ${APP_SOURCES} memory-sub-view.vala)
set (APP_SOURCES ${APP_SOURCES} network-graph-table.vala)
set (APP_SOURCES ${APP_SOURCES} network-graph.vala)
set (APP_SOURCES ${APP_SOURCES} network-monitor.vala)
set (APP_SOURCES ${APP_SOURCES} network-sub-view.vala)
set (APP_SOURCES ${APP_SOURCES} performance-view.vala)
......@@ -69,7 +71,6 @@ set (APP_SOURCES ${APP_SOURCES} storage-view.vala)
set (APP_SOURCES ${APP_SOURCES} sub-process-list-box.vala)
set (APP_SOURCES ${APP_SOURCES} sub-process-sub-row.vala)
set (APP_SOURCES ${APP_SOURCES} system-monitor.vala)
set (APP_SOURCES ${APP_SOURCES} test-netinfo.vala)
set (APP_SOURCES ${APP_SOURCES} view.vala)
set (APP_SOURCES ${APP_SOURCES} window.vala)
......
......@@ -7,7 +7,6 @@ namespace Usage
public Settings settings;
public Window window;
public SystemMonitor monitor;
public NetMonitor net_monitor;
private const GLib.ActionEntry app_entries[] =
{
......@@ -20,7 +19,6 @@ namespace Usage
application_id = "org.gnome.usage";
settings = new Settings();
monitor = new SystemMonitor();
net_monitor = new NetMonitor();
}
public override void activate()
......
// project version=0.2.8
// project version=0.3.0
public static int main (string[] args)
{
......
......@@ -15,6 +15,9 @@ namespace Usage {
label.ellipsize = Pango.EllipsizeMode.END;
label.max_width_chars = 15;
value_label = new Gtk.Label("0 %");
value_label.width_chars = 5;
value_label.width_chars = 5;
value_label.xalign = 1;
this.pack_start(color_rectangle, false, false);
this.pack_start(label, false, true, 5);
this.pack_end(value_label, false, true, 10);
......
......@@ -22,7 +22,7 @@ namespace Usage
public GraphSwitcherButton.network(string label)
{
Rg.Graph network_graph = new MemoryGraph();
Rg.Graph network_graph = new NetworkGraph();
child = createContent(network_graph, label);
}
......
......@@ -34,7 +34,7 @@ namespace Usage {
double ram_usage = monitor.ram_usage;
iter.set (column_ram_id, ram_usage, -1);
iter.set (column_swap_id, (GLib.Application.get_default() as Application).monitor.swap_usage, -1);
iter.set (column_swap_id, monitor.swap_usage, -1);
if(ram_usage >= 90)
{
......
......@@ -38,7 +38,7 @@ namespace Usage
GTop.get_mem (out mem);
GTop.get_proc_mem (out proc_mem, pid);
mem_usage = (proc_mem.resident - proc_mem.share) / 1000000;
mem_usage = (proc_mem.resident - proc_mem.share);
mem_usage_percentages = ((double) (proc_mem.resident - proc_mem.share) / mem.total) * 100;
}
}
......
using Rg;
namespace Usage {
public class NetworkGraphTable : Rg.Table
{
public const int column_download_id = 0;
public const int column_upload_id = 1;
private double max_value = 10;
public NetworkGraphTable ()
{
var settings = (GLib.Application.get_default() as Application).settings;
set_timespan (settings.graph_timespan * 1000);
set_max_samples (settings.graph_max_samples);
var column_download = new Rg.Column("DOWNLOAD", Type.from_name("gdouble"));
add_column(column_download);
var column_upload = new Rg.Column("UPLOAD", Type.from_name("gdouble"));
add_column(column_upload);
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;
double net_download = monitor.net_download;
double net_upload = monitor.net_upload;
iter.set (column_download_id, net_download, -1);
iter.set (column_upload_id, net_upload, -1);
double max_iter_value_download = get_max_iter_value(column_download_id);
double max_iter_value_upload = get_max_iter_value(column_upload_id);
double max_iter_value = max_iter_value_download > max_iter_value_upload ? max_iter_value_download : max_iter_value_upload;
if(max_iter_value > max_value)
max_value = max_iter_value * 1.5;
else
if(max_iter_value < (max_value/3))
max_value = max_iter_value * 1.5;
if(max_value < 10)
max_value = 10;
this.value_max = max_value;
return true;
}
}
}
using Rg;
namespace Usage
{
public class NetworkGraph : Rg.Graph
{
private static NetworkGraphTable rg_table;
private Gdk.RGBA color_download;
private Gdk.RGBA color_line_download;
private Gdk.RGBA color_upload;
private Gdk.RGBA color_line_upload;
class construct
{
set_css_name("rg-graph");
}
public NetworkGraph ()
{
color_line_download.parse("#4a90d9");
color_download.parse("#c4dbff");
color_line_upload.parse("#ff9900");
color_upload.parse("#fcd8a2");
if(rg_table == null)
{
rg_table = new NetworkGraphTable();
set_table(rg_table);
}
else
set_table(rg_table);
var renderer_download = new StackedRenderer();
renderer_download.column = NetworkGraphTable.column_download_id;
renderer_download.stroke_color_rgba = color_line_download;
renderer_download.stacked_color_rgba = color_download;
renderer_download.line_width = 1.2;
add_renderer(renderer_download);
var renderer_upload = new StackedRenderer();
renderer_upload.column = NetworkGraphTable.column_upload_id;
renderer_upload.stroke_color_rgba = color_line_upload;
renderer_upload.stacked_color_rgba = color_upload;
renderer_upload.line_width = 1.2;
add_renderer(renderer_upload);
}
}
public class NetworkGraphBig : Rg.Graph
{
private static NetworkGraphTable rg_table;
private Gdk.RGBA color_download;
private Gdk.RGBA color_upload;
class construct
{
set_css_name("rg-graph");
}
public NetworkGraphBig()
{
color_download.parse("#4a90d9");
color_upload.parse("#ff9900");
get_style_context().add_class("big");
if(rg_table == null)
{
rg_table = new NetworkGraphTable();
set_table(rg_table);
}
else
set_table(rg_table);
LineRenderer renderer_download = new LineRenderer();
renderer_download.column = NetworkGraphTable.column_download_id;
renderer_download.stroke_color_rgba = color_download;
renderer_download.line_width = 1.5;
add_renderer(renderer_download);
LineRenderer renderer_upload = new LineRenderer();
renderer_upload.column = NetworkGraphTable.column_upload_id;
renderer_upload.stroke_color_rgba = color_upload;
renderer_upload.line_width = 1.5;
add_renderer(renderer_upload);
}
}
}
using NI;
using Posix;
namespace Usage
{
public class NetworkMonitor
{
private uint64 download_usage;
private uint64 upload_usage;
private uint64 net_usage;
private NetInfo netinfo;
private NetStatistics stat;
public NetworkMonitor()
{
/*unowned NetInterface[] net_interfaces_arrary = null;
ErrorCode e;
unowned NetInterface[] net_interfaces_arrary = null;
handle_error(NetInterface.list_net_interface(out net_interfaces_arrary));
handle_error(NetInfo.init(net_interfaces_arrary, net_interfaces_arrary.length, out netinfo));
handle_error(NetInterface.free_net_interface_array(net_interfaces_arrary));
// get all network interfaces that netinfo can work with
e = NetInterface.list_net_interface(out net_interfaces_arrary);
handle_error(e);
handle_error(netinfo.set_min_refresh_interval(1, 1000));
handle_error(netinfo.start());
}
~NetworkMonitor ()
{
handle_error(netinfo.clear());
}
for(uint32 i = 0; i < net_interfaces_arrary.length; i++)
{
print_net_interface_info(net_interfaces_arrary[i]); //TODO create array length
}
public void update()
{
handle_thread_errors();
handle_error(netinfo.get_net_statistics(out stat));
// initialize our netinfo object to capture traffic
NetInfo netinfo;
uint64 bytes_out;
uint64 bytes_in;
uint64 bytes_all;
handle_error(stat.get_bytes_by_inout_type(InoutEnum.OUTGOING, out bytes_out));
handle_error(stat.get_bytes_by_inout_type(InoutEnum.INCOMING, out bytes_in));
handle_error(stat.get_total_bytes(out bytes_all));
e = NetInfo.init(net_interfaces_arrary, net_interfaces_arrary.length, out netinfo);
handle_error(e);
upload_usage = bytes_out;
download_usage = bytes_in;
net_usage = bytes_all;
e = NetInterface.free_net_interface_array(net_interfaces_arrary); // this is safe; "netinfo_init()" does not keep references
handle_error(e);
handle_error(netinfo.clear());
}
// start capturing
handle_error(netinfo.set_min_refresh_interval(1, 100));
handle_error(netinfo.start());*/
public uint64 get_net_download()
{
return download_usage;
}
public void update()
public uint64 get_net_upload()
{
return upload_usage;
}
public uint64 get_net_usage()
{
return net_usage;
}
public void get_network_info_for_pid(pid_t pid, ref uint64 download, ref uint64 upload, ref uint64 all)
{
uint64 bytes_out = 1;
Inout inout = InoutEnum.OUTGOING;
TransportType? transport_type = null;
NI.Pid pid_ni = (uint64)pid;
handle_error(stat.get_bytes_per_attr(ref pid_ni, ref inout, ref transport_type, out bytes_out));
uint64 bytes_in = 1;
pid_ni = pid;
inout = InoutEnum.INCOMING;
transport_type = null;
handle_error(stat.get_bytes_per_attr(ref pid_ni, ref inout, ref transport_type, out bytes_in));
uint64 bytes_all = 1;
pid_ni = pid;
handle_error(stat.get_bytes_per_pid(pid_ni, out bytes_all));
upload = bytes_out;
download = bytes_in;
all = bytes_all;
}
private void handle_error(ErrorCode e)
{
if(e < 0)
{
GLib.stdout.printf("NETINFO ERROR: " + get_error_description(e).to_string() + "\n");
GLib.stdout.printf("Do you have sudo, or setcap for binary?\n");
}
}
void handle_thread_errors()
{
unowned ErrorCode[] errors = null;
uint32 num_errors = 0;
handle_error(netinfo.pop_thread_errors(out errors));
if(errors.length > 0)
{
handle_error(errors[0]);
}
handle_error(netinfo.free_thread_error_array(errors));
}
}
}
\ No newline at end of file
......@@ -5,6 +5,39 @@ namespace Usage
public NetworkSubView()
{
name = "NETWORK";
var label = new Gtk.Label("<span font_desc=\"14.0\">" + _("Network") + "</span>");
label.set_use_markup(true);
label.margin_top = 25;
label.margin_bottom = 15;
var network_graph = new NetworkGraphBig();
network_graph.hexpand = true;
var network_graph_box = new GraphBox(network_graph);
network_graph_box.height_request = 225;
network_graph_box.width_request = 600;
network_graph_box.valign = Gtk.Align.START;
var process_list_box = new ProcessListBoxNew(ProcessListBoxType.NETWORK);
process_list_box.margin_bottom = 20;
process_list_box.margin_top = 30;
var memory_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0);
memory_box.pack_start(label, false, false, 0);
memory_box.pack_start(network_graph_box, false, false, 0);
memory_box.pack_start(process_list_box, false, false, 0);
var better_box = new Better.Box();
better_box.max_width_request = 600;
better_box.halign = Gtk.Align.CENTER;
better_box.orientation = Gtk.Orientation.HORIZONTAL;