@johngaynor/ocnus 2.0.1-next.22 → 2.0.1-next.27

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.
package/cli/lib/host.sh CHANGED
@@ -33,9 +33,7 @@
33
33
  # turn, as herdr-core's status for its terminal says, and waiting while it is
34
34
  # open but its turn has ended, it waits on the human in its tab, it hit an
35
35
  # error, or it reports no status. A tab that holds its shell alone is not
36
- # open, so it is neither. `host report` shows, for each number of agents
37
- # working, how much of the time the host was at its limit, and from which
38
- # number the host was the limit.
36
+ # open, so it is neither.
39
37
  #
40
38
  # Beside the readings go the test runs: each run of a repo's tests that an
41
39
  # agent starts through `ocnus tests run` (tests.sh), with its card and
@@ -43,16 +41,12 @@
43
41
  # memory it held at once. A test run is named by its card and repo alone.
44
42
  # Its command is kept only as a fingerprint, a number the same for the same
45
43
  # command and from which its text cannot be read back, and nothing else of
46
- # its command line is kept. `host report` ranks the test runs too, and sets
47
- # runs of the same command in the same repo against each other to say how
48
- # much slower they were with more agents working.
44
+ # its command line is kept. `host report` ranks the test runs too.
49
45
  #
50
46
  # With each reading go the shares of the test runs going then, too, each
51
47
  # worked out as a terminal's is, from the processes under the run's job,
52
48
  # which are in their terminal's share as well. A run that ended since the
53
- # reading before gets the rest of its CPU in the next one. `host report`
54
- # names the cards' steps and the test runs going in the longest stretches
55
- # when the CPU or memory was at its limit.
49
+ # reading before gets the rest of its CPU in the next one.
56
50
  #
57
51
  # While recording is on, `task new` and `task build` start claude with hooks
58
52
  # that mark its agent's time (host_hooks): cli/host-mark appends a word and
@@ -64,16 +58,10 @@
64
58
  # those marks (host_splits): on the host, while its tools run, and waiting
65
59
  # on the model. The rest of the time its agent was open is neither, such as
66
60
  # waiting on the human. `host report` says where the steps' time went by
67
- # them, and ends with its verdict on the host, which weighs each reading by
68
- # the agents' time on the host in it: what to upgrade first, if anything.
61
+ # them.
69
62
  #
70
63
  # From the same marks, each wait on the model is kept too, as its start and
71
- # end alone, by the reading it ended in. A wait is slow at over twice the
72
- # median of every wait kept. When slow waits came while the CPU, memory and
73
- # disk were all below their limit, `host report` says the network may be the
74
- # cause, and when they were at least a tenth of the period's waits, and no
75
- # resource was the one to upgrade, its verdict is that the network was the
76
- # limit.
64
+ # end alone, by the reading it ended in.
77
65
  #
78
66
  # A share's card, phase and step, a split's, a wait's, and a test run's card
79
67
  # and repo, are the only text the readings hold, and only the values
@@ -1218,11 +1206,11 @@ host_day() {
1218
1206
 
1219
1207
  # How the CPU, memory and disk were, over a period: how much of the time it
1220
1208
  # was recorded, and how much of that each was at its limit. Time with no
1221
- # reading is shown as missing, never as idle. It ends with whether the
1222
- # network may be the cause of slow waits on the model, and the verdict on
1223
- # the host: what to upgrade first, if anything (host_verdict_sql).
1209
+ # reading is shown as missing, never as idle. Then come the steps, phases
1210
+ # and test runs that used the most (host_ranks_sql), and it ends with where
1211
+ # the steps' time went (host_split_sql).
1224
1212
  host_report() {
1225
- local period=${1:-7d} now start end n first last row works runs working shared splits power slower waits
1213
+ local period=${1:-7d} now start end n first last row works splits
1226
1214
  [ "$#" -le 1 ] || die "$HOST_USAGE"
1227
1215
  now=$(date +%s)
1228
1216
  case $period in
@@ -1262,38 +1250,20 @@ host_report() {
1262
1250
  say "Recording is on, and takes a reading every $HOST_EVERY seconds while an ocnus agent is open."
1263
1251
  return 0
1264
1252
  fi
1265
- # A store the recorder has not opened since the shares, the cores, the
1266
- # test runs and their shares, the agents working, the splits, the power
1267
- # state, the fingerprints of the test runs' commands, and the waits on the
1268
- # model came has none of them: one digit each, 1 for what it has, and for
1269
- # the power state how many of its 3 columns it has. The report only reads
1270
- # the store, so it never adds them, and leaves out what is missing.
1253
+ # A store the recorder has not opened since the cores, the shares, the
1254
+ # test runs and the splits came has none of them: one digit each, 1 for
1255
+ # what it has. The report only reads the store, so it never adds them, and
1256
+ # leaves out what is missing.
1271
1257
  row=$(store "$HOST_DB" "select (select count(*) from pragma_table_info('readings') where name = 'cores')
1272
1258
  || (select count(*) from sqlite_master where type = 'table' and name = 'shares')
1273
1259
  || (select count(*) from sqlite_master where type = 'table' and name = 'test_runs')
1274
- || (select count(*) from sqlite_master where type = 'table' and name = 'run_shares')
1275
- || (select count(*) from pragma_table_info('readings') where name = 'working')
1276
- || (select count(*) from pragma_table_info('shares') where name = 'working')
1277
- || (select count(*) from sqlite_master where type = 'table' and name = 'splits')
1278
- || (select count(*) from pragma_table_info('readings') where name in ('on_battery', 'low_power', 'thermal'))
1279
- || (select count(*) from pragma_table_info('test_runs') where name = 'cmd')
1280
- || (select count(*) from sqlite_master where type = 'table' and name = 'model_waits');") || row=
1281
- works=0 runs=0 working=0 shared=0 splits=0 power=0 slower=0 waits=0
1282
- case $row in ?1????????) works=1 ;; esac
1283
- case $row in ??11??????) runs=1 ;; esac
1284
- case $row in ????1?????) working=1 ;; esac
1285
- case $row in ?1???1????) shared=1 ;; esac
1286
- case $row in ?1????1???) splits=1 ;; esac
1287
- case $row in ???????3??) power=1 ;; esac
1288
- case $row in ????1???1?) slower=1 ;; esac
1289
- case $row in ?????????1) waits=1 ;; esac
1290
- case $row in 111???????) row=1 ;; *) row=0 ;; esac
1260
+ || (select count(*) from sqlite_master where type = 'table' and name = 'splits');") || row=
1261
+ works=0 splits=0
1262
+ case $row in ?1??) works=1 ;; esac
1263
+ case $row in ?1?1) splits=1 ;; esac
1264
+ case $row in 111?) row=1 ;; *) row=0 ;; esac
1291
1265
  store "$HOST_DB" "$(host_report_sql "$start" "$end" "$period" "$row")" ||
