[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 04/29: Allow to configure which CPU time is counted for CPU usage monitor

noreply at xfce.org noreply at xfce.org
Mon Dec 18 12:45:35 CET 2017


This is an automated email from the git hooks/post-receive script.

o   m   e   g   a   p   h   i   l       p   u   s   h   e   d       a       c   o   m   m   i   t       t   o       b   r   a   n   c   h       m   a   s   t   e   r   
   in repository panel-plugins/xfce4-hardware-monitor-plugin.

commit 5b8d4f931580ce446d6b05ad956b5d33f6192f26
Author: OmegaPhil <OmegaPhil at startmail.com>
Date:   Sun Nov 19 15:50:34 2017 +0000

    Allow to configure which CPU time is counted for CPU usage monitor
    
    As mentioned in #13910 / https://bugzilla.xfce.org/show_bug.cgi?id=13910
    the CPU usage monitor has always dropped low priority CPU time in
    order to avoid SETI at home CPU usage swamping out anything else. This
    is now configurable - the user can now choose to include low priority
    CPU time and IO wait
---
 src/choose-monitor-window.cpp |  22 ++++-
 src/choose-monitor-window.hpp |   3 +-
 src/monitor-impls.cpp         |  49 +++++++---
 src/monitor-impls.hpp         |   9 +-
 src/ui.glade                  | 216 ++++++++++++++++++++++++++----------------
 5 files changed, 198 insertions(+), 101 deletions(-)

diff --git a/src/choose-monitor-window.cpp b/src/choose-monitor-window.cpp
index bc76a08..2e97e02 100644
--- a/src/choose-monitor-window.cpp
+++ b/src/choose-monitor-window.cpp
@@ -66,6 +66,10 @@ ChooseMonitorWindow::ChooseMonitorWindow(XfcePanelPlugin* xfce_plugin,
   ui->get_widget("all_cpus_radiobutton", all_cpus_radiobutton);
   ui->get_widget("one_cpu_radiobutton", one_cpu_radiobutton);
   ui->get_widget("cpu_no_spinbutton", cpu_no_spinbutton);
+  ui->get_widget("cpu_usage_incl_low_checkbutton",
+                 cpu_usage_incl_low_checkbutton);
+  ui->get_widget("cpu_usage_incl_iowait_checkbutton",
+                 cpu_usage_incl_iowait_checkbutton);
   ui->get_widget("cpu_usage_tag_entry", cpu_tag);
   ui->get_widget("cpu_usage_refresh_delay_spinbutton",
                  cpu_usage_refresh_delay_spinbutton);
@@ -271,6 +275,9 @@ ChooseMonitorWindow::ChooseMonitorWindow(XfcePanelPlugin* xfce_plugin,
   // Note 1 off to avoid counting from zero in the interface
   cpu_no_spinbutton->set_range(1, CpuUsageMonitor::max_no_cpus);
 
+  cpu_usage_incl_low_checkbutton->set_active(false);
+  cpu_usage_incl_iowait_checkbutton->set_active(false);
+
   /* While I have set the defaults in the ui.glade Adjustment.Values, best to
    * maintain it here */
   cpu_usage_refresh_delay_spinbutton->set_value(
@@ -579,6 +586,13 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
         else {
           all_cpus_radiobutton->set_active();
         }
+
+        bool incl_low_prio = xfce_rc_read_bool_entry(settings_ro,
+          "include_low_priority", false);
+        cpu_usage_incl_low_checkbutton->set_active(incl_low_prio);
+        bool incl_iowait = xfce_rc_read_bool_entry(settings_ro,
+          "include_iowait", false);
+        cpu_usage_incl_iowait_checkbutton->set_active(incl_iowait);
       }
 
       // Fill in disk usage info
@@ -853,11 +867,15 @@ Monitor *ChooseMonitorWindow::run(const Glib::ustring &mon_dir)
         if (one_cpu_radiobutton->get_active())
           mon = new CpuUsageMonitor(
                 int(cpu_no_spinbutton->get_value()) - 1, cpu_tag->get_text(),
-                int(cpu_usage_refresh_delay_spinbutton->get_value() * 1000));
+                int(cpu_usage_refresh_delay_spinbutton->get_value() * 1000),
+                cpu_usage_incl_low_checkbutton->get_active(),
+                cpu_usage_incl_iowait_checkbutton->get_active());
         else
           mon = new CpuUsageMonitor(
                 cpu_tag->get_text(),
-                int(cpu_usage_refresh_delay_spinbutton->get_value() * 1000));
+                int(cpu_usage_refresh_delay_spinbutton->get_value() * 1000),
+                cpu_usage_incl_low_checkbutton->get_active(),
+                cpu_usage_incl_iowait_checkbutton->get_active());
       }
       else if (memory_usage_radiobutton->get_active())
       {
diff --git a/src/choose-monitor-window.hpp b/src/choose-monitor-window.hpp
index 6506da3..ec5b39f 100644
--- a/src/choose-monitor-window.hpp
+++ b/src/choose-monitor-window.hpp
@@ -92,7 +92,8 @@ private:
            *swap_usage_options;
   Gtk::Entry *mount_dir_entry, *disk_usage_tag, *disk_stats_tag, *memory_usage_tag,
              *swap_usage_tag;
-  Gtk::CheckButton *show_free_checkbutton;
+  Gtk::CheckButton *show_free_checkbutton, *cpu_usage_incl_low_checkbutton,
+                   *cpu_usage_incl_iowait_checkbutton;
 
   Gtk::ComboBox *disk_stats_device_combobox, *disk_stats_stat_combobox;
 
diff --git a/src/monitor-impls.cpp b/src/monitor-impls.cpp
index c9ddec4..db8d897 100644
--- a/src/monitor-impls.cpp
+++ b/src/monitor-impls.cpp
@@ -91,11 +91,22 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
         if (update_interval == -1)
           update_interval = CpuUsageMonitor::update_interval_default;
 
+        bool incl_low_prio = xfce_rc_read_bool_entry(settings_ro,
+          "include_low_priority", false);
+        bool incl_iowait = xfce_rc_read_bool_entry(settings_ro,
+          "include_iowait", false);
+
         // Creating CPU usage monitor with provided number if valid
         if (cpu_no == -1)
-          monitors.push_back(new CpuUsageMonitor(tag, update_interval));
+        {
+          monitors.push_back(new CpuUsageMonitor(tag, update_interval,
+                                                 incl_low_prio, incl_iowait));
+        }
         else
-          monitors.push_back(new CpuUsageMonitor(cpu_no, tag, update_interval));
+        {
+          monitors.push_back(new CpuUsageMonitor(cpu_no, tag, update_interval,
+                                                 incl_low_prio, incl_iowait));
+        }
       }
       else if (type == "memory_usage")
       {
@@ -330,7 +341,7 @@ load_monitors(XfceRc *settings_ro, XfcePanelPlugin *panel_plugin)
 
   // Always start with a CpuUsageMonitor
   if (monitors.empty())
-    monitors.push_back(new CpuUsageMonitor("", 1000));
+    monitors.push_back(new CpuUsageMonitor("", 1000, false, false));
 
   return monitors;
 }
