duel 0.1.6 → 0.1.8

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.
data/lib/duel/runner.rb CHANGED
@@ -12,6 +12,7 @@ require_relative "message"
12
12
  require_relative "resource"
13
13
  require_relative "rubies"
14
14
  require_relative "process_sample"
15
+ require_relative "memory"
15
16
 
16
17
  module Duel
17
18
  # The most seconds each benchmark runs before it's measured, unless
@@ -59,11 +60,14 @@ module Duel
59
60
 
60
61
  # How a run is set up (see Duel::CLI for where each comes from).
61
62
  # @api private
63
+ # Of +jobs+ and +processes+, +fit+ names those Duel may lower to fit
64
+ # the memory available (see Runner#fit): the defaults, but not what
65
+ # an option set.
62
66
  Settings = Struct.new(:base, :base_dir, :candidate_dir, :filter, :jobs, :processes, :limit, :confidence, :warm, :force,
63
- :config_path, :timeout, :ruby, :comment, :fail_on, :pushed, :target, :time_limit, :accepted) do
67
+ :config_path, :timeout, :ruby, :comment, :fail_on, :pushed, :target, :time_limit, :accepted, :fit) do
64
68
  # @type self: singleton(Settings)
65
69
  def self.defaults = new(filter: //, jobs: 1, processes: PROCESSES, limit: 1.02, confidence: 0.99, warm: nil, force: false,
66
- timeout: TIMEOUT, time_limit: TIME_LIMIT)
70
+ timeout: TIMEOUT, time_limit: TIME_LIMIT, fit: [])
67
71
  end
68
72
 
69
73
  # One version as a run has it (see Runner#prepare), +name+d "baseline"
@@ -1222,6 +1226,7 @@ module Duel
1222
1226
  # What #run does, with its versions prepared in its directory.
1223
1227
  def compare_all(started)
1224
1228
  @sides = prepare
1229
+ fit
1225
1230
  names, results = with_lanes do |lanes|
1226
1231
  found = lanes.first.benchmarks.keys.grep(@settings.filter)
1227
1232
  @benchmarks = lanes.first.benchmarks
@@ -1277,6 +1282,62 @@ module Duel
1277
1282
  end
1278
1283
  end
1279
1284
 
1285
+ # The memory Runner#fit leaves for everything but the workers and
1286
+ # their resources: the runner, the system, and other processes.
1287
+ RESERVE = 1 << 30
1288
+
1289
+ # How much more than what it took to start a pair of workers takes
1290
+ # while it measures (its heap grows, and so do its resources'), by
1291
+ # Runner#fit's reckoning.
1292
+ HEADROOM = 1.25
1293
+
1294
+ # How many times what a worker took as it started one on a JIT's
1295
+ # engine takes once it's warm, by Runner#fit's reckoning, as the JIT
1296
+ # compiles: a TruffleRuby worker that started at some 510 MB grew to
1297
+ # some 1.5 GB (and HEADROOM covers the rest).
1298
+ JIT_GROWTH = {"truffleruby" => 2.5}.freeze
1299
+
1300
+ # Lowers Settings#jobs, and then Settings#processes, as far as
1301
+ # Settings#fit lets it, where their workers (and each one's
1302
+ # resources, a database server, say) wouldn't fit in the memory
1303
+ # available: more than that and the machine swaps, or a CI runner
1304
+ # stops answering and its job is lost. What one worker of each
1305
+ # version takes is found by starting them (a lane of them), and every
1306
+ # pair is taken to need that, HEADROOM over (and on a JIT's engine,
1307
+ # JIT_GROWTH times that, as its workers grow as they warm up), or what
1308
+ # the plugins say each worker's resources take at most
1309
+ # (Config#worker_memory), if that's more: a database server takes
1310
+ # more as it's used.
1311
+ def fit
1312
+ return if @settings.fit.empty?
1313
+
1314
+ available = Memory.available or return
1315
+ taken = Lane.open(@config, @settings, @sides, processes: 1) { available - (Memory.available || available) }
1316
+ said = 2 * @config.worker_memory
1317
+ growth = @sides.each_value.map { |side| JIT_GROWTH.fetch(side.engine, 1.0) }.max
1318
+ pair = [(taken * HEADROOM * growth).ceil, said].max
1319
+ return unless pair.positive?
1320
+
1321
+ pairs = [(available - RESERVE) / pair, 1].max
1322
+ processes = @settings.fit.include?(:processes) ? [@settings.processes, pairs].min : @settings.processes
1323
+ # (More jobs than the settings' are never taken: only fewer are.)
1324
+ jobs = @settings.fit.include?(:jobs) ? [pairs / processes, 1].max : @settings.jobs
1325
+ fewer = [("#{Runner.count(jobs, "benchmark")} at a time (not #{@settings.jobs})" if jobs < @settings.jobs),
1326
+ ("#{Runner.count(processes, "worker")} of each version (not #{@settings.processes})" if processes < @settings.processes)].compact
1327
+ return if fewer.empty?
1328
+
1329
+ takes = if said == pair then "#{gigabytes(said)} GB, with its resources, as its plugins say"
1330
+ elsif growth > 1 then "#{gigabytes(taken)} GB, with its resources, as it starts, and some #{growth}x that once warm"
1331
+ else "#{gigabytes(taken)} GB, with its resources"
1332
+ end
1333
+ @out.puts "A worker of each version takes #{takes}, of #{gigabytes(available)} GB available, so to fit: #{fewer.join(", and ")}"
1334
+ @settings.jobs = jobs
1335
+ @settings.processes = processes
1336
+ end
1337
+
1338
+ # +bytes+ in gigabytes, to a tenth.
1339
+ def gigabytes(bytes) = format("%.1f", bytes.fdiv(1 << 30))
1340
+
1280
1341
  def with_lanes
