sidekiq-benchmark 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -6,7 +6,8 @@ Version](https://badge.fury.io/rb/sidekiq-benchmark.png)](https://rubygems.org/g
6
6
  [![Coverage
7
7
  Status](https://coveralls.io/repos/kosmatov/sidekiq-benchmark/badge.png?branch=master)](https://coveralls.io/r/kosmatov/sidekiq-benchmark)
8
8
 
9
- Adds benchmarking methods to Sidekiq workers, keeps metrics and adds tab to Web UI to let you browse them.
9
+ Adds benchmarking methods to
10
+ [Sidekiq](https://github.com/mperham/sidekiq) workers, keeps metrics and adds tab to Web UI to let you browse them.
10
11
 
11
12
  ## Installation
12
13
 
@@ -1,5 +1,5 @@
1
1
  module Sidekiq
2
2
  module Benchmark
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
@@ -39,6 +39,9 @@ module Sidekiq
39
39
  stats.each do |key, value|
40
40
  @charts[type][:stats] << [key.to_f, value.to_i]
41
41
  end
42
+
43
+ @charts[type][:stats].sort! { |a, b| a[0] <=> b[0] }
44
+ @charts[type][:stats].map! { |a| [a[0].to_s, a[1]] }
42
45
  end
43
46
  end
44
47
 
data/test/lib/web_test.rb CHANGED
@@ -25,6 +25,23 @@ module Sidekiq
25
25
  get '/benchmarks'
26
26
  last_response.status.must_equal 200, last_response.body
27
27
  end
28
+
29
+ it "should remove benchmarks data" do
30
+ WorkerMock.new
31
+
32
+ Sidekiq.redis do |conn|
33
+ keys = conn.keys "benchmark:*"
34
+ keys.wont_be_empty
35
+ end
36
+
37
+ post '/benchmarks/remove'
38
+ last_response.status.must_equal 302
39
+
40
+ Sidekiq.redis do |conn|
41
+ keys = conn.keys "benchmark:*"
42
+ keys.must_be_empty
43
+ end
44
+ end
28
45
  end
29
46
  end
30
47
  end
@@ -16,20 +16,21 @@ module Sidekiq
16
16
  metrics = @worker.bm_obj.metrics
17
17
 
18
18
  @worker.metric_names.each do |metric_name|
19
- assert metrics[metric_name]
19
+ metrics[metric_name].wont_be_nil
20
20
  end
21
21
 
22
- assert @worker.bm_obj.start_time
23
- assert @worker.bm_obj.finish_time
22
+ @worker.bm_obj.start_time.wont_be_nil
23
+ @worker.bm_obj.finish_time.wont_be_nil
24
+ metrics[:assigned_metric].must_equal @worker.assigned_metric
24
25
  end
25
26
 
26
27
  it "should save metrics to redis" do
27
28
  Sidekiq.redis do |conn|
28
29
  total_time = conn.hget("#{@worker.benchmark_redis_base_key}:total", :job_time)
29
- assert total_time, "Total time: #{total_time.inspect}"
30
+ total_time.wont_be_nil
30
31
 
31
32
  metrics = conn.hkeys("#{@worker.benchmark_redis_base_key}:stats")
32
- assert metrics.any?, "Metrics: #{metrics.inspect}"
33
+ metrics.wont_be_empty
33
34
  end
34
35
  end
35
36
  end
data/test/test_helper.rb CHANGED
@@ -24,9 +24,11 @@ module Sidekiq
24
24
  include Sidekiq::Worker
25
25
  include Sidekiq::Benchmark::Worker
26
26
 
27
- attr_reader :bm_obj, :metric_names
27
+ attr_reader :bm_obj, :metric_names, :assigned_metric
28
28
 
29
29
  def initialize
30
+ @assigned_metric = 0.1
31
+
30
32
  @bm_obj = benchmark do |bm|
31
33
  bm.test_metric do
32
34
  2.times do |i|
@@ -36,6 +38,8 @@ module Sidekiq
36
38
  end
37
39
  end
38
40
  end
41
+
42
+ bm.assigned_metric @assigned_metric
39
43
  end
40
44
 
41
45
  @metric_names = [:test_metric, :nested_test_metric_1, :job_time]
@@ -1,46 +1,51 @@
1
+ /*
2
+ * Chartkick.js
3
+ * Create beautiful Javascript charts with minimal code
4
+ * https://github.com/ankane/chartkick.js
5
+ * v1.0.2
6
+ * MIT License
7
+ */
8
+
1
9
  /*jslint browser: true, indent: 2, plusplus: true */
2
10
  /*global google, $*/
3
11
 
4
12
  (function() {
5
13
  'use strict';
6
14
 
7
- // http://stackoverflow.com/questions/728360/most-elegant-way-to-clone-a-javascript-object
8
- function clone(obj) {
9
- var copy, i, attr, len;
10
-
11
- // Handle the 3 simple types, and null or undefined
12
- if (null === obj || "object" !== typeof obj) {
13
- return obj;
14
- }
15
+ // helpers
15
16
 
16
- // Handle Date
17
- if (obj instanceof Date) {
18
- copy = new Date();
19
- copy.setTime(obj.getTime());
20
- return copy;
21
- }
17
+ function isArray(variable) {
18
+ return Object.prototype.toString.call(variable) === "[object Array]";
19
+ }
22
20
 
23
- // Handle Array
24
- if (obj instanceof Array) {
25
- copy = [];
26
- for (i = 0, len = obj.length; i < len; i++) {
27
- copy[i] = clone(obj[i]);
28
- }
29
- return copy;
30
- }
21
+ function isPlainObject(variable) {
22
+ return variable instanceof Object;
23
+ }
31
24
 
32
- // Handle Object
33
- if (obj instanceof Object) {
34
- copy = {};
35
- for (attr in obj) {
36
- if (obj.hasOwnProperty(attr)) {
37
- copy[attr] = clone(obj[attr]);
25
+ // https://github.com/madrobby/zepto/blob/master/src/zepto.js
26
+ function extend(target, source) {
27
+ var key;
28
+ for (key in source) {
29
+ if (isPlainObject(source[key]) || isArray(source[key])) {
30
+ if (isPlainObject(source[key]) && !isPlainObject(target[key])) {
31
+ target[key] = {};
32
+ }
33
+ if (isArray(source[key]) && !isArray(target[key])) {
34
+ target[key] = [];
38
35
  }
36
+ extend(target[key], source[key]);
37
+ }
38
+ else if (source[key] !== undefined) {
39
+ target[key] = source[key];
39
40
  }
40
- return copy;
41
41
  }
42
+ }
42
43
 
43
- throw new Error("Unable to copy obj! Its type isn't supported.");
44
+ function merge(obj1, obj2) {
45
+ var target = {};
46
+ extend(target, obj1);
47
+ extend(target, obj2);
48
+ return target;
44
49
  }
45
50
 
46
51
  // https://github.com/Do/iso8601.js
@@ -93,10 +98,11 @@
93
98
 
94
99
  function jsOptionsFunc(defaultOptions, hideLegend, setMin, setMax) {
95
100
  return function(series, opts) {
96
- var options = clone(defaultOptions);
101
+ var options = merge({}, defaultOptions);
97
102
 
98
103
  // hide legend
99
- if (series.length === 1) {
104
+ // this is *not* an external option!
105
+ if (opts.hideLegend) {
100
106
  hideLegend(options);
101
107
  }
102
108
 
@@ -113,6 +119,9 @@
113
119
  setMax(options, opts.max);
114
120
  }
115
121
 
122
+ // merge library last
123
+ options = merge(options, opts.library || {});
124
+
116
125
  return options;
117
126
  };
118
127
  }
@@ -173,7 +182,7 @@
173
182
  renderLineChart = function(element, series, opts) {
174
183
  var options = jsOptions(series, opts), data, i, j;
175
184
  options.xAxis.type = "datetime";
176
- options.chart = {type: "spline"};
185
+ options.chart = {type: "spline", renderTo: element.id};
177
186
 
178
187
  for (i = 0; i < series.length; i++) {
179
188
  data = series[i].data;
@@ -183,22 +192,23 @@
183
192
  series[i].marker = {symbol: "circle"};
184
193
  }
185
194
  options.series = series;
186
- $(element).highcharts(options);
195
+ new Highcharts.Chart(options);
187
196
  };
188
197
 
189
198
  renderPieChart = function(element, series, opts) {
190
- var options = clone(defaultOptions);
199
+ var options = merge(defaultOptions, opts.library || {});
200
+ options.chart = {renderTo: element.id};
191
201
  options.series = [{
192
202
  type: "pie",
193
203
  name: "Value",
194
204
  data: series
195
205
  }];
196
- $(element).highcharts(options);
206
+ new Highcharts.Chart(options);
197
207
  };
198
208
 
199
209
  renderColumnChart = function(element, series, opts) {
200
210
  var options = jsOptions(series, opts), i, j, s, d, rows = [];
201
- options.chart = {type: "column"};
211
+ options.chart = {type: "column", renderTo: element.id};
202
212
 
203
213
  for (i = 0; i < series.length; i++) {
204
214
  s = series[i];
@@ -234,7 +244,7 @@
234
244
  }
235
245
  options.series = newSeries;
236
246
 
237
- $(element).highcharts(options);
247
+ new Highcharts.Chart(options);
238
248
  };
239
249
  } else if ("google" in window) { // Google charts
240
250
  // load from google
@@ -330,6 +340,10 @@
330
340
  rows2.push([(columnType === "datetime") ? new Date(toFloat(i)) : i].concat(rows[i]));
331
341
  }
332
342
  }
343
+ if (columnType === "datetime") {
344
+ rows2.sort(sortByTime);
345
+ }
346
+
333
347
  data.addRows(rows2);
334
348
 
335
349
  return data;
@@ -346,7 +360,7 @@
346
360
 
347
361
  renderPieChart = function(element, series, opts) {
348
362
  waitForLoaded(function() {
349
- var options = clone(defaultOptions);
363
+ var options = merge(defaultOptions, opts.library || {});
350
364
  options.chartArea = {
351
365
  top: "10%",
352
366
  height: "80%"
@@ -420,12 +434,6 @@
420
434
  }
421
435
  }
422
436
 
423
- // helpers
424
-
425
- function isArray(variable) {
426
- return Object.prototype.toString.call(variable) === "[object Array]";
427
- }
428
-
429
437
  // type conversions
430
438
 
431
439
  function toStr(n) {
@@ -469,12 +477,15 @@
469
477
  return a[0].getTime() - b[0].getTime();
470
478
  }
471
479
 
472
- function processSeries(series, time) {
480
+ function processSeries(series, opts, time) {
473
481
  var i, j, data, r, key;
474
482
 
475
483
  // see if one series or multiple
476
484
  if (!isArray(series) || typeof series[0] !== "object" || isArray(series[0])) {
477
485
  series = [{name: "Value", data: series}];
486
+ opts.hideLegend = true;
487
+ } else {
488
+ opts.hideLegend = false;
478
489
  }
479
490
 
480
491
  // right format
@@ -496,11 +507,11 @@
496
507
  }
497
508
 
498
509
  function processLineData(element, data, opts) {
499
- renderLineChart(element, processSeries(data, true), opts);
510
+ renderLineChart(element, processSeries(data, opts, true), opts);
500
511
  }
501
512
 
502
513
  function processColumnData(element, data, opts) {
503
- renderColumnChart(element, processSeries(data, false), opts);
514
+ renderColumnChart(element, processSeries(data, opts, false), opts);
504
515
  }
505
516
 
506
517
  function processPieData(element, data, opts) {
@@ -11,8 +11,9 @@ section
11
11
  h4= type
12
12
  figure.row
13
13
  .span5
14
- h5 Count jobs by execution time
15
- == column_chart @charts[type][:stats]
14
+ h5 Amount of tasks by execution time
15
+ == column_chart @charts[type][:stats],
16
+ library: { hAxis: { title: "Execution time" }, vAxis: { title: "Tasks" } }
16
17
  .span4
17
18
  h5 Average execution time
18
19
  == pie_chart @charts[type][:total]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sidekiq-benchmark
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-13 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chartkick