@@ -392,15 +403,19 @@ int const CpuUsageMonitor::max_no_cpus = GLIBTOP_NCPU;
 int const CpuUsageMonitor::update_interval_default = 1000;
 
 
-CpuUsageMonitor::CpuUsageMonitor(const Glib::ustring &tag_string, int interval)
-  : Monitor(tag_string, interval), cpu_no(all_cpus), total_time(0), nice_time(0),
-    idle_time(0), iowait_time(0)
+CpuUsageMonitor::CpuUsageMonitor(const Glib::ustring &tag_string, int interval,
+                                 bool incl_low_prio, bool incl_iowait)
+  : Monitor(tag_string, interval), cpu_no(all_cpus),
+    incl_low_prio_priv(incl_low_prio), incl_iowait_priv(incl_iowait),
+    total_time(0), nice_time(0), idle_time(0), iowait_time(0)
 {}
 
 CpuUsageMonitor::CpuUsageMonitor(int cpu, const Glib::ustring &tag_string,
-                                 int interval)
-  : Monitor(tag_string, interval), cpu_no(cpu), total_time(0), nice_time(0),
-    idle_time(0), iowait_time(0)
+                                 int interval, bool incl_low_prio,
+                                 bool incl_iowait)
+  : Monitor(tag_string, interval), cpu_no(cpu),
+    incl_low_prio_priv(incl_low_prio), incl_iowait_priv(incl_iowait),
+    total_time(0), nice_time(0), idle_time(0), iowait_time(0)
 {
   if (cpu_no < 0 || cpu_no >= max_no_cpus)
     cpu_no = all_cpus;
@@ -427,7 +442,7 @@ double CpuUsageMonitor::do_measure()
     io = cpu.xcpu_iowait[cpu_no];
   }
 
-  // calculate ticks since last call
+  // Calculate ticks since last call
   guint64
     dtotal = t - total_time,
     dnice = n - nice_time,
@@ -440,9 +455,13 @@ double CpuUsageMonitor::do_measure()
   idle_time = i;
   iowait_time = io;
 
-  // don't count in dnice to avoid always showing 100% with SETI at home and
-  // similar applications running
-  double res = double(dtotal - dnice - didle - diowait) / dtotal;
+  // Count nice and iowait if the user desires
+  double res = double(dtotal - didle);
+  if (!incl_low_prio_priv)
+    res -= double(dnice);
+  if (!incl_iowait_priv)
+    res -= double(diowait);
+  res /= double(dtotal);
 
   if (res > 0)
     return res;