1281
1342
  # @type var lanes: Array[Lane]
1282
1343
  lanes = []
data/lib/duel/summary.rb CHANGED
@@ -27,9 +27,11 @@ module Duel
27
27
  FAILED = %w[regressed error].freeze
28
28
 
29
29
  # What the heading starts with: a run that passed, one that failed (or
30
- # couldn't compare), and one with nothing compared.
30
+ # couldn't compare), one that failed but was accepted (see
31
+ # Config#accept_label), and one with nothing compared.
31
32
  PASSED_MARK = "🟢"
32
33
  FAILED_MARK = "🔻"
34
+ ACCEPTED_MARK = "🟡"
33
35
  NEUTRAL_MARK = "⬜"
34
36
 
35
37
  # What an unsettled timing means.
@@ -91,9 +93,11 @@ module Duel
91
93
  # +runner+ ran, and made +results+, comparing +baseline+ with
92
94
  # +candidate+ (each a description, in Markdown, whose commit stands
93
95
  # bare, so GitHub links it) as +settings+ say, with a +note+ (in
94
- # Markdown) under the heading, if there's one.
95
- def initialize(runner, results, settings:, baseline:, candidate:, note: nil)
96
+ # Markdown) under the heading, if there's one, and whether what failed
97
+ # was +accepted+ (see Config#accept_label).
98
+ def initialize(runner, results, settings:, baseline:, candidate:, note: nil, accepted: nil)
96
99
  @note = note
100
+ @accepted = accepted
97
101
  @runner = runner
98
102
  @results = results
99
103
  @settings = settings
@@ -120,14 +124,16 @@ module Duel
120
124
  end
121
125
 
122
126
  # The verdict: what failed (benchmarks, or a metric across the board),
123
- # or that every benchmark compared passed, and those skipped.
127
+ # and whether that was accepted, or that every benchmark compared
128
+ # passed, and those skipped.
124
129
  def heading
125
130
  skipped = @results.count(&:skipped)
126
131
  compared = @results.size > skipped
127
132
  slower = @runner.regressed_across
128
133
  said = [("#{Runner.count(@failed.size, "benchmark")} failed" unless @failed.empty?),
129
134
  ("slower across the board in #{slower.join(", ")}" unless slower.empty?)].compact
130
- mark = if said.any? then FAILED_MARK
135
+ said << "accepted" if @accepted && said.any?
136
+ mark = if said.any? then @accepted ? ACCEPTED_MARK : FAILED_MARK
131
137
  elsif compared then PASSED_MARK
132
138
  else NEUTRAL_MARK
133
139
  end
@@ -64,9 +64,11 @@
64
64
  # The report, as a new comment on the merge request, when Duel says to:
