From 03ccf2869810a4092988a1eaa89d4b7ea999fe5a Mon Sep 17 00:00:00 2001 From: stsdc Date: Mon, 22 Jun 2020 23:29:53 +0200 Subject: [PATCH 01/18] add stack --- meson.build | 2 ++ src/MainWindow.vala | 25 +++++++++++-------------- src/Views/SystemView/SystemView.vala | 12 ++++++++++++ 3 files changed, 25 insertions(+), 14 deletions(-) create mode 100644 src/Views/SystemView/SystemView.vala diff --git a/meson.build b/meson.build index bc29b153..423d3cee 100644 --- a/meson.build +++ b/meson.build @@ -66,6 +66,8 @@ executable( 'src/Views/ProcessView/ProcessInfoView/ProcessInfoView.vala', 'src/Views/ProcessView/ProcessTreeView/CPUProcessTreeView.vala', + 'src/Views/SystemView/SystemView.vala', + # Widgets related only to ProcessInfoView 'src/Views/ProcessView/ProcessInfoView/Preventor.vala', 'src/Views/ProcessView/ProcessInfoView/RoundyLabel.vala', diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 2ea83eb4..ab208244 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -7,6 +7,7 @@ // private Gtk.Button process_info_button; public ProcessView process_view; + public SystemView system_view; private Statusbar statusbar; @@ -23,29 +24,25 @@ get_style_context ().add_class ("rounded"); + process_view = new ProcessView (); + system_view = new SystemView (); - // button_box.get_style_context ().add_class (Gtk.STYLE_CLASS_LINKED); - - // setup process info button - // process_info_button = new Gtk.Button.from_icon_name ("dialog-information-symbolic", Gtk.IconSize.LARGE_TOOLBAR); - // process_info_button.get_style_context ().remove_class ("image-button"); - // button_box.add (process_info_button); - - // setup kill process button - - - // TODO: Granite.Widgets.ModeButton to switch between view modes + Gtk.Stack stack = new Gtk.Stack (); + stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT); + stack.add_titled (process_view, "process_view", "Processes"); + stack.add_titled (system_view, "system_view", "System"); - // process_manager = new ProcessManager(); - process_view = new ProcessView (); + Gtk.StackSwitcher stack_switcher = new Gtk.StackSwitcher (); + stack_switcher.set_stack(stack); headerbar = new Headerbar (this); + headerbar.set_custom_title (stack_switcher); set_titlebar (headerbar); statusbar = new Statusbar (); var main_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); - main_box.pack_start (process_view, true, true, 0); + main_box.pack_start (stack, true, true, 0); main_box.pack_start (statusbar, false, true, 0); this.add (main_box); diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala new file mode 100644 index 00000000..15bae590 --- /dev/null +++ b/src/Views/SystemView/SystemView.vala @@ -0,0 +1,12 @@ +public class Monitor.SystemView : Gtk.Box { + + construct { + + } + + public SystemView () { + var label = new Gtk.Label("System things"); + add(label); + } + +} \ No newline at end of file From 794df18eb8e9be159b7e16e5d68d5b789d8068c5 Mon Sep 17 00:00:00 2001 From: stsdc Date: Wed, 1 Jul 2020 23:03:37 +0200 Subject: [PATCH 02/18] using single timer --- src/MainWindow.vala | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index ab208244..d8e755f7 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -52,14 +52,10 @@ updater.update.connect ((sysres) => { statusbar.update (sysres); dbusserver.update (sysres); + process_view.update(); dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state")); }); - // updating processes every 2 seconds - Timeout.add_seconds (2, () => { - process_view.update(); - return true; - }); dbusserver.quit.connect (() => app.quit()); dbusserver.show.connect (() => { From d8f7c63559b9b73c6878ab55aeed7393cf346656 Mon Sep 17 00:00:00 2001 From: stsdc Date: Thu, 2 Jul 2020 00:15:48 +0200 Subject: [PATCH 03/18] refactored a bit serialization of resources --- meson.build | 4 ++++ src/Indicator/Services/DBusClient.vala | 16 ++++++++++++- src/MainWindow.vala | 7 +++--- src/Resources/Resources.vala | 25 ++++++++++++++++++++ src/Resources/ResourcesSerialized.vala | 10 ++++++++ src/Services/DBusServer.vala | 2 +- src/Services/Updater.vala | 32 ++++++-------------------- src/Utils.vala | 11 --------- src/Widgets/Statusbar/Statusbar.vala | 2 +- 9 files changed, 67 insertions(+), 42 deletions(-) create mode 100644 src/Resources/Resources.vala create mode 100644 src/Resources/ResourcesSerialized.vala diff --git a/meson.build b/meson.build index 423d3cee..93e02db3 100644 --- a/meson.build +++ b/meson.build @@ -97,6 +97,9 @@ executable( 'src/Services/DBusServer.vala', 'src/Services/Updater.vala', + # Resources + 'src/Resources/Resources.vala', + 'src/Resources/ResourcesSerialized.vala', 'src/Resources/CPU.vala', 'src/Resources/Core.vala', 'src/Resources/Memory.vala', @@ -127,6 +130,7 @@ shared_module( 'monitor', 'src/Indicator/Indicator.vala', 'src/Utils.vala', + 'src/Resources/ResourcesSerialized.vala', 'src/Indicator/Widgets/DisplayWidget.vala', 'src/Indicator/Widgets/PopoverWidget.vala', diff --git a/src/Indicator/Services/DBusClient.vala b/src/Indicator/Services/DBusClient.vala index 116f66cf..c8c339d7 100644 --- a/src/Indicator/Services/DBusClient.vala +++ b/src/Indicator/Services/DBusClient.vala @@ -1,8 +1,22 @@ + +// // this should be defined in one place -> in Resources, but it can't see it +// public struct ResourcesStruct { +// public int cpu_percentage; +// public double cpu_frequency; +// public int memory_percentage; +// public double memory_used; +// public double memory_total; +// public int swap_percentage; +// public double swap_used; +// public double swap_total; +// } + + [DBus (name = "com.github.stsdc.monitor")] public interface Monitor.DBusClientInterface : Object { public abstract void quit_monitor () throws Error; public abstract void show_monitor () throws Error; - public signal void update (Utils.SystemResources data); + public signal void update (ResourcesSerialized data); public signal void indicator_state (bool state); } diff --git a/src/MainWindow.vala b/src/MainWindow.vala index d8e755f7..b20020d6 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -49,9 +49,10 @@ updater = Updater.get_default (); dbusserver = DBusServer.get_default (); - updater.update.connect ((sysres) => { - statusbar.update (sysres); - dbusserver.update (sysres); + updater.update.connect ((resources) => { + var res = resources.serialize (); + statusbar.update (res); + dbusserver.update (res); process_view.update(); dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state")); }); diff --git a/src/Resources/Resources.vala b/src/Resources/Resources.vala new file mode 100644 index 00000000..ba26e3b6 --- /dev/null +++ b/src/Resources/Resources.vala @@ -0,0 +1,25 @@ +public class Monitor.Resources : Object { + public CPU cpu; + public Memory memory; + public Swap swap; + + construct { + memory = new Memory (); + cpu = new CPU (); + swap = new Swap (); + } + + public ResourcesSerialized serialize () { + return new ResourcesSerialized () { + cpu_percentage = cpu.percentage, + cpu_frequency = cpu.frequency, + memory_percentage = memory.percentage, + memory_used = memory.used, + memory_total = memory.total, + swap_percentage = swap.percentage, + swap_used = swap.used, + swap_total = swap.total + }; + } + +} \ No newline at end of file diff --git a/src/Resources/ResourcesSerialized.vala b/src/Resources/ResourcesSerialized.vala new file mode 100644 index 00000000..019f5382 --- /dev/null +++ b/src/Resources/ResourcesSerialized.vala @@ -0,0 +1,10 @@ +public struct ResourcesSerialized { + public int cpu_percentage; + public double cpu_frequency; + public int memory_percentage; + public double memory_used; + public double memory_total; + public int swap_percentage; + public double swap_used; + public double swap_total; +} \ No newline at end of file diff --git a/src/Services/DBusServer.vala b/src/Services/DBusServer.vala index 79c35f05..d802c75b 100644 --- a/src/Services/DBusServer.vala +++ b/src/Services/DBusServer.vala @@ -9,7 +9,7 @@ public class Monitor.DBusServer : Object { return instance.once (() => { return new DBusServer (); }); } - public signal void update (Utils.SystemResources data); + public signal void update (ResourcesSerialized data); public signal void indicator_state (bool state); public signal void quit (); public signal void show (); diff --git a/src/Services/Updater.vala b/src/Services/Updater.vala index 9825644c..d7217d62 100644 --- a/src/Services/Updater.vala +++ b/src/Services/Updater.vala @@ -8,34 +8,16 @@ namespace Monitor { private int interval = 2; // in secs - private CPU cpu; - private Memory memory; - private Swap swap; - private Utils.SystemResources sysres; + private Resources resources; - public signal void update (Utils.SystemResources sysres); + public signal void update (Resources resources); construct { - memory = new Memory (); - cpu = new CPU (); - swap = new Swap (); - - Timeout.add_seconds (interval, update_resources); - } - - private bool update_resources () { - sysres = Utils.SystemResources () { - cpu_percentage = cpu.percentage, - cpu_frequency = cpu.frequency, - memory_percentage = memory.percentage, - memory_used = memory.used, - memory_total = memory.total, - swap_percentage = swap.percentage, - swap_used = swap.used, - swap_total = swap.total - }; - update (sysres); - return true; + resources = new Resources (); + Timeout.add_seconds (interval, () => { + update (resources); + return true; + }); } } } diff --git a/src/Utils.vala b/src/Utils.vala index 40df65e5..7aca14b9 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -1,15 +1,4 @@ namespace Monitor.Utils { - public struct SystemResources { - public int cpu_percentage; - public double cpu_frequency; - public int memory_percentage; - public double memory_used; - public double memory_total; - public int swap_percentage; - public double swap_used; - public double swap_total; - } - const string NOT_AVAILABLE = (_("N/A")); const string NO_DATA = "\u2014"; } diff --git a/src/Widgets/Statusbar/Statusbar.vala b/src/Widgets/Statusbar/Statusbar.vala index 2689bcc9..aebe914f 100644 --- a/src/Widgets/Statusbar/Statusbar.vala +++ b/src/Widgets/Statusbar/Statusbar.vala @@ -31,7 +31,7 @@ public class Monitor.Statusbar : Gtk.ActionBar { public Statusbar () { } - public bool update (Utils.SystemResources sysres) { + public bool update (ResourcesSerialized sysres) { cpu_usage_label.set_text (("%d%%").printf (sysres.cpu_percentage)); memory_usage_label.set_text (("%d%%").printf (sysres.memory_percentage)); From 265e0e5821bfb9cc16518fad86fdb7199c5224b9 Mon Sep 17 00:00:00 2001 From: stsdc Date: Thu, 2 Jul 2020 00:18:43 +0200 Subject: [PATCH 04/18] remove commented code --- src/Indicator/Services/DBusClient.vala | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/src/Indicator/Services/DBusClient.vala b/src/Indicator/Services/DBusClient.vala index c8c339d7..2f6522d7 100644 --- a/src/Indicator/Services/DBusClient.vala +++ b/src/Indicator/Services/DBusClient.vala @@ -1,17 +1,3 @@ - -// // this should be defined in one place -> in Resources, but it can't see it -// public struct ResourcesStruct { -// public int cpu_percentage; -// public double cpu_frequency; -// public int memory_percentage; -// public double memory_used; -// public double memory_total; -// public int swap_percentage; -// public double swap_used; -// public double swap_total; -// } - - [DBus (name = "com.github.stsdc.monitor")] public interface Monitor.DBusClientInterface : Object { public abstract void quit_monitor () throws Error; From 3f7f0db0521f7ac677710b9f88f96658ae0f8264 Mon Sep 17 00:00:00 2001 From: stsdc Date: Sat, 4 Jul 2020 23:18:33 +0200 Subject: [PATCH 05/18] adds cores to cpu --- src/Resources/CPU.vala | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Resources/CPU.vala b/src/Resources/CPU.vala index a3b37805..26e8088e 100644 --- a/src/Resources/CPU.vala +++ b/src/Resources/CPU.vala @@ -12,6 +12,8 @@ public class Monitor.CPU : Object { } } + public Gee.ArrayList cores_list; + private double _frequency; public double frequency { get { @@ -24,9 +26,15 @@ public class Monitor.CPU : Object { construct { last_used = 0; last_total = 0; - } - public CPU () { + cores_list = new Gee.ArrayList (); + + + debug ("Number of cores: %d", (int) get_num_processors ()); + for (int i = 0; i < (int) get_num_processors (); i++) { + var core = new Core(i); + cores_list.add (core); + } } private void update_percentage () { From e037558d0dac9b42748d724da31cd730b0d7ad2b Mon Sep 17 00:00:00 2001 From: stsdc Date: Mon, 6 Jul 2020 00:30:49 +0200 Subject: [PATCH 06/18] add basic core usage chart --- meson.build | 1 + src/MainWindow.vala | 1 + src/Resources/CPU.vala | 6 +-- src/Resources/Core.vala | 2 + src/Views/SystemView/SystemCPUChart.vala | 69 ++++++++++++++++++++++++ src/Views/SystemView/SystemView.vala | 13 +++-- 6 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 src/Views/SystemView/SystemCPUChart.vala diff --git a/meson.build b/meson.build index 93e02db3..e102a95f 100644 --- a/meson.build +++ b/meson.build @@ -67,6 +67,7 @@ executable( 'src/Views/ProcessView/ProcessTreeView/CPUProcessTreeView.vala', 'src/Views/SystemView/SystemView.vala', + 'src/Views/SystemView/SystemCPUChart.vala', # Widgets related only to ProcessInfoView 'src/Views/ProcessView/ProcessInfoView/Preventor.vala', diff --git a/src/MainWindow.vala b/src/MainWindow.vala index b20020d6..1a654799 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -54,6 +54,7 @@ statusbar.update (res); dbusserver.update (res); process_view.update(); + system_view.update(resources); dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state")); }); diff --git a/src/Resources/CPU.vala b/src/Resources/CPU.vala index 26e8088e..406eff10 100644 --- a/src/Resources/CPU.vala +++ b/src/Resources/CPU.vala @@ -12,7 +12,7 @@ public class Monitor.CPU : Object { } } - public Gee.ArrayList cores_list; + public Gee.ArrayList core_list; private double _frequency; public double frequency { @@ -27,13 +27,13 @@ public class Monitor.CPU : Object { last_used = 0; last_total = 0; - cores_list = new Gee.ArrayList (); + core_list = new Gee.ArrayList (); debug ("Number of cores: %d", (int) get_num_processors ()); for (int i = 0; i < (int) get_num_processors (); i++) { var core = new Core(i); - cores_list.add (core); + core_list.add (core); } } diff --git a/src/Resources/Core.vala b/src/Resources/Core.vala index bed3b5b0..4d385d55 100644 --- a/src/Resources/Core.vala +++ b/src/Resources/Core.vala @@ -31,6 +31,8 @@ namespace Monitor { last_used = (float) used; last_total = (float) cpu.xcpu_total[number]; + + // debug("Core %d: %f%%", number, _percentage_used); } } } diff --git a/src/Views/SystemView/SystemCPUChart.vala b/src/Views/SystemView/SystemCPUChart.vala new file mode 100644 index 00000000..c5d7f265 --- /dev/null +++ b/src/Views/SystemView/SystemCPUChart.vala @@ -0,0 +1,69 @@ +public class Monitor.SystemCPUChart : Gtk.Box { + private LiveChart.Chart chart; + private LiveChart.Config config; + + private Gee.ArrayList serie_list; + + + construct { + serie_list = new Gee.ArrayList (); + + + + vexpand = true; + height_request = 60; + + config = new LiveChart.Config (); + config.y_axis.unit = "%"; + config.y_axis.tick_interval = 25; + config.y_axis.fixed_max = 100.0; + config.y_axis.labels.visible = false; + config.x_axis.labels.visible = false; + + config.padding = LiveChart.Padding () { + smart = LiveChart.AutoPadding.NONE, + top = 0, + right = 0, + bottom = 0, + left = 0 + }; + + chart = new LiveChart.Chart (config); + chart.expand = true; + chart.legend.visible = false; + chart.grid.visible = true; + chart.background.main_color = Gdk.RGBA () { + red= 0, green= 0, blue= 0, alpha= 1 + }; //White background + + + } + + public SystemCPUChart (int cores_quantity) { + for (int i = 0; i < cores_quantity; i++) { + var renderer = new LiveChart.SmoothLineArea (new LiveChart.Values(1000)); + var serie = new LiveChart.Serie ("Core x", renderer); + serie.set_main_color ({ 0.35 + i/20, 0.8, 0.1, 1.0}); + chart.add_serie (serie); + serie_list.add (serie); + } + + add (chart); + } + + public void update (int serie_number, double value) { + chart.add_value (serie_list.get(serie_number), value); + } + + // public void set_data (Gee.ArrayList history) { + // var refresh_rate_is_ms = 2000; //your own refresh rate in milliseconds + // chart.add_unaware_timestamp_collection(serie_list[0], history, refresh_rate_is_ms); + // } + + public void clear () { + // var series = chart.series; + // foreach (var serie in serie_list) { + // serie.clear(); + // } + } +} diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala index 15bae590..bc293682 100644 --- a/src/Views/SystemView/SystemView.vala +++ b/src/Views/SystemView/SystemView.vala @@ -1,12 +1,19 @@ public class Monitor.SystemView : Gtk.Box { + private SystemCPUChart cpu_chart; construct { - + cpu_chart = new SystemCPUChart (8); } public SystemView () { - var label = new Gtk.Label("System things"); - add(label); + add (cpu_chart); } + public void update (Resources resources) { + for (int i = 0; i < resources.cpu.core_list.size; i++) { + debug("%d", i); + cpu_chart.update(i, resources.cpu.core_list[i].percentage_used); + } + + } } \ No newline at end of file From 52ebb0493bfbfeb2d385f0942e681f09ba14f248 Mon Sep 17 00:00:00 2001 From: stsdc Date: Mon, 6 Jul 2020 18:32:26 +0200 Subject: [PATCH 07/18] removing updater --- meson.build | 1 - src/MainWindow.vala | 16 ++++++++++------ src/Resources/Resources.vala | 2 +- src/Services/Updater.vala | 23 ----------------------- src/Views/SystemView/SystemView.vala | 10 +++++++--- 5 files changed, 18 insertions(+), 34 deletions(-) delete mode 100644 src/Services/Updater.vala diff --git a/meson.build b/meson.build index e102a95f..b67f98a7 100644 --- a/meson.build +++ b/meson.build @@ -96,7 +96,6 @@ executable( 'src/Services/Shortcuts.vala', 'src/Services/DBusServer.vala', - 'src/Services/Updater.vala', # Resources 'src/Resources/Resources.vala', diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 1a654799..66941c68 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -2,6 +2,8 @@ // application reference private Shortcuts shortcuts; + private Resources resources; + // Widgets public Headerbar headerbar; // private Gtk.Button process_info_button; @@ -13,8 +15,6 @@ public DBusServer dbusserver; - private Updater updater; - // Constructs a main window public MainWindow (MonitorApp app) { @@ -24,8 +24,10 @@ get_style_context ().add_class ("rounded"); + resources = new Resources (); + process_view = new ProcessView (); - system_view = new SystemView (); + system_view = new SystemView (resources); Gtk.Stack stack = new Gtk.Stack (); stack.set_transition_type (Gtk.StackTransitionType.SLIDE_LEFT_RIGHT); @@ -46,16 +48,18 @@ main_box.pack_start (statusbar, false, true, 0); this.add (main_box); - updater = Updater.get_default (); dbusserver = DBusServer.get_default (); + + - updater.update.connect ((resources) => { + Timeout.add_seconds (2, () => { var res = resources.serialize (); statusbar.update (res); dbusserver.update (res); process_view.update(); - system_view.update(resources); + system_view.update(); dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state")); + return true; }); diff --git a/src/Resources/Resources.vala b/src/Resources/Resources.vala index ba26e3b6..9251d012 100644 --- a/src/Resources/Resources.vala +++ b/src/Resources/Resources.vala @@ -10,7 +10,7 @@ public class Monitor.Resources : Object { } public ResourcesSerialized serialize () { - return new ResourcesSerialized () { + return ResourcesSerialized () { cpu_percentage = cpu.percentage, cpu_frequency = cpu.frequency, memory_percentage = memory.percentage, diff --git a/src/Services/Updater.vala b/src/Services/Updater.vala deleted file mode 100644 index d7217d62..00000000 --- a/src/Services/Updater.vala +++ /dev/null @@ -1,23 +0,0 @@ -namespace Monitor { - - public class Updater : Object { - private static GLib.Once instance; - public static unowned Updater get_default () { - return instance.once (() => { return new Updater (); }); - } - - private int interval = 2; // in secs - - private Resources resources; - - public signal void update (Resources resources); - - construct { - resources = new Resources (); - Timeout.add_seconds (interval, () => { - update (resources); - return true; - }); - } - } -} diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala index bc293682..158bca9b 100644 --- a/src/Views/SystemView/SystemView.vala +++ b/src/Views/SystemView/SystemView.vala @@ -1,15 +1,19 @@ public class Monitor.SystemView : Gtk.Box { private SystemCPUChart cpu_chart; + private Resources resources; construct { - cpu_chart = new SystemCPUChart (8); + } - public SystemView () { + public SystemView (Resources _resources) { + resources = _resources; + cpu_chart = new SystemCPUChart (resources.cpu.core_list.size); + add (cpu_chart); } - public void update (Resources resources) { + public void update () { for (int i = 0; i < resources.cpu.core_list.size; i++) { debug("%d", i); cpu_chart.update(i, resources.cpu.core_list[i].percentage_used); From a1dab89e4d7214a6eac38fab6fbe4bebcbe1592a Mon Sep 17 00:00:00 2001 From: stsdc Date: Mon, 6 Jul 2020 19:34:24 +0200 Subject: [PATCH 08/18] some basic layout for cpu usage --- meson.build | 1 + src/Views/SystemView/SystemCPUChart.vala | 4 +-- src/Views/SystemView/SystemCPUView.vala | 39 ++++++++++++++++++++++++ src/Views/SystemView/SystemView.vala | 19 ++++++------ 4 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/Views/SystemView/SystemCPUView.vala diff --git a/meson.build b/meson.build index b67f98a7..3363d632 100644 --- a/meson.build +++ b/meson.build @@ -68,6 +68,7 @@ executable( 'src/Views/SystemView/SystemView.vala', 'src/Views/SystemView/SystemCPUChart.vala', + 'src/Views/SystemView/SystemCPUView.vala', # Widgets related only to ProcessInfoView 'src/Views/ProcessView/ProcessInfoView/Preventor.vala', diff --git a/src/Views/SystemView/SystemCPUChart.vala b/src/Views/SystemView/SystemCPUChart.vala index c5d7f265..8715c059 100644 --- a/src/Views/SystemView/SystemCPUChart.vala +++ b/src/Views/SystemView/SystemCPUChart.vala @@ -11,7 +11,7 @@ public class Monitor.SystemCPUChart : Gtk.Box { vexpand = true; - height_request = 60; + height_request = 120; config = new LiveChart.Config (); config.y_axis.unit = "%"; @@ -33,7 +33,7 @@ public class Monitor.SystemCPUChart : Gtk.Box { chart.legend.visible = false; chart.grid.visible = true; chart.background.main_color = Gdk.RGBA () { - red= 0, green= 0, blue= 0, alpha= 1 + red= 1, green= 1, blue= 1, alpha= 1 }; //White background diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala new file mode 100644 index 00000000..2e546802 --- /dev/null +++ b/src/Views/SystemView/SystemCPUView.vala @@ -0,0 +1,39 @@ +public class Monitor.SystemCPUView : Gtk.Grid { + private SystemCPUChart cpu_chart; + private CPU cpu; + + private Gtk.Label cpu_percentage_label; + + construct { + margin = 12; + column_spacing = 12; + set_vexpand (false); + + + } + + + + public SystemCPUView(CPU _cpu) { + cpu = _cpu; + + cpu_percentage_label = new Gtk.Label ("CPU: " + Utils.NO_DATA); + cpu_percentage_label.get_style_context ().add_class ("h2"); + cpu_percentage_label.valign = Gtk.Align.START; + + cpu_chart = new SystemCPUChart (cpu.core_list.size); + + attach (cpu_percentage_label, 0, 0, 1, 2); + attach (cpu_chart, 1, 0, 1, 1); + + } + + + public void update () { + for (int i = 0; i < cpu.core_list.size; i++) { + cpu_chart.update(i, cpu.core_list[i].percentage_used); + } + + cpu_percentage_label.set_text ((_("CPU: %d%%")).printf (cpu.percentage)); + } +} \ No newline at end of file diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala index 158bca9b..3219a7af 100644 --- a/src/Views/SystemView/SystemView.vala +++ b/src/Views/SystemView/SystemView.vala @@ -1,23 +1,24 @@ public class Monitor.SystemView : Gtk.Box { - private SystemCPUChart cpu_chart; private Resources resources; + private SystemCPUView cpu_view; + construct { - + orientation = Gtk.Orientation.VERTICAL; + hexpand = true; + + } public SystemView (Resources _resources) { resources = _resources; - cpu_chart = new SystemCPUChart (resources.cpu.core_list.size); - add (cpu_chart); + cpu_view = new SystemCPUView (resources.cpu); + + add (cpu_view); } public void update () { - for (int i = 0; i < resources.cpu.core_list.size; i++) { - debug("%d", i); - cpu_chart.update(i, resources.cpu.core_list[i].percentage_used); - } - + cpu_view.update(); } } \ No newline at end of file From 09e7972db8c73551533ccb054b57bc7fee3ba2f5 Mon Sep 17 00:00:00 2001 From: stsdc Date: Mon, 6 Jul 2020 21:07:50 +0200 Subject: [PATCH 09/18] display core usage --- src/Views/SystemView/SystemCPUChart.vala | 1 + src/Views/SystemView/SystemCPUView.vala | 42 +++++++++++++++++++++--- 2 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/Views/SystemView/SystemCPUChart.vala b/src/Views/SystemView/SystemCPUChart.vala index 8715c059..6f68f2e1 100644 --- a/src/Views/SystemView/SystemCPUChart.vala +++ b/src/Views/SystemView/SystemCPUChart.vala @@ -52,6 +52,7 @@ public class Monitor.SystemCPUChart : Gtk.Box { } public void update (int serie_number, double value) { + // debug("%f", value); chart.add_value (serie_list.get(serie_number), value); } diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala index 2e546802..d42aa31e 100644 --- a/src/Views/SystemView/SystemCPUView.vala +++ b/src/Views/SystemView/SystemCPUView.vala @@ -4,12 +4,14 @@ public class Monitor.SystemCPUView : Gtk.Grid { private Gtk.Label cpu_percentage_label; + private Gee.ArrayList core_label_list; + construct { margin = 12; column_spacing = 12; set_vexpand (false); - + core_label_list = new Gee.ArrayList (); } @@ -20,20 +22,50 @@ public class Monitor.SystemCPUView : Gtk.Grid { cpu_percentage_label = new Gtk.Label ("CPU: " + Utils.NO_DATA); cpu_percentage_label.get_style_context ().add_class ("h2"); cpu_percentage_label.valign = Gtk.Align.START; + cpu_percentage_label.halign = Gtk.Align.START; cpu_chart = new SystemCPUChart (cpu.core_list.size); - attach (cpu_percentage_label, 0, 0, 1, 2); - attach (cpu_chart, 1, 0, 1, 1); + attach (cpu_percentage_label, 0, 0, 1, 1); + attach (grid_core_labels (), 0, 1, 1); + attach (cpu_chart, 1, 0, 1, 2); + + } public void update () { for (int i = 0; i < cpu.core_list.size; i++) { - cpu_chart.update(i, cpu.core_list[i].percentage_used); + // donno why, but gives -nan if not stored + // someone explain, plz + double core_percentage = cpu.core_list[i].percentage_used; + cpu_chart.update(i, core_percentage); + core_label_list[i].set_text ((_("Core " + i.to_string() + ":% 3d%%")).printf ( (int)core_percentage)); + } + + cpu_percentage_label.set_text ((_("CPU: % 3d%%")).printf (cpu.percentage)); + } + + private Gtk.Grid grid_core_labels () { + Gtk.Grid grid = new Gtk.Grid (); + grid.column_spacing = 12; + int column = 0; + int row = 0; + for (int i = 0; i < cpu.core_list.size; i++) { + var core_label = new Gtk.Label("Core " + i.to_string() + ": " + Utils.NO_DATA); + core_label.halign = Gtk.Align.START; + core_label_list.add (core_label); + + grid.attach(core_label, column, row, 1, 1); + + column++; + if (column > 1) { + row++; + column = 0; + } } - cpu_percentage_label.set_text ((_("CPU: %d%%")).printf (cpu.percentage)); + return grid; } } \ No newline at end of file From 76e4801ba4de2193a6ef0bb63421ac1a03380408 Mon Sep 17 00:00:00 2001 From: stsdc Date: Mon, 6 Jul 2020 22:24:20 +0200 Subject: [PATCH 10/18] fixed cpu updating --- src/MainWindow.vala | 3 +++ src/Resources/CPU.vala | 11 +++++++++-- src/Resources/Core.vala | 4 ++-- src/Resources/Resources.vala | 3 +++ src/Views/SystemView/SystemCPUChart.vala | 4 ++-- src/Views/SystemView/SystemCPUView.vala | 3 ++- 6 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 66941c68..6aef3498 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -53,10 +53,13 @@ Timeout.add_seconds (2, () => { + resources.update(); var res = resources.serialize (); statusbar.update (res); dbusserver.update (res); process_view.update(); + + debug ("%d", resources.cpu.percentage); system_view.update(); dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state")); return true; diff --git a/src/Resources/CPU.vala b/src/Resources/CPU.vala index 406eff10..df0ded16 100644 --- a/src/Resources/CPU.vala +++ b/src/Resources/CPU.vala @@ -7,7 +7,6 @@ public class Monitor.CPU : Object { public int percentage { get { - update_percentage (); return (int)(Math.round (load * 100)); } } @@ -17,7 +16,6 @@ public class Monitor.CPU : Object { private double _frequency; public double frequency { get { - update_frequency (); // Convert kH to GHz return (double)(_frequency / 1000000); } @@ -37,6 +35,15 @@ public class Monitor.CPU : Object { } } + public void update () { + update_percentage(); + update_frequency(); + + foreach (var core in core_list) { + core.update(); + } + } + private void update_percentage () { GTop.get_cpu (out cpu); diff --git a/src/Resources/Core.vala b/src/Resources/Core.vala index 4d385d55..1a13113f 100644 --- a/src/Resources/Core.vala +++ b/src/Resources/Core.vala @@ -8,7 +8,7 @@ namespace Monitor { public int number { get; set; } public float percentage_used { - get { update_percentage_used (); return _percentage_used; } + get { return _percentage_used; } } public Core (int number) { @@ -17,7 +17,7 @@ namespace Monitor { last_total = 0; } - private void update_percentage_used () { + public void update () { GTop.Cpu cpu; GTop.get_cpu (out cpu); diff --git a/src/Resources/Resources.vala b/src/Resources/Resources.vala index 9251d012..a23f2f91 100644 --- a/src/Resources/Resources.vala +++ b/src/Resources/Resources.vala @@ -9,6 +9,9 @@ public class Monitor.Resources : Object { swap = new Swap (); } + public void update() { + cpu.update(); + } public ResourcesSerialized serialize () { return ResourcesSerialized () { cpu_percentage = cpu.percentage, diff --git a/src/Views/SystemView/SystemCPUChart.vala b/src/Views/SystemView/SystemCPUChart.vala index 6f68f2e1..8759a8ac 100644 --- a/src/Views/SystemView/SystemCPUChart.vala +++ b/src/Views/SystemView/SystemCPUChart.vala @@ -8,7 +8,7 @@ public class Monitor.SystemCPUChart : Gtk.Box { construct { serie_list = new Gee.ArrayList (); - + get_style_context ().add_class ("graph"); vexpand = true; height_request = 120; @@ -25,7 +25,7 @@ public class Monitor.SystemCPUChart : Gtk.Box { top = 0, right = 0, bottom = 0, - left = 0 + left = -1 }; chart = new LiveChart.Chart (config); diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala index d42aa31e..2be40f09 100644 --- a/src/Views/SystemView/SystemCPUView.vala +++ b/src/Views/SystemView/SystemCPUView.vala @@ -41,7 +41,8 @@ public class Monitor.SystemCPUView : Gtk.Grid { // someone explain, plz double core_percentage = cpu.core_list[i].percentage_used; cpu_chart.update(i, core_percentage); - core_label_list[i].set_text ((_("Core " + i.to_string() + ":% 3d%%")).printf ( (int)core_percentage)); + string percentage_formatted = ("% 3d%%").printf ( (int)core_percentage); + core_label_list[i].set_text ((_("Core " + i.to_string() + ":" + percentage_formatted))); } cpu_percentage_label.set_text ((_("CPU: % 3d%%")).printf (cpu.percentage)); From b4dc0fb72cc03e73398cf17174feb201733ed092 Mon Sep 17 00:00:00 2001 From: stsdc Date: Tue, 7 Jul 2020 00:57:11 +0200 Subject: [PATCH 11/18] add memory percentage --- meson.build | 1 + src/MainWindow.vala | 2 -- src/Resources/Memory.vala | 3 +- src/Resources/Resources.vala | 1 + src/Views/SystemView/SystemMemoryView.vala | 37 ++++++++++++++++++++++ src/Views/SystemView/SystemView.vala | 4 +++ 6 files changed, 44 insertions(+), 4 deletions(-) create mode 100644 src/Views/SystemView/SystemMemoryView.vala diff --git a/meson.build b/meson.build index 3363d632..8f1f0d30 100644 --- a/meson.build +++ b/meson.build @@ -69,6 +69,7 @@ executable( 'src/Views/SystemView/SystemView.vala', 'src/Views/SystemView/SystemCPUChart.vala', 'src/Views/SystemView/SystemCPUView.vala', + 'src/Views/SystemView/SystemMemoryView.vala', # Widgets related only to ProcessInfoView 'src/Views/ProcessView/ProcessInfoView/Preventor.vala', diff --git a/src/MainWindow.vala b/src/MainWindow.vala index 6aef3498..5c0c673a 100644 --- a/src/MainWindow.vala +++ b/src/MainWindow.vala @@ -58,8 +58,6 @@ statusbar.update (res); dbusserver.update (res); process_view.update(); - - debug ("%d", resources.cpu.percentage); system_view.update(); dbusserver.indicator_state (MonitorApp.settings.get_boolean ("indicator-state")); return true; diff --git a/src/Resources/Memory.vala b/src/Resources/Memory.vala index b5a63a01..81558256 100644 --- a/src/Resources/Memory.vala +++ b/src/Resources/Memory.vala @@ -8,7 +8,6 @@ namespace Monitor { public int percentage { get { - update (); return (int) (Math.round ((used / total) * 100)); } } @@ -20,7 +19,7 @@ namespace Monitor { public Memory () { } - private void update () { + public void update () { GTop.get_mem (out mem); total = (double) (mem.total / 1024 / 1024) / 1000; used = (double) (mem.user / 1024 / 1024) / 1000; diff --git a/src/Resources/Resources.vala b/src/Resources/Resources.vala index a23f2f91..1deef74c 100644 --- a/src/Resources/Resources.vala +++ b/src/Resources/Resources.vala @@ -11,6 +11,7 @@ public class Monitor.Resources : Object { public void update() { cpu.update(); + memory.update(); } public ResourcesSerialized serialize () { return ResourcesSerialized () { diff --git a/src/Views/SystemView/SystemMemoryView.vala b/src/Views/SystemView/SystemMemoryView.vala new file mode 100644 index 00000000..e067ec24 --- /dev/null +++ b/src/Views/SystemView/SystemMemoryView.vala @@ -0,0 +1,37 @@ +public class Monitor.SystemMemoryView : Gtk.Grid { + // private SystemChart memory_chart; + private Memory memory; + + private Gtk.Label memory_percentage_label; + + construct { + margin = 12; + column_spacing = 12; + set_vexpand (false); + + } + + + + public SystemMemoryView(Memory _memory) { + memory = _memory; + + memory_percentage_label = new Gtk.Label ("Memory: " + Utils.NO_DATA); + memory_percentage_label.get_style_context ().add_class ("h2"); + memory_percentage_label.valign = Gtk.Align.START; + memory_percentage_label.halign = Gtk.Align.START; + + // memory_chart = new SystemCPUChart (memory.core_list.size); + + attach (memory_percentage_label, 0, 0, 1, 1); + // attach (grid_core_labels (), 0, 1, 1); + // attach (memory_chart, 1, 0, 1, 2); + + } + + + public void update () { + memory_percentage_label.set_text ((_("Memory: % 3d%%")).printf (memory.percentage)); + } + +} \ No newline at end of file diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala index 3219a7af..6d5ab6de 100644 --- a/src/Views/SystemView/SystemView.vala +++ b/src/Views/SystemView/SystemView.vala @@ -2,6 +2,7 @@ public class Monitor.SystemView : Gtk.Box { private Resources resources; private SystemCPUView cpu_view; + private SystemMemoryView memory_view; construct { orientation = Gtk.Orientation.VERTICAL; @@ -14,11 +15,14 @@ public class Monitor.SystemView : Gtk.Box { resources = _resources; cpu_view = new SystemCPUView (resources.cpu); + memory_view = new SystemMemoryView (resources.memory); add (cpu_view); + add (memory_view); } public void update () { cpu_view.update(); + memory_view.update(); } } \ No newline at end of file From e7541d8a5e0db3e5481e465eb1ae7eb88c0f79fe Mon Sep 17 00:00:00 2001 From: stsdc Date: Tue, 7 Jul 2020 22:08:37 +0200 Subject: [PATCH 12/18] add more memory labels --- src/Resources/Memory.vala | 10 ++++++- src/Views/SystemView/SystemMemoryView.vala | 34 ++++++++++++++++++++-- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/src/Resources/Memory.vala b/src/Resources/Memory.vala index 81558256..860106e8 100644 --- a/src/Resources/Memory.vala +++ b/src/Resources/Memory.vala @@ -3,6 +3,10 @@ namespace Monitor { public class Memory : Object { public double total; public double used; + public double shared; + public double buffer; + public double cached; + public double locked; private GTop.Memory mem; @@ -21,8 +25,12 @@ namespace Monitor { public void update () { GTop.get_mem (out mem); - total = (double) (mem.total / 1024 / 1024) / 1000; + total = (mem.total); used = (double) (mem.user / 1024 / 1024) / 1000; + shared = (double) (mem.shared / 1024 / 1024) / 1000; + buffer = (double) (mem.buffer / 1024 / 1024) / 1000; + cached = (double) (mem.cached / 1024 / 1024) / 1000; + locked = (double) (mem.locked / 1024 / 1024) / 1000; } } } diff --git a/src/Views/SystemView/SystemMemoryView.vala b/src/Views/SystemView/SystemMemoryView.vala index e067ec24..e7c97cb8 100644 --- a/src/Views/SystemView/SystemMemoryView.vala +++ b/src/Views/SystemView/SystemMemoryView.vala @@ -3,6 +3,12 @@ public class Monitor.SystemMemoryView : Gtk.Grid { private Memory memory; private Gtk.Label memory_percentage_label; + private Gtk.Label memory_shared_label; + private Gtk.Label memory_buffered_label; + private Gtk.Label memory_cached_label; + private Gtk.Label memory_locked_label; + private Gtk.Label memory_total_label; + private Gtk.Label memory_used_label; construct { margin = 12; @@ -18,20 +24,42 @@ public class Monitor.SystemMemoryView : Gtk.Grid { memory_percentage_label = new Gtk.Label ("Memory: " + Utils.NO_DATA); memory_percentage_label.get_style_context ().add_class ("h2"); - memory_percentage_label.valign = Gtk.Align.START; memory_percentage_label.halign = Gtk.Align.START; + memory_total_label = new Gtk.Label ("Total: " + Utils.NO_DATA); + memory_used_label = new Gtk.Label ("Used: " + Utils.NO_DATA); + memory_shared_label = new Gtk.Label ("Shared: " + Utils.NO_DATA); + memory_buffered_label = new Gtk.Label ("Buffered: " + Utils.NO_DATA); + memory_cached_label = new Gtk.Label ("Cached: " + Utils.NO_DATA); + memory_locked_label = new Gtk.Label ("Locked: " + Utils.NO_DATA); + // memory_chart = new SystemCPUChart (memory.core_list.size); - attach (memory_percentage_label, 0, 0, 1, 1); - // attach (grid_core_labels (), 0, 1, 1); + attach (memory_percentage_label, 0, 0, 2, 1); + attach (memory_usage_grid (), 0, 1, 1); // attach (memory_chart, 1, 0, 1, 2); } + private Gtk.Grid memory_usage_grid () { + Gtk.Grid grid = new Gtk.Grid (); + grid.column_spacing = 12; + + grid.attach (memory_total_label, 0, 0, 1, 1); + grid.attach (memory_used_label, 1, 0, 1, 1); + grid.attach (memory_shared_label, 0, 1, 1, 1); + grid.attach (memory_buffered_label, 1, 1, 1, 1); + grid.attach (memory_cached_label, 0, 2, 1, 1); + grid.attach (memory_locked_label, 1, 2, 1, 1); + + return grid; + } + public void update () { memory_percentage_label.set_text ((_("Memory: % 3d%%")).printf (memory.percentage)); + + memory_total_label.set_text ((_("Total: %f")).printf (memory.total)); } } \ No newline at end of file From 0a14e5149bff618bab121cc586f466365ec96f0c Mon Sep 17 00:00:00 2001 From: stsdc Date: Sat, 11 Jul 2020 22:13:52 +0200 Subject: [PATCH 13/18] convert units correctly using Utils; show more info about ram usage --- src/Resources/Memory.vala | 13 +++++++------ src/Utils.vala | 18 +++++++++++------- .../ProcessInfoView/ProcessInfoIOStats.vala | 6 +++--- src/Views/SystemView/SystemCPUView.vala | 4 ++-- src/Views/SystemView/SystemMemoryView.vala | 18 +++++++++++++++++- src/Widgets/Statusbar/Statusbar.vala | 2 +- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/Resources/Memory.vala b/src/Resources/Memory.vala index 860106e8..9ef7f4da 100644 --- a/src/Resources/Memory.vala +++ b/src/Resources/Memory.vala @@ -25,12 +25,13 @@ namespace Monitor { public void update () { GTop.get_mem (out mem); - total = (mem.total); - used = (double) (mem.user / 1024 / 1024) / 1000; - shared = (double) (mem.shared / 1024 / 1024) / 1000; - buffer = (double) (mem.buffer / 1024 / 1024) / 1000; - cached = (double) (mem.cached / 1024 / 1024) / 1000; - locked = (double) (mem.locked / 1024 / 1024) / 1000; + total = (double) (mem.total ); + used = (double) mem.user; + shared = (double) (mem.shared); + buffer = (double) (mem.buffer); + cached = (double) (mem.cached); + locked = (double) (mem.locked); + } } } diff --git a/src/Utils.vala b/src/Utils.vala index 7aca14b9..4d020acf 100644 --- a/src/Utils.vala +++ b/src/Utils.vala @@ -29,22 +29,26 @@ namespace Monitor.Utils { return current_size_formatted; } - public static string int_bytes_to_human(int bytes) { - double bytes_double = (double)bytes; + public static string double_bytes_to_human(double bytes) { string units = _ ("B"); // convert to MiB if needed - if (bytes_double > 1024.0) { - bytes_double /= 1024.0; + if (bytes > 1024.0) { + bytes /= 1024.0; units = _ ("KiB"); } // convert to GiB if needed - if (bytes_double > 1024.0) { - bytes_double /= 1024.0; + if (bytes > 1024.0) { + bytes /= 1024.0; units = _ ("MiB"); } - return "%.1f %s".printf (bytes_double, units); + if (bytes > 1024.0) { + bytes /= 1024.0; + units = _ ("GiB"); + } + + return "%.1f %s".printf (bytes, units); } } diff --git a/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala b/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala index fb5905ba..c9b2bac3 100644 --- a/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala +++ b/src/Views/ProcessView/ProcessInfoView/ProcessInfoIOStats.vala @@ -57,9 +57,9 @@ public class Monitor.ProcessInfoIOStats : Gtk.Grid { } public void update (Process process) { - write_bytes_label.set_text (Utils.HumanUnitFormatter.int_bytes_to_human((int)process.io.write_bytes)); - read_bytes_label.set_text (Utils.HumanUnitFormatter.int_bytes_to_human((int)process.io.read_bytes)); - cancelled_write_bytes_label.set_text (Utils.HumanUnitFormatter.int_bytes_to_human((int)process.io.cancelled_write_bytes)); + write_bytes_label.set_text (Utils.HumanUnitFormatter.double_bytes_to_human(process.io.write_bytes)); + read_bytes_label.set_text (Utils.HumanUnitFormatter.double_bytes_to_human(process.io.read_bytes)); + cancelled_write_bytes_label.set_text (Utils.HumanUnitFormatter.double_bytes_to_human(process.io.cancelled_write_bytes)); open_files_listbox.update (process); } diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala index 2be40f09..b3350a38 100644 --- a/src/Views/SystemView/SystemCPUView.vala +++ b/src/Views/SystemView/SystemCPUView.vala @@ -42,7 +42,7 @@ public class Monitor.SystemCPUView : Gtk.Grid { double core_percentage = cpu.core_list[i].percentage_used; cpu_chart.update(i, core_percentage); string percentage_formatted = ("% 3d%%").printf ( (int)core_percentage); - core_label_list[i].set_text ((_("Core " + i.to_string() + ":" + percentage_formatted))); + core_label_list[i].set_text ((_("Thread " + i.to_string() + ":" + percentage_formatted))); } cpu_percentage_label.set_text ((_("CPU: % 3d%%")).printf (cpu.percentage)); @@ -54,7 +54,7 @@ public class Monitor.SystemCPUView : Gtk.Grid { int column = 0; int row = 0; for (int i = 0; i < cpu.core_list.size; i++) { - var core_label = new Gtk.Label("Core " + i.to_string() + ": " + Utils.NO_DATA); + var core_label = new Gtk.Label("Thread " + i.to_string() + ": " + Utils.NO_DATA); core_label.halign = Gtk.Align.START; core_label_list.add (core_label); diff --git a/src/Views/SystemView/SystemMemoryView.vala b/src/Views/SystemView/SystemMemoryView.vala index e7c97cb8..93d2955e 100644 --- a/src/Views/SystemView/SystemMemoryView.vala +++ b/src/Views/SystemView/SystemMemoryView.vala @@ -27,11 +27,22 @@ public class Monitor.SystemMemoryView : Gtk.Grid { memory_percentage_label.halign = Gtk.Align.START; memory_total_label = new Gtk.Label ("Total: " + Utils.NO_DATA); + memory_total_label.halign = Gtk.Align.START; + memory_used_label = new Gtk.Label ("Used: " + Utils.NO_DATA); + memory_used_label.halign = Gtk.Align.START; + memory_shared_label = new Gtk.Label ("Shared: " + Utils.NO_DATA); + memory_shared_label.halign = Gtk.Align.START; + memory_buffered_label = new Gtk.Label ("Buffered: " + Utils.NO_DATA); + memory_buffered_label.halign = Gtk.Align.START; + memory_cached_label = new Gtk.Label ("Cached: " + Utils.NO_DATA); + memory_cached_label.halign = Gtk.Align.START; + memory_locked_label = new Gtk.Label ("Locked: " + Utils.NO_DATA); + memory_locked_label.halign = Gtk.Align.START; // memory_chart = new SystemCPUChart (memory.core_list.size); @@ -59,7 +70,12 @@ public class Monitor.SystemMemoryView : Gtk.Grid { public void update () { memory_percentage_label.set_text ((_("Memory: % 3d%%")).printf (memory.percentage)); - memory_total_label.set_text ((_("Total: %f")).printf (memory.total)); + memory_total_label.set_text ((_("Total: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.total))); + memory_used_label.set_text ((_("Used: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.used))); + memory_shared_label.set_text ((_("Shared: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.shared))); + memory_buffered_label.set_text ((_("Buffered: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.buffer))); + memory_cached_label.set_text ((_("Cached: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.cached))); + memory_locked_label.set_text ((_("Locked: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.locked))); } } \ No newline at end of file diff --git a/src/Widgets/Statusbar/Statusbar.vala b/src/Widgets/Statusbar/Statusbar.vala index aebe914f..d30193e6 100644 --- a/src/Widgets/Statusbar/Statusbar.vala +++ b/src/Widgets/Statusbar/Statusbar.vala @@ -38,7 +38,7 @@ public class Monitor.Statusbar : Gtk.ActionBar { string cpu_tooltip_text = ("%.2f %s").printf (sysres.cpu_frequency, _ ("GHz")); cpu_usage_label.tooltip_text = cpu_tooltip_text; - string memory_tooltip_text = ("%.1f %s / %.1f %s").printf (sysres.memory_used, _ ("GiB"), sysres.memory_total, _ ("GiB")); + string memory_tooltip_text = ("%s / %s").printf (Utils.HumanUnitFormatter.double_bytes_to_human(sysres.memory_used), Utils.HumanUnitFormatter.double_bytes_to_human(sysres.memory_total)); memory_usage_label.tooltip_text = memory_tooltip_text; // The total amount of the swap is 0 when it is unavailable From 9227f490657d7d19a3a14e6a51498fdf443a3cec Mon Sep 17 00:00:00 2001 From: stsdc Date: Sat, 11 Jul 2020 22:16:38 +0200 Subject: [PATCH 14/18] update live-chart --- subprojects/live-chart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/subprojects/live-chart b/subprojects/live-chart index 34f6a173..7e1d4ca8 160000 --- a/subprojects/live-chart +++ b/subprojects/live-chart @@ -1 +1 @@ -Subproject commit 34f6a1735561358cdd4c0c598c90f01a3b948fdc +Subproject commit 7e1d4ca8e3c0fee3b88b5ff0cdd447d8001824a2 From 5da52d135f3cdaaf471828228829ca7991af5797 Mon Sep 17 00:00:00 2001 From: stsdc Date: Sat, 11 Jul 2020 23:00:06 +0200 Subject: [PATCH 15/18] display memory chart --- src/Views/SystemView/SystemCPUChart.vala | 9 +++++---- src/Views/SystemView/SystemMemoryView.vala | 8 +++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Views/SystemView/SystemCPUChart.vala b/src/Views/SystemView/SystemCPUChart.vala index 8759a8ac..492112c6 100644 --- a/src/Views/SystemView/SystemCPUChart.vala +++ b/src/Views/SystemView/SystemCPUChart.vala @@ -2,11 +2,11 @@ public class Monitor.SystemCPUChart : Gtk.Box { private LiveChart.Chart chart; private LiveChart.Config config; - private Gee.ArrayList serie_list; + // private Gee.ArrayList serie_list; construct { - serie_list = new Gee.ArrayList (); + // serie_list = new Gee.ArrayList (); get_style_context ().add_class ("graph"); @@ -45,7 +45,7 @@ public class Monitor.SystemCPUChart : Gtk.Box { var serie = new LiveChart.Serie ("Core x", renderer); serie.set_main_color ({ 0.35 + i/20, 0.8, 0.1, 1.0}); chart.add_serie (serie); - serie_list.add (serie); + // serie_list.add (serie); } add (chart); @@ -53,7 +53,8 @@ public class Monitor.SystemCPUChart : Gtk.Box { public void update (int serie_number, double value) { // debug("%f", value); - chart.add_value (serie_list.get(serie_number), value); + // chart.add_value (serie_list.get(serie_number), value); + chart.add_value_by_index (serie_number, value); } // public void set_data (Gee.ArrayList history) { diff --git a/src/Views/SystemView/SystemMemoryView.vala b/src/Views/SystemView/SystemMemoryView.vala index 93d2955e..67ac6341 100644 --- a/src/Views/SystemView/SystemMemoryView.vala +++ b/src/Views/SystemView/SystemMemoryView.vala @@ -1,5 +1,5 @@ public class Monitor.SystemMemoryView : Gtk.Grid { - // private SystemChart memory_chart; + private SystemCPUChart memory_chart; private Memory memory; private Gtk.Label memory_percentage_label; @@ -25,6 +25,7 @@ public class Monitor.SystemMemoryView : Gtk.Grid { memory_percentage_label = new Gtk.Label ("Memory: " + Utils.NO_DATA); memory_percentage_label.get_style_context ().add_class ("h2"); memory_percentage_label.halign = Gtk.Align.START; + memory_percentage_label.valign = Gtk.Align.START; memory_total_label = new Gtk.Label ("Total: " + Utils.NO_DATA); memory_total_label.halign = Gtk.Align.START; @@ -44,11 +45,11 @@ public class Monitor.SystemMemoryView : Gtk.Grid { memory_locked_label = new Gtk.Label ("Locked: " + Utils.NO_DATA); memory_locked_label.halign = Gtk.Align.START; - // memory_chart = new SystemCPUChart (memory.core_list.size); + memory_chart = new SystemCPUChart (1); attach (memory_percentage_label, 0, 0, 2, 1); attach (memory_usage_grid (), 0, 1, 1); - // attach (memory_chart, 1, 0, 1, 2); + attach (memory_chart, 1, 0, 1, 2); } @@ -69,6 +70,7 @@ public class Monitor.SystemMemoryView : Gtk.Grid { public void update () { memory_percentage_label.set_text ((_("Memory: % 3d%%")).printf (memory.percentage)); + memory_chart.update (0, memory.percentage); memory_total_label.set_text ((_("Total: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.total))); memory_used_label.set_text ((_("Used: %s")).printf (Utils.HumanUnitFormatter.double_bytes_to_human(memory.used))); From 51041f202b4553d948cc20f289228e941675f46d Mon Sep 17 00:00:00 2001 From: stsdc Date: Sun, 12 Jul 2020 23:37:27 +0200 Subject: [PATCH 16/18] change label order --- src/Views/SystemView/SystemMemoryView.vala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Views/SystemView/SystemMemoryView.vala b/src/Views/SystemView/SystemMemoryView.vala index 67ac6341..e63d7951 100644 --- a/src/Views/SystemView/SystemMemoryView.vala +++ b/src/Views/SystemView/SystemMemoryView.vala @@ -57,8 +57,8 @@ public class Monitor.SystemMemoryView : Gtk.Grid { Gtk.Grid grid = new Gtk.Grid (); grid.column_spacing = 12; - grid.attach (memory_total_label, 0, 0, 1, 1); - grid.attach (memory_used_label, 1, 0, 1, 1); + grid.attach (memory_used_label, 0, 0, 1, 1); + grid.attach (memory_total_label, 1, 0, 1, 1); grid.attach (memory_shared_label, 0, 1, 1, 1); grid.attach (memory_buffered_label, 1, 1, 1, 1); grid.attach (memory_cached_label, 0, 2, 1, 1); From 2ec55d4242083066257dabfe3cbfd74e137c4a03 Mon Sep 17 00:00:00 2001 From: stsdc Date: Sun, 19 Jul 2020 00:14:26 +0200 Subject: [PATCH 17/18] percentage label in system view is now on a chart --- src/Views/SystemView/SystemCPUView.vala | 10 ++++------ src/Views/SystemView/SystemMemoryView.vala | 7 ++++--- src/Views/SystemView/SystemView.vala | 2 -- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/Views/SystemView/SystemCPUView.vala b/src/Views/SystemView/SystemCPUView.vala index b3350a38..f0d567a7 100644 --- a/src/Views/SystemView/SystemCPUView.vala +++ b/src/Views/SystemView/SystemCPUView.vala @@ -23,22 +23,19 @@ public class Monitor.SystemCPUView : Gtk.Grid { cpu_percentage_label.get_style_context ().add_class ("h2"); cpu_percentage_label.valign = Gtk.Align.START; cpu_percentage_label.halign = Gtk.Align.START; + cpu_percentage_label.margin_start = 6; cpu_chart = new SystemCPUChart (cpu.core_list.size); - attach (cpu_percentage_label, 0, 0, 1, 1); - attach (grid_core_labels (), 0, 1, 1); + attach (grid_core_labels (), 0, 0, 1); + attach (cpu_percentage_label, 1, 0, 1, 1); attach (cpu_chart, 1, 0, 1, 2); - - } public void update () { for (int i = 0; i < cpu.core_list.size; i++) { - // donno why, but gives -nan if not stored - // someone explain, plz double core_percentage = cpu.core_list[i].percentage_used; cpu_chart.update(i, core_percentage); string percentage_formatted = ("% 3d%%").printf ( (int)core_percentage); @@ -51,6 +48,7 @@ public class Monitor.SystemCPUView : Gtk.Grid { private Gtk.Grid grid_core_labels () { Gtk.Grid grid = new Gtk.Grid (); grid.column_spacing = 12; + grid.width_request = 300; int column = 0; int row = 0; for (int i = 0; i < cpu.core_list.size; i++) { diff --git a/src/Views/SystemView/SystemMemoryView.vala b/src/Views/SystemView/SystemMemoryView.vala index e63d7951..25ee3b0a 100644 --- a/src/Views/SystemView/SystemMemoryView.vala +++ b/src/Views/SystemView/SystemMemoryView.vala @@ -14,7 +14,6 @@ public class Monitor.SystemMemoryView : Gtk.Grid { margin = 12; column_spacing = 12; set_vexpand (false); - } @@ -26,6 +25,7 @@ public class Monitor.SystemMemoryView : Gtk.Grid { memory_percentage_label.get_style_context ().add_class ("h2"); memory_percentage_label.halign = Gtk.Align.START; memory_percentage_label.valign = Gtk.Align.START; + memory_percentage_label.margin_start = 6; memory_total_label = new Gtk.Label ("Total: " + Utils.NO_DATA); memory_total_label.halign = Gtk.Align.START; @@ -47,8 +47,8 @@ public class Monitor.SystemMemoryView : Gtk.Grid { memory_chart = new SystemCPUChart (1); - attach (memory_percentage_label, 0, 0, 2, 1); - attach (memory_usage_grid (), 0, 1, 1); + attach (memory_percentage_label, 1, 0, 1, 1); + attach (memory_usage_grid (), 0, 0, 1); attach (memory_chart, 1, 0, 1, 2); } @@ -56,6 +56,7 @@ public class Monitor.SystemMemoryView : Gtk.Grid { private Gtk.Grid memory_usage_grid () { Gtk.Grid grid = new Gtk.Grid (); grid.column_spacing = 12; + grid.width_request = 300; grid.attach (memory_used_label, 0, 0, 1, 1); grid.attach (memory_total_label, 1, 0, 1, 1); diff --git a/src/Views/SystemView/SystemView.vala b/src/Views/SystemView/SystemView.vala index 6d5ab6de..162d5467 100644 --- a/src/Views/SystemView/SystemView.vala +++ b/src/Views/SystemView/SystemView.vala @@ -7,8 +7,6 @@ public class Monitor.SystemView : Gtk.Box { construct { orientation = Gtk.Orientation.VERTICAL; hexpand = true; - - } public SystemView (Resources _resources) { From b97706d0e95d29a3962fb74665f71afb31c374ad Mon Sep 17 00:00:00 2001 From: stsdc Date: Sun, 19 Jul 2020 00:31:12 +0200 Subject: [PATCH 18/18] bump version 0.8.0 --- data/com.github.stsdc.monitor.appdata.xml.in | 5 ++--- debian/changelog | 6 ++++++ meson.build | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/data/com.github.stsdc.monitor.appdata.xml.in b/data/com.github.stsdc.monitor.appdata.xml.in index 6c258f0d..211c65fc 100644 --- a/data/com.github.stsdc.monitor.appdata.xml.in +++ b/data/com.github.stsdc.monitor.appdata.xml.in @@ -25,11 +25,10 @@ https://github.com/stsdc/monitor/issues - +
    -
  • Small bugfix
  • -
  • Added tooltips (Ryo Nakano)
  • +
  • System resources tab
diff --git a/debian/changelog b/debian/changelog index d6f7f459..4e3b60f4 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +com.github.stsdc.monitor (0.8.0) bionic; urgency=low + + * System resources tab + +-- Stanisław Dac Sun, 19 Jul 2020 00:30:43 +0200 + com.github.stsdc.monitor (0.7.3) bionic; urgency=low * Added tooltips to process state label (Ryo Nakano) diff --git a/meson.build b/meson.build index 8f1f0d30..294674c5 100644 --- a/meson.build +++ b/meson.build @@ -1,4 +1,4 @@ -project('com.github.stsdc.monitor', 'vala', 'c', version: '0.7.3') +project('com.github.stsdc.monitor', 'vala', 'c', version: '0.8.0') # these are Meson modules gnome = import('gnome')