sampling_prof 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a0b06029c982d8f0e5935128e7db6bb16526a55a
4
- data.tar.gz: 3b82d033647c5c4da28953802d751ea56f821446
3
+ metadata.gz: 9dd5ce616e57b19270ca4194dc382d4a4ee09367
4
+ data.tar.gz: 99c255e3688a28e30d2350f584bf4c4f0d024982
5
5
  SHA512:
6
- metadata.gz: 199df42d125c17554d633e51b8aaef95dafa1d114ac6650d28eafebea695d1577c2e47493a8cb9bccb4221a3ed0731cd3d89119d475286a8f60084e0148086b3
7
- data.tar.gz: 3abfaf96cb25d9c6e946b7e4d51dddbf7117160ee5438ead5190f5d78a80d742c1d317f7233b1b21b76b7f7b37b138b21e0427aea2705b86f545dbf30abcab25
6
+ metadata.gz: e518e426037a41899fca11bd5ab5485aadd7a9f5b10c19113dbbb32b6f9ce7dd69237aba938bf3cf7865c4249d3024d4dc2ed5c03a089979f60b87fb3a84145b
7
+ data.tar.gz: e05fc8223c08ebf488526438b1d52e1f39120ddd3aa389ced6e2661013240610ba7cb62e6d5fb4ef32f75ccc5dcb54d1396f76c0d96ce485773a3354ad04f985
Binary file
@@ -4,8 +4,7 @@ class SamplingProf
4
4
  end
5
5
 
6
6
  class Sampling
7
- def initialize(target)
8
- @target = target
7
+ def initialize
9
8
  @samples = Hash.new{|h,k| h[k] = [0, 0] }
10
9
  @call_graph = Hash.new{|h,k| h[k] = 0}
11
10
  @nodes = {}
@@ -15,14 +14,14 @@ class SamplingProf
15
14
  [@nodes.to_a, @samples.to_a, @call_graph.to_a]
16
15
  end
17
16
 
18
- def snapshot
19
- locations = @target.backtrace_locations
17
+ def process(locations)
20
18
  from = -1
21
19
  paths = []
22
20
  calls = []
21
+ top_index = locations.size - 1
23
22
  locations.reverse.each_with_index do |loc, i|
24
- node_id = node_id(loc.path)
25
- if i == 0
23
+ node_id = node_id(loc)
24
+ if i == top_index
26
25
  @samples[node_id][0] += 1
27
26
  end
28
27
 
@@ -39,8 +38,12 @@ class SamplingProf
39
38
  end
40
39
  end
41
40
 
42
- def node_id(path)
43
- @nodes[path] ||= @nodes.size
41
+ def node_id(loc)
42
+ @nodes[call_element(loc)] ||= @nodes.size
43
+ end
44
+
45
+ def call_element(loc)
46
+ [loc.path, loc.lineno, loc.label].join(":")
44
47
  end
45
48
  end
46
49
 
@@ -55,10 +58,10 @@ class SamplingProf
55
58
  @running = true
56
59
  target = Thread.current
57
60
  @sampling_thread = Thread.start do
58
- sampling = Sampling.new(target)
61
+ sampling = Sampling.new
59
62
  loop do
60
63
  break unless @running
61
- sampling.snapshot
64
+ sampling.process(target.backtrace_locations)
62
65
  sleep @period
63
66
  end
64
67
  block.call(sampling.result)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sampling_prof
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2014-02-15 00:00:00 Z
12
+ date: 2014-02-19 00:00:00 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake-compiler