65
65
  # always (post), or only when its last comment's status differs from this
66
66
  # run's (change), so the latest comment is never stale. It never edits or
67
- # deletes a comment.
67
+ # deletes a comment. It runs `duel comment`, from RubyGems (none of the
68
+ # merge request's code), so a fix to how it comments comes with a release
69
+ # of Duel.
68
70
  <%= gitlab_job %>:comment:
69
- image: alpine:3
71
+ image: ruby:slim
70
72
  stage: .post
71
73
  needs: [<%= gitlab_job %>]
72
74
  rules:
@@ -75,23 +77,10 @@
75
77
  variables:
76
78
  GIT_STRATEGY: none # it runs none of the code
77
79
  script:
78
- - apk add --no-cache --quiet curl jq
79
- - |
80
- case "$DUEL_COMMENT" in post|change) ;; *) exit 0 ;; esac
81
- report=<%= working_directory ? "#{working_directory}/" : "" %>duel.md
82
- [ -f "$report" ] || exit 0
83
- api="$CI_API_V4_URL/projects/$CI_PROJECT_ID"
84
- token="PRIVATE-TOKEN: $DUEL_COMMENT_TOKEN"
85
- marker="<!-- <%= marker %>"
86
- me=$(curl -sf -H "$token" "$CI_API_V4_URL/user" | jq .id)
87
- # The first line of the last comment Duel posted here: its marker,
88
- # with its status.
89
- last=$(curl -sf -H "$token" "$api/merge_requests/$CI_MERGE_REQUEST_IID/notes?sort=desc&order_by=created_at&per_page=100" |
90
- jq -r --argjson me "$me" --arg marker "$marker status=" '.[] | select(.author.id == $me) | .body | split("\n")[0] | rtrimstr("\r") | select(startswith($marker))' | head -n 1)
91
- if [ "$DUEL_COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$DUEL_STATUS -->" ]; }; then
92
- { echo "$marker status=$DUEL_STATUS -->"; cat "$report"; } | jq -Rs '{body: .}' |
93
- curl -sf -H "$token" -H "Content-Type: application/json" --data @- "$api/merge_requests/$CI_MERGE_REQUEST_IID/notes" > /dev/null
94
- fi
80
+ - gem install duel --version '~> <%= Duel::Comment::SINCE %>' --no-document
81
+ # (The merge request's head: in a merged results pipeline, not the
82
+ # commit that merges it.)
83
+ - duel comment --gitlab --report <%= working_directory || "." %> --head "${CI_MERGE_REQUEST_SOURCE_BRANCH_SHA:-$CI_COMMIT_SHA}" --marker '<%= marker.gsub("'") { "'\\''" } %>'
95
84
 
96
85
  # The report, as a new comment on a pushed commit, when Duel says to, as
97
86
  # for a merge request: only where a regression in a push passes (see
@@ -3,14 +3,15 @@ name: Perf comment<%= " (#{working_directory})" if working_directory %>
3
3
  # Duel's report, as a new comment on the pull request, when Duel says to:
4
4
  # always (post), or only when its last comment's status differs from the
5
5
  # run's (change), so the latest comment is never stale. It never edits or
6
- # deletes a comment. It runs once the Perf workflow has, with this
7
- # repository's own workflow and a token that can write, so a pull request
8
- # from a fork gets a comment too. It checks nothing out and runs none of
9
- # the pull request's code, and of what the Duel job kept (where that code
10
- # ran), it trusts only what that job could have said: the pull request's
11
- # number, if it names the pull request the run compared, and the comment
12
- # and the status, if they're ones Duel says. A fork's report, which the
13
- # fork's code wrote, is shown as text.
6
+ # deletes a comment, but hides Duel's earlier ones as outdated, so the
7
+ # newest is the one in view. It runs once the Perf workflow has, with
8
+ # this repository's own workflow and a token that can write, so a pull
9
+ # request from a fork gets a comment too. It checks nothing out and runs
10
+ # none of the pull request's code, only `duel comment` (see Duel's
11
+ # docs/ci.md), which trusts only what the Duel job could have said in
12
+ # what it kept: the pull request's number, if it names the pull request
13
+ # the run compared, and the comment and the status, if they're ones Duel
14
+ # says. Its report, a fork's too, is the comment, as Markdown.
14
15
  <% if accept_label -%>
