aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/ruby/qps/histogram.rb
diff options
context:
space:
mode:
authorGravatar ZhouyihaiDing <ddyihai@google.com>2017-09-28 15:00:15 -0700
committerGravatar ZhouyihaiDing <ddyihai@google.com>2017-10-06 15:25:14 -0700
commitd0153898231c615d626176c2b3ffc42095eb42c3 (patch)
tree8f9bdaa0392c77e8d4b6cf2270664806c782797b /src/ruby/qps/histogram.rb
parent1ed8dd119571a370407534dfdf6662bb5c809d4a (diff)
exclude uploading stats, add unconstained php benchmark
php7 build once
Diffstat (limited to 'src/ruby/qps/histogram.rb')
-rw-r--r--src/ruby/qps/histogram.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/ruby/qps/histogram.rb b/src/ruby/qps/histogram.rb
index 1a27e17218..e48fb842be 100644
--- a/src/ruby/qps/histogram.rb
+++ b/src/ruby/qps/histogram.rb
@@ -16,6 +16,8 @@
# Histogram class for use in performance testing and measurement
+require 'thread'
+
class Histogram
# Determine the bucket index for a given value
# @param {number} value The value to check
@@ -27,6 +29,7 @@ class Histogram
# @param {number} resolution The resolution of the histogram
# @param {number} max_possible The maximum value for the histogram
def initialize(resolution, max_possible)
+ @lock = Mutex.new
@resolution=resolution
@max_possible=max_possible
@sum=0
@@ -70,4 +73,16 @@ class Histogram
def contents
@buckets
end
+
+ def merge(hist)
+ @lock.synchronize do
+ @min_seen = hist.min_seen
+ @max_seen = hist.max_seen
+ @sum += hist.sum
+ @sum_of_squares += hist.sum_of_squares
+ @count += hist.count
+ received_bucket = hist.bucket.to_a
+ @buckets = @buckets.map.with_index{ |m,i| m + received_bucket[i].to_i }
+ end
+ end
end