pf2 0.11.3 → 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 +35 -0
- data/README.md +11 -15
- data/Rakefile +1 -0
- data/THIRD_PARTY_LICENSES.txt +59 -0
- data/ext/patches/libbacktrace/0001-Support-MACH_O_MH_BUNDLE.patch +32 -0
- data/ext/pf2/configuration.c +14 -0
- data/ext/pf2/configuration.h +3 -0
- data/ext/pf2/extconf.rb +37 -3
- data/ext/pf2/khashl.h +506 -0
- data/ext/pf2/sample.h +2 -2
- data/ext/pf2/serializer.c +115 -32
- data/ext/pf2/serializer.h +2 -0
- data/ext/pf2/session.c +247 -104
- data/ext/pf2/session.h +155 -3
- data/lib/pf2/cli.rb +1 -1
- data/lib/pf2/serve.rb +1 -2
- data/lib/pf2/version.rb +1 -1
- data/lib/pf2.rb +15 -2
- data/vendor/libbacktrace/atomic.c +1 -1
- data/vendor/libbacktrace/configure +12 -4
- data/vendor/libbacktrace/configure.ac +6 -1
- data/vendor/libbacktrace/elf.c +4 -4
- data/vendor/libbacktrace/fileline.c +35 -1
- data/vendor/libbacktrace/filetype.awk +1 -0
- metadata +4 -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,40 @@
|
|
|
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
|
+
|
|
16
|
+
## [0.12.0] - 2026-01-09
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- `Pf2.profile` now accepts the same options as `Pf2.start`.
|
|
21
|
+
- The resulting profile now has `collected_sample_count` and `dropped_sample_count` fields.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- Samples captured after the collector thread was stopped now get included in the profile.
|
|
26
|
+
- This shouldn't matter in practice (this all happens after `Pf2.stop` is called).
|
|
27
|
+
|
|
28
|
+
### Changed
|
|
29
|
+
|
|
30
|
+
- Accepted max stack depth is expanded to 1024 for Ruby (was 200) and 512 for native (was 300).
|
|
31
|
+
- This is not configurable, but should be sufficient for most use cases. Please open an issue if you need higher limits.
|
|
32
|
+
- Pf2.profile now accepts the same parameters as Pf2.start.
|
|
33
|
+
- Internal changes
|
|
34
|
+
- Updated libbacktrace to the latest version as of 2026/1/8.
|
|
35
|
+
- Tests are now much more stabilized.
|
|
36
|
+
|
|
37
|
+
|
|
3
38
|
## [0.11.3] - 2025-12-28
|
|
4
39
|
|
|
5
40
|
This version is for testing the new release process through [Trusted Publishing](https://guides.rubygems.org/trusted-publishing/). All code is identical to 0.11.2.
|
data/README.md
CHANGED
|
@@ -6,6 +6,7 @@ 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
|
+
|
|
9
10
|
Notable Capabilites
|
|
10
11
|
--------
|
|
11
12
|
|
|
@@ -96,10 +97,7 @@ Pf2 accepts the following configuration keys:
|
|
|
96
97
|
```rb
|
|
97
98
|
Pf2.start(
|
|
98
99
|
interval_ms: 9, # Integer: The sampling interval in milliseconds (default: 9)
|
|
99
|
-
time_mode: :cpu,
|
|
100
|
-
# (default: `:cpu` for SignalScheduler, `:wall` for TimerThreadScheduler)
|
|
101
|
-
threads: [th1, th2], # `Array<Thread>` | `:all`: A list of Ruby Threads to be tracked.
|
|
102
|
-
# When `:all` or unspecified, Pf2 will track all active Threads.
|
|
100
|
+
time_mode: :cpu, # `:cpu` or `:wall`: The sampling timer's mode
|
|
103
101
|
)
|
|
104
102
|
```
|
|
105
103
|
|
|
@@ -130,36 +128,33 @@ Pf2 is a _sampling profiler_. This means that Pf2 collects _samples_ of program
|
|
|
130
128
|
|
|
131
129
|
Pf2 uses the `rb_profile_thread_frames()` API for sampling. When to do so is controlled by _Schedulers_, described in the following section.
|
|
132
130
|
|
|
133
|
-
###
|
|
131
|
+
### Scheduling
|
|
134
132
|
|
|
135
|
-
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).
|
|
136
134
|
|
|
137
|
-
####
|
|
135
|
+
#### Signal-based scheduling
|
|
138
136
|
|
|
139
|
-
|
|
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.
|
|
140
138
|
|
|
141
|
-
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.
|
|
142
140
|
|
|
143
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.
|
|
144
142
|
|
|
145
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`).
|
|
146
144
|
|
|
147
|
-
####
|
|
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.
|
|
148
148
|
|
|
149
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.
|
|
150
150
|
|
|
151
151
|
This scheduler is wall-time only, and does not support CPU-time based profiling.
|
|
152
152
|
|
|
153
|
-
#### macOS Support
|
|
154
|
-
|
|
155
|
-
On platforms where `timer_create()` is not supported (namely macOS), Pf2 falls back to `setitimer()`.
|
|
156
|
-
|
|
157
153
|
|
|
158
154
|
Wishlist
|
|
159
155
|
--------
|
|
160
156
|
|
|
161
157
|
- [Flame Scopes](https://www.brendangregg.com/flamescope.html)
|
|
162
|
-
- More unit/e2e tests
|
|
163
158
|
- more
|
|
164
159
|
|
|
165
160
|
Development
|
|
@@ -172,3 +167,4 @@ License
|
|
|
172
167
|
--------
|
|
173
168
|
|
|
174
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.
|
data/Rakefile
CHANGED
|
@@ -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.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
From 4cd047583bc48ad0617fb6c036174de062573e68 Mon Sep 17 00:00:00 2001
|
|
2
|
+
From: Daisuke Aritomo <osyoyu@osyoyu.com>
|
|
3
|
+
Date: Wed, 7 Jan 2026 02:50:54 +0900
|
|
4
|
+
Subject: [PATCH] Support MACH_O_MH_BUNDLE
|
|
5
|
+
|
|
6
|
+
---
|
|
7
|
+
macho.c | 2 ++
|
|
8
|
+
1 file changed, 2 insertions(+)
|
|
9
|
+
|
|
10
|
+
diff --git a/macho.c b/macho.c
|
|
11
|
+
index 9f8738d..5ea07ae 100644
|
|
12
|
+
--- a/macho.c
|
|
13
|
+
+++ b/macho.c
|
|
14
|
+
@@ -92,6 +92,7 @@ struct macho_header_fat
|
|
15
|
+
|
|
16
|
+
#define MACH_O_MH_EXECUTE 0x02
|
|
17
|
+
#define MACH_O_MH_DYLIB 0x06
|
|
18
|
+
+#define MACH_O_MH_BUNDLE 0x08
|
|
19
|
+
#define MACH_O_MH_DSYM 0x0a
|
|
20
|
+
|
|
21
|
+
/* A component of a fat file. A fat file starts with a
|
|
22
|
+
@@ -1062,6 +1063,7 @@ macho_add (struct backtrace_state *state, const char *filename, int descriptor,
|
|
23
|
+
{
|
|
24
|
+
case MACH_O_MH_EXECUTE:
|
|
25
|
+
case MACH_O_MH_DYLIB:
|
|
26
|
+
+ case MACH_O_MH_BUNDLE:
|
|
27
|
+
case MACH_O_MH_DSYM:
|
|
28
|
+
break;
|
|
29
|
+
default:
|
|
30
|
+
--
|
|
31
|
+
2.39.5 (Apple Git-154)
|
|
32
|
+
|
data/ext/pf2/configuration.c
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
#include <ruby.h>
|
|
2
2
|
#include <stdlib.h>
|
|
3
|
+
#include <stdbool.h>
|
|
3
4
|
|
|
4
5
|
#include "configuration.h"
|
|
5
6
|
|
|
6
7
|
static int extract_interval_ms(VALUE options_hash);
|
|
7
8
|
static enum pf2_time_mode extract_time_mode(VALUE options_hash);
|
|
9
|
+
static bool extract__test_no_install_timer(VALUE options_hash);
|
|
8
10
|
|
|
9
11
|
struct pf2_configuration *
|
|
10
12
|
pf2_configuration_new_from_options_hash(VALUE options_hash)
|
|
@@ -16,6 +18,7 @@ pf2_configuration_new_from_options_hash(VALUE options_hash)
|
|
|
16
18
|
|
|
17
19
|
config->interval_ms = extract_interval_ms(options_hash);
|
|
18
20
|
config->time_mode = extract_time_mode(options_hash);
|
|
21
|
+
config->_test_no_install_timer = extract__test_no_install_timer(options_hash);
|
|
19
22
|
|
|
20
23
|
return config;
|
|
21
24
|
}
|
|
@@ -57,6 +60,17 @@ extract_time_mode(VALUE options_hash)
|
|
|
57
60
|
}
|
|
58
61
|
}
|
|
59
62
|
|
|
63
|
+
static bool
|
|
64
|
+
extract__test_no_install_timer(VALUE options_hash)
|
|
65
|
+
{
|
|
66
|
+
if (options_hash == Qnil) {
|
|
67
|
+
return PF2_DEFAULT__TEST_NO_INSTALL_TIMER;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
VALUE _test_no_install_timer = rb_hash_aref(options_hash, ID2SYM(rb_intern("_test_no_install_timer")));
|
|
71
|
+
return RTEST(_test_no_install_timer);
|
|
72
|
+
}
|
|
73
|
+
|
|
60
74
|
void
|
|
61
75
|
pf2_configuration_free(struct pf2_configuration *config)
|
|
62
76
|
{
|
data/ext/pf2/configuration.h
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
#define PF2_CONFIGURATION_H
|
|
3
3
|
|
|
4
4
|
#include <ruby.h>
|
|
5
|
+
#include <stdbool.h>
|
|
5
6
|
|
|
6
7
|
enum pf2_time_mode {
|
|
7
8
|
PF2_TIME_MODE_CPU_TIME,
|
|
@@ -11,10 +12,12 @@ enum pf2_time_mode {
|
|
|
11
12
|
struct pf2_configuration {
|
|
12
13
|
int interval_ms;
|
|
13
14
|
enum pf2_time_mode time_mode;
|
|
15
|
+
bool _test_no_install_timer; // for testing only
|
|
14
16
|
};
|
|
15
17
|
|
|
16
18
|
#define PF2_DEFAULT_INTERVAL_MS 9
|
|
17
19
|
#define PF2_DEFAULT_TIME_MODE PF2_TIME_MODE_CPU_TIME
|
|
20
|
+
#define PF2_DEFAULT__TEST_NO_INSTALL_TIMER false
|
|
18
21
|
|
|
19
22
|
struct pf2_configuration *pf2_configuration_new_from_options_hash(VALUE options_hash);
|
|
20
23
|
void pf2_configuration_free(struct pf2_configuration *config);
|
data/ext/pf2/extconf.rb
CHANGED
|
@@ -1,10 +1,44 @@
|
|
|
1
1
|
require 'mkmf'
|
|
2
2
|
require 'mini_portile2'
|
|
3
|
+
require 'fileutils'
|
|
4
|
+
require 'optparse'
|
|
5
|
+
|
|
6
|
+
gem_root = File.expand_path(File.join(File.dirname(__FILE__), '..', '..'))
|
|
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)
|
|
3
25
|
|
|
4
26
|
libbacktrace = MiniPortile.new('libbacktrace', '1.0.0')
|
|
5
|
-
libbacktrace.source_directory = File.
|
|
27
|
+
libbacktrace.source_directory = File.join(gem_root, 'vendor', 'libbacktrace')
|
|
28
|
+
libbacktrace.patch_files = Dir.glob(File.join(gem_root, 'ext', 'patches', 'libbacktrace', '*.patch'))
|
|
6
29
|
libbacktrace.configure_options << 'CFLAGS=-fPIC'
|
|
7
|
-
|
|
30
|
+
|
|
31
|
+
# Expand 'libbacktrace.cook' to call #patch on source_directory files
|
|
32
|
+
libbacktrace.prepare_build_directory
|
|
33
|
+
# Added: Copy source to build_directory
|
|
34
|
+
build_directory = libbacktrace.send(:work_path)
|
|
35
|
+
FileUtils.cp_r(File.join(libbacktrace.source_directory, '.'), build_directory)
|
|
36
|
+
libbacktrace.patch
|
|
37
|
+
libbacktrace.configure unless libbacktrace.configured?
|
|
38
|
+
libbacktrace.compile
|
|
39
|
+
libbacktrace.install unless libbacktrace.installed?
|
|
40
|
+
# END expand 'libbacktrace.cook'
|
|
41
|
+
|
|
8
42
|
libbacktrace.mkmf_config
|
|
9
43
|
|
|
10
44
|
if !have_func('backtrace_full', 'backtrace.h')
|
|
@@ -13,7 +47,7 @@ end
|
|
|
13
47
|
|
|
14
48
|
append_ldflags('-lrt') # for timer_create
|
|
15
49
|
append_cflags('-fvisibility=hidden')
|
|
16
|
-
append_cflags('-DPF2_DEBUG') if
|
|
50
|
+
append_cflags('-DPF2_DEBUG') if options[:debug]
|
|
17
51
|
|
|
18
52
|
# Check for timer functions
|
|
19
53
|
have_timer_create = have_func('timer_create')
|