15
16
  #
16
17
  # And when the label that accepts a regression (c.accept_label in
@@ -52,46 +53,20 @@ jobs:
52
53
  path: ${{ runner.temp }}/report
53
54
  run-id: ${{ github.event.workflow_run.id }}
54
55
  github-token: ${{ github.token }}
56
+ - uses: ruby/setup-ruby@v1
57
+ if: steps.report.outcome == 'success'
58
+ with:
59
+ ruby-version: ruby
60
+ # Duel's own code, from RubyGems (none of the pull request's), so a
61
+ # fix to how it comments comes with a release of Duel.
55
62
  - name: Comment on the pull request
56
63
  if: steps.report.outcome == 'success'
57
64
  env:
58
65
  GH_TOKEN: ${{ github.token }}
59
66
  HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
60
67
  run: |
61
- said() { grep -xE "$1=($2)" "$RUNNER_TEMP/report/comment.env" | tail -n 1 | cut -d= -f2; }
62
- PR=$(said pr '[0-9]+')
63
- COMMENT=$(said comment 'post|change')
64
- STATUS=$(said status 'passed|failed|neutral')
65
- [ -n "$PR" ] && [ -n "$COMMENT" ] && [ -n "$STATUS" ] || exit 0
66
- # (The pull request's head commit, and the repository it's from.)
67
- head=$(gh api "repos/$GITHUB_REPOSITORY/pulls/$PR" --jq '"\(.head.sha) \(.head.repo.full_name)"')
68
- [ "${head%% *}" = "$HEAD_SHA" ] || exit 0
69
- # The report, as Markdown for a branch of this repository (whose
70
- # author can push here anyway), but for a fork's, as text: its run
71
- # ran the fork's code, which could have written anything in it. In
72
- # a code block, fenced with more backticks than any run of them in
73
- # the report, it can't mention anyone, link anywhere or show an
74
- # image. It's cut short where a comment couldn't hold it, and loses
75
- # any NUL bytes, which GitHub wouldn't take, and grep reads it as
76
- # text whatever's in it, so it finds every run of backticks.
77
- report() {
78
- if [ "${head#* }" = "$GITHUB_REPOSITORY" ]; then cat "$RUNNER_TEMP/report/duel.md" && return; fi
79
- text="$RUNNER_TEMP/report.txt"
80
- LC_ALL=C tr -d '\000' < "$RUNNER_TEMP/report/duel.md" | head -c 60000 > "$text"
81
- fence=$(LC_ALL=C grep -ao '``*' "$text" | awk '{ if (length > n) n = length } END { n = (n < 3) ? 3 : n + 1; while (n-- > 0) printf "`" }')
82
- printf 'From a fork, so shown as text:\n\n%s\n' "$fence"
83
- cat "$text"
84
- printf '\n%s\n' "$fence"
85
- }
86
- marker="<!-- <%= marker %>"
87
- # The first line of the last comment Duel posted here: its marker,
88
- # with its status (none in Duel 0.1.0's, which counts as another).
89
- last=$(gh api --paginate "repos/$GITHUB_REPOSITORY/issues/$PR/comments" \
90
- --jq ".[] | select(.user.login == \"github-actions[bot]\") | .body | split(\"\n\")[0] | rtrimstr(\"\r\") | select(startswith(\"$marker status=\") or . == \"$marker -->\")" | tail -n 1)
91
- if [ "$COMMENT" = post ] || { [ -n "$last" ] && [ "$last" != "$marker status=$STATUS -->" ]; }; then
92
- { echo "$marker status=$STATUS -->"; report; } > "$RUNNER_TEMP/comment.md"
93
- gh api --method POST "repos/$GITHUB_REPOSITORY/issues/$PR/comments" -F body=@"$RUNNER_TEMP/comment.md" > /dev/null
94
- fi
68
+ gem install duel --version '~> <%= Duel::Comment::SINCE %>' --no-document
69
+ duel comment --report "$RUNNER_TEMP/report" --head "$HEAD_SHA" --marker '<%= marker.gsub("'") { "'\\''" } %>'
95
70
  <% if accept_label -%>
96
71
 
97
72
  again:
@@ -306,13 +306,15 @@ jobs:
306
306
  <% end -%>
307
307
  <% if badge? -%>
308
308
 
309
- # Duel's badge, for the README: green (perf guarded) or red (perf
310
- # regressed), as the last push to the default branch that Duel compared
311
- # left it. It's red where the Duel job failed or found a regression,
312
- # even one that passed (with c.fail_on = :pull_requests in .duel.rb). A
313
- # push with nothing to compare leaves it as it was, and so does a run
314
- # for an older push than the badge's. This job writes the badge, alone,
315
- # to a branch of its own, which the README shows:
309
+ # Duel's badge, for the README: green (perf guarded), red (perf
310
+ # regressed) or grey (not measured), as the last push to the default
311
+ # branch that Duel compared left it. It's red where Duel failed the push
312
+ # or found a regression, even one that passed (with
313
+ # c.fail_on = :pull_requests in .duel.rb), and grey where the Duel job
314
+ # failed before Duel could judge the push (its runner ran out of memory,
315
+ # say). A push with nothing to compare leaves it as it was, and so does
316
+ # a run for an older push than the badge's. This job writes the badge,
317
+ # alone, to a branch of its own, which the README shows:
316
318
  #
317
319
  # [![Duel](https://raw.githubusercontent.com/OWNER/REPO/<%= badge_branch %>/badge.svg)](https://github.com/sferik/duel-ruby)
318
320
  #
@@ -358,10 +360,13 @@ jobs:
358
360
  last=$(gh api "repos/$GITHUB_REPOSITORY/commits/$BRANCH" --jq .commit.message 2>/dev/null | sed -n 's/^Duel.s badge, for \([0-9a-f]*\)$/\1/p') || true
359
361
  if [ -n "$last" ] && [ "$(gh api "repos/$GITHUB_REPOSITORY/compare/$GITHUB_SHA...$last" --jq .status 2>/dev/null)" = ahead ]; then exit 0; fi
360
362
  # (Its image, written here rather than fetched from anywhere: green,
361
- # or red where the Duel job failed or found a regression.)
363
+ # red where Duel failed the push or found a regression, or grey
364
+ # where the Duel job failed before Duel said either.)
362
365
  state="perf guarded" width=133 top="#34D058" bottom="#28A745" right="76.939C78.629 0 80 1.343 80"
363
- if [ "$RESULT" = failure ] || [ "$STATUS" = failed ]; then
366
+ if [ "$STATUS" = failed ]; then
364
367
  state="perf regressed" width=142 top="#EA4A5A" bottom="#D73A49" right="85.939C87.629 0 89 1.343 89"
368
+ elif [ "$RESULT" = failure ] && [ "$STATUS" != passed ]; then
369
+ state="not measured" width=138 top="#959DA5" bottom="#6A737D" right="81.939C83.629 0 85 1.343 85"
365
370
  fi
366
371
  cat > "$RUNNER_TEMP/badge.svg" <<SVG
367
372
  <svg xmlns="http://www.w3.org/2000/svg" width="$width" height="20">
data/lib/duel/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Duel
4
- VERSION = "0.1.6"
4
+ VERSION = "0.1.8"
5
5
  end
data/lib/duel.rb CHANGED
@@ -196,6 +196,14 @@ module Duel
196
196
  # end
197
197
  # end
198
198
  #
199
+ # Where what it starts for each worker (a database server, say) takes
200
+ # more memory than Duel can see as it starts, its module says how much
201
+ # at most, in bytes, as +worker_memory+: Runner#fit counts that much
202
+ # for each worker, at least, as it fits the workers in the memory
203
+ # available. (A version of Duel before it asked ignores it.)
204
+ #
205
+ # def self.worker_memory = 450 << 20
206
+ #
199
207
  # Its own kinds of benchmark, if it has any, are the methods of its
200
208
  # module's DSL module, which files of benchmarks get as .duel.rb uses
201
209
  # it (see DSL.add):
data/sig/duel/cli.rbs CHANGED
@@ -5,6 +5,10 @@ module Duel
5
5
  # The environment (ENV, or a Hash in its place).
6
6
  interface _Env
7
7
  def reject: () { (String name, String value) -> boolish } -> _Variables
8
+
9
+ def fetch: (String name) -> String
10
+
11
+ def []: (String name) -> String?
8
12
  end
