Blob Blame History Raw
commit c8c24917452665d3ea42019f8700c9164bf3091a
Author: Martin Cermak <mcermak@redhat.com>
Date:   Mon Aug 28 13:01:40 2017 +0200

    PR22005: Fix @min() and @max() extractor functions.
    
    Commit 26382d613f4d26 introduced a regression in @min()
    and @max() extractor functions.  Example:
    
    $ stap -e 'global n probe oneshot {n<<<12 n<<<34 println(@max(n))}'
    12
    $
    
    This commit fixes the regression and adds a testcase.

diff --git a/runtime/stat-common.c b/runtime/stat-common.c
index 764d84c..835fe62 100644
--- a/runtime/stat-common.c
+++ b/runtime/stat-common.c
@@ -307,9 +307,9 @@ static inline void __stp_stat_add(Hist st, stat_data *sd, int64_t val,
 			sd->count++;
 		if(stat_op_sum)
 			sd->sum += val;
-		if (stat_op_min && (val > sd->max))
+		if (stat_op_max && (val > sd->max))
 			sd->max = val;
-		if (stat_op_max && (val < sd->min))
+		if (stat_op_min && (val < sd->min))
 			sd->min = val;
 		/*
 		 * Below, we use Welford's online algorithm for computing variance.
diff --git a/testsuite/systemtap.base/pr22005.exp b/testsuite/systemtap.base/pr22005.exp
new file mode 100644
index 0000000..c760fdc
--- /dev/null
+++ b/testsuite/systemtap.base/pr22005.exp
@@ -0,0 +1,7 @@
+set test_name "pr22005"
+
+set ::result_string "34"
+stap_run2 -e "global l probe oneshot \{l<<<12 l<<<34 println(@max(l))\}"
+
+set ::result_string "21"
+stap_run2 -e "global l probe oneshot \{l<<<43 l<<<21 println(@min(l))\}"