[Xfce4-commits] [panel-plugins/xfce4-hardware-monitor-plugin] 02/03: Fix overflow in monitor max determination due to ints used rather than doubles, extra debug code
noreply at xfce.org
noreply at xfce.org
Sat Dec 23 14:40:20 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 f3e418963eef3082d9f7c30b427acdd5b740529f
Author: OmegaPhil <OmegaPhil at startmail.com>
Date: Sat Dec 23 13:24:07 2017 +0000
Fix overflow in monitor max determination due to ints used rather than doubles, extra debug code
---
src/canvas-view.cpp | 20 +++++++++++++++++---
src/canvas-view.hpp | 2 +-
src/curve-view.cpp | 7 +++++++
src/monitor-impls.cpp | 4 ++++
src/value-history.cpp | 13 +++++++++----
5 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/src/canvas-view.cpp b/src/canvas-view.cpp
index dfccf96..46e5e64 100644
--- a/src/canvas-view.cpp
+++ b/src/canvas-view.cpp
@@ -30,6 +30,7 @@
#include "column-view.hpp"
#include "curve-view.hpp"
#include "flame-view.hpp"
+#include "ucompose.hpp"
int const CanvasView::draw_interval = 100;
@@ -164,7 +165,7 @@ std::list<std::pair<T*, double>> CanvasView::process_mon_maxes_text_overlay(
* initialised */
// Monitor maxes maintained as a pair of <normal max>, <fixed max>
- std::map<Glib::ustring, std::pair<int, int>> monitor_maxes;
+ std::map<Glib::ustring, std::pair<double, double>> monitor_maxes;
// Monitors collected by type to allow easy access to separated data sets
typename std::map<Glib::ustring, std::list<T*>> elems_by_mon_type;
@@ -212,8 +213,20 @@ std::list<std::pair<T*, double>> CanvasView::process_mon_maxes_text_overlay(
monitor_maxes[mon_type].first = (*i)->get_max_value();
else if ((*i)->monitor->fixed_max()
&& (*i)->monitor->max() > monitor_maxes[mon_type].second)
+ {
+ // Debug code
+ /*std::cout << "CanvasView::process_mon_maxes_text_overlay: Monitor "
+ << (*i)->monitor->get_short_name() << ", fixed max detected and "
+ "new max value of " << (*i)->monitor->max() << std::endl;*/
+
monitor_maxes[mon_type].second = (*i)->monitor->max();
+ // Debug code
+ /*std::cout << "CanvasView::process_mon_maxes_text_overlay: "
+ "monitor_maxes[mon_type].second: "
+ << monitor_maxes[mon_type].second << std::endl;*/
+ }
+
// Record curve in monitor type list
it_mon_type = elems_by_mon_type.find(mon_type);
if (it_mon_type == elems_by_mon_type.end())
@@ -264,8 +277,9 @@ std::list<std::pair<T*, double>> CanvasView::process_mon_maxes_text_overlay(
// Debug code
/*plugin->debug_log(
- String::ucompose("CurveView::do_draw_loop: In top curve monitor types"
- " loop, monitor type '%1', max %2", i->first, max));*/
+ String::ucompose("CanvasView::process_mon_maxes_text_overlay: In top "
+ "curve monitor types loop, monitor type '%1', max %2",
+ i->first, max));*/
if (text_overlay_enabled)
{
diff --git a/src/canvas-view.hpp b/src/canvas-view.hpp
index 0893c36..c6137dd 100644
--- a/src/canvas-view.hpp
+++ b/src/canvas-view.hpp
@@ -54,7 +54,7 @@ public:
/* Used to locate monitor type of interest in monitor_maxes during
* visualisation draw loop */
- typedef std::map<Glib::ustring, std::pair<int, int>>::iterator
+ typedef std::map<Glib::ustring, std::pair<double, double>>::iterator
mon_type_iterator;
static const Glib::ustring text_overlay_position_to_string(
diff --git a/src/curve-view.cpp b/src/curve-view.cpp
index c06910d..e75d927 100644
--- a/src/curve-view.cpp
+++ b/src/curve-view.cpp
@@ -126,6 +126,13 @@ double Curve::get_max_value()
{
/* Used as part of determination of the max value for all curves in
* the view */
+
+ // Debug code
+ // To get the real type, Monitor* must be dereferenced too...
+ /*std::cout << "In Curve::get_max_value! Monitor type "
+ << monitor->get_short_name() << ", max: "
+ << value_history.get_max_value() << std::endl;*/
+
return value_history.get_max_value();
}
diff --git a/src/monitor-impls.cpp b/src/monitor-impls.cpp
index cca4cc4..820e091 100644
--- a/src/monitor-impls.cpp
+++ b/src/monitor-impls.cpp
@@ -969,6 +969,10 @@ double DiskUsageMonitor::do_measure()
v = (fsusage.blocks - fsusage.bfree) * fsusage.block_size;
}
+ // Debug code
+ /*std::cout << "In DiskUsageMonitor::do_measure, returning " << v
+ << ", max_value " << max_value << std::endl;*/
+
return v;
}
diff --git a/src/value-history.cpp b/src/value-history.cpp
index ca02450..70960f4 100644
--- a/src/value-history.cpp
+++ b/src/value-history.cpp
@@ -44,7 +44,7 @@ void ValueHistory::update(unsigned int max_samples, bool &new_value)
// Debug code
/*std::cout << "ValueHistory::update: Called (monitor "
- << monitor->get_short_name() << ")\n";*/
+ << monitor->get_short_name() << ")" << std::endl;*/
if (waits_remaining <= 0) {
new_value = true;
@@ -52,7 +52,8 @@ void ValueHistory::update(unsigned int max_samples, bool &new_value)
// Debug code
/*std::cout << "ValueHistory::update: Measurement made (monitor "
- << monitor->get_short_name() << ")\n";*/
+ << monitor->get_short_name() << "), current max " << max_value
+ << std::endl;*/
// Fetching new measurement
double measurement = monitor->value();
@@ -62,6 +63,10 @@ void ValueHistory::update(unsigned int max_samples, bool &new_value)
{
max_value = measurement;
max_count = 1;
+
+ // Debug code
+ /*std::cout << "ValueHistory::update: Max value updated to " << max_value
+ << std::endl;*/
}
else if (measurement == max_value)
++max_count;
@@ -93,14 +98,14 @@ void ValueHistory::update(unsigned int max_samples, bool &new_value)
// Debug code
/*std::cout << "ValueHistory::update: Dropping samples, dropping "
- "max detected: " << max_value << ", count: " << max_count << "\n";*/
+ "max detected: " << max_value << ", count: " << max_count << std::endl;*/
max_value = *std::max_element(values.begin(), values.end());
max_count = std::count(values.begin(), values.end(), max_value);
// Debug code
/*std::cout << "New max: " << max_value << ", new count: " <<
- max_count << "\n";*/
+ max_count << std::endl;*/
}
}
}
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list