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 +4 -4
- data/README.md +7 -0
- data/lib/yuslow.rb +4 -4
- data/lib/yuslow/investigation.rb +26 -18
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 30c27065a08a4b7140a74cf6aa520a5785648d21516ebc45e80ccaad063df9b0
|
4
|
+
data.tar.gz: 3e664aeffaee96cdc09632ae470df633976e0f811c4f5cde6a16a560aab190ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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 |
|
data/lib/yuslow.rb
CHANGED
@@ -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
|
data/lib/yuslow/investigation.rb
CHANGED
@@ -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
|
-
@
|
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?
|
23
|
-
if @
|
24
|
-
@execution[thread_id][:current]
|
25
|
-
@execution[thread_id][:current].fork object: trace_point.defined_class,
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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, @
|
34
|
-
@
|
35
|
-
|
40
|
+
debug trace_point, @depth
|
41
|
+
@depth += 1
|
36
42
|
elsif %i(return c_return).include? trace_point.event
|
37
|
-
@
|
38
|
-
debug trace_point, @
|
43
|
+
@depth -= 1
|
44
|
+
debug trace_point, @depth
|
39
45
|
|
40
|
-
@
|
41
|
-
|
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
|