pf2 0.12.0 → 0.13.0
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/CHANGELOG.md +13 -0
- data/README.md +10 -16
- data/THIRD_PARTY_LICENSES.txt +59 -0
- data/ext/pf2/extconf.rb +20 -1
- data/ext/pf2/khashl.h +506 -0
- data/ext/pf2/serializer.c +108 -35
- data/ext/pf2/session.c +163 -38
- data/ext/pf2/session.h +152 -3
- data/lib/pf2/serve.rb +1 -2
- data/lib/pf2/version.rb +1 -1
- data/lib/pf2.rb +5 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 84ea10eb9b861a910a1190ea017ad276ad593bc460c01687aabce8128392e35a
|
|
4
|
+
data.tar.gz: abd41b0b0ca74ebbcfeb1a202b75a4eec52f7c48b5b87e80d6e3052516304415
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7f17ba3e89269c97398559f97b87033a598e590b4c20efe341b76ce4841a47080a75c6324cce0881f83b6d68a336892ccd7ca593b953f5963097cf99b0a065ab
|
|
7
|
+
data.tar.gz: d09630c20fbddb0e5b072c20cf97ad0af0f541db7fa4265090427a0a64af0bf4b565923fe9e988438a623e060c902ba92243b75d6b0f257df57b11674d8d4d1b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
## [Unreleased]
|
|
2
2
|
|
|
3
|
+
## [0.13.0] - 2026-01-18
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- Pf2 should now have a dramatically lower memory footprint.
|
|
8
|
+
- Samples are now stored in a compact hashmap internally.
|
|
9
|
+
- See https://github.com/osyoyu/pf2/pull/85 for details.
|
|
10
|
+
|
|
11
|
+
### Fixed
|
|
12
|
+
|
|
13
|
+
- `pf2 serve` command now properly works. (Thanks @hanazuki)
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## [0.12.0] - 2026-01-09
|
|
4
17
|
|
|
5
18
|
### Added
|
data/README.md
CHANGED
|
@@ -6,7 +6,6 @@ A experimental sampling-based profiler for Ruby 3.3+.
|
|
|
6
6
|
- GitHub: https://github.com/osyoyu/pf2
|
|
7
7
|
- Documentation: https://osyoyu.github.io/pf2/
|
|
8
8
|
|
|
9
|
-
NOTE: This README contains some outdated information!
|
|
10
9
|
|
|
11
10
|
Notable Capabilites
|
|
12
11
|
--------
|
|
@@ -98,10 +97,7 @@ Pf2 accepts the following configuration keys:
|
|
|
98
97
|
```rb
|
|
99
98
|
Pf2.start(
|
|
100
99
|
interval_ms: 9, # Integer: The sampling interval in milliseconds (default: 9)
|
|
101
|
-
time_mode: :cpu,
|
|
102
|
-
# (default: `:cpu` for SignalScheduler, `:wall` for TimerThreadScheduler)
|
|
103
|
-
threads: [th1, th2], # `Array<Thread>` | `:all`: A list of Ruby Threads to be tracked.
|
|
104
|
-
# When `:all` or unspecified, Pf2 will track all active Threads.
|
|
100
|
+
time_mode: :cpu, # `:cpu` or `:wall`: The sampling timer's mode
|
|
105
101
|
)
|
|
106
102
|
```
|
|
107
103
|
|
|
@@ -132,36 +128,33 @@ Pf2 is a _sampling profiler_. This means that Pf2 collects _samples_ of program
|
|
|
132
128
|
|
|
133
129
|
Pf2 uses the `rb_profile_thread_frames()` API for sampling. When to do so is controlled by _Schedulers_, described in the following section.
|
|
134
130
|
|
|
135
|
-
###
|
|
131
|
+
### Scheduling
|
|
136
132
|
|
|
137
|
-
Schedulers determine when to execute sample collection, based on configuration (time mode and interval).
|
|
133
|
+
Schedulers determine when to execute sample collection, based on configuration (time mode and interval).
|
|
138
134
|
|
|
139
|
-
####
|
|
135
|
+
#### Signal-based scheduling
|
|
140
136
|
|
|
141
|
-
|
|
137
|
+
Pf2 schedules sample collection using POSIX timers. It creates a POSIX timer using `timer_create(3)` where available, or otherwise `setitimer(3)`. This leaves the actual time-keeping to the operating system kernel, which is capable of tracking accurate per-thread CPU time usage.
|
|
142
138
|
|
|
143
|
-
When the specified interval has arrived (the timer has _expired_), the OS delivers us a SIGPROF signal.
|
|
139
|
+
When the specified interval has arrived (the timer has _expired_), the OS delivers us a SIGPROF signal.
|
|
144
140
|
|
|
145
141
|
Signals are directed to Ruby Threads' underlying pthread, effectively "pausing" the Thread's activity. This routing is done using `SIGEV_THREAD_ID`, which is a Linux-only feature. Sample collection is done in the signal handler, which is expected to be more _accurate_, capturing the paused Thread's activity.
|
|
146
142
|
|
|
147
143
|
This scheduler heavily relies on Ruby's 1:N Thread model (1 Ruby Threads is strongly tied to a native pthread). It will not work properly in MaNy (`RUBY_MN_THREADS=1`).
|
|
148
144
|
|
|
149
|
-
####
|
|
145
|
+
#### ~~Timer-thread based scheduling~~
|
|
146
|
+
|
|
147
|
+
Note: Timer thread-based scheduling has been removed in v0.10.0, when the profiling backend has been rewritten in C. This may come back in the future if needed.
|
|
150
148
|
|
|
151
149
|
Another scheduler is the `TimerThreadScheduler`, which maintains a time-keeping thread by itself. A new native thread (pthread on Linux/macOS) will be created, and an infinite loop will be run inside. After `sleep(2)`-ing for the specified interval time, sampling will be queued using Ruby's Postponed Job API.
|
|
152
150
|
|
|
153
151
|
This scheduler is wall-time only, and does not support CPU-time based profiling.
|
|
154
152
|
|
|
155
|
-
#### macOS Support
|
|
156
|
-
|
|
157
|
-
On platforms where `timer_create()` is not supported (namely macOS), Pf2 falls back to `setitimer()`.
|
|
158
|
-
|
|
159
153
|
|
|
160
154
|
Wishlist
|
|
161
155
|
--------
|
|
162
156
|
|
|
163
157
|
- [Flame Scopes](https://www.brendangregg.com/flamescope.html)
|
|
164
|
-
- More unit/e2e tests
|
|
165
158
|
- more
|
|
166
159
|
|
|
167
160
|
Development
|
|
@@ -174,3 +167,4 @@ License
|
|
|
174
167
|
--------
|
|
175
168
|
|
|
176
169
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
170
|
+
See [LICENSE.txt](/LICENSE.txt) and [THIRD_PARTY_LICENSES.txt](/THIRD_PARTY_LICENSES.txt) for details.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
This project includes the following third-party software:
|
|
2
|
+
|
|
3
|
+
## khashl
|
|
4
|
+
|
|
5
|
+
The MIT License
|
|
6
|
+
|
|
7
|
+
Copyright (c) 2019- by Attractive Chaos <attractor@live.co.uk>
|
|
8
|
+
|
|
9
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
10
|
+
a copy of this software and associated documentation files (the
|
|
11
|
+
"Software"), to deal in the Software without restriction, including
|
|
12
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
13
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
14
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
15
|
+
the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be
|
|
18
|
+
included in all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
22
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
24
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
25
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
26
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
## libbacktrace
|
|
30
|
+
|
|
31
|
+
Copyright (C) 2012-2016 Free Software Foundation, Inc.
|
|
32
|
+
|
|
33
|
+
Redistribution and use in source and binary forms, with or without
|
|
34
|
+
modification, are permitted provided that the following conditions are
|
|
35
|
+
met:
|
|
36
|
+
|
|
37
|
+
(1) Redistributions of source code must retain the above copyright
|
|
38
|
+
notice, this list of conditions and the following disclaimer.
|
|
39
|
+
|
|
40
|
+
(2) Redistributions in binary form must reproduce the above copyright
|
|
41
|
+
notice, this list of conditions and the following disclaimer in
|
|
42
|
+
the documentation and/or other materials provided with the
|
|
43
|
+
distribution.
|
|
44
|
+
|
|
45
|
+
(3) The name of the author may not be used to
|
|
46
|
+
endorse or promote products derived from this software without
|
|
47
|
+
specific prior written permission.
|
|
48
|
+
|
|
49
|
+
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
50
|
+
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
51
|
+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
52
|
+
DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
|
|
53
|
+
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
54
|
+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
55
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
56
|
+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
57
|
+
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
58
|
+
IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
59
|
+
POSSIBILITY OF SUCH DAMAGE.
|
data/ext/pf2/extconf.rb
CHANGED
|
@@ -1,9 +1,28 @@
|
|
|
1
1
|
require 'mkmf'
|
|
2
2
|
require 'mini_portile2'
|
|
3
3
|
require 'fileutils'
|
|
4
|
+
require 'optparse'
|
|
4
5
|
|
|
5
6
|
gem_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
|
6
7
|
|
|
8
|
+
options = {
|
|
9
|
+
debug: ENV['PF2_DEBUG'] == '1',
|
|
10
|
+
}
|
|
11
|
+
option_parser = OptionParser.new do |opts|
|
|
12
|
+
opts.on('--debug[=BOOL]') do |debug|
|
|
13
|
+
options[:debug] =
|
|
14
|
+
case debug
|
|
15
|
+
when nil, "true"
|
|
16
|
+
true
|
|
17
|
+
when "false"
|
|
18
|
+
false
|
|
19
|
+
else
|
|
20
|
+
raise OptionParser::InvalidArgument, "Expected true or false for --debug"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
option_parser.parse!(ARGV)
|
|
25
|
+
|
|
7
26
|
libbacktrace = MiniPortile.new('libbacktrace', '1.0.0')
|
|
8
27
|
libbacktrace.source_directory = File.join(gem_root, 'vendor', 'libbacktrace')
|
|
9
28
|
libbacktrace.patch_files = Dir.glob(File.join(gem_root, 'ext', 'patches', 'libbacktrace', '*.patch'))
|
|
@@ -28,7 +47,7 @@ end
|
|
|
28
47
|
|
|
29
48
|
append_ldflags('-lrt') # for timer_create
|
|
30
49
|
append_cflags('-fvisibility=hidden')
|
|
31
|
-
append_cflags('-DPF2_DEBUG') if
|
|
50
|
+
append_cflags('-DPF2_DEBUG') if options[:debug]
|
|
32
51
|
|
|
33
52
|
# Check for timer functions
|
|
34
53
|
have_timer_create = have_func('timer_create')
|