1292
1266
  die "could not read $HOST_DB"
1293
- store "$HOST_DB" "$(host_working_sql "$start" "$end" "$working" "$slower")" ||
1294
- die "could not read $HOST_DB"
1295
- store "$HOST_DB" "$(host_peaks_sql "$start" "$end" "$works" "$runs" "$shared")" ||
1296
- die "could not read $HOST_DB"
1297
1267
  if [ "$row" = 1 ]; then
1298
1268
  store "$HOST_DB" "$(host_ranks_sql "$start" "$end")" || die "could not read $HOST_DB"
1299
1269
  else
@@ -1301,7 +1271,6 @@ host_report() {
1301
1271
  say 'No step, phase or test run was recorded in this period.'
1302
1272
  fi
1303
1273
  store "$HOST_DB" "$(host_split_sql "$start" "$end" "$works" "$splits")" || die "could not read $HOST_DB"
1304
- store "$HOST_DB" "$(host_verdict_sql "$start" "$end" "$splits" "$power" "$waits")" || die "could not read $HOST_DB"
1305
1274
  }
1306
1275
 
1307
1276
  # The report's query, for the period from $1 to $2, named $3. A reading
@@ -1366,178 +1335,6 @@ select line from lines order by n, k;
1366
1335
  EOF
1367
1336
  }
1368
1337
 