9
13
 
10
14
  # What's left of it.
@@ -54,6 +58,7 @@ module Duel
54
58
  @config: Config?
55
59
  @passed: bool?
56
60
  @note: String?
61
+ @accepted: bool?
57
62
 
58
63
  def initialize: (Array[String] argv, ?env: _Env, ?out: _Output, ?err: _Output) -> void
59
64
 
@@ -153,6 +158,12 @@ module Duel
153
158
  # The candidate, in Markdown.
154
159
  def described_candidate: (Config config, Settings settings) -> String
155
160
 
161
+ def merged: (String dir) -> String?
162
+
163
+ def merge_request: () -> Hash[String, untyped]
164
+
165
+ def pull_request: () -> Hash[String, untyped]?
166
+
156
167
  # What chose a baseline of the last release: the release, or a change
157
168
  # since it accepted with the label.
158
169
  def last_release: (Config config, Baseline baseline) -> String
@@ -0,0 +1,82 @@
1
+ module Duel
2
+ # `duel comment`: what the Perf comment workflow runs, to comment on a
3
+ # pull request with Duel's report.
4
+ # @api private
5
+ class Comment
6
+ USAGE: String
7
+
8
+ # The first release whose `duel comment` the workflow can run.
9
+ SINCE: String
10
+
11
+ # Where GitLab CI has what Duel said.
12
+ GITLAB: Hash[String, String]
13
+
14
+ # What Duel says in comment.env, as each line must have it.
15
+ SAID: Hash[String, Regexp]
16
+
17
+ # The comments on a pull request, a page at a time.
18
+ COMMENTS: String
19
+
20
+ # The jq that picks GitHub Actions' token's comments.
21
+ LISTED: String
22
+
23
+ @argv: Array[String]
24
+ @env: CLI::_Env
25
+ @out: _Output
26
+ @err: _Output
27
+ @marker: String
28
+ @report: String?
29
+ @head: String?
30
+ @gitlab: bool?
31
+
32
+ def initialize: (Array[String] argv, env: CLI::_Env, out: _Output, err: _Output) -> void
33
+
34
+ # Returns the exit status: 0 commented (or had nothing to say), 1
35
+ # GitHub wouldn't take it, 2 a bad option.
36
+ def run: () -> Integer
37
+
38
+ private
39
+
40
+ def parser: () -> OptionParser
41
+
42
+ # Comments, if Duel said to, and the pull request's head is still the
43
+ # run's.
44
+ def comment: (String report) -> Integer
45
+
46
+ # Posts +body+ as a new comment, or nil.
47
+ def post: (String pr, String body) -> untyped
48
+
49
+ # What Duel said in comment.env, or nil.
50
+ def said: (String name, String report) -> String?
51
+
52
+ # Duel's comments on the pull request, oldest first, or nil.
53
+ def earlier: (String pr) -> Array[Hash[String, untyped]]?
54
+
55
+ # The merge request, as GitLab's API has it, or nil.
56
+ def merge_request: (String pr) -> untyped
57
+
58
+ # The token's notes on the merge request, or nil.
59
+ def notes: (String pr) -> Array[Hash[String, untyped]]?
60
+
61
+ # What GitLab's API says, or nil.
62
+ def gitlab: (Symbol verb, String path, ?Hash[String, String]? body, ?pages: bool) -> untyped
63
+
64
+ # A connection to +uri+'s host, not yet started.
65
+ def connection: (URI::Generic uri) -> Net::HTTP
66
+
67
+ # Hides an earlier comment as outdated.
68
+ def hide: (String id) -> void
69
+
70
+ # What gh api prints, or nil where it fails.
71
+ def gh: (*String args) -> String?
72
+
73
+ # Says why it doesn't comment, and returns 0.
74
+ def quiet: (String why) -> Integer
75
+
76
+ def marker: () -> String
77
+
78
+ def repository: () -> String
79
+
80
+ def project: () -> String
81
+ end
82
+ end
data/sig/duel/config.rbs CHANGED
@@ -36,6 +36,7 @@ module Duel
36
36
  @in_workers: Array[^(Stops stops) -> void]
37
37
  @hooks: Hash[Symbol, Array[hook]]
