perfetto 0.1.15-x86_64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rubocop.yml +18 -0
- data/README.md +109 -0
- data/Rakefile +18 -0
- data/example/example.png +0 -0
- data/example/example.rb +88 -0
- data/ext/perfetto/LICENSE +189 -0
- data/ext/perfetto/README.md +11 -0
- data/ext/perfetto/extconf.rb +11 -0
- data/ext/perfetto/perfetto.c +139 -0
- data/ext/perfetto/perfetto_internal.cc +200 -0
- data/ext/perfetto/perfetto_internal.h +48 -0
- data/ext/perfetto/sdk.cc +62532 -0
- data/ext/perfetto/sdk.h +154360 -0
- data/lib/perfetto/configure.rb +12 -0
- data/lib/perfetto/core_ext/configurable.rb +45 -0
- data/lib/perfetto/interceptor.rb +115 -0
- data/lib/perfetto/middleware.rb +37 -0
- data/lib/perfetto/perfetto.rb +49 -0
- data/lib/perfetto/perfetto_native.so +0 -0
- data/lib/perfetto/version.rb +5 -0
- data/lib/perfetto.rb +30 -0
- data/perfetto.gemspec +34 -0
- data/sig/perfetto.rbs +4 -0
- metadata +71 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: d5ae34b8295e0d919e3044cb77884fb583441bc3b5f218920d11d5ded9506849
|
4
|
+
data.tar.gz: 1e89f789a7e043718dc9fbf1068416a9b779b92b6c2b71729990dc8854d6d33b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0c0d832b5acbbdd6a5857e216b9853bc48b43f213e6687a33db40e9480d02b8fefcb4c444fbb59d0390e0021ef163a24ad51bc3b60f5a39de9ed3425d0488b87
|
7
|
+
data.tar.gz: 45cc831c7eb2234c3546cd3f8cf2a7ca3e1f90eb04b21258eaeb9e405d106230c71115693587c9677928b3c959c8b13d82b06d7fa2a7ac2baca9d822da04f68f
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.3
|
3
|
+
NewCops: enable
|
4
|
+
|
5
|
+
Style/StringLiterals:
|
6
|
+
Enabled: true
|
7
|
+
EnforcedStyle: double_quotes
|
8
|
+
|
9
|
+
Style/StringLiteralsInInterpolation:
|
10
|
+
Enabled: true
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Layout/LineLength:
|
14
|
+
Max: 120
|
15
|
+
|
16
|
+
require:
|
17
|
+
- rubocop-rake
|
18
|
+
- rubocop-minitest
|
data/README.md
ADDED
@@ -0,0 +1,109 @@
|
|
1
|
+
# Perfetto
|
2
|
+
|
3
|
+
## Visualization
|
4
|
+
|
5
|
+
https://ui.perfetto.dev/
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
### Basic
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
require "perfetto"
|
13
|
+
|
14
|
+
Perfetto.setup enable_tracing: true
|
15
|
+
|
16
|
+
Perfetto.start_tracing
|
17
|
+
|
18
|
+
# Slice
|
19
|
+
# Stack frame is inferred from the begin event with the same category 'cpu_work'
|
20
|
+
Perfetto.trace_event_begin "cpu_work", "example_task"
|
21
|
+
sleep 0.1
|
22
|
+
Perfetto.trace_event_end "cpu_work"
|
23
|
+
|
24
|
+
# Slice with debug info
|
25
|
+
# Same as above, but "key"=>"value" is added to the event details
|
26
|
+
Perfetto.trace_event_begin_with_debug_info "cpu_work", "example_task2", "key", "value"
|
27
|
+
sleep 0.1
|
28
|
+
Perfetto.trace_event_end "cpu_work"
|
29
|
+
|
30
|
+
# Counter
|
31
|
+
10.times do |n|
|
32
|
+
Perfetto.trace_counter "rendering", "frame_rate", n.even? ? 60 : 30
|
33
|
+
sleep 0.1
|
34
|
+
end
|
35
|
+
Perfetto.trace_counter "rendering", "frame_rate", 0
|
36
|
+
|
37
|
+
# Instant
|
38
|
+
Perfetto.trace_event_instant "cpu_work", "example_instant"
|
39
|
+
|
40
|
+
sleep 0.1
|
41
|
+
|
42
|
+
# Instant with debug info
|
43
|
+
Perfetto.trace_event_instant_with_debug_info "cpu_work", "example_instant2", "key", "value"
|
44
|
+
|
45
|
+
sleep 0.1
|
46
|
+
|
47
|
+
class Foo
|
48
|
+
# Intercept instance methods
|
49
|
+
include Perfetto::Interceptor
|
50
|
+
perfetto_trace_all
|
51
|
+
|
52
|
+
def bar(a, b = 1, c: 2)
|
53
|
+
yield(a + b + c)
|
54
|
+
end
|
55
|
+
|
56
|
+
def baz(x)
|
57
|
+
puts x
|
58
|
+
sleep 0.1
|
59
|
+
end
|
60
|
+
|
61
|
+
def self.buf
|
62
|
+
puts "buf"
|
63
|
+
sleep 0.1
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
class Bar < Foo
|
68
|
+
def say
|
69
|
+
puts "hello"
|
70
|
+
sleep 0.1
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
f = Foo.new
|
75
|
+
b = Bar.new
|
76
|
+
f.bar(1, 2, c: 3) do |n|
|
77
|
+
n.times do |x|
|
78
|
+
f.baz x + n
|
79
|
+
Foo.buf
|
80
|
+
b.say
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
Perfetto.stop_tracing "example.pftrace"
|
85
|
+
```
|
86
|
+
|
87
|
+
![example](./example/example.png)
|
88
|
+
|
89
|
+
### Rack Middleware
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
# frozen_string_literal: true
|
93
|
+
|
94
|
+
require "sinatra/base"
|
95
|
+
require "perfetto"
|
96
|
+
|
97
|
+
class Server < Sinatra::Base
|
98
|
+
use Perfetto::Middleware, env_proc: ->(env) { env.to_json }
|
99
|
+
|
100
|
+
get "/" do
|
101
|
+
"Hello World"
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
Perfetto.setup enable_tracing: true
|
106
|
+
Perfetto.start_tracing
|
107
|
+
Server.run!
|
108
|
+
Perfetto.stop_tracing "middleware.pftrace"
|
109
|
+
```
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
require "rake/extensiontask"
|
6
|
+
gemspec = Gem::Specification.load("perfetto.gemspec")
|
7
|
+
Rake::ExtensionTask.new("perfetto_native", gemspec) do |ext|
|
8
|
+
ext.ext_dir = "ext/perfetto"
|
9
|
+
ext.lib_dir = "lib/perfetto"
|
10
|
+
end
|
11
|
+
|
12
|
+
require "minitest/test_task"
|
13
|
+
Minitest::TestTask.create
|
14
|
+
|
15
|
+
require "rubocop/rake_task"
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
task default: %i[test rubocop]
|
data/example/example.png
ADDED
Binary file
|
data/example/example.rb
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable Naming/MethodParameterName
|
4
|
+
# rubocop:disable Style/Documentation
|
5
|
+
|
6
|
+
require_relative "../lib/perfetto"
|
7
|
+
|
8
|
+
Perfetto.setup enable_tracing: true
|
9
|
+
|
10
|
+
Perfetto.start_tracing
|
11
|
+
|
12
|
+
# Slice
|
13
|
+
# Stack frame is inferred from the begin event with the same category 'cpu_work'
|
14
|
+
Perfetto.trace_event_begin "cpu_work", "example_task"
|
15
|
+
sleep 0.1
|
16
|
+
Perfetto.trace_event_end "cpu_work"
|
17
|
+
|
18
|
+
# Slice with debug info
|
19
|
+
# Same as above, but "key"=>"value" is added to the event details
|
20
|
+
Perfetto.trace_event_begin_with_debug_info "cpu_work", "example_task2", "key", "value"
|
21
|
+
sleep 0.1
|
22
|
+
Perfetto.trace_event_end "cpu_work"
|
23
|
+
|
24
|
+
# Counter
|
25
|
+
10.times do |n|
|
26
|
+
Perfetto.trace_counter "rendering", "frame_rate", n.even? ? 60 : 30
|
27
|
+
sleep 0.1
|
28
|
+
end
|
29
|
+
Perfetto.trace_counter "rendering", "frame_rate", 0
|
30
|
+
|
31
|
+
# Instant
|
32
|
+
Perfetto.trace_event_instant "cpu_work", "example_instant"
|
33
|
+
|
34
|
+
sleep 0.1
|
35
|
+
|
36
|
+
# Instant with debug info
|
37
|
+
Perfetto.trace_event_instant_with_debug_info "cpu_work", "example_instant2", "key", "value"
|
38
|
+
|
39
|
+
sleep 0.1
|
40
|
+
|
41
|
+
class Foo
|
42
|
+
# Intercept instance methods
|
43
|
+
include Perfetto::Interceptor
|
44
|
+
perfetto_trace_all
|
45
|
+
|
46
|
+
def bar(a, b = 1, c: 2)
|
47
|
+
yield(a + b + c)
|
48
|
+
end
|
49
|
+
|
50
|
+
def baz(x)
|
51
|
+
puts x
|
52
|
+
sleep 0.1
|
53
|
+
end
|
54
|
+
|
55
|
+
def self.buf
|
56
|
+
puts "buf"
|
57
|
+
sleep 0.1
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
class Bar < Foo
|
62
|
+
def self.buf2
|
63
|
+
puts "buf2"
|
64
|
+
sleep 0.1
|
65
|
+
end
|
66
|
+
|
67
|
+
def say
|
68
|
+
puts "hello"
|
69
|
+
sleep 0.1
|
70
|
+
Bar.buf2
|
71
|
+
Foo.buf
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
f = Foo.new
|
76
|
+
b = Bar.new
|
77
|
+
f.bar(1, 2, c: 3) do |n|
|
78
|
+
n.times do |x|
|
79
|
+
f.baz x + n
|
80
|
+
Foo.buf
|
81
|
+
b.say
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
Perfetto.stop_tracing "example.pftrace"
|
86
|
+
|
87
|
+
# rubocop:enable Naming/MethodParameterName
|
88
|
+
# rubocop:enable Style/Documentation
|
@@ -0,0 +1,189 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
Copyright (c) 2017, The Android Open Source Project
|
179
|
+
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
181
|
+
you may not use this file except in compliance with the License.
|
182
|
+
|
183
|
+
Unless required by applicable law or agreed to in writing, software
|
184
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
185
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
186
|
+
See the License for the specific language governing permissions and
|
187
|
+
limitations under the License.
|
188
|
+
|
189
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "mkmf"
|
4
|
+
|
5
|
+
# Rubocop
|
6
|
+
# rubocop:disable Style/GlobalVars
|
7
|
+
$CXXFLAGS += " -std=c++17 -O3 -pthread"
|
8
|
+
$CFLAGS += " -std=c11 -O3 -pthread"
|
9
|
+
# rubocop:enable Style/GlobalVars
|
10
|
+
|
11
|
+
create_makefile "perfetto/perfetto_native"
|
@@ -0,0 +1,139 @@
|
|
1
|
+
#include <ruby.h>
|
2
|
+
|
3
|
+
#include "perfetto_internal.h"
|
4
|
+
|
5
|
+
/* Modules */
|
6
|
+
static VALUE rb_mPerfetto;
|
7
|
+
static VALUE rb_mFiber;
|
8
|
+
|
9
|
+
/* Methods */
|
10
|
+
|
11
|
+
static VALUE rb_perfetto_start_tracing(VALUE self, VALUE buffer_size_kb)
|
12
|
+
{
|
13
|
+
return perfetto_start_tracing(NUM2UINT(buffer_size_kb)) ? Qtrue : Qfalse;
|
14
|
+
}
|
15
|
+
|
16
|
+
static VALUE rb_perfetto_stop_tracing(VALUE self, VALUE output_file)
|
17
|
+
{
|
18
|
+
return perfetto_stop_tracing(StringValuePtr(output_file)) ? Qtrue : Qfalse;
|
19
|
+
}
|
20
|
+
|
21
|
+
static VALUE rb_perfetto_trace_event_begin(VALUE self, VALUE category, VALUE name)
|
22
|
+
{
|
23
|
+
perfetto_trace_event_begin(StringValuePtr(category), StringValuePtr(name));
|
24
|
+
return Qnil;
|
25
|
+
}
|
26
|
+
|
27
|
+
static VALUE rb_perfetto_trace_event_end(VALUE self, VALUE category)
|
28
|
+
{
|
29
|
+
perfetto_trace_event_end(StringValuePtr(category));
|
30
|
+
return Qnil;
|
31
|
+
}
|
32
|
+
|
33
|
+
static VALUE rb_perfetto_trace_counter_i64(VALUE self, VALUE category, VALUE name, VALUE value)
|
34
|
+
{
|
35
|
+
perfetto_trace_counter_i64(StringValuePtr(category), StringValuePtr(name), NUM2LL(value));
|
36
|
+
return Qnil;
|
37
|
+
}
|
38
|
+
|
39
|
+
static VALUE rb_perfetto_trace_counter_double(VALUE self, VALUE category, VALUE name, VALUE value)
|
40
|
+
{
|
41
|
+
perfetto_trace_counter_double(StringValuePtr(category), StringValuePtr(name), NUM2DBL(value));
|
42
|
+
return Qnil;
|
43
|
+
}
|
44
|
+
|
45
|
+
static VALUE rb_perfetto_trace_event_instant(VALUE self, VALUE category, VALUE name)
|
46
|
+
{
|
47
|
+
perfetto_trace_event_instant(StringValuePtr(category), StringValuePtr(name));
|
48
|
+
return Qnil;
|
49
|
+
}
|
50
|
+
|
51
|
+
static VALUE rb_perfetto_trace_event_instant_with_debug_info(VALUE self, VALUE category, VALUE name, VALUE debug_info_key, VALUE debug_info_value)
|
52
|
+
{
|
53
|
+
perfetto_trace_event_instant_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value));
|
54
|
+
return Qnil;
|
55
|
+
}
|
56
|
+
|
57
|
+
static VALUE rb_perfetto_trace_event_begin_with_debug_info(VALUE self, VALUE category, VALUE name, VALUE debug_info_key, VALUE debug_info_value)
|
58
|
+
{
|
59
|
+
perfetto_trace_event_begin_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value));
|
60
|
+
return Qnil;
|
61
|
+
}
|
62
|
+
|
63
|
+
static VALUE rb_perfetto_trace_counter(VALUE self, VALUE category, VALUE name, VALUE value)
|
64
|
+
{
|
65
|
+
if (TYPE(value) == T_FIXNUM)
|
66
|
+
{
|
67
|
+
return rb_perfetto_trace_counter_i64(self, category, name, value);
|
68
|
+
}
|
69
|
+
else if (TYPE(value) == T_FLOAT)
|
70
|
+
{
|
71
|
+
return rb_perfetto_trace_counter_double(self, category, name, value);
|
72
|
+
}
|
73
|
+
else
|
74
|
+
{
|
75
|
+
rb_raise(rb_eTypeError, "Value must be a Fixnum or Float");
|
76
|
+
}
|
77
|
+
}
|
78
|
+
|
79
|
+
/* Ruby Fiber */
|
80
|
+
static int current_fiber_object_id(void)
|
81
|
+
{
|
82
|
+
VALUE fiber = rb_funcall(rb_mFiber, rb_intern("current"), 0);
|
83
|
+
VALUE object_id = rb_funcall(fiber, rb_intern("object_id"), 0);
|
84
|
+
return NUM2LL(object_id);
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE rb_perfetto_fiber_trace_event_begin(VALUE self, VALUE category, VALUE name)
|
88
|
+
{
|
89
|
+
perfetto_fiber_trace_event_begin(StringValuePtr(category), StringValuePtr(name), current_fiber_object_id());
|
90
|
+
return Qnil;
|
91
|
+
}
|
92
|
+
|
93
|
+
static VALUE rb_perfetto_fiber_trace_event_end(VALUE self, VALUE category)
|
94
|
+
{
|
95
|
+
perfetto_fiber_trace_event_end(StringValuePtr(category), current_fiber_object_id());
|
96
|
+
return Qnil;
|
97
|
+
}
|
98
|
+
|
99
|
+
static VALUE rb_perfetto_fiber_trace_event_instant(VALUE self, VALUE category, VALUE name)
|
100
|
+
{
|
101
|
+
perfetto_fiber_trace_event_instant(StringValuePtr(category), StringValuePtr(name), current_fiber_object_id());
|
102
|
+
return Qnil;
|
103
|
+
}
|
104
|
+
|
105
|
+
static VALUE rb_perfetto_fiber_trace_event_instant_with_debug_info(VALUE self, VALUE category, VALUE name, VALUE debug_info_key, VALUE debug_info_value)
|
106
|
+
{
|
107
|
+
perfetto_fiber_trace_event_instant_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value), current_fiber_object_id());
|
108
|
+
return Qnil;
|
109
|
+
}
|
110
|
+
|
111
|
+
static VALUE rb_perfetto_fiber_trace_event_begin_with_debug_info(VALUE self, VALUE category, VALUE name, VALUE debug_info_key, VALUE debug_info_value)
|
112
|
+
{
|
113
|
+
perfetto_fiber_trace_event_begin_with_debug_info(StringValuePtr(category), StringValuePtr(name), StringValuePtr(debug_info_key), StringValuePtr(debug_info_value), current_fiber_object_id());
|
114
|
+
return Qnil;
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
void Init_perfetto_native(void)
|
119
|
+
{
|
120
|
+
rb_mPerfetto = rb_define_module("Perfetto");
|
121
|
+
rb_mFiber = rb_define_class("Fiber", rb_cObject);
|
122
|
+
|
123
|
+
rb_define_module_function(rb_mPerfetto, "start_tracing", rb_perfetto_start_tracing, 1);
|
124
|
+
rb_define_module_function(rb_mPerfetto, "stop_tracing", rb_perfetto_stop_tracing, 1);
|
125
|
+
rb_define_module_function(rb_mPerfetto, "trace_event_begin", rb_perfetto_trace_event_begin, 2);
|
126
|
+
rb_define_module_function(rb_mPerfetto, "trace_event_end", rb_perfetto_trace_event_end, 1);
|
127
|
+
rb_define_module_function(rb_mPerfetto, "trace_counter_i64", rb_perfetto_trace_counter_i64, 3);
|
128
|
+
rb_define_module_function(rb_mPerfetto, "trace_counter_double", rb_perfetto_trace_counter_double, 3);
|
129
|
+
rb_define_module_function(rb_mPerfetto, "trace_counter", rb_perfetto_trace_counter, 3);
|
130
|
+
rb_define_module_function(rb_mPerfetto, "trace_event_instant", rb_perfetto_trace_event_instant, 2);
|
131
|
+
rb_define_module_function(rb_mPerfetto, "trace_event_instant_with_debug_info", rb_perfetto_trace_event_instant_with_debug_info, 4);
|
132
|
+
rb_define_module_function(rb_mPerfetto, "trace_event_begin_with_debug_info", rb_perfetto_trace_event_begin_with_debug_info, 4);
|
133
|
+
|
134
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_begin", rb_perfetto_fiber_trace_event_begin, 2);
|
135
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_end", rb_perfetto_fiber_trace_event_end, 1);
|
136
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_instant", rb_perfetto_fiber_trace_event_instant, 2);
|
137
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_instant_with_debug_info", rb_perfetto_fiber_trace_event_instant_with_debug_info, 4);
|
138
|
+
rb_define_module_function(rb_mPerfetto, "fiber_trace_event_begin_with_debug_info", rb_perfetto_fiber_trace_event_begin_with_debug_info, 4);
|
139
|
+
}
|