1369
- # The agents working at once, from $1 to $2: for each number of agents
1370
- # working that the readings counted, from none up, how long that many were
1371
- # working, and how much of that time the CPU or the memory was at its limit,
1372
- # as the report counts it. Each reading counts for the part of it in the
1373
- # period. A reading from before the agents working were counted has no
1374
- # count, and nor has any when $3 is not 1, as the store has no column for
1375
- # them yet: it is left out, never counted as none working, and its time is
1376
- # on a line of its own. Last, the fewest working at which the CPU or memory
1377
- # was at its limit for at least a quarter of the time is named as the number
1378
- # from which the host was the limit; or it says there is no such number, or
1379
- # that no reading counted the agents working.
1380
- #
1381
- # Under each number from 2 up, with $4 as 1, which says the store has the
1382
- # fingerprints of the test runs' commands, comes how much slower test runs
1383
- # were than with one working. A test run that started in the period counts
1384
- # at the number working that covers most of its time, over the readings
1385
- # that counted them, and at the larger number on a tie. A run that was cut
1386
- # short, is still going, has no fingerprint, as one from before they were
1387
- # kept, or overlaps no reading with a count, is left out. A command is a
1388
- # repo and a fingerprint, so only runs of the same command in the same repo
1389
- # are set against each other, and a command counts at a number when it ran
1390
- # at least 3 times with that many working and 3 times with one. Its ratio is
1391
- # its runs' median time with that many working over their median time with
1392
- # one, and the figure is the median of the commands' ratios, so one odd run,
1393
- # such as one that failed early, does not move it. With no such command, it
1394
- # says it cannot tell yet.
1395
- host_working_sql() {
1396
- local s=$1 e=$2 working=working slower=0 runs='select null, null, null, null, null where 0' counted=null
1397
- [ "${3:-0}" = 1 ] || working=null
1398
- if [ "$working" = working ] && [ "${4:-0}" = 1 ]; then
1399
- slower=1 counted=g.working
1400
- runs="select id, repo, cmd, started, secs from test_runs
1401
- where started >= $s and started < $e and ended is not null and cut = 0 and cmd is not null and secs is not null"
1402
- fi
1403
- cat <<EOF
1404
- with
1405
- parts(n, d, lim) as (
1406
- select $working, max(0, min(at, $e) - max(at - secs, $s)), coalesce(cpu_busy >= 90 or mem_pressure >= 2, 0)
1407
- from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e),
1408
- counts(n, len, lim) as (
1409
- select n, sum(d), sum(case when lim then d else 0 end) from parts where n is not null group by n),
1410
- uncounted(len) as (select coalesce(sum(d), 0) from parts where n is null),
1411
- fewest(n) as (select min(n) from counts where len > 0 and 4 * lim >= len),
1412
- runs(id, repo, cmd, started, secs) as ($runs),
1413
- -- A cross join keeps the runs outside, so that each one looks up only its
1414
- -- own readings by their at, never every reading for each run.
1415
- over(id, n, d) as (
1416
- select r.id, $counted, sum(max(0, min(g.at, r.started + r.secs) - max(g.at - g.secs, r.started)))
1417
- from runs r cross join readings g
1418
- on g.at > r.started and g.at < r.started + r.secs + $HOST_GAP and g.at - g.secs < r.started + r.secs
1419
- where $counted is not null group by r.id, $counted),
1420
- at_n(id, n) as (
1421
- select id, n from (select id, n, row_number() over (partition by id order by d desc, n desc) k from over) where k = 1),
1422
- timed(repo, cmd, n, secs, i, c) as (
1423
- select r.repo, r.cmd, a.n, r.secs, row_number() over (partition by r.repo, r.cmd, a.n order by r.secs),
1424
- count(*) over (partition by r.repo, r.cmd, a.n)
1425
- from runs r join at_n a on a.id = r.id),
1426
- medians(repo, cmd, n, runs, secs) as (
1427
- select repo, cmd, n, max(c), avg(secs) from timed where i in ((c + 1) / 2, (c + 2) / 2) group by repo, cmd, n),
1428
- ratios(n, ratio, runs, base, i, c) as (
1429
- select m.n, m.secs / b.secs, m.runs, b.runs, row_number() over (partition by m.n order by m.secs / b.secs),
1430
- count(*) over (partition by m.n)
1431
- from medians m join medians b on b.repo = m.repo and b.cmd = m.cmd and b.n = 1
1432
- where m.n >= 2 and m.runs >= 3 and b.runs >= 3 and b.secs > 0),
1433
- slower(n, ratio) as (select n, avg(ratio) from ratios where i in ((c + 1) / 2, (c + 2) / 2) group by n),
1434
- rested(n, cmds, runs, base) as (select n, count(*), sum(runs), sum(base) from ratios group by n),
1435
- lines(part, n, o, line) as (
1436
- select 0, 0, 0, ''
1437
- union all select 0, 1, 0, 'Agents working at once:'
1438
- union all
1439
- select 1, n, 0, ' ' || printf('%-11s', n || ' working') || ' ' || $(sql_took len) || ', CPU or memory at its limit '
1440
- || $(sql_took lim) || ', ' || printf('%.1f%%', 100.0 * lim / nullif(len, 0)) || ' of it'
1441
- from counts
1442
- union all
1443
- select 1, c.n, 1, ' test runs' || case when s.ratio is null
1444
- then ': cannot tell yet, as no command ran at least 3 times with ' || c.n || ' working and 3 times with 1'
1445
- else ' ' || case when s.ratio >= 1 then printf('%.0f%% slower', 100.0 * (s.ratio - 1))
1446
- else printf('%.0f%% faster', 100.0 * (1 - s.ratio)) end
1447
- || ' than with 1 working, from ' || r.runs || ' runs of ' || r.cmds || case when r.cmds = 1 then ' command' else ' commands' end
1448
- || ' against ' || r.base || ' with 1 working' end
1449
- from counts c left join slower s on s.n = c.n left join rested r on r.n = c.n
1450
- where c.n >= 2 and $slower
1451
- union all
1452
- select 2, 0, 0, ' not counted ' || $(sql_took len) || ', by readings from before the agents working were counted'
1453
- from uncounted where len > 0
1454
- union all
1455
- select 3, 0, 0, case
1456
- when not exists (select 1 from counts) then ' No reading in this period counted the agents working.'
1457
- when n is null then ' The host was not the limit at any number of working agents in this period: at each, the CPU or memory was at its limit for under a quarter of the time.'
1458
- else ' The host was the limit from ' || n || ' working ' || case when n = 1 then 'agent' else 'agents' end
1459
- || ': the fewest at which the CPU or memory was at its limit for at least a quarter of the time.' end
1460
- from fewest)
1461
- select line from lines order by part, n, o;
1462
- EOF
1463
- }
1464
-
1465
- # The longest stretches from $1 to $2 when the CPU or the memory was at its
1466
- # limit, as the report counts it, five at most, longest first. A stretch is
1467
- # readings in a row at the limit, each starting where the one before ended,
1468
- # and each counts for the part of it in the period, as the report counts a
1469
- # reading. Each says when it started, how long it lasted and which of the
1470
- # two was at its limit, then the work going in it: each card's step, or its
1471
- # phase when its card is in none, from the shares when $3 is 1, then each
1472
- # test run, from their shares when $4 is 1. Each has its share of all cores
1473
- # over the stretch, its share in each reading counted for that reading's
1474
- # part, and the most memory it held in one reading. Each card also has how
1475
- # much of the stretch its agent was working: the parts of the readings in
1476
- # which a share of its was working, over the stretch's length. With $5 not 1,
1477
- # the shares have no column for it, and with no share that says, as from
1478
- # before the agents working were told apart, it says it was not read. A
1479
- # share that names no card is left out. With no stretch, it says the host was
1480
- # never at its limit.
1481
- host_peaks_sql() {
1482
- local s=$1 e=$2 shares runs
1483
- shares='select at, card, phase, step, cpu, mem_mb, working from shares'
1484
- [ "${5:-0}" = 1 ] || shares='select at, card, phase, step, cpu, mem_mb, null from shares'
1485
- [ "${3:-0}" = 1 ] || shares='select null, null, null, null, null, null, null where 0'
1486
- runs='select r.at, r.run, t.card, t.repo, t.started, r.cpu, r.mem_mb from run_shares r join test_runs t on t.id = r.run'
1487
- [ "${4:-0}" = 1 ] || runs='select null, null, null, null, null, null, null where 0'
1488
- cat <<EOF
1489
- with
1490
- lim(at, start, d, cpu, mem, new) as (
1491
- select at, max(at - secs, $s), max(0, min(at, $e) - max(at - secs, $s)),
1492
- coalesce(cpu_busy >= 90, 0), coalesce(mem_pressure >= 2, 0),
1493
- case when lag(at) over (order by at) = at - secs then 0 else 1 end
1494
- from readings
1495
- where at > $s and at < $e + $HOST_GAP and at - secs < $e and (cpu_busy >= 90 or mem_pressure >= 2)),
1496
- grouped(at, start, d, cpu, mem, n) as (
1497
- select at, start, d, cpu, mem, sum(new) over (order by at rows between unbounded preceding and current row) from lim),
1498
- stretches(n, start, len, cpu, mem) as (
1499
- select n, min(start), sum(d), max(cpu), max(mem) from grouped group by n),
1500
- ranked(k, n, start, len, cpu, mem) as (
1501
- select row_number() over (order by len desc, start), n, start, len, cpu, mem from stretches),
1502
- top(k, n, start, len, cpu, mem) as (select k, n, start, len, cpu, mem from ranked where k <= 5),
1503
- parts(k, len, at, d) as (select t.k, t.len, g.at, g.d from top t join grouped g on g.n = t.n),
1504
- sh(at, card, phase, step, cpu, mem, working) as ($shares),
1505
- rs(at, run, card, repo, started, cpu, mem) as ($runs),
1506
- cards(k, len, at, d, name, cpu, mem, working) as (
1507
- select p.k, p.len, p.at, p.d, sh.card || ' ' || coalesce(sh.step || ' step', sh.phase || ' phase'), sum(sh.cpu), sum(sh.mem),
1508
- max(sh.working)
1509
- from parts p join sh on sh.at = p.at
1510
- where sh.card is not null and coalesce(sh.step, sh.phase) is not null
1511
- group by p.k, p.at, sh.card, sh.step, sh.phase),
1512
- work(k, part, name, cpu, mem, working) as (
1513
- select k, 1, name, sum(1.0 * cpu * d) / len, max(mem),
1514
- case when count(working) > 0 then 100.0 * sum(case when working = 1 then d else 0 end) / len end
1515
- from cards group by k, name
1516
- union all
1517
- select p.k, 2, rs.card || ' ' || rs.repo || ' test run ' || strftime('%Y-%m-%d %H:%M', rs.started, 'unixepoch', 'localtime'),
1518
- sum(1.0 * rs.cpu * p.d) / p.len, max(rs.mem), null
1519
- from parts p join rs on rs.at = p.at group by p.k, rs.run),
1520
- lines(k, part, o, line) as (
1521
- select -1, 0, 0, ''
1522
- union all select 0, 0, 0, 'Longest stretches with CPU or memory at its limit:' where exists (select 1 from top)
1523
- union all select 0, 0, 0, 'The host was never at its limit for CPU or memory in this period.' where not exists (select 1 from top)
1524
- union all
1525
- select k, 0, 0, ' ' || strftime('%Y-%m-%d %H:%M:%S', start, 'unixepoch', 'localtime') || ' for ' || $(sql_took len) || ', '
1526
- || case when cpu and mem then 'CPU and memory at their limit' when cpu then 'CPU at its limit' else 'memory at its limit' end
1527
- from top
1528
- union all
1529
- select k, part, row_number() over (partition by k, part order by cpu desc, name),
1530
- ' ' || printf('%-44s', name) || ' ' || case when cpu is null then 'CPU not read' else 'CPU ' || printf('%.1f%%', cpu) end
1531
- || ', ' || case when mem is null then 'memory not read' else 'memory ' || mem || ' MB' end
1532
- || case when part = 2 then '' when working is null then ', working not read'
1533
- else ', working ' || printf('%.0f%%', working) || ' of it' end
1534
- from work
1535
- union all
1536
- select k, 3, 0, ' no card or test run was going' from top t where not exists (select 1 from work w where w.k = t.k))
1537
- select line from lines order by k, part, o;
1538
- EOF
1539
- }
1540
-
1541
1338
  # The steps and the phases that used the most CPU time, and that held the