38
38
  @used: Hash[Symbol, Used]
39
+ @worker_memory: Integer
39
40
  @measures: Hash[String, Hash[Symbol, untyped]]
40
41
  @loader: (^(String version_root) -> void)?
41
42
 
@@ -125,6 +126,10 @@ module Duel
125
126
  # @api private
126
127
  attr_reader measures: Hash[String, Hash[Symbol, untyped]]
127
128
 
129
+ # The memory that what the plugins used start for each worker takes at
130
+ # most, as they say, in bytes.
131
+ attr_reader worker_memory: Integer
132
+
128
133
  # A configuration of the conventions, for the project at +root+.
129
134
  def initialize: (?String root) -> void
130
135
 
data/sig/duel/init.rbs CHANGED
@@ -15,18 +15,31 @@ module Duel
15
15
  # A Gemfile's development group.
16
16
  DEVELOPMENT: Regexp
17
17
 
18
+ # The color of the label it creates.
19
+ LABEL_COLOR: String
20
+
21
+ # Where it reads an answer.
22
+ interface _Input
23
+ def tty?: () -> bool
24
+
25
+ def gets: () -> String?
26
+ end
27
+
18
28
  @argv: Array[String]
19
29
  @out: _Output
20
30
  @err: _Output
31
+ @input: _Input
21
32
  @root: String
33
+ @label: bool?
22
34
  @force: bool?
23
35
  @dry_run: bool?
36
+ @check: bool?
24
37
  @gitlab: bool?
25
38
  @badge: bool?
26
39
  @settings: Config?
27
40
  @stackprof: bool?
28
41
 
29
- def initialize: (Array[String] argv, ?out: _Output, ?err: _Output, ?root: String) -> void
42
+ def initialize: (Array[String] argv, ?out: _Output, ?err: _Output, ?input: _Input, ?root: String) -> void
30
43
 
31
44
  # Returns the exit status: 0 set up, 1 a Rails app, 2 a bad option.
32
45
  def run: () -> Integer
@@ -38,6 +51,31 @@ module Duel
38
51
 
39
52
  def parser: () -> OptionParser
40
53
 
54
+ # Says whether each workflow is what it writes, or how it differs.
55
+ def check: () -> Integer
56
+
57
+ # Whether the file at +path+ is +content+, saying so, or how it differs.
58
+ def same?: (String path, String content) -> bool
59
+
60
+ # Creates the label that accepts a regression, with gh, if it's missing
61
+ # and the answer to whether to is yes.
62
+ def create_label: () -> void
63
+
64
+ # The names of the GitHub repository's labels gh finds, or nil.
65
+ def github_labels: (String repo, String label) -> Array[String]?
66
+
67
+ # The project's GitLab project, as glab has it, or nil.
68
+ def gitlab_project: () -> String?
69
+
70
+ # The names of the GitLab project's labels, or nil.
71
+ def gitlab_labels: (String repo) -> Array[String]?
72
+
73
+ # What gh (or glab) prints, run in the project, or nil.
74
+ def cli: (String program, *String args) -> String?
75
+
76
+ # A pull request, or on GitLab, a merge request.
77
+ def request: () -> String
78
+
41
79
  # Says to use duel-rails's generator instead.
42
80
  def rails: () -> Integer
43
81
 
@@ -0,0 +1,30 @@
1
+ module Duel
2
+ # The memory a run's workers can take: what the machine has available,
3
+ # or what its cgroup's limit leaves.
4
+ # @api private
5
+ module Memory
6
+ # The kinds of pages macOS's vm_stat counts as available.
7
+ MAC_PAGES: Array[String]
8
+
9
+ # Where Linux's proc and sys are.
10
+ ROOT: String
11
+
12
+ # The bytes available, or nil where Duel can't tell.
13
+ def self.available: (?root: String, ?vm_stat: ^() -> String?) -> Integer?
14
+
15
+ # MemAvailable, at most what the cgroup leaves, or nil.
16
+ def self.linux: (String root) -> Integer?
17
+
18
+ # What a cgroup (v2) at +dir+ leaves of its limit, or nil.
19
+ def self.cgroup: (String dir) -> Integer?
20
+
21
+ # The bytes in vm_stat's available pages, or nil.
22
+ def self.mac: (String? output) -> Integer?
23
+
24
+ # A file's contents, or nil.
25
+ def self.read: (String path) -> String?
26
+
27
+ # What a command prints, or nil.
28
+ def self.command: (*String args) -> String?
29
+ end
30
+ end
data/sig/duel/runner.rbs CHANGED
@@ -66,17 +66,20 @@ module Duel
66
66
  # a pull request with Config#accept_label (DUEL_ACCEPTED): see
