duel 0.1.3 → 0.1.4
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 +41 -1
- data/docs/ci.md +6 -3
- data/docs/how-it-works.md +3 -1
- data/docs/troubleshooting.md +14 -0
- data/lib/duel/context.rb +1 -1
- data/lib/duel/message.rb +25 -0
- data/lib/duel/native.rb +37 -10
- data/lib/duel/runner.rb +17 -8
- data/lib/duel/templates/perf.yml.erb +6 -3
- data/lib/duel/version.rb +1 -1
- data/lib/duel/worker.rb +33 -13
- data/sig/duel/message.rbs +11 -0
- data/sig/duel/native.rbs +11 -3
- data/sig/duel/runner.rbs +4 -0
- data/sig/duel/worker.rbs +11 -3
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15e688ef3d4a4d3c89f10bfef8621961c6025933456c845c3cdca1d048b3d2dd
|
|
4
|
+
data.tar.gz: 71d90787a6a0993a5161acd2f7e9594498bc2e6e297d07d3970acd86c07471c5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3275eb44aeec1133c699604b391c716a989242e657acd51fb48fb2ebb8aabad55f658b09151e5c07250a07f4d9d1e5e7b201bbd47f6e760b4b30a9516a6681f7
|
|
7
|
+
data.tar.gz: 795438481087f53a0cb8faee6a61155d787ef5d808c079f2a222e1f0b2a12d957526080103d7d144990f096f1482dcd60bc27c9321f252f619a005a0eb4d2a3a
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,45 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.1.4] - 2026-11-06
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- In json's own repository, every baseline worker loaded the
|
|
15
|
+
candidate's json, extensions and all, before the baseline's, as the
|
|
16
|
+
worker loaded json for its own messages to the runner before it
|
|
17
|
+
loaded the version. A worker and the runner now send each other
|
|
18
|
+
their messages marshaled, so a worker loads nothing a version could
|
|
19
|
+
be before it loads the version.
|
|
20
|
+
- A worker loaded etc, a gem, before it loaded the version it
|
|
21
|
+
measures, for the page size that `/proc/self/statm` counts resident
|
|
22
|
+
memory in. In etc's own repository, a worker would load the
|
|
23
|
+
bundle's etc before the version's own. A worker now reads resident
|
|
24
|
+
memory, in kB, from `/proc/self/status` (VmRSS), and loads no etc.
|
|
25
|
+
- A worker loaded fiddle, a gem, as Duel loaded, before it loaded the
|
|
26
|
+
version it measures, so in fiddle's own repository, a worker would
|
|
27
|
+
load the bundle's fiddle before the version's own. Duel now loads
|
|
28
|
+
fiddle as it first calls into the operating system, once the
|
|
29
|
+
version has loaded (and on JRuby, which Duel makes no such calls
|
|
30
|
+
on, never).
|
|
31
|
+
- A worker that loaded a native extension twice, the candidate's that
|
|
32
|
+
something required before the worker loaded the version and then the
|
|
33
|
+
version's own over it, went unnoticed, as loading the version took
|
|
34
|
+
the candidate's off `$LOADED_FEATURES`. Duel now fails, and names the
|
|
35
|
+
extension and both of its files.
|
|
36
|
+
- On JRuby, peak memory came out short, by tens of megabytes at times,
|
|
37
|
+
and a benchmark that needed more memory could pass. A peak is
|
|
38
|
+
measured above what's in use after the garbage is collected, but
|
|
39
|
+
JRuby's `GC.start` collects nothing, so the garbage left from before
|
|
40
|
+
stayed in use until the benchmark's own objects made room. Duel now
|
|
41
|
+
collects it with the JVM's own call (`java.lang.System.gc`).
|
|
42
|
+
- Where a repository's history was replaced, so the commit that
|
|
43
|
+
`duel/passed/BRANCH` marks has no history in common with a push, the
|
|
44
|
+
Mark the commit passed job failed, as GitHub can't compare the two.
|
|
45
|
+
It now moves the branch to the push, as it does where history was
|
|
46
|
+
rewritten. Update the job in `.github/workflows/perf.yml` to pick
|
|
47
|
+
this up.
|
|
48
|
+
|
|
10
49
|
## [0.1.3] - 2026-11-04
|
|
11
50
|
|
|
12
51
|
### Added
|
|
@@ -488,7 +527,8 @@ needs Ruby 3.4 or later (or JRuby 10, or TruffleRuby 40).
|
|
|
488
527
|
Anything marked `@api private`, in lib/ and sig/, may change in any
|
|
489
528
|
release.
|
|
490
529
|
|
|
491
|
-
[Unreleased]: https://github.com/sferik/duel-ruby/compare/v0.1.
|
|
530
|
+
[Unreleased]: https://github.com/sferik/duel-ruby/compare/v0.1.4...HEAD
|
|
531
|
+
[0.1.4]: https://github.com/sferik/duel-ruby/compare/v0.1.3...v0.1.4
|
|
492
532
|
[0.1.3]: https://github.com/sferik/duel-ruby/compare/v0.1.2...v0.1.3
|
|
493
533
|
[0.1.2]: https://github.com/sferik/duel-ruby/compare/v0.1.1...v0.1.2
|
|
494
534
|
[0.1.1]: https://github.com/sferik/duel-ruby/compare/v0.1.0...v0.1.1
|
data/docs/ci.md
CHANGED
|
@@ -204,12 +204,15 @@ jobs:
|
|
|
204
204
|
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null || blocked
|
|
205
205
|
exit 0
|
|
206
206
|
fi
|
|
207
|
-
compared=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$at" --jq .status)
|
|
207
|
+
compared=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$at" --jq .status 2>&1) || case "$compared" in
|
|
208
|
+
# (GitHub can't compare commits with no history in common.)
|
|
209
|
+
*"No common ancestor"*) compared=unrelated ;;
|
|
210
|
+
esac
|
|
208
211
|
case "$compared" in
|
|
209
212
|
# (A newer push's run moved it, or this one's did, run again.)
|
|
210
213
|
ahead | identical) ;;
|
|
211
|
-
# (History rewritten, a force push's, say: moved anyway.)
|
|
212
|
-
diverged | behind) gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" -F force=true > /dev/null ;;
|
|
214
|
+
# (History rewritten, a force push's, say, or replaced: moved anyway.)
|
|
215
|
+
diverged | behind | unrelated) gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" -F force=true > /dev/null ;;
|
|
213
216
|
*) echo "::error::Couldn't compare $BRANCH with this push: $compared" && exit 1 ;;
|
|
214
217
|
esac
|
|
215
218
|
|
data/docs/how-it-works.md
CHANGED
|
@@ -234,5 +234,7 @@ Neither has an allocation count, an instruction count, or profiles.
|
|
|
234
234
|
TruffleRuby has peak memory only on Linux. JRuby measures peak memory in
|
|
235
235
|
the JVM's heap in use, on any operating system, because the JVM takes
|
|
236
236
|
memory for its heap ahead of time, so resident memory barely moves as
|
|
237
|
-
a benchmark's objects fill it.
|
|
237
|
+
a benchmark's objects fill it. The peak starts from the heap in use
|
|
238
|
+
after a collection that Duel asks the JVM for, as JRuby's `GC.start`
|
|
239
|
+
collects nothing. StackProf runs on CRuby only: Duel
|
|
238
240
|
doesn't use it on JRuby or TruffleRuby, even where it's installed.
|
data/docs/troubleshooting.md
CHANGED
|
@@ -72,6 +72,20 @@ happens, Duel stops and tells you to set `c.build` to a command that
|
|
|
72
72
|
builds each version, such as `c.build = "make"`. See
|
|
73
73
|
[Prepare each version](configuration.md#prepare-each-version).
|
|
74
74
|
|
|
75
|
+
## Duel says a version loaded an extension twice
|
|
76
|
+
|
|
77
|
+
A worker loads `.duel.rb` and your plugins before it loads its version.
|
|
78
|
+
If one of them requires your library, or a gem that requires it, the
|
|
79
|
+
worker finds the library wherever the load path leads, such as the
|
|
80
|
+
candidate's `lib/` or an installed release. Duel then loads the
|
|
81
|
+
version's own build, but a native extension can't be unloaded, so both
|
|
82
|
+
stay loaded, and the comparison wouldn't be of the version's code alone.
|
|
83
|
+
Duel stops and names the extension and both of its files.
|
|
84
|
+
|
|
85
|
+
To fix it, require what loads your library in a block that runs once the
|
|
86
|
+
version has loaded, such as `c.in_worker`, not at the top of `.duel.rb`
|
|
87
|
+
or as a plugin loads.
|
|
88
|
+
|
|
75
89
|
## Duel says that the versions' paths differ in length
|
|
76
90
|
|
|
77
91
|
The baseline's path is as long and as deep as your project's, because
|
data/lib/duel/context.rb
CHANGED
data/lib/duel/message.rb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Duel
|
|
4
|
+
# What the runner and a worker say to each other, over the worker's
|
|
5
|
+
# socket: plain Hashes, Arrays, Strings, numbers, true, false and nil,
|
|
6
|
+
# marshaled. Not JSON: the worker would load json before it loads the
|
|
7
|
+
# version it measures, and in json's own repository, every baseline
|
|
8
|
+
# worker would load the candidate's json first, and the baseline's
|
|
9
|
+
# over it. Marshal is Ruby's own, with nothing to load (so a version's
|
|
10
|
+
# code is the first of it the worker loads), and it keeps a String's
|
|
11
|
+
# encoding. (Both ends are Duel's own processes, and the socket is in
|
|
12
|
+
# the run's own directory.)
|
|
13
|
+
# @api private
|
|
14
|
+
module Message
|
|
15
|
+
# Sends +message+ over +io+.
|
|
16
|
+
def self.write(io, message) = io.write(Marshal.dump(message))
|
|
17
|
+
|
|
18
|
+
# The next message over +io+, or nil once the other end has closed it.
|
|
19
|
+
def self.read(io)
|
|
20
|
+
Marshal.load(io)
|
|
21
|
+
rescue EOFError
|
|
22
|
+
nil
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
data/lib/duel/native.rb
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "etc"
|
|
4
|
-
require "fiddle"
|
|
5
3
|
require "rbconfig"
|
|
6
4
|
|
|
7
5
|
module Duel
|
|
@@ -16,9 +14,19 @@ module Duel
|
|
|
16
14
|
CPU = RbConfig::CONFIG["host_cpu"]
|
|
17
15
|
UINT64 = 8 # bytes, the size of every count read
|
|
18
16
|
|
|
17
|
+
# Loads Fiddle, as the first C function is made (see .function): not
|
|
18
|
+
# as Duel loads, which in a worker is before its version (in fiddle's
|
|
19
|
+
# own repository, fiddle).
|
|
20
|
+
# mutant:disable -- the tests' process has Fiddle loaded from the start,
|
|
21
|
+
# so a require changes nothing there: WorkerTest's
|
|
22
|
+
# test_loads_no_gem_a_version_could_be_before_the_version checks it, in
|
|
23
|
+
# a process of its own
|
|
24
|
+
def self.require_fiddle = require("fiddle")
|
|
25
|
+
|
|
19
26
|
# A C function of the process's own libraries, by name, taking and
|
|
20
27
|
# returning Fiddle types (:INT, :LONG, :VOIDP...).
|
|
21
28
|
def self.function(name, args, returns)
|
|
29
|
+
require_fiddle
|
|
22
30
|
Fiddle::Function.new(Fiddle.dlopen(nil)[name], args.map { |type| Fiddle.const_get(:"TYPE_#{type}") },
|
|
23
31
|
Fiddle.const_get(:"TYPE_#{returns}"))
|
|
24
32
|
end
|
|
@@ -145,23 +153,37 @@ module Duel
|
|
|
145
153
|
|
|
146
154
|
# This process's resident memory in bytes, or nil where it can't tell.
|
|
147
155
|
module Memory
|
|
148
|
-
|
|
149
|
-
#
|
|
150
|
-
|
|
156
|
+
# (Its VmRSS line, in kB: no page size to know, as /proc/self/statm's
|
|
157
|
+
# pages need, which would take Etc, a gem a worker would load before
|
|
158
|
+
# its version.)
|
|
159
|
+
STATUS = "/proc/self/status"
|
|
160
|
+
# macOS's counter, which reads resident memory there, or nil: opened
|
|
161
|
+
# as resident memory is first read, as opening it loads Fiddle.
|
|
162
|
+
# mutant:disable -- kept only so as not to open it again: it's the
|
|
163
|
+
# same counter however often it's opened
|
|
164
|
+
def self.macos_counter
|
|
165
|
+
return @macos if defined?(@macos)
|
|
166
|
+
|
|
167
|
+
# (Never false: Steep doesn't see that false || nil is nil.)
|
|
168
|
+
@macos = (FIDDLE && MacOS.open) || nil #: MacOS?
|
|
169
|
+
end
|
|
151
170
|
|
|
152
171
|
# From /proc (Linux), else from macOS's counter, else nil.
|
|
153
|
-
def self.resident(
|
|
154
|
-
return macos&.resident unless File.readable?(
|
|
172
|
+
def self.resident(status: STATUS, macos: macos_counter)
|
|
173
|
+
return macos&.resident unless File.readable?(status)
|
|
155
174
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
Integer(File.read(statm).split.fetch(1)) * page_size
|
|
175
|
+
kb = File.read(status)[/^VmRSS:\s+(\d+) kB$/, 1] #: String
|
|
176
|
+
Integer(kb) * 1024
|
|
159
177
|
end
|
|
160
178
|
|
|
161
179
|
# The memory a benchmark's peak is measured in (see MemorySample),
|
|
162
180
|
# in bytes, or nil where it can't tell: resident memory, but on
|
|
163
181
|
# JRuby, the JVM's heap in use.
|
|
164
182
|
def self.used = resident
|
|
183
|
+
|
|
184
|
+
# Collects every object that's garbage, so that what's in use (see
|
|
185
|
+
# .used) is what's live: a full collection, swept at once.
|
|
186
|
+
def self.collect = GC.start(full_mark: true, immediate_sweep: true)
|
|
165
187
|
end
|
|
166
188
|
|
|
167
189
|
# simplecov:disable JRuby's heap is the JVM's (JRuby's test run covers
|
|
@@ -175,6 +197,11 @@ module Duel
|
|
|
175
197
|
HEAP = java.lang.management.ManagementFactory.getMemoryMXBean
|
|
176
198
|
|
|
177
199
|
def self.used = HEAP.getHeapMemoryUsage.getUsed
|
|
200
|
+
|
|
201
|
+
# JRuby's GC.start collects nothing. The JVM's own call does:
|
|
202
|
+
# without it, a peak was measured above garbage that the benchmark's
|
|
203
|
+
# objects then made room for, and came out tens of megabytes short.
|
|
204
|
+
def self.collect = java.lang.System.gc
|
|
178
205
|
end
|
|
179
206
|
end
|
|
180
207
|
# simplecov:enable
|
data/lib/duel/runner.rb
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require "fileutils"
|
|
4
|
-
require "json"
|
|
5
4
|
require "rbconfig"
|
|
6
5
|
require "socket"
|
|
7
6
|
require "tmpdir"
|
|
@@ -9,6 +8,7 @@ require_relative "../duel"
|
|
|
9
8
|
require_relative "stats"
|
|
10
9
|
require_relative "profile"
|
|
11
10
|
require_relative "across"
|
|
11
|
+
require_relative "message"
|
|
12
12
|
require_relative "resource"
|
|
13
13
|
require_relative "rubies"
|
|
14
14
|
require_relative "process_sample"
|
|
@@ -85,9 +85,10 @@ module Duel
|
|
|
85
85
|
attr_reader :label, :benchmarks, :metrics, :memory, :profiler, :yjit
|
|
86
86
|
|
|
87
87
|
# The Ruby it runs on (RUBY_DESCRIPTION), the native extensions it
|
|
88
|
-
# loaded (see Worker.extensions),
|
|
89
|
-
# installed in (see
|
|
90
|
-
|
|
88
|
+
# loaded (see Worker.extensions), those it loaded twice (see
|
|
89
|
+
# Worker.twice), and the directories gems are installed in (see
|
|
90
|
+
# Worker.gem_dirs).
|
|
91
|
+
attr_reader :description, :extensions, :twice, :gem_dirs
|
|
91
92
|
|
|
92
93
|
# Where a worker on +ruby+ loads Duel from, ahead of anything else
|
|
93
94
|
# (a version's own bundle, which may not have Duel, or an older one):
|
|
@@ -128,13 +129,15 @@ module Duel
|
|
|
128
129
|
@yjit = hello.fetch("yjit")
|
|
129
130
|
@description = hello.fetch("ruby")
|
|
130
131
|
@extensions = hello.fetch("extensions")
|
|
132
|
+
@twice = hello.fetch("twice")
|
|
131
133
|
@gem_dirs = hello.fetch("gem_dirs")
|
|
132
134
|
end
|
|
133
135
|
|
|
134
136
|
# Sends a request, and returns the reply, or raises Failed with its
|
|
135
137
|
# error.
|
|
136
138
|
def request(op, name, **args)
|
|
137
|
-
|
|
139
|
+
# (By name: +args+ come by keyword, as Symbols.)
|
|
140
|
+
Message.write(@socket, {"op" => op, "name" => name, **args.transform_keys(&:to_s)})
|
|
138
141
|
reply = read
|
|
139
142
|
raise Failed, "#{@label}: #{reply.fetch("error")}\n #{reply.fetch("backtrace").join("\n ")}" if reply.key?("error")
|
|
140
143
|
|
|
@@ -185,8 +188,7 @@ module Duel
|
|
|
185
188
|
|
|
186
189
|
def read
|
|
187
190
|
hung("answer") unless @socket.wait_readable(@timeout)
|
|
188
|
-
|
|
189
|
-
JSON.parse(line)
|
|
191
|
+
Message.read(@socket) or raise Failed, "#{@label} worker exited"
|
|
190
192
|
end
|
|
191
193
|
|
|
192
194
|
# Kills a worker that didn't +what+ within the timeout, and fails.
|
|
@@ -366,10 +368,17 @@ module Duel
|
|
|
366
368
|
# be of its code. An installed gem's extension (in the directories
|
|
367
369
|
# gems are installed in, by the worker that loaded it) is in no
|
|
368
370
|
# version's tree, even in a bundle there (vendor/bundle, say, which
|
|
369
|
-
# both versions may load from).
|
|
371
|
+
# both versions may load from). And fails if a version's workers
|
|
372
|
+
# loaded one twice (see Worker.twice): the candidate's, that something
|
|
373
|
+
# required before Duel loaded the version, and then its own over it.
|
|
370
374
|
def check_builds
|
|
371
375
|
workers = {"baseline" => @bases.first, "candidate" => @candidates.first}
|
|
372
376
|
workers.each do |side, worker|
|
|
377
|
+
worker.twice.each do |feature, paths|
|
|
378
|
+
raise Failed, "the #{side} loaded #{feature} twice, from #{paths.join(" and ")}: something required it before " \
|
|
379
|
+
"Duel loaded the #{side}, and both stay loaded. Require what loads it in a block that runs once the version " \
|
|
380
|
+
"has loaded (c.in_worker, in .duel.rb), not as .duel.rb or a plugin loads"
|
|
381
|
+
end
|
|
373
382
|
other = (side == "baseline") ? "candidate" : "baseline"
|
|
374
383
|
theirs = workers.fetch(other).then { |w| w.extensions.select { |_, path| inside?(path, other, w) } }
|
|
375
384
|
worker.extensions.each do |feature, path|
|
|
@@ -251,12 +251,15 @@ jobs:
|
|
|
251
251
|
gh api --method POST "repos/$GITHUB_REPOSITORY/git/refs" -f ref="refs/heads/$BRANCH" -f sha="$GITHUB_SHA" > /dev/null || blocked
|
|
252
252
|
exit 0
|
|
253
253
|
fi
|
|
254
|
-
compared=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$at" --jq .status)
|
|
254
|
+
compared=$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$at" --jq .status 2>&1) || case "$compared" in
|
|
255
|
+
# (GitHub can't compare commits with no history in common.)
|
|
256
|
+
*"No common ancestor"*) compared=unrelated ;;
|
|
257
|
+
esac
|
|
255
258
|
case "$compared" in
|
|
256
259
|
# (A newer push's run moved it, or this one's did, run again.)
|
|
257
260
|
ahead | identical) ;;
|
|
258
|
-
# (History rewritten, a force push's, say: moved anyway.)
|
|
259
|
-
diverged | behind) gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" -F force=true > /dev/null ;;
|
|
261
|
+
# (History rewritten, a force push's, say, or replaced: moved anyway.)
|
|
262
|
+
diverged | behind | unrelated) gh api --method PATCH "repos/$GITHUB_REPOSITORY/git/refs/heads/$BRANCH" -f sha="$GITHUB_SHA" -F force=true > /dev/null ;;
|
|
260
263
|
*) echo "::error::Couldn't compare $BRANCH with this push: $compared" && exit 1 ;;
|
|
261
264
|
esac
|
|
262
265
|
|
data/lib/duel/version.rb
CHANGED
data/lib/duel/worker.rb
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require "json"
|
|
4
3
|
require "rbconfig"
|
|
5
4
|
require "socket"
|
|
6
5
|
require_relative "../duel"
|
|
7
6
|
require_relative "context"
|
|
7
|
+
require_relative "message"
|
|
8
8
|
require_relative "profile"
|
|
9
9
|
|
|
10
10
|
module Duel
|
|
@@ -13,8 +13,8 @@ module Duel
|
|
|
13
13
|
# WorkerProcess) with Worker.main(VERSION_ROOT, CANDIDATE_ROOT, CONTROL
|
|
14
14
|
# [, CONFIG]), it gives its main object the DSL, loads the benchmarks,
|
|
15
15
|
# connects to the runner's Unix socket at CONTROL, sends what it has
|
|
16
|
-
# (see #hello), and answers
|
|
17
|
-
#
|
|
16
|
+
# (see #hello), and answers each request with a reply (see Message).
|
|
17
|
+
# (Not over stdin: a JRuby started by JRuby sees its stdin pipe
|
|
18
18
|
# closed.)
|
|
19
19
|
# @api private
|
|
20
20
|
class Worker
|
|
@@ -25,6 +25,9 @@ module Duel
|
|
|
25
25
|
|
|
26
26
|
def self.main(version_root, candidate_root, control, config_path = nil)
|
|
27
27
|
config = config_path ? Duel.load_config(config_path) : (Duel.config = Config.new(candidate_root))
|
|
28
|
+
# (What was loaded before the version, which loading it may take off
|
|
29
|
+
# $LOADED_FEATURES, to load its own over: see Worker.twice.)
|
|
30
|
+
before = $LOADED_FEATURES.dup
|
|
28
31
|
config.load_into(File.expand_path(version_root))
|
|
29
32
|
TOPLEVEL_BINDING.receiver.extend(DSL)
|
|
30
33
|
config.benchmark_files.each { |file| load file }
|
|
@@ -34,11 +37,13 @@ module Duel
|
|
|
34
37
|
begin
|
|
35
38
|
# The benchmarks are the only work in this process: it starts tidy.
|
|
36
39
|
GC.start
|
|
37
|
-
worker = new(config.metrics, config.measures, hooks: config.hooks)
|
|
40
|
+
worker = new(config.metrics, config.measures, hooks: config.hooks, before: before)
|
|
38
41
|
begin
|
|
39
42
|
socket = UNIXSocket.new(control)
|
|
40
|
-
socket
|
|
41
|
-
|
|
43
|
+
Message.write(socket, worker.hello)
|
|
44
|
+
while (request = Message.read(socket))
|
|
45
|
+
Message.write(socket, worker.handle(request))
|
|
46
|
+
end
|
|
42
47
|
ensure
|
|
43
48
|
worker.close
|
|
44
49
|
end
|
|
@@ -49,8 +54,10 @@ module Duel
|
|
|
49
54
|
|
|
50
55
|
# Its metric instances: the plugins' outermost, then the built-in
|
|
51
56
|
# ones, CPU innermost (see Worker.made). +hooks+: the configuration's
|
|
52
|
-
# (see Harness).
|
|
53
|
-
|
|
57
|
+
# (see Harness). +before+: the features loaded before the version was
|
|
58
|
+
# (see Worker.main).
|
|
59
|
+
def initialize(plugin_metrics = [], measures = {}, hooks: NO_HOOKS, before: [])
|
|
60
|
+
@before = before
|
|
54
61
|
@metrics, @specs = Worker.made(plugin_metrics + BUILT_IN, measures)
|
|
55
62
|
@benchmarks = Duel.benchmarks
|
|
56
63
|
@hooks = hooks
|
|
@@ -88,7 +95,7 @@ module Duel
|
|
|
88
95
|
def hello
|
|
89
96
|
{"benchmarks" => @benchmarks.values.map(&:to_h), "metrics" => @specs, "ruby" => RUBY_DESCRIPTION,
|
|
90
97
|
"memory" => !Native::Memory.used.nil?, "profiler" => Worker.profiler?, "yjit" => Worker.yjit?,
|
|
91
|
-
"extensions" => Worker.extensions, "gem_dirs" => Worker.gem_dirs}
|
|
98
|
+
"extensions" => Worker.extensions, "twice" => Worker.twice(@before + $LOADED_FEATURES), "gem_dirs" => Worker.gem_dirs}
|
|
92
99
|
end
|
|
93
100
|
|
|
94
101
|
# The native extensions loaded (CRuby's and TruffleRuby's builds, and
|
|
@@ -96,13 +103,26 @@ module Duel
|
|
|
96
103
|
# from the directory on the load path it was found in (the deepest,
|
|
97
104
|
# of several), "my_gem/my_gem.bundle", say, or else its file's name.
|
|
98
105
|
# (For the runner to check each version loaded its own builds: see
|
|
106
|
+
# Lane#check_builds.) Of a feature loaded from more than one file, the
|
|
107
|
+
# last.
|
|
108
|
+
def self.extensions(features = $LOADED_FEATURES, load_path = $LOAD_PATH) = loaded(features, load_path).transform_values(&:last)
|
|
109
|
+
|
|
110
|
+
# The native extensions of +features+ loaded from more than one file,
|
|
111
|
+
# as {feature => real paths}, in the order they loaded. In a baseline
|
|
112
|
+
# worker, one of the candidate's that something required before the
|
|
113
|
+
# worker loaded the version (Duel's own json, in json's repository,
|
|
114
|
+
# say), and then the version's own: as an extension can't be
|
|
115
|
+
# unloaded, both stay loaded. (For the runner to fail: see
|
|
99
116
|
# Lane#check_builds.)
|
|
100
|
-
def self.
|
|
117
|
+
def self.twice(features, load_path = $LOAD_PATH) = loaded(features, load_path).select { |_, paths| paths.size > 1 }
|
|
118
|
+
|
|
119
|
+
# The native extensions loaded, as {feature => real paths}.
|
|
120
|
+
def self.loaded(features, load_path)
|
|
101
121
|
dirs = load_path.map { |dir| File.join(File.expand_path(dir), "") }
|
|
102
|
-
features.select { |feature| File.absolute_path?(feature) && feature.end_with?(".#{RbConfig::CONFIG.fetch("DLEXT")}") }.
|
|
122
|
+
features.select { |feature| File.absolute_path?(feature) && feature.end_with?(".#{RbConfig::CONFIG.fetch("DLEXT")}") }.group_by do |path|
|
|
103
123
|
dir = dirs.select { |prefix| path.start_with?(prefix) }.max_by(&:size)
|
|
104
|
-
|
|
105
|
-
end
|
|
124
|
+
dir ? path.delete_prefix(dir) : File.basename(path)
|
|
125
|
+
end.transform_values { |paths| paths.map { |path| File.realpath(path) }.uniq }
|
|
106
126
|
end
|
|
107
127
|
|
|
108
128
|
# The directories gems are installed in, Gem.path's that are there, as
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Duel
|
|
2
|
+
# What the runner and a worker say to each other, marshaled.
|
|
3
|
+
# @api private
|
|
4
|
+
module Message
|
|
5
|
+
# Sends +message+ over +io+.
|
|
6
|
+
def self.write: (IO io, untyped message) -> Integer
|
|
7
|
+
|
|
8
|
+
# The next message over +io+, or nil once the other end has closed it.
|
|
9
|
+
def self.read: (IO io) -> untyped
|
|
10
|
+
end
|
|
11
|
+
end
|
data/sig/duel/native.rbs
CHANGED
|
@@ -15,6 +15,9 @@ module Duel
|
|
|
15
15
|
|
|
16
16
|
# A C function of the process's own libraries, by name, taking and
|
|
17
17
|
# returning Fiddle types (:INT, :LONG, :VOIDP...).
|
|
18
|
+
# Loads Fiddle, as the first C function is made.
|
|
19
|
+
def self.require_fiddle: () -> bool
|
|
20
|
+
|
|
18
21
|
def self.function: (String name, Array[Symbol] args, Symbol returns) -> _Function
|
|
19
22
|
|
|
20
23
|
# Instructions retired in user space, from the CPU's counters.
|
|
@@ -89,12 +92,17 @@ module Duel
|
|
|
89
92
|
|
|
90
93
|
# This process's resident memory in bytes, or nil where it can't tell.
|
|
91
94
|
module Memory
|
|
92
|
-
|
|
93
|
-
|
|
95
|
+
STATUS: String
|
|
96
|
+
self.@macos: MacOS?
|
|
97
|
+
|
|
98
|
+
# macOS's counter, opened as resident memory is first read, or nil.
|
|
99
|
+
def self.macos_counter: () -> MacOS?
|
|
94
100
|
|
|
95
|
-
def self.resident: (?
|
|
101
|
+
def self.resident: (?status: String, ?macos: MacOS?) -> Integer?
|
|
96
102
|
|
|
97
103
|
def self.used: () -> Integer?
|
|
104
|
+
|
|
105
|
+
def self.collect: () -> void
|
|
98
106
|
end
|
|
99
107
|
end
|
|
100
108
|
end
|
data/sig/duel/runner.rbs
CHANGED
|
@@ -108,6 +108,7 @@ module Duel
|
|
|
108
108
|
@runs: ProcessSample?
|
|
109
109
|
@description: String
|
|
110
110
|
@extensions: Hash[String, String]
|
|
111
|
+
@twice: Hash[String, Array[String]]
|
|
111
112
|
@gem_dirs: Array[String]
|
|
112
113
|
@pid: Integer
|
|
113
114
|
@socket: UNIXSocket
|
|
@@ -135,6 +136,9 @@ module Duel
|
|
|
135
136
|
# The native extensions it loaded, by feature.
|
|
136
137
|
attr_reader extensions: Hash[String, String]
|
|
137
138
|
|
|
139
|
+
# Those it loaded from more than one file, by feature.
|
|
140
|
+
attr_reader twice: Hash[String, Array[String]]
|
|
141
|
+
|
|
138
142
|
# The directories gems are installed in, as real paths ending in "/".
|
|
139
143
|
attr_reader gem_dirs: Array[String]
|
|
140
144
|
|
data/sig/duel/worker.rbs
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
module Duel
|
|
2
2
|
# A worker process: loads one version of the code and the candidate's
|
|
3
|
-
# benchmarks, and answers the runner's requests
|
|
3
|
+
# benchmarks, and answers the runner's requests (see Message).
|
|
4
4
|
# @api private
|
|
5
5
|
class Worker
|
|
6
6
|
type hello = { "benchmarks" => Array[Definition::summary], "metrics" => Array[Metric::spec], "ruby" => String,
|
|
7
7
|
"memory" => bool, "profiler" => bool, "yjit" => bool, "extensions" => Hash[String, String],
|
|
8
|
-
"gem_dirs" => Array[String] }
|
|
8
|
+
"twice" => Hash[String, Array[String]], "gem_dirs" => Array[String] }
|
|
9
9
|
|
|
10
10
|
type ok = { "ok" => true }
|
|
11
11
|
|
|
@@ -24,6 +24,7 @@ module Duel
|
|
|
24
24
|
@specs: Array[Metric::spec]
|
|
25
25
|
@benchmarks: Hash[String, Definition]
|
|
26
26
|
@hooks: Hash[Symbol, Array[hook]]
|
|
27
|
+
@before: Array[String]
|
|
27
28
|
@harnesses: Hash[String, Harness]
|
|
28
29
|
|
|
29
30
|
def self.main: (String version_root, String candidate_root, String control, ?String? config_path) -> void
|
|
@@ -31,6 +32,13 @@ module Duel
|
|
|
31
32
|
# The native extensions loaded, by feature, at their real paths.
|
|
32
33
|
def self.extensions: (?Array[String] features, ?Array[String] load_path) -> Hash[String, String]
|
|
33
34
|
|
|
35
|
+
# Those of +features+ loaded from more than one file, by feature, at
|
|
36
|
+
# their real paths, in the order they loaded.
|
|
37
|
+
def self.twice: (Array[String] features, ?Array[String] load_path) -> Hash[String, Array[String]]
|
|
38
|
+
|
|
39
|
+
# The native extensions loaded, by feature, at their real paths.
|
|
40
|
+
def self.loaded: (Array[String] features, Array[String] load_path) -> Hash[String, Array[String]]
|
|
41
|
+
|
|
34
42
|
# The directories gems are installed in, as real paths ending in "/".
|
|
35
43
|
def self.gem_dirs: (?Array[String] dirs) -> Array[String]
|
|
36
44
|
|
|
@@ -44,7 +52,7 @@ module Duel
|
|
|
44
52
|
def self.yjit?: () -> bool
|
|
45
53
|
|
|
46
54
|
def initialize: (?Array[singleton(Metric)] plugin_metrics, ?Hash[String, Hash[Symbol, untyped]] measures,
|
|
47
|
-
?hooks: Hash[Symbol, Array[hook]]) -> void
|
|
55
|
+
?hooks: Hash[Symbol, Array[hook]], ?before: Array[String]) -> void
|
|
48
56
|
|
|
49
57
|
# Closes its metrics, last first, as it ends.
|
|
50
58
|
def close: () -> void
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: duel
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Erik Berlin
|
|
@@ -57,6 +57,7 @@ files:
|
|
|
57
57
|
- lib/duel/init.rb
|
|
58
58
|
- lib/duel/json_report.rb
|
|
59
59
|
- lib/duel/lock.rb
|
|
60
|
+
- lib/duel/message.rb
|
|
60
61
|
- lib/duel/metric.rb
|
|
61
62
|
- lib/duel/native.rb
|
|
62
63
|
- lib/duel/process_sample.rb
|
|
@@ -84,6 +85,7 @@ files:
|
|
|
84
85
|
- sig/duel/init.rbs
|
|
85
86
|
- sig/duel/json_report.rbs
|
|
86
87
|
- sig/duel/lock.rbs
|
|
88
|
+
- sig/duel/message.rbs
|
|
87
89
|
- sig/duel/metric.rbs
|
|
88
90
|
- sig/duel/native.rbs
|
|
89
91
|
- sig/duel/process_sample.rbs
|
|
@@ -120,7 +122,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
120
122
|
- !ruby/object:Gem::Version
|
|
121
123
|
version: '0'
|
|
122
124
|
requirements: []
|
|
123
|
-
rubygems_version: 4.0.
|
|
125
|
+
rubygems_version: 4.0.24
|
|
124
126
|
specification_version: 4
|
|
125
127
|
summary: 'Performance regression guards: fail when a change makes your code slower'
|
|
126
128
|
test_files: []
|