1542
1339
  # most memory at once, from $1 to $2: ten of each, each one card's own. Each
1543
1340
  # counts what its shares say for the part of their reading in the period,
@@ -1663,133 +1460,6 @@ select line from lines order by k;
1663
1460
  EOF
1664
1461
  }
1665
1462
 
1666
- # The verdict on the host from $1 to $2, from the splits when $3 is 1, and
1667
- # the power state of the readings when $4 is 1, and the waits on the model
1668
- # when $5 is 1: the report's last line, after the network line when there
1669
- # is one.
1670
- #
1671
- # A wait on the model is slow when it took over twice the median of every
1672
- # wait in model_waits, so 90 days at most: the wait halfway in order of
1673
- # length, the later of the two for an even count. A slow wait counts for the
1674
- # network when there is a reading over it, and every reading over it, in
1675
- # whole or in part, had the CPU, memory and disk below their limit, as the
1676
- # report counts it. The period's waits are those that ended in it. With any
1677
- # that count, the network line, between blank lines, says the network may
1678
- # be the cause: how many of the period's waits were slow while the host was
1679
- # below its limit, and the median. A store with no waits on the model has
1680
- # none.
1681
- #
1682
- # The agents' time on the host is their splits' seconds on the host, an
1683
- # agent's second each, each split counted for the part of its reading in the
1684
- # period, as the report counts a reading. The verdict is the first of these
1685
- # that holds:
1686
- # - too little data yet, with under HOST_VERDICT_STEPS steps with a split
1687
- # in the period, each one card's own, or under HOST_VERDICT_SECS of the
1688
- # agents' time on the host. It says how many and how long, against them.
1689
- # - of the CPU, memory and disk, the one at its limit, as the report counts
1690
- # it, for the most of the agents' time on the host, and for at least
1691
- # HOST_VERDICT_PCT% of it, the CPU before memory before the disk when two
1692
- # were as long: the power state was the limit, when over half of that
1693
- # one's time at its limit was on battery, in Low Power Mode or with the
1694
- # thermal state at serious or critical, and otherwise it is the one to
1695
- # upgrade first.
1696
- # - the network was the limit, when the waits that count for it are at
1697
- # least HOST_VERDICT_PCT% of the period's waits on the model. It gives
1698
- # that share and the median.
1699
- # - no upgrade is needed.
1700
- # All but the first say how much of the agents' time on the host each was at
1701
- # its limit. A store with no splits has too little data, and one whose
1702
- # readings have no power state counts them as on power, as a reading with
1703
- # none of it does.
1704
- HOST_VERDICT_STEPS=10
1705
- HOST_VERDICT_SECS=3600
1706
- HOST_VERDICT_PCT=10
1707
- host_verdict_sql() {
1708
- local s=$1 e=$2 splits power waits took median
1709
- splits='select at, card, step, host_secs from splits'
1710
- [ "${3:-0}" = 1 ] || splits='select null, null, null, null where 0'
1711
- power='coalesce(on_battery = 1 or low_power = 1 or thermal >= 2, 0)'
1712
- [ "${4:-0}" = 1 ] || power=0
1713
- waits='select ended - started, started, ended from model_waits'
1714
- [ "${5:-0}" = 1 ] || waits='select null, null, null where 0'
1715
- took=$(sql_took 'cast(round(t.host) as integer)')
1716
- # A median under a minute is given to a tenth of a second.
1717
- median="case when m < 59.95 then printf('%.1fs', m) else $(sql_took 'cast(round(m) as integer)') end"
1718
- cat <<EOF
1719
- with
1720
- parts(at, secs, d, cpu, mem, disk, power) as (
1721
- select at, secs, max(0, min(at, $e) - max(at - secs, $s)),
1722
- coalesce(cpu_busy >= 90, 0), coalesce(mem_pressure >= 2, 0), coalesce(disk_free_pct < 10, 0), $power
1723
- from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e and secs > 0),
1724
- x(at, card, step, host) as ($splits),
1725
- sp(card, step, host, cpu, mem, disk, power) as (
1726
- select x.card, x.step, 1.0 * coalesce(x.host, 0) * p.d / p.secs, p.cpu, p.mem, p.disk, p.power
1727
- from parts p join x on x.at = p.at),
1728
- total(steps, host) as (
1729
- select (select count(*) from (select distinct card, step from sp where card is not null and step is not null)),
1730
- coalesce(sum(host), 0) from sp),
1731
- res(o, name, lim, pow) as (
1732
- select 1, 'the CPU', coalesce(sum(case when cpu then host end), 0), coalesce(sum(case when cpu and power then host end), 0) from sp
1733
- union all
1734
- select 2, 'memory', coalesce(sum(case when mem then host end), 0), coalesce(sum(case when mem and power then host end), 0) from sp
1735
- union all
1736
- select 3, 'the disk', coalesce(sum(case when disk then host end), 0), coalesce(sum(case when disk and power then host end), 0) from sp),
1737
- pcts(cpu, mem, disk) as (
1738
- select max(case when o = 1 then pct end), max(case when o = 2 then pct end), max(case when o = 3 then pct end)
1739
- from (select o, printf('%.1f%%', 100.0 * lim / nullif(t.host, 0)) pct from res, total t)),
1740
- named(o, name, lim, pow) as (
1741
- select o, name, lim, pow from res, total t
1742
- where lim > 0 and 100.0 * lim >= $HOST_VERDICT_PCT * t.host order by lim desc, o limit 1),
1743
- w(d, started, ended) as ($waits),
1744
- med(m) as (select d from w order by d limit 1 offset (select count(*) / 2 from w)),
1745
- inp(d, started, ended) as (select d, started, ended from w where ended >= $s and ended < $e),
1746
- slow(started, ended) as (select i.started, i.ended from inp i, med where i.d > 2 * med.m),
1747
- span(secs) as (select coalesce(max(secs), 0) from readings),
1748
- below(n) as (
1749
- select count(*) from slow, span
1750
- where exists (select 1 from readings r
1751
- where r.at > slow.started and r.at < slow.ended + span.secs and r.at - r.secs < slow.ended)
1752
- and not exists (select 1 from readings r
1753
- where r.at > slow.started and r.at < slow.ended + span.secs and r.at - r.secs < slow.ended
1754
- and (coalesce(r.cpu_busy >= 90, 0) or coalesce(r.mem_pressure >= 2, 0) or coalesce(r.disk_free_pct < 10, 0)))),
1755
- net(n, total, median) as (select b.n, (select count(*) from inp), $median from below b, med),
1756
- lines(k, line) as (
1757
- select 0, ''
1758
- union all
1759
- select 1, 'The network may be the cause: ' || n || ' of ' || total || case when total = 1 then ' wait' else ' waits' end
1760
- || ' on the model ' || case when n = 1 then 'was' else 'were' end || ' slow (over twice the median of ' || median
1761
- || ') while CPU, memory and disk were below their limit.'
1762
- from net where n > 0
1763
- union all
1764
- select 2, '' from net where n > 0
1765
- union all
1766
- select 3, 'Verdict: ' || case
1767
- when t.steps < $HOST_VERDICT_STEPS or t.host < $HOST_VERDICT_SECS then
1768
- 'too little data yet: ' || t.steps || case when t.steps = 1 then ' step had its' else ' steps had their' end
1769
- || ' time split, with ' || $took || ' of the agents'' time on the host, and a verdict takes at least '
1770
- || '$HOST_VERDICT_STEPS steps and ' || $(sql_took $HOST_VERDICT_SECS) || '.'
1771
- when f.o is not null then
1772
- case when 2 * f.pow > f.lim then 'the power state was the limit, not ' || f.name else 'upgrade ' || f.name || ' first' end
1773
- || ': it was at its limit for ' || printf('%.1f%%', 100.0 * f.lim / t.host) || ' of the agents'' ' || $took || ' on the host'
1774
- || case when 2 * f.pow > f.lim then ', ' || printf('%.1f%%', 100.0 * f.pow / f.lim)
1775
- || ' of that on battery, in Low Power Mode or with the thermal state at serious or critical' else '' end
1776
- || ' (' || case f.o when 1 then 'memory ' || p.mem || ', disk ' || p.disk
1777
- when 2 then 'CPU ' || p.cpu || ', disk ' || p.disk else 'CPU ' || p.cpu || ', memory ' || p.mem end || ').'
1778
- when nt.n > 0 and 100 * nt.n >= $HOST_VERDICT_PCT * nt.total then
1779
- 'the network was the limit: ' || printf('%.1f%%', 100.0 * nt.n / nt.total) || ' of the ' || nt.total
1780
- || case when nt.total = 1 then ' wait on the model was' else ' waits on the model were' end
1781
- || ' slow (over twice the median of ' || nt.median || ') while CPU, memory and disk were below their limit,'
1782
- || ' and each was at its limit for under $HOST_VERDICT_PCT% of the agents'' ' || $took
1783
- || ' on the host (CPU ' || p.cpu || ', memory ' || p.mem || ', disk ' || p.disk || ').'
1784
- else
1785
- 'no upgrade is needed: CPU, memory and disk were each at their limit for under $HOST_VERDICT_PCT% of the agents'' '
1786
- || $took || ' on the host (CPU ' || p.cpu || ', memory ' || p.mem || ', disk ' || p.disk || ').'
1787
- end
1788
- from total t left join named f on 1 left join pcts p on 1 left join net nt on 1)
1789
- select line from lines order by k;
1790
- EOF
1791
- }
1792
-
1793
1463
  cmd_host() {
1794
1464
  case ${1:-} in
1795
1465
  '') [ "$#" -le 1 ] || die "$HOST_USAGE"; host_show ;;
