sampling_prof 0.4.1 → 0.4.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38b88b218151e0d854a3cd7acfd68a00d09798e7
4
- data.tar.gz: 1b64bde640e0d08c597b13fa7d86cdf2247e6f52
3
+ metadata.gz: 55fa2ebf8d44c1f2cae2b54e7d12c06a52d6ee0f
4
+ data.tar.gz: 700e7f64be7f0dc5b2c9c38c95e4c80455ef136f
5
5
  SHA512:
6
- metadata.gz: 9afcdf7d910cbe4c2d2a1414c878010882847d35edf1f3be10de5b56809475acb45ee9af7cc3a031d554b6fb58ae2ea7635471a38b75cb1358402df43498e1c7
7
- data.tar.gz: b991f709c0e1faa49dc11abc423fcfa48f5426af5e5833e10496758fe649059b6b6f6c7bb6e862e17c661196da69ac6eca9be2bb99beb7a8049601c31e007d18
6
+ metadata.gz: 6ede9199b87ecf2cfbd8a17ce955853cd00ddde02abb9f9f4a8a15eeb47bf36cfce22f213d88e8801c967b0096736d5155f9a087d8b28c5e27925d1611b6b7df
7
+ data.tar.gz: 0a33b15d7d041e1706a22cdb74935a0b0f9c7e4be06fa524b6a75ee150f3ae6986dabfb14f735b0114f7bc204b6f486c7e8c3d592ceeea3096ad66ddc1e4042e
Binary file
data/lib/sampling_prof.rb CHANGED
@@ -11,9 +11,11 @@ class SamplingProf
11
11
 
12
12
  # options:
13
13
  # sampling_interval: default to 0.1 second
14
+ # profiling_threshold: default to 0 second
14
15
  # &output_handler: default to write into output_file
15
16
  def initialize(*args, &output_handler)
16
17
  self.sampling_interval = args[0] || 0.1
18
+ self.profiling_threshold = args[1] || 0
17
19
  self.output_handler = block_given? ? output_handler : default_output_handler
18
20
  internal_initialize if respond_to?(:internal_initialize)
19
21
  end
@@ -60,7 +60,7 @@ class SamplingProf
60
60
  end
61
61
  end
62
62
 
63
- attr_accessor :sampling_interval, :output_handler
63
+ attr_accessor :sampling_interval, :output_handler, :profiling_threshold
64
64
 
65
65
  def internal_initialize
66
66
  @samplings = {}
@@ -77,7 +77,9 @@ class SamplingProf
77
77
  def stop
78
78
  if @running
79
79
  if sampling = @samplings.delete(Thread.current)
80
- output(Thread.current, sampling)
80
+ if sampling.sampling_data?
81
+ @output_handler.call(sampling.result)
82
+ end
81
83
  true
82
84
  end
83
85
  end
@@ -103,23 +105,13 @@ class SamplingProf
103
105
  @sampling_thread ||= Thread.start do
104
106
  loop do
105
107
  @samplings.dup.each do |t, s|
106
- s.process(t)
108
+ if s.runtime >= @profiling_threshold
109
+ s.process(t)
110
+ end
107
111
  end
108
112
  sleep @sampling_interval
109
113
  break unless @running
110
114
  end
111
- @samplings.each do |thread, sampling|
112
- output(thread, sampling)
113
- end
114
- end
115
- end
116
-
117
- def output(thread, sampling)
118
- if sampling.sampling_data?
119
- o = @output_handler
120
- thread.instance_eval do
121
- o.call(sampling.result)
122
- end
123
115
  end
124
116
  end
125
117
  end
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.4.1
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Xiao Li