perfetto 0.1.4 → 0.1.5
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 +4 -4
- data/README.md +18 -4
- data/example/example.png +0 -0
- data/example/example.rb +19 -4
- data/lib/perfetto/interceptor.rb +89 -20
- data/lib/perfetto/version.rb +1 -1
- 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: 9989cb452ab1dd59f10629d8b29dd9ea035954d24fd013120bbeef3787adfcc9
|
4
|
+
data.tar.gz: 017cfdfd0a27a8e4c93d0d3ec74575b2455a4139491c6ef131608cc389487dd8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6af238ffdf8008e4edb49b35bd8e10de5005c7d2cd307158651ef88ba711b28e16a8d4f04d5481a87f9871ee16f5ae573151bda33f0f02475cf62b49e0b2f3be
|
7
|
+
data.tar.gz: a27cf64202e4731cf07a9b3752d6b3afce376585c91b9f2609aa3971ecd06c5d15cbe06ef3cee0935692cb37d4c8cfb9003efaf2afe1e5ce35b970480b5a35d0
|
data/README.md
CHANGED
@@ -7,7 +7,6 @@ https://ui.perfetto.dev/
|
|
7
7
|
# Usage
|
8
8
|
|
9
9
|
```ruby
|
10
|
-
|
11
10
|
require "perfetto"
|
12
11
|
|
13
12
|
Perfetto.setup enable_tracing: true
|
@@ -44,6 +43,10 @@ Perfetto.trace_event_instant_with_debug_info "cpu_work", "example_instant2", "ke
|
|
44
43
|
sleep 0.1
|
45
44
|
|
46
45
|
class Foo
|
46
|
+
# Intercept instance methods
|
47
|
+
include Perfetto::Interceptor
|
48
|
+
perfetto_trace_all
|
49
|
+
|
47
50
|
def bar(a, b = 1, c: 2)
|
48
51
|
yield(a + b + c)
|
49
52
|
end
|
@@ -53,15 +56,26 @@ class Foo
|
|
53
56
|
sleep 0.1
|
54
57
|
end
|
55
58
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
+
def self.buf
|
60
|
+
puts "buf"
|
61
|
+
sleep 0.1
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class Bar < Foo
|
66
|
+
def say
|
67
|
+
puts "hello"
|
68
|
+
sleep 0.1
|
69
|
+
end
|
59
70
|
end
|
60
71
|
|
61
72
|
f = Foo.new
|
73
|
+
b = Bar.new
|
62
74
|
f.bar(1, 2, c: 3) do |n|
|
63
75
|
n.times do |x|
|
64
76
|
f.baz x + n
|
77
|
+
Foo.buf
|
78
|
+
b.say
|
65
79
|
end
|
66
80
|
end
|
67
81
|
|
data/example/example.png
CHANGED
Binary file
|
data/example/example.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
# rubocop:disable Naming/MethodParameterName
|
4
4
|
# rubocop:disable Style/Documentation
|
5
5
|
|
6
|
-
|
6
|
+
require_relative "../lib/perfetto"
|
7
7
|
|
8
8
|
Perfetto.setup enable_tracing: true
|
9
9
|
|
@@ -39,6 +39,10 @@ Perfetto.trace_event_instant_with_debug_info "cpu_work", "example_instant2", "ke
|
|
39
39
|
sleep 0.1
|
40
40
|
|
41
41
|
class Foo
|
42
|
+
# Intercept instance methods
|
43
|
+
include Perfetto::Interceptor
|
44
|
+
perfetto_trace_all
|
45
|
+
|
42
46
|
def bar(a, b = 1, c: 2)
|
43
47
|
yield(a + b + c)
|
44
48
|
end
|
@@ -48,15 +52,26 @@ class Foo
|
|
48
52
|
sleep 0.1
|
49
53
|
end
|
50
54
|
|
51
|
-
|
52
|
-
|
53
|
-
|
55
|
+
def self.buf
|
56
|
+
puts "buf"
|
57
|
+
sleep 0.1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Bar < Foo
|
62
|
+
def say
|
63
|
+
puts "hello"
|
64
|
+
sleep 0.1
|
65
|
+
end
|
54
66
|
end
|
55
67
|
|
56
68
|
f = Foo.new
|
69
|
+
b = Bar.new
|
57
70
|
f.bar(1, 2, c: 3) do |n|
|
58
71
|
n.times do |x|
|
59
72
|
f.baz x + n
|
73
|
+
Foo.buf
|
74
|
+
b.say
|
60
75
|
end
|
61
76
|
end
|
62
77
|
|
data/lib/perfetto/interceptor.rb
CHANGED
@@ -4,31 +4,100 @@ module Perfetto
|
|
4
4
|
# To intercept method calls in other classes
|
5
5
|
module Interceptor
|
6
6
|
def self.included(base)
|
7
|
-
|
7
|
+
if Perfetto::Configure.enable_tracing
|
8
|
+
base.extend ImplMethods
|
9
|
+
else
|
10
|
+
base.extend StubMethods
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
|
-
#
|
11
|
-
module
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
14
|
+
# Stub methods
|
15
|
+
module StubMethods
|
16
|
+
def perfetto_trace_instance_method(_method_name); end
|
17
|
+
def perfetto_trace_class_method(_method_name); end
|
18
|
+
def perfetto_trace_all; end
|
19
|
+
|
20
|
+
def perfetto_traced_instance_method?(_method_name)
|
21
|
+
false
|
22
|
+
end
|
23
|
+
|
24
|
+
def perfetto_traced_class_method?(_method_name)
|
25
|
+
false
|
26
|
+
end
|
27
|
+
|
28
|
+
def perfetto_traced_instance_methods
|
29
|
+
[]
|
30
|
+
end
|
31
|
+
|
32
|
+
def perfetto_traced_class_methods
|
33
|
+
[]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
# Real Implementation
|
38
|
+
module ImplMethods
|
39
|
+
def perfetto_trace_instance_method(method_name)
|
40
|
+
return if method_name.to_s.start_with? "_pfi_"
|
41
|
+
|
42
|
+
# warn "Perfetto[InstanceMethod]: #{name}##{method_name}"
|
43
|
+
perfetto_traced_instance_methods << method_name
|
44
|
+
|
45
|
+
original_method = instance_method(method_name)
|
46
|
+
alias_method "_pfi_#{method_name}", method_name
|
47
|
+
|
48
|
+
define_method(method_name) do |*args, **kwargs, &block|
|
49
|
+
Perfetto.trace_event_begin self.class.name, method_name.to_s
|
50
|
+
original_method.bind(self).call(*args, **kwargs, &block)
|
51
|
+
ensure
|
52
|
+
Perfetto.trace_event_end self.class.name
|
22
53
|
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def perfetto_trace_class_method(method_name)
|
57
|
+
return if method_name.to_s == "singleton_method_added" || method_name.to_s.start_with?("_pfc_")
|
23
58
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
59
|
+
# warn "Perfetto[ClassMethod]: #{name}.#{method_name}"
|
60
|
+
perfetto_traced_class_methods << method_name
|
61
|
+
|
62
|
+
original_method = method(method_name)
|
63
|
+
singleton_class.send(:alias_method, "_pfc_#{method_name}", method_name)
|
64
|
+
|
65
|
+
define_singleton_method(method_name) do |*args, **kwargs, &block|
|
66
|
+
Perfetto.trace_event_begin name, method_name.to_s
|
67
|
+
original_method.call(*args, **kwargs, &block)
|
68
|
+
ensure
|
69
|
+
Perfetto.trace_event_end name
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def perfetto_trace_all
|
74
|
+
define_singleton_method(:method_added) do |method_name|
|
75
|
+
return if perfetto_traced_instance_method?(method_name)
|
76
|
+
|
77
|
+
perfetto_trace_instance_method method_name
|
78
|
+
end
|
79
|
+
|
80
|
+
define_singleton_method(:singleton_method_added) do |method_name|
|
81
|
+
return if perfetto_traced_class_method?(method_name)
|
82
|
+
|
83
|
+
perfetto_trace_class_method method_name
|
28
84
|
end
|
29
|
-
|
30
|
-
|
31
|
-
|
85
|
+
end
|
86
|
+
|
87
|
+
def perfetto_traced_instance_method?(method_name)
|
88
|
+
perfetto_traced_instance_methods.include? method_name
|
89
|
+
end
|
90
|
+
|
91
|
+
def perfetto_traced_class_method?(method_name)
|
92
|
+
perfetto_traced_class_methods.include? method_name
|
93
|
+
end
|
94
|
+
|
95
|
+
def perfetto_traced_instance_methods
|
96
|
+
@perfetto_traced_instance_methods ||= []
|
97
|
+
end
|
98
|
+
|
99
|
+
def perfetto_traced_class_methods
|
100
|
+
@perfetto_traced_class_methods ||= []
|
32
101
|
end
|
33
102
|
end
|
34
103
|
end
|
data/lib/perfetto/version.rb
CHANGED