simple_profiler 0.1.2 → 0.2.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 192c79b43fd1311c910e1abc311f75ecfe9565adc5373bc00c7f00ce2e0eae2b
4
- data.tar.gz: 74d9d8e4b07a29674a9beaf28b327be0acb2849cd2452204d8d6111f052df0c3
3
+ metadata.gz: bc8593ed097953477f51f8fd48c73ea5c19ecfe62d3c665bd1936ebe560c484a
4
+ data.tar.gz: 3f9245c4f2eb83e8b35bb167f82af1513133e2913485e44c6c210ce85f9e897a
5
5
  SHA512:
6
- metadata.gz: 3741c4678d6e655a953a6f26c53912f8eb8d21b5cf9ea6df269fe841ed6c300e9d41b6c33ec0da1e92fff921e7bbc6495cf07918c18ba11d4e77723f53da44bf
7
- data.tar.gz: ccfda2c9d418658b85c1a1d0f89b88efae2056cd0d775530b4fc6483509fe9393d59ea91fb88c154c528f957420da0263e5eecf0c4edc8f11cec5143257433dc
6
+ metadata.gz: 55a24eabdfbfa96c2bdcd9ced024b91c71626a88672c7a8ea81dc918d324eb6df09d024d4eb5fb112ba982c3e207aa4ac221808e68b302de28d8fad9379d9aaa
7
+ data.tar.gz: c87b09ae79ecea94cbd485368db2175edfbaf90106b0b1d074b21e8b1c25ae5d99d25d87edbe2b4ab1e0372e53cf209b6f14f0d342bbad19cb06b11324c8d02b
@@ -15,7 +15,9 @@ module SimpleProfiler
15
15
  def ranking(options={})
16
16
  order = options.fetch(:sort_by, :total_time)
17
17
 
18
- events_by_method = events.group_by {|e| {klass: e.klass.to_s, method: e.method, target: e.target}}
18
+ # TODO: find why some events are nil, the current thought is that when the program is concurrent, the events notify may have some problems
19
+ events_by_method = events.compact.group_by {|e| {klass: e.klass.to_s, method: e.method, target: e.target}}
20
+
19
21
  ranking = events_by_method.map do |key, values|
20
22
  key.merge statistics_for(values)
21
23
  end
@@ -36,15 +38,33 @@ module SimpleProfiler
36
38
  total_memory += e.used_memory
37
39
  end
38
40
 
41
+ avg_time = count == 0 ? 0 : total_time / count.to_f
42
+ avg_memory = count == 0 ? 0 : total_memory / count.to_f
43
+
39
44
  {
40
45
  hits: count,
41
46
  total_time: total_time,
42
- avg_time: count == 0 ? 0 : total_time / count,
43
- total_memory: total_memory,
44
- avg_memory: count == 0 ? 0 : total_memory / count
47
+ avg_time: avg_time,
48
+ variance_time: variance_for(events.map(&:total_time), avg_time),
49
+ total_memory: total_memory,
50
+ avg_memory: avg_memory,
51
+ variance_memory: variance_for(events.map(&:used_memory), avg_memory)
45
52
  }
46
53
  end
47
54
 
55
+ def variance_for(array, mean)
56
+ if array.count > 1
57
+ cuadratic_error = array.inject(0) do |acum, value|
58
+ acum + (value - mean)**2
59
+ end
60
+
61
+ cuadratic_error / (array.count - 1)
62
+ else
63
+ 0
64
+ end
65
+ end
66
+
48
67
  end
68
+
49
69
  end
50
70
  end
@@ -1,3 +1,3 @@
1
1
  module SimpleProfiler
2
- VERSION = '0.1.2'
2
+ VERSION = '0.2.0'
3
3
  end
@@ -3,10 +3,12 @@ require 'minitest_helper'
3
3
  describe 'Summary' do
4
4
 
5
5
  let(:events) do
6
+ now = Time.now
7
+
6
8
  [
7
- SimpleProfiler::Event.new(Struct, :class, :run, [], Time.now, Time.now+1, 5, 10),
8
- SimpleProfiler::Event.new(Struct, :class, :run, [], Time.now, Time.now+1, 10, 15),
9
- SimpleProfiler::Event.new(Struct, :instance, :run, [], Time.now, Time.now+1, 15, 16)
9
+ SimpleProfiler::Event.new(Struct, :class, :run, [], now, now+1, 5, 10),
10
+ SimpleProfiler::Event.new(Struct, :class, :run, [], now, now+2, 10, 12),
11
+ SimpleProfiler::Event.new(Struct, :instance, :run, [], now, now+1, 15, 20)
10
12
  ]
11
13
  end
12
14
 
@@ -27,14 +29,28 @@ describe 'Summary' do
27
29
  ranking = summary.ranking(sort_by: :hits)
28
30
 
29
31
  ranking.count.must_equal 2
32
+
30
33
  ranking[0][:klass].must_equal 'Struct'
31
34
  ranking[0][:target].must_equal :class
32
35
  ranking[0][:method].must_equal :run
33
36
  ranking[0][:hits].must_equal 2
37
+ ranking[0][:total_time].must_equal 3.0
38
+ ranking[0][:avg_time].must_equal 1.5
39
+ ranking[0][:variance_time].must_equal 0.5
40
+ ranking[0][:total_memory].must_equal 7
41
+ ranking[0][:avg_memory].must_equal 3.5
42
+ ranking[0][:variance_memory].must_equal 4.5
43
+
34
44
  ranking[1][:klass].must_equal 'Struct'
35
45
  ranking[1][:target].must_equal :instance
36
46
  ranking[1][:method].must_equal :run
37
47
  ranking[1][:hits].must_equal 1
48
+ ranking[1][:total_time].must_equal 1
49
+ ranking[1][:avg_time].must_equal 1
50
+ ranking[1][:variance_time].must_equal 0
51
+ ranking[1][:total_memory].must_equal 5
52
+ ranking[1][:avg_memory].must_equal 5
53
+ ranking[1][:variance_memory].must_equal 0
38
54
  end
39
55
 
40
56
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_profiler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Naiman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-10 00:00:00.000000000 Z
11
+ date: 2018-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: datacenter