package/cli/lib/merges.sh CHANGED
@@ -70,8 +70,9 @@
70
70
  # live terminal hold a name, so there is never more than one watch.
71
71
  #
72
72
  # What it saw is left for `task log`, which says when nothing can see a
73
- # card's pull requests (merges_seen, read by card_agent in agents.sh), and
74
- # for `ocnus status`, which says whether the watch runs (merges_status).
73
+ # card's pull requests, and counts the card as ready to merge once every one
74
+ # of them is open and ready (merges_seen, read by card_agent in agents.sh),
75
+ # and for `ocnus status`, which says whether the watch runs (merges_status).
75
76
  # As a pass begins it writes the time to merges/.alive, and after each card's
76
77
  # turn it writes merges/<space>/<card>: on one line, the time, then what it
77
78
  # saw (merges_saw). A pass whose call to GitHub failed as a whole writes
@@ -429,9 +430,12 @@ merges_tidy() {
429
430
  # What a check of a card's pull requests saw, as MERGES_SAW, for the card's
430
431
  # file: closed and the URL of each closed without merging, as a closed one
431
432
  # comes first; else conflict and each in conflict; else failed and why
432
- # GitHub could not be asked about one; else open while one is open, merged
433
- # once all have, or none when the card has none. It is none too for a card
434
- # the pass did not check, as one whose task is not on this machine.
433
+ # GitHub could not be asked about one; else ready when every pull request of
434
+ # the card is open and ready to merge, as GitHub said of each (GITHUB_READ),
435
+ # or open while one is open and that does not hold, as when another has
436
+ # merged; else merged once all have, or none when the card has none. It is
437
+ # none too for a card the pass did not check, as one whose task is not on
438
+ # this machine.
435
439
  # merges_saw <the check's lines>
436
440
  MERGES_SAW=none
437
441
  merges_saw() {
@@ -445,6 +449,7 @@ merges_saw() {
445
449
  if [ -n "$closed" ]; then MERGES_SAW="closed $closed"
446
450
  elif [ -n "$conflict" ]; then MERGES_SAW="conflict $conflict"
447
451
  elif [ "$CHECK_FAILED" -gt 0 ]; then MERGES_SAW="failed $(plain_note "$CHECK_WHY")"
452
+ elif [ "$CHECK_OPEN" -gt 0 ] && [ "$CHECK_READY" = "$CHECK_OPEN" ] && [ "$CHECK_MERGED" = 0 ]; then MERGES_SAW=ready
448
453
  elif [ "$CHECK_OPEN" -gt 0 ]; then MERGES_SAW=open
449
454
  elif [ "$CHECK_MERGED" -gt 0 ]; then MERGES_SAW=merged
450
455
  else MERGES_SAW=none
@@ -483,8 +488,8 @@ MERGES_NOW='' MERGES_CORE=''
483
488
  # is:
484
489
  # '' ocnus's watch is watching them, or nothing is
485
490
  # known: it ran a pass within MERGES_FRESH seconds and
486
- # saw them open, merged or none, or has not seen the
487
- # card in that time
491
+ # saw them ready, open, merged or none, or has not seen
492
+ # the card in that time
488
493
  # closed, conflict ocnus's watch is running and, within MERGES_FRESH
489
494
  # seconds, saw one closed without merging or in
490
495
  # conflict: MERGES_PULLS are their URLs, a space between
@@ -493,13 +498,15 @@ MERGES_NOW='' MERGES_CORE=''
493
498
  # ocnus's watch has not begun a pass within
494
499
  # MERGES_FRESH seconds, or GitHub could not be asked, as
495
500
  # its last pass saw
496
- # Whether an agent runs to be woken is card_agent's to say.
501
+ # MERGES_READY is 1 when ocnus's watch is running and, within MERGES_FRESH
502
+ # seconds, saw every pull request of the card open and ready to merge, and 0
503
+ # otherwise. Whether an agent runs to be woken is card_agent's to say.
497
504
  # merges_seen <space> <card ID, in upper case>
498
505
  MERGES_FRESH=$((3 * MERGES_PAUSE))
499
- MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY=''
506
+ MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY='' MERGES_READY=0
500
507
  merges_seen() {
501
508
  local space=$1 card=$2 at what rest
502
- MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY=''
509
+ MERGES_SEEN='' MERGES_PULLS='' MERGES_WHY='' MERGES_READY=0
503
510
  MERGES_SEEN=unwatched
504
511
  have_hc || { MERGES_WHY="Herdr's hc not installed"; return 0; }
505
512
  if [ -z "$MERGES_CORE" ]; then
@@ -519,6 +526,7 @@ merges_seen() {
519
526
  case $what in
520
527
  closed | conflict) [ -z "$rest" ] || MERGES_SEEN=$what MERGES_PULLS=$rest ;;
521
528
  failed) MERGES_SEEN=unwatched MERGES_WHY=${rest:-gh failed} ;;
529
+ ready) MERGES_READY=1 ;;
522
530
  esac
523
531
  }
524
532
 
@@ -708,7 +716,9 @@ merge_wake_agent() {
708
716
 
709
717
  # What GitHub said of a card's pull requests, from the card's lines of
710
718
  # github_pulls: a line for each pull request, merged, open, closed or
711
- # conflict, then its URL, and the CHECK_* counts. A branch with no pull request is skipped, since the work
719
+ # conflict, then its URL, and the CHECK_* counts. An open one that GitHub
720
+ # called ready is open here too, and is counted in CHECK_READY as well. A
721
+ # branch with no pull request is skipped, since the work
712
722
  # did not change that repo. One that GitHub could not be asked about is
713
723
  # counted in CHECK_FAILED, with the first why in CHECK_WHY, and said on
714
724
  # stderr; CHECK_SIGN_IN is 1 for it when gh needs signing in.
@@ -716,13 +726,14 @@ merge_wake_agent() {
716
726
  merges_pulls() {
717
727
  local key state rest
718
728
  CHECK_OPEN=0 CHECK_CLOSED=0 CHECK_MERGED=0 CHECK_CONFLICT=0 CHECK_FAILED=0
719
- CHECK_SIGN_IN=0 CHECK_WHY=''
729
+ CHECK_READY=0 CHECK_SIGN_IN=0 CHECK_WHY=''
720
730
  while read -r key state rest; do
721
731
  case $state in
722
732
  merged) CHECK_MERGED=$((CHECK_MERGED + 1)); say "merged $rest" ;;
723
733
  closed) CHECK_CLOSED=$((CHECK_CLOSED + 1)); say "closed $rest" ;;
724
734
  conflict) CHECK_CONFLICT=$((CHECK_CONFLICT + 1)); say "conflict $rest" ;;
725
735
  open) CHECK_OPEN=$((CHECK_OPEN + 1)); say "open $rest" ;;