@@ -492,6 +511,10 @@ void CpuUsageMonitor::save(XfceRc *settings_w)
   xfce_rc_set_group(settings_w, dir.c_str());
   xfce_rc_write_entry(settings_w, "type", "cpu_usage");
   xfce_rc_write_int_entry(settings_w, "cpu_no", cpu_no);
+  xfce_rc_write_bool_entry(settings_w, "include_low_priority",
+                           incl_low_prio_priv);
+  xfce_rc_write_bool_entry(settings_w, "include_iowait",
+                           incl_iowait_priv);
   xfce_rc_write_entry(settings_w, "tag", tag.c_str());
   xfce_rc_write_int_entry(settings_w, "update_interval", update_interval());
 }
diff --git a/src/monitor-impls.hpp b/src/monitor-impls.hpp
index 3301cc8..8e1ea38 100644
--- a/src/monitor-impls.hpp
+++ b/src/monitor-impls.hpp
@@ -50,10 +50,12 @@ class CpuUsageMonitor: public Monitor
 public:
 
   // Monitor all CPUs
-  CpuUsageMonitor(const Glib::ustring &tag_string, int interval);
+  CpuUsageMonitor(const Glib::ustring &tag_string, int interval,
+                  bool incl_low_prio, bool incl_iowait);
 
   // Monitor only CPU no.
-  CpuUsageMonitor(int cpu_no, const Glib::ustring &tag_string, int interval);
+  CpuUsageMonitor(int cpu_no, const Glib::ustring &tag_string, int interval,
+                  bool incl_low_prio, bool incl_iowait);
 
   virtual double max();
   virtual bool fixed_max();
@@ -79,6 +81,9 @@ private:
   static int const all_cpus = -1;
   int cpu_no;
 
+  // Define whether these are included in CPU time or not
+  bool incl_low_prio_priv, incl_iowait_priv;
+
   // we need to save these values to compute the difference next time the
   // monitor is updated
   guint64 total_time, nice_time, idle_time, iowait_time;
diff --git a/src/ui.glade b/src/ui.glade
index f83169b..a2c896a 100644
--- a/src/ui.glade
+++ b/src/ui.glade
@@ -263,104 +263,154 @@
                                 <property name="can_focus">True</property>
                                 <property name="spacing">5</property>
                                 <child>
-                                  <object class="GtkTable" id="table1">
+                                  <object class="GtkVBox" id="vbox2">
                                     <property name="visible">True</property>
                                     <property name="can_focus">False</property>
-                                    <property name="n_rows">2</property>
-                                    <property name="n_columns">4</property>
-                                    <property name="column_spacing">5</property>
-                                    <property name="row_spacing">5</property>
                                     <child>
-                                      <object class="GtkLabel" id="cpu_usage_tag_label">
+                                      <object class="GtkTable" id="table10">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
-                                        <property name="xalign">0</property>
-                                        <property name="label" translatable="yes">Tag:  </property>
-                                      </object>
-                                    </child>
-                                    <child>
-                                      <object class="GtkEntry" id="cpu_usage_tag_entry">
-                                        <property name="width_request">80</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="tooltip_text" translatable="yes">Tag to display along with monitor data
-in the optional text overlay in a curve
-view</property>
-                                        <property name="invisible_char">●</property>
-                                        <property name="invisible_char_set">True</property>
-                                        <property name="primary_icon_activatable">False</property>
-                                        <property name="secondary_icon_activatable">False</property>
-                                        <property name="primary_icon_sensitive">True</property>
-                                        <property name="secondary_icon_sensitive">True</property>
-                                      </object>
-                                      <packing>
-                                        <property name="left_attach">1</property>
-                                        <property name="right_attach">2</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <object class="GtkLabel" id="cpu_usage_refresh_delay_label">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">False</property>
-                                        <property name="label" translatable="yes">Refresh every</property>
+                                        <property name="n_rows">2</property>
+                                        <child>
+                                          <object class="GtkCheckButton" id="cpu_usage_incl_low_checkbutton">
+                                            <property name="label" translatable="yes">Include low priority</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="receives_default">False</property>
+                                            <property name="tooltip_text" translatable="yes">CPU usage for processes nice'd to
+less than default priority</property>
+                                            <property name="draw_indicator">True</property>
+                                          </object>
+                                        </child>
+                                        <child>
+                                          <object class="GtkCheckButton" id="cpu_usage_incl_iowait_checkbutton">
+                                            <property name="label" translatable="yes">Include I/O wait</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="receives_default">False</property>
+                                            <property name="tooltip_text" translatable="yes">CPU time spent waiting for I/O
+(usually disk latency)</property>
+                                            <property name="draw_indicator">True</property>
+                                          </object>
+                                          <packing>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
                                       </object>
                                       <packing>