67
67
  # Baseline#last_release.
68
68
  attr_accessor accepted: String?
69
+ # Of jobs and processes, those Duel may lower to fit the memory
70
+ # available (see Runner#fit).
71
+ attr_accessor fit: Array[:jobs | :processes]
69
72
 
70
73
  def self.new: (?String? base, ?String? base_dir, ?String? candidate_dir, ?Regexp filter, ?Integer jobs,
71
74
  ?Integer processes, ?Float limit, ?Float confidence, ?Float? warm, ?bool force, ?String? config_path,
72
75
  ?Float timeout, ?Config::ruby ruby, ?Config::comment? comment,
73
76
  ?Config::fail_on? fail_on, ?String? pushed,
74
- ?String? target, ?Float time_limit, ?String? accepted) -> instance
77
+ ?String? target, ?Float time_limit, ?String? accepted, ?Array[:jobs | :processes] fit) -> instance
75
78
  | (?base: String?, ?base_dir: String?, ?candidate_dir: String?, ?filter: Regexp, ?jobs: Integer,
76
79
  ?processes: Integer, ?limit: Float, ?confidence: Float, ?warm: Float?, ?force: bool,
77
80
  ?config_path: String?, ?timeout: Float, ?ruby: Config::ruby, ?comment: Config::comment?,
78
81
  ?fail_on: Config::fail_on?, ?pushed: String?,
79
- ?target: String?, ?time_limit: Float, ?accepted: String?) -> instance
82
+ ?target: String?, ?time_limit: Float, ?accepted: String?, ?fit: Array[:jobs | :processes]) -> instance
80
83
 
81
84
  def self.defaults: () -> Settings
82
85
  end
@@ -647,6 +650,23 @@ module Duel
647
650
  # The most workers of each version #interval_over looks at.
648
651
  PROCESSES_CHECKED: Integer
649
652
 
653
+ # The memory #fit leaves for everything but the workers.
654
+ RESERVE: Integer
655
+
656
+ # How much more than starting them a pair of workers takes, by #fit's
657
+ # reckoning.
658
+ HEADROOM: Float
659
+
660
+ # How many times a JIT engine's worker grows as it warms up.
661
+ JIT_GROWTH: Hash[String, Float]
662
+
663
+ # Lowers the jobs, then the processes, that Settings#fit lets it, to
664
+ # fit the memory available.
665
+ def fit: () -> void
666
+
667
+ # +bytes+ in gigabytes, to a tenth.
668
+ def gigabytes: (Integer bytes) -> String
669
+
650
670
  def with_lanes: [T] () { (Array[Lane] lanes) -> T } -> T
651
671
 
652
672
  def judge_across: (Array[Result] results, Array[String] names) -> Hash[String, Across::verdict]
data/sig/duel/summary.rbs CHANGED
@@ -17,6 +17,7 @@ module Duel
17
17
  # What the heading starts with.
18
18
  PASSED_MARK: String
19
19
  FAILED_MARK: String
20
+ ACCEPTED_MARK: String
20
21
  NEUTRAL_MARK: String
21
22
 
22
23
  # What an unsettled timing means.
@@ -26,6 +27,7 @@ module Duel
26
27
  DECIDES: String
27
28
 
28
29
  @note: String?
30
+ @accepted: bool?
29
31
  @runner: Runner
30
32
  @results: Array[Result]
31
33
  @settings: Settings
@@ -53,7 +55,7 @@ module Duel
53
55
  def self.changed_counts: (Result result) -> Hash[String, [Float, Float]]
54
56
 
55
57
  def initialize: (Runner runner, Array[Result] results, settings: Settings, baseline: String, candidate: String,
56
- ?note: String?) -> void
58
+ ?note: String?, ?accepted: bool?) -> void
57
59
 
58
60
  # The Markdown.
59
61
  def markdown: () -> String