736
+ ready) CHECK_OPEN=$((CHECK_OPEN + 1)); CHECK_READY=$((CHECK_READY + 1)); say "open $rest" ;;
726
737
  none) ;;
727
738
  *)
728
739
  CHECK_FAILED=$((CHECK_FAILED + 1))
package/cli/lib/tests.sh CHANGED
@@ -107,9 +107,8 @@ tests_set() {
107
107
  # readings is there too. The job's row goes in test_runs as it starts, with
108
108
  # its card, repo, start and the job's pid, and the fingerprint of its
109
109
  # command, cmd: the first 15 hex digits of the SHA-256 of its arguments, each
110
- # ended by a NUL, as a number. It is the same for the same command, so that
111
- # `host report` can set runs of the same command in the same repo against
112
- # each other, and the command's text cannot be read back from it. It is all
110
+ # ended by a NUL, as a number. It is the same for the same command,
111
+ # and the command's text cannot be read back from it. It is all
113
112
  # that is kept of the command line. While the job runs, the sampler adds up
114
113
  # the memory of its processes every second, and writes the most it saw to
115
114
  # the row. When the job ends, the row gets its end and the figures, and what
package/cli/ocnus CHANGED
@@ -92,15 +92,11 @@ Usage:
92
92
  ocnus host say whether how hard this machine works is recorded
93
93
  ocnus host on record it every 10 seconds while an agent is open
94
94
  ocnus host off stop recording, and delete every reading
95
- ocnus host report [<period>] how often CPU, memory and disk were at their limit, how often
96
- CPU or memory was with each number of agents working, and
97
- how much slower test runs were then, the work going in the
98
- 5 longest stretches when it was, the steps, phases and test
99
- runs that used the most CPU and memory, where the steps'
100
- time went, whether the network may be the cause of slow
101
- waits on the model, and a verdict on what to upgrade first:
102
- <n>d or <n>h back from now (7d when none is given), a day
103
- YYYY-MM-DD, or <day>..<day>
95
+ ocnus host report [<period>] how often CPU, memory and disk were at their limit, the
96
+ steps, phases and test runs that used the most CPU and
97
+ memory, and where the steps' time went: <n>d or <n>h back
98
+ from now (7d when none is given), a day YYYY-MM-DD, or
99
+ <day>..<day>
104
100
  ocnus help
105
101
 
106
102
  A space groups repos that belong together, with a SPACE.md saying what
@@ -296,20 +292,9 @@ at their limit: CPU at least 90% busy across all cores, memory pressure at
296
292
  warning or critical, and under 10% of the home folder's disk free. Time with
297
293
  no reading, such as when no agent was open, is shown as missing, never as
298
294
  idle. It also says how much of the CPU recording used, watching the test
299
- runs included. For each number of agents working at once, it says how long
300
- that many were working and how much of that time CPU or memory was at its
301
- limit, and names the fewest working at which that was at least a quarter of
302
- the time, as the number from which the host was the limit. For each number
303
- from 2 up, it says how much slower test runs were than with one working,
304
- setting only runs of the same command in the same repo against each other,
305
- once a command has run at least 3 times with each; until then, it says it
306
- cannot tell yet. It names the 5 longest stretches when CPU or memory was at
307
- its limit, each with when it started, how long it lasted, which was at its
308
- limit, and every card's step and every test run going then, with its share
309
- of the CPU and the most memory it held, and for each card how much of the
310
- stretch its agent was working. Then it lists the 10 steps and the 10
311
- phases, each one card's own, that used the most CPU time, and that held the
312
- most memory at once, then the 10 test runs that did.
295
+ runs included. Then it lists the 10 steps and the 10 phases, each one
296
+ card's own, that used the most CPU time, and that held the most memory at
297
+ once, then the 10 test runs that did.
313
298
 
314
299
  While the host is recorded, `task new` and `task build` also start claude
315
300
  with hooks that mark when its agent starts and stops, is given a prompt,
@@ -323,22 +308,7 @@ same for the 10 steps open longest, and how many steps had no split, as an
323
308
  agent started in another harness or while recording was off has none.
324
309
 
325
310
  Each wait on the model is kept too, as its start and end alone, for 90
326
- days. A wait is slow when it took over twice the median of every wait
327
- kept. When waits in the period were slow while CPU, memory and disk were
328
- all below their limit, `host report` says the network may be the cause,
329
- with how many were slow and the median.
330
-
331
- Last, `host report` gives its verdict, one line with its numbers. With
332
- fewer than 10 steps with their time split in the period, or under an hour
333
- of the agents' time on the host, the time their tools ran, there is too
334
- little data yet. Otherwise, of CPU, memory and disk, the one at its limit
335
- for the most of the agents' time on the host, when that is at least 10% of
336
- it, is the one to upgrade first, unless over half of its time at its limit
337
- was on battery, in Low Power Mode or with the thermal state at serious or
338
- critical: then the power state was the limit. With none at 10%, the network
339
- was the limit when at least 10% of the period's waits on the model were
340
- slow while CPU, memory and disk were below their limit, and otherwise no
341
- upgrade is needed.
311
+ days.
342
312
 
343
313
  `tests run <command> [<arg>...]` runs a repo's test command, whole suite or
344
314
  part, as in `ocnus tests run npm test`: its output goes straight