-                                        <property name="top_attach">1</property>
-                                        <property name="bottom_attach">2</property>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="padding">5</property>
+                                        <property name="position">0</property>
                                       </packing>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
-                                      <object class="GtkLabel" id="label10">
+                                      <object class="GtkTable" id="table1">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
-                                        <property name="label" translatable="yes"> seconds</property>
-                                      </object>
-                                      <packing>
-                                        <property name="left_attach">2</property>
-                                        <property name="right_attach">3</property>
-                                        <property name="top_attach">1</property>
-                                        <property name="bottom_attach">2</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
-                                      <object class="GtkButton" id="cpu_usage_refresh_delay_default_button">
-                                        <property name="label" translatable="yes">Reset</property>
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="receives_default">True</property>
-                                      </object>
-                                      <packing>
-                                        <property name="left_attach">3</property>
-                                        <property name="right_attach">4</property>
-                                        <property name="top_attach">1</property>
-                                        <property name="bottom_attach">2</property>
-                                      </packing>
-                                    </child>
-                                    <child>
-                                      <object class="GtkSpinButton" id="cpu_usage_refresh_delay_spinbutton">
-                                        <property name="visible">True</property>
-                                        <property name="can_focus">True</property>
-                                        <property name="tooltip_text" translatable="yes">Seconds delay between measurements
+                                        <property name="n_rows">2</property>
+                                        <property name="n_columns">4</property>
+                                        <property name="column_spacing">5</property>
+                                        <property name="row_spacing">5</property>
+                                        <child>
+                                          <object class="GtkLabel" id="cpu_usage_tag_label">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="xalign">0</property>
+                                            <property name="label" translatable="yes">Tag:  </property>
+                                          </object>
+                                        </child>
+                                        <child>
+                                          <object class="GtkEntry" id="cpu_usage_tag_entry">
+                                            <property name="width_request">80</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="tooltip_text" translatable="yes">Tag to display along with monitor data
+in the optional text overlay in a curve
+view</property>
+                                            <property name="invisible_char">●</property>
+                                            <property name="invisible_char_set">True</property>
+                                            <property name="primary_icon_activatable">False</property>
+                                            <property name="secondary_icon_activatable">False</property>
+                                            <property name="primary_icon_sensitive">True</property>
+                                            <property name="secondary_icon_sensitive">True</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="cpu_usage_refresh_delay_label">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes">Refresh every</property>
+                                          </object>
+                                          <packing>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkLabel" id="label10">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">False</property>
+                                            <property name="label" translatable="yes"> seconds</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">2</property>
+                                            <property name="right_attach">3</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <placeholder/>
+                                        </child>
+                                        <child>
+                                          <object class="GtkButton" id="cpu_usage_refresh_delay_default_button">
+                                            <property name="label" translatable="yes">Reset</property>
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="receives_default">True</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">3</property>
+                                            <property name="right_attach">4</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <object class="GtkSpinButton" id="cpu_usage_refresh_delay_spinbutton">
+                                            <property name="visible">True</property>
+                                            <property name="can_focus">True</property>
+                                            <property name="tooltip_text" translatable="yes">Seconds delay between measurements
 taken by the monitor</property>
-                                        <property name="invisible_char">●</property>
-                                        <property name="primary_icon_activatable">False</property>
-                                        <property name="secondary_icon_activatable">False</property>
-                                        <property name="primary_icon_sensitive">True</property>
-                                        <property name="secondary_icon_sensitive">True</property>
-                                        <property name="adjustment">cpu_usage_refresh_delay_adjustment</property>
-                                        <property name="climb_rate">1</property>
+                                            <property name="invisible_char">●</property>
+                                            <property name="primary_icon_activatable">False</property>
+                                            <property name="secondary_icon_activatable">False</property>
+                                            <property name="primary_icon_sensitive">True</property>
+                                            <property name="secondary_icon_sensitive">True</property>
+                                            <property name="adjustment">cpu_usage_refresh_delay_adjustment</property>
+                                            <property name="climb_rate">1</property>
+                                          </object>
+                                          <packing>
+                                            <property name="left_attach">1</property>
+                                            <property name="right_attach">2</property>
+                                            <property name="top_attach">1</property>
+                                            <property name="bottom_attach">2</property>
+                                          </packing>
+                                        </child>
+                                        <child>
+                                          <placeholder/>
+                                        </child>
                                       </object>
                                       <packing>
-                                        <property name="left_attach">1</property>
-                                        <property name="right_attach">2</property>
-                                        <property name="top_attach">1</property>
-                                        <property name="bottom_attach">2</property>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
                                       </packing>
                                     </child>
                                   </object>

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Xfce4-commits mailing list