Commit 4804bca2 authored by Guido Gunther's avatar Guido Gunther

Merge branch 'thermal-adaptive' into 'pureos/sloppy'

Add thermal view

See merge request !2
parents 3b326478 103e9551
Pipeline #53231 passed with stages
in 4 minutes and 54 seconds
include:
- 'https://source.puri.sm/Librem5/librem5-ci/raw/master/librem5-pipeline-definitions.yml'
stages:
- package
- test-package
package:deb-debian-buster:
extends: .l5-build-debian-package
package:deb-debian-buster:arm64:
tags:
- librem5:arm64
extends: .l5-build-debian-package
autopkgtest-debian-buster-package:
dependencies:
- package:deb-debian-buster
extends: .l5-autopkgtest-debian-package
......@@ -3,6 +3,7 @@ resource_data = files(
'ui/primary-menu.ui',
'ui/header-bar.ui',
'ui/memory-speedometer.ui',
'ui/no-gthd-view.ui',
'ui/no-results-found-view.ui',
'ui/performance-view.ui',
'ui/process-row.ui',
......
......@@ -6,6 +6,7 @@
<file preprocess="xml-stripblanks">ui/primary-menu.ui</file>
<file preprocess="xml-stripblanks">ui/header-bar.ui</file>
<file preprocess="xml-stripblanks">ui/memory-speedometer.ui</file>
<file preprocess="xml-stripblanks">ui/no-gthd-view.ui</file>
<file preprocess="xml-stripblanks">ui/no-results-found-view.ui</file>
<file preprocess="xml-stripblanks">ui/performance-view.ui</file>
<file preprocess="xml-stripblanks">ui/quit-process-dialog.ui</file>
......@@ -14,5 +15,7 @@
<file preprocess="xml-stripblanks">ui/storage-view.ui</file>
<file preprocess="xml-stripblanks">ui/process-row.ui</file>
<file preprocess="xml-stripblanks">ui/swap-speedometer.ui</file>
<file preprocess="xml-stripblanks">ui/thermal-row.ui</file>
<file preprocess="xml-stripblanks">ui/thermal-view.ui</file>
</gresource>
</gresources>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.9 -->
<template class="UsageNoGthdView" parent="UsageView">
<property name="visible">True</property>
<child>
<object class="GtkBox">
<property name="margin-top">40</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage">
<property name="margin">10</property>
<property name="icon-name">system-run-symbolic</property>
<property name="pixel-size">72</property>
</object>
</child>
<child>
<object class="GtkLabel">
<attributes>
<attribute name="font-desc" value="16"/>
<attribute name="weight" value="PANGO_WEIGHT_BOLD"/>
</attributes>
<property name="label" translatable="yes">Thermal daemon is not running</property>
<property name="margin">10</property>
</object>
</child>
<child>
<object class="GtkLabel">
<attributes>
<attribute name="font-desc" value="12"/>
</attributes>
<property name="label" translatable="yes">Please start gthd</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
<template class="UsageThermalZoneRow" parent="GtkListBoxRow">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel" id="type_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">6</property>
<property name="wrap">True</property>
<property name="ellipsize">end</property>
<property name="max_width_chars">60</property>
<attributes>
<attribute name="scale" value="1"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="temp_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_right">10</property>
<property name="ellipsize">end</property>
<property name="max_width_chars">30</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">end</property>
<property name="position">3</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
</object>
</child>
</template>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.9 -->
<template class="UsageThermalView" parent="UsageView">
<property name="visible">True</property>
<child>
<object class="HdyLeaflet" id="leaflet">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="mode-transition-type">slide</property>
<property name="visible-child">content_box</property>
<child>
<object class="GtkBox" id="switcher_box">
<property name="hexpand">False</property>
<property name="hexpand-set">True</property>
<property name="width-request">200</property>
<style>
<class name="sidebar"/>
</style>
</object>
</child>
<child>
<object class="GtkBox" id="content_box">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="width-request">360</property>
<child>
<object class="UsageAnimatedScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="vexpand">True</property>
<child>
<object class="HdyColumn">
<property name="visible">True</property>
<property name="margin-start">12</property>
<property name="margin-end">12</property>
<property name="expand">True</property>
<property name="maximum-width">600</property>
<property name="linear-growth-width">400</property>
<child>
<object class="GtkBox" id="thermal_content">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="spacing">30</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</template>
</interface>
......@@ -11,10 +11,12 @@ Build-Depends: debhelper-compat (= 12),
gnome-pkg-tools,
libdazzle-1.0-dev (>= 3.30.0),
libglib2.0-dev (>= 2.38.0),
libgtherm-dev,
libgtk-3-dev (>= 3.20.10),
libgtop2-dev (>= 2.34.0),
libhandy-0.0-dev (>= 0.0.10),
meson (>= 0.37),
libtracker-sparql-2.0-dev,
valac
Standards-Version: 4.3.0
Vcs-Browser: https://salsa.debian.org/gnome-team/gnome-usage
......@@ -25,6 +27,7 @@ Package: gnome-usage
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends}
Recommends: gthd
Description: simple system monitor app for GNOME
Usage is an application for GNOME that allows monitoring of system resources
such as memory, CPU, and disk space.
......@@ -7,10 +7,12 @@ Build-Depends: debhelper-compat (= 12),
gnome-pkg-tools,
libdazzle-1.0-dev (>= 3.30.0),
libglib2.0-dev (>= 2.38.0),
libgtherm-dev,
libgtk-3-dev (>= 3.20.10),
libgtop2-dev (>= 2.34.0),
libhandy-0.0-dev (>= 0.0.10),
meson (>= 0.37),
libtracker-sparql-2.0-dev,
valac
Standards-Version: 4.3.0
Vcs-Browser: https://salsa.debian.org/gnome-team/gnome-usage
......@@ -21,6 +23,7 @@ Package: gnome-usage
Architecture: any
Depends: ${misc:Depends},
${shlibs:Depends}
Recommends: gthd
Description: simple system monitor app for GNOME
Usage is an application for GNOME that allows monitoring of system resources
such as memory, CPU, and disk space.
......@@ -14,6 +14,9 @@ gio_dep = dependency('gio-2.0')
gtk_dep = dependency('gtk+-3.0', version : '>=3.20.10')
libdazzle_dep = dependency('libdazzle-1.0', version : '>=3.30')
libhandy_dep = dependency('libhandy-0.0', version : '>=0.0.10')
libgtop_dep = dependency('libgtop-2.0', version : '>= 2.34.0')
tracker_dep = dependency('tracker-sparql-2.0')
gtherm_dep = dependency('libgtherm-0.0')
gnome = import('gnome')
i18n = import('i18n')
......
......@@ -36,6 +36,12 @@ namespace Usage
child = createContent(memory_graph, label);
}
public GraphSwitcherButton.temperature(string label)
{
var thermal_graph = new ThermalGraph();
child = createContent(thermal_graph, label);
}
private Gtk.Box createContent(Dazzle.GraphView graph, string label_text)
{
graph.height_request = 80;
......
......@@ -19,6 +19,7 @@ vala_sources = [
'memory-speedometer.vala',
'memory-sub-view.vala',
'monitor.vala',
'no-gthd-view.vala',
'no-results-found-view.vala',
'performance-view.vala',
'pie-chart.vala',
......@@ -39,6 +40,14 @@ vala_sources = [
'storage-worker.vala',
'swap-speedometer.vala',
'system-monitor.vala',
'thermal-list-box.vala',
'thermal-row.vala',
'thermal-graph.vala',
'thermal-graph-stack-switcher.vala',
'thermal-graph-model.vala',
'thermal-monitor.vala',
'thermal-view.vala',
'thermal-sub-view.vala',
'utils.vala',
'view.vala',
'window.vala'
......@@ -48,6 +57,7 @@ deps = [
gio_dep,
glib_dep,
gobject_dep,
gtherm_dep,
gtk_dep,
dependency('libgtop-2.0', version : '>= 2.34.0'),
libdazzle_dep,
......
/* no-results-found-box.vala
*
* Copyright (C) 2020 Purism SPC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
namespace Usage
{
[GtkTemplate (ui = "/org/gnome/Usage/ui/no-gthd-view.ui")]
public class NoGthdView : View { }
}
......@@ -23,6 +23,7 @@ namespace Usage
public class SystemMonitor : Object
{
public bool process_list_ready { get; private set; default = false; }
public bool thermal_list_ready { get; private set; default = false; }
public double cpu_load { get; private set; }
public double[] x_cpu_load { get; private set; }
public uint64 ram_usage { get; private set; }
......@@ -30,9 +31,11 @@ namespace Usage
public uint64 swap_usage { get; private set; }
public uint64 swap_total { get; private set; }
public bool group_system_apps { get; set; default = true; }
public double[] x_temp { get; private set; }
private CpuMonitor cpu_monitor;
private MemoryMonitor memory_monitor;
private ThermalMonitor thermal_monitor;
private HashTable<string, AppItem> app_table;
private int process_mode = GTop.KERN_PROC_ALL;
......@@ -56,6 +59,12 @@ namespace Usage
return app_table.get(name);
}
public GLib.GenericArray<Gth.ThermalZone> get_thermal_zones()
{
return thermal_monitor.get_thermal_zones ();
}
public SystemMonitor()
{
GTop.init();
......@@ -63,6 +72,7 @@ namespace Usage
cpu_monitor = new CpuMonitor();
memory_monitor = new MemoryMonitor();
thermal_monitor = new ThermalMonitor();
app_table = new HashTable<string, AppItem>(str_hash, str_equal);
var settings = Settings.get_default();
......@@ -80,6 +90,7 @@ namespace Usage
var settings = Settings.get_default();
app_table.remove_all();
process_list_ready = false;
thermal_list_ready = false;
if(group_system_apps) {
var system = new AppItem.system();
......@@ -90,6 +101,7 @@ namespace Usage
Timeout.add(settings.data_update_interval, () =>
{
process_list_ready = true;
thermal_list_ready = true;
return false;
});
}
......@@ -98,6 +110,7 @@ namespace Usage
{
cpu_monitor.update();
memory_monitor.update();
thermal_monitor.update();
cpu_load = cpu_monitor.get_cpu_load();
x_cpu_load = cpu_monitor.get_x_cpu_load();
......@@ -105,6 +118,7 @@ namespace Usage
ram_total = memory_monitor.get_ram_total();
swap_usage = memory_monitor.get_swap_usage();
swap_total = memory_monitor.get_swap_total();
x_temp = thermal_monitor.get_x_temp();
GTop.Proclist proclist;
var pids = GTop.get_proclist (out proclist, process_mode);
......
/* thermal-graph-model.vala
*
* Copyright (C) 2019 Purism SPC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Guido Guenther <agx@sigxcpu.org>
*/
using Dazzle;
namespace Usage {
public class ThermalGraphModel : GraphModel {
public int num_zones;
public ThermalGraphModel () {
var settings = Settings.get_default();
SystemMonitor monitor = SystemMonitor.get_default();
set_timespan (settings.graph_timespan * 1000);
set_max_samples (settings.graph_max_samples);
num_zones = monitor.x_temp.length;
for (int i = 0; i < num_zones; i++) {
/* TODO: use correct zone numbers */
var column_x_temp = new GraphColumn("ThermalZone: " + i.to_string(), Type.from_name("gdouble"));
add_column(column_x_temp);
}
Timeout.add(settings.graph_update_interval, update_data);
}
bool update_data() {
GraphModelIter iter;
push (out iter, get_monotonic_time ());
SystemMonitor monitor = SystemMonitor.get_default();
for (int i = 0; i < num_zones; i++) {
iter_set_value(iter, i, monitor.x_temp[i]);
}
return true;
}
}
}
/* graph-stack-switcher.vala
*
* Copyright (C) 2019 Purism SPC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Guido Guenther <agx@sigxcpu.org>
*/
namespace Usage
{
public class ThermalGraphStackSwitcher : Gtk.Box
{
View[] sub_views;
AnimatedScrolledWindow scrolled_window;
GraphSwitcherButton[] buttons;
class construct
{
set_css_name("graph-stack-switcher");
}
public ThermalGraphStackSwitcher(AnimatedScrolledWindow scrolled_window, View[] sub_views)
{
Object(orientation: Gtk.Orientation.VERTICAL, spacing: 0);
this.sub_views = sub_views;
this.scrolled_window = scrolled_window;
scrolled_window.scroll_changed.connect(on_scroll_changed);
buttons = {
new GraphSwitcherButton.temperature(_("Temperature")),
};
foreach(GraphSwitcherButton button in buttons)
{
this.pack_start(button, false, true, 0);
button.button_release_event.connect(() => {
var button_number = get_button_number(button);
scroll_to_view(button_number);
return false;
});
}
}
private int get_button_number(Gtk.Button button)
{
for(int i = 0; i < buttons.length; i++)
{
if(buttons[i] == button)
return i;
}
return 0;
}
private void scroll_to_view(int button_number)
{
Gtk.Allocation alloc;
this.sub_views[button_number].get_allocation(out alloc);
scrolled_window.animated_scroll_vertically(alloc.y);
}
private void on_scroll_changed(double y)
{
Gtk.Allocation alloc;
var button_number = 0;
for(int i = 1; i < buttons.length; i++)
{
this.sub_views[i].get_allocation(out alloc);
if(y < alloc.y)
break;
button_number = i;
}
buttons[button_number].set_active(true);
}
}
}
/* thermal-graph.vala
*
* Copyright (C) 2019 Purism SPC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authors: Guido Guenther <agx@sigxcpu.org>
*/
using Dazzle;
namespace Usage
{
public class ThermalGraph : GraphView
{
private static ThermalGraphModel graph_model;
private GraphLineRenderer[] renderers;
private Gdk.RGBA line_color_max;
private Gdk.RGBA line_color_normal;
class construct
{
set_css_name("rg-graph");
}
public ThermalGraph()
{
get_style_context().add_class("line_max");
line_color_max = get_style_context().get_color(get_style_context().get_state());
get_style_context().remove_class("line_max");
get_style_context().add_class("line");
line_color_normal = get_style_context().get_color(get_style_context().get_state());
get_style_context().remove_class("line");
get_style_context().add_class("big");
if(graph_model == null)
graph_model = new ThermalGraphModel();
set_model(graph_model);
renderers = new GraphLineRenderer[graph_model.num_zones];
for(int i = 0; i < graph_model.num_zones; i++)
{
renderers[i] = new GraphLineRenderer();
renderers[i].column = i;
renderers[i].stroke_color_rgba = line_color_normal;
renderers[i].line_width = 1.5;
add_renderer(renderers[i]);
}
}
}
}