yuslow 0.0.3 → 0.1.0

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
  SHA256:
3
- metadata.gz: 5246c2535d0277df7d0117c0abdb1a9ce9eeb49c434d0df1db0bfa85f71fbdd5
4
- data.tar.gz: e2408ca24e820cd5d91cfa10b441bbbf8246e7476f7aab48f657bc6cd82fe1b8
3
+ metadata.gz: 30c27065a08a4b7140a74cf6aa520a5785648d21516ebc45e80ccaad063df9b0
4
+ data.tar.gz: 3e664aeffaee96cdc09632ae470df633976e0f811c4f5cde6a16a560aab190ef
5
5
  SHA512:
6
- metadata.gz: a89ddd6dd6063d40a3614904226728771d15f746a29d326e2b01cc96b2f6895f01e0366c375b6dccb6862a1492cebb94386e4e0a176bf88266d8f61c0c26b482
7
- data.tar.gz: 9c0c568bcd841ac8b0e78927b00fa7cc73d1bdf4cb0bc2a6e140679de948d5e853210798137158c6403583f1fa07d6cf7a1a1172418284dbbc108e4126538ec9
6
+ metadata.gz: adf2247d500446139937b95b7f663caac86cfada0be0a2ba57241e48e149cd9751b8df41608911675f40252965ff01053b8780add96433e5b137d245e8fb586e
7
+ data.tar.gz: ccd64c90d53730765d6e62c6c86bb2a75e33dae05ea212f07d06722cd06eb49f027a61f512fd85f7356efc4d8a937d04c60346c5125beba4e5e451df8b9806bb
data/README.md CHANGED
@@ -42,3 +42,10 @@ Thread[1]:
42
42
  Object#root_cause elapsed 1000 ms
43
43
  Kernel#sleep elapsed 1000 ms
44
44
  ```
45
+
46
+ ## Parameters
47
+ | Parameter | Options | Default | Description |
48
+ |---------------|-------------------|-----------|-----------------------------------------------------|
49
+ | **output** | `false` `:stdout` | `:stdout` | Defines how the profiling results will be presented |
50
+ | **max_level** | `number`, `nil` | `nil` | Specifies maximum profiling depth |
51
+ | **debug** | `true` `false` | false | Prints debug information while profiling |
@@ -5,18 +5,18 @@ require_relative 'yuslow/stdout_printer'
5
5
  module Yuslow
6
6
  extend self
7
7
 
8
- def run(debug: false, output: nil)
8
+ def run(debug: false, output: nil, max_depth: nil)
9
9
  raise 'Block expected' unless block_given?
10
10
 
11
- investigation = Investigation.new debug: debug, printer: printer_from(output)
11
+ investigation = Investigation.new debug: debug, printer: printer_from(output), max_depth: max_depth
12
12
  investigation.start
13
13
  yield
14
14
  investigation.finish
15
15
  investigation
16
16
  end
17
17
 
18
- def investigation(debug: false, output: nil)
19
- Investigation.new debug: debug, printer: printer_from(output)
18
+ def investigation(debug: false, output: nil, max_depth: nil)
19
+ Investigation.new debug: debug, printer: printer_from(output), max_depth: max_depth
20
20
  end
21
21
 
22
22
  private
@@ -1,11 +1,17 @@
1
1
  module Yuslow
2
2
  class Investigation
3
- def initialize(debug: false, printer: nil)
3
+ def initialize(debug: false, printer: nil, max_depth:)
4
+ if max_depth
5
+ raise ArgumentError, 'max_depth must be a number' if !max_depth.is_a? Numeric
6
+ raise ArgumentError, 'max_depth cannot be less than 1' if max_depth < 1
7
+ end
8
+
4
9
  @printer = printer
5
10
  @debug = debug
6
11
  @tracing = false
7
12
  @trace = nil
8
- @indent = 0
13
+ @depth = 0
14
+ @max_depth = max_depth
9
15
  @execution = {}
10
16
  end
11
17
 
@@ -19,26 +25,28 @@ module Yuslow
19
25
  elsif trace_point.defined_class == self.class && trace_point.callee_id == :finish
20
26
  @tracing = false
21
27
  elsif @tracing
22
- if %i(call c_call).include? trace_point.event
23
- if @execution[thread_id][:current]
24
- @execution[thread_id][:current] =
25
- @execution[thread_id][:current].fork object: trace_point.defined_class,
26
- method: trace_point.callee_id
27
- else
28
- operation = Operation.new object: trace_point.defined_class, method: trace_point.callee_id
29
- @execution[thread_id][:root] = operation
30
- @execution[thread_id][:current] = operation
28
+ if %i(call c_call).include?(trace_point.event)
29
+ if @depth < @max_depth
30
+ if @execution[thread_id][:current]
31
+ @execution[thread_id][:current] = @execution[thread_id][:current].fork object: trace_point.defined_class,
32
+ method: trace_point.callee_id
33
+ else
34
+ operation = Operation.new object: trace_point.defined_class, method: trace_point.callee_id
35
+ @execution[thread_id][:root] = operation
36
+ @execution[thread_id][:current] = operation
37
+ end
31
38
  end
32
39
 
33
- debug trace_point, @indent
34
- @indent += 1
35
-
40
+ debug trace_point, @depth
41
+ @depth += 1
36
42
  elsif %i(return c_return).include? trace_point.event
37
- @indent -= 1
38
- debug trace_point, @indent
43
+ @depth -= 1
44
+ debug trace_point, @depth
39
45
 
40
- @execution[thread_id][:current]&.complete
41
- @execution[thread_id][:current] = @execution[thread_id][:current]&.parent
46
+ if @depth < @max_depth
47
+ @execution[thread_id][:current]&.complete
48
+ @execution[thread_id][:current] = @execution[thread_id][:current]&.parent
49
+ end
42
50
  end
43
51
  end
44
52
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yuslow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Deyan Dobrinov