@johngaynor/ocnus 2.0.1-next.7 → 2.0.1-next.73
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/README.md +518 -98
- package/cli/lib/agents.sh +32 -16
- package/cli/lib/asks.sh +762 -0
- package/cli/lib/banner.sh +181 -0
- package/cli/lib/brief.sh +375 -0
- package/cli/lib/chain.sh +363 -0
- package/cli/lib/close.sh +5 -3
- package/cli/lib/cost.sh +500 -0
- package/cli/lib/finish.sh +30 -4
- package/cli/lib/github.sh +106 -26
- package/cli/lib/guard.sh +39 -10
- package/cli/lib/handoff.sh +196 -31
- package/cli/lib/host.sh +340 -384
- package/cli/lib/linear.sh +552 -56
- package/cli/lib/links.sh +6 -3
- package/cli/lib/merges.sh +126 -27
- package/cli/lib/sessions.sh +132 -0
- package/cli/lib/settings.sh +31 -15
- package/cli/lib/task.sh +169 -54
- package/cli/lib/tests.sh +302 -7
- package/cli/lib/usage.sh +204 -0
- package/cli/ocnus +274 -76
- package/herdr/README.md +930 -232
- package/herdr/layouts/default.json +30 -11
- package/herdr/layouts/showcase.json +291 -0
- package/herdr/layouts/vibe.json +162 -0
- package/herdr/layouts/vibe.svg +41 -0
- package/herdr/mods/agent-settings/main.js +19 -7
- package/herdr/mods/memory/main.js +128 -0
- package/herdr/mods/memory/mod.json +1 -0
- package/herdr/mods/memory/reading.js +88 -0
- package/herdr/mods/names/main.js +22 -4
- package/herdr/mods/step-counts/main.js +281 -0
- package/herdr/mods/step-counts/mod.json +1 -0
- package/herdr/mods/usage/main.js +149 -0
- package/herdr/mods/usage/mod.json +1 -0
- package/package.json +1 -1
- package/prompts/task-new.md +1 -1
- package/skills/brief/SKILL.md +8 -0
- package/skills/sdlc-breakdown/SKILL.md +66 -18
- package/skills/sdlc-build/SKILL.md +6 -2
- package/skills/sdlc-pr/SKILL.md +2 -2
- package/skills/sdlc-review/SKILL.md +5 -5
package/cli/lib/host.sh
CHANGED
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
# under a terminal labelled with a space, apart from everything else on the
|
|
20
20
|
# host, which is one number each, and the recorder's own CPU apart from both.
|
|
21
21
|
# A process outside those terminals is never written down, not even its pid.
|
|
22
|
+
# `host report` sums those numbers up for a period, as totals, averages and
|
|
23
|
+
# peaks, and how long each state lasted, and judges none of them.
|
|
22
24
|
#
|
|
23
25
|
# With each reading go the shares of those terminals, one each: the CPU and
|
|
24
26
|
# memory of every process under it, the commands its agent started included,
|
|
@@ -33,9 +35,7 @@
|
|
|
33
35
|
# turn, as herdr-core's status for its terminal says, and waiting while it is
|
|
34
36
|
# open but its turn has ended, it waits on the human in its tab, it hit an
|
|
35
37
|
# error, or it reports no status. A tab that holds its shell alone is not
|
|
36
|
-
# open, so it is neither.
|
|
37
|
-
# working, how much of the time the host was at its limit, and from which
|
|
38
|
-
# number the host was the limit.
|
|
38
|
+
# open, so it is neither.
|
|
39
39
|
#
|
|
40
40
|
# Beside the readings go the test runs: each run of a repo's tests that an
|
|
41
41
|
# agent starts through `ocnus tests run` (tests.sh), with its card and
|
|
@@ -43,16 +43,12 @@
|
|
|
43
43
|
# memory it held at once. A test run is named by its card and repo alone.
|
|
44
44
|
# Its command is kept only as a fingerprint, a number the same for the same
|
|
45
45
|
# 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
|
|
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.
|
|
46
|
+
# its command line is kept. `host report` ranks the test runs too.
|
|
49
47
|
#
|
|
50
48
|
# With each reading go the shares of the test runs going then, too, each
|
|
51
49
|
# worked out as a terminal's is, from the processes under the run's job,
|
|
52
50
|
# 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.
|
|
54
|
-
# names the cards' steps and the test runs going in the longest stretches
|
|
55
|
-
# when the CPU or memory was at its limit.
|
|
51
|
+
# reading before gets the rest of its CPU in the next one.
|
|
56
52
|
#
|
|
57
53
|
# While recording is on, `task new` and `task build` start claude with hooks
|
|
58
54
|
# that mark its agent's time (host_hooks): cli/host-mark appends a word and
|
|
@@ -64,16 +60,15 @@
|
|
|
64
60
|
# those marks (host_splits): on the host, while its tools run, and waiting
|
|
65
61
|
# on the model. The rest of the time its agent was open is neither, such as
|
|
66
62
|
# waiting on the human. `host report` says where the steps' time went by
|
|
67
|
-
# them
|
|
68
|
-
# the agents' time on the host in it: what to upgrade first, if anything.
|
|
63
|
+
# them.
|
|
69
64
|
#
|
|
70
65
|
# 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.
|
|
72
|
-
#
|
|
73
|
-
#
|
|
74
|
-
#
|
|
75
|
-
#
|
|
76
|
-
#
|
|
66
|
+
# end alone, by the reading it ended in.
|
|
67
|
+
#
|
|
68
|
+
# `host report --card <space> <card> --json` gives a program the readings
|
|
69
|
+
# taken while each of a card's steps ran, as one line of JSON (host_card):
|
|
70
|
+
# the whole host's CPU and memory, with each step's start and end from the
|
|
71
|
+
# hand-off store, which it only reads.
|
|
77
72
|
#
|
|
78
73
|
# A share's card, phase and step, a split's, a wait's, and a test run's card
|
|
79
74
|
# and repo, are the only text the readings hold, and only the values
|
|
@@ -215,7 +210,7 @@ host_table() {
|
|
|
215
210
|
[ -z "$sql" ] || store "$HOST_DB" "begin; ${sql}commit;"
|
|
216
211
|
}
|
|
217
212
|
|
|
218
|
-
HOST_USAGE='usage: ocnus host [on|off|report [<period>]] (see: ocnus help)'
|
|
213
|
+
HOST_USAGE='usage: ocnus host [on|off|report [<period>]|report --card <space> <card> --json] (see: ocnus help)'
|
|
219
214
|
HOST_PERIODS='a period is <n>d or <n>h back from now, like 7d or 12h; a day, like 2026-11-29; or two days and every day between, like 2026-11-01..2026-11-29'
|
|
220
215
|
|
|
221
216
|
# --- on and off -------------------------------------------------------------
|
|
@@ -1216,13 +1211,18 @@ host_day() {
|
|
|
1216
1211
|
[ "$ok" = 1 ] && [ -n "$DAY_START" ] && [ -n "$DAY_END" ]
|
|
1217
1212
|
}
|
|
1218
1213
|
|
|
1219
|
-
# How the
|
|
1220
|
-
# was recorded,
|
|
1221
|
-
#
|
|
1222
|
-
#
|
|
1223
|
-
#
|
|
1214
|
+
# How the host worked over a period, in its numbers alone: how much of the
|
|
1215
|
+
# period was recorded, in all and on each day, with time with no reading
|
|
1216
|
+
# shown as missing, never as idle (host_report_sql). Then the host's numbers
|
|
1217
|
+
# summed up (host_numbers_sql), the steps, phases and test runs that used the
|
|
1218
|
+
# most (host_ranks_sql), and it ends with where the steps' time went
|
|
1219
|
+
# (host_split_sql).
|
|
1224
1220
|
host_report() {
|
|
1225
|
-
local period=${1:-7d} now start end n first last row
|
|
1221
|
+
local period=${1:-7d} now start end n first last row have ranks=0 works=0 splits=0
|
|
1222
|
+
# A card's readings, as JSON, are a form of their own.
|
|
1223
|
+
for n in "$@"; do
|
|
1224
|
+
case $n in --card | --json) host_card "$@"; return ;; esac
|
|
1225
|
+
done
|
|
1226
1226
|
[ "$#" -le 1 ] || die "$HOST_USAGE"
|
|
1227
1227
|
now=$(date +%s)
|
|
1228
1228
|
case $period in
|
|
@@ -1262,59 +1262,40 @@ host_report() {
|
|
|
1262
1262
|
say "Recording is on, and takes a reading every $HOST_EVERY seconds while an ocnus agent is open."
|
|
1263
1263
|
return 0
|
|
1264
1264
|
fi
|
|
1265
|
-
# A store the recorder has not opened since
|
|
1266
|
-
#
|
|
1267
|
-
#
|
|
1268
|
-
#
|
|
1269
|
-
#
|
|
1270
|
-
#
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
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
|
|
1291
|
-
store "$HOST_DB" "$(host_report_sql "$start" "$end" "$period" "$row")" ||
|
|
1292
|
-
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
|
-
if [ "$row" = 1 ]; then
|
|
1265
|
+
# A store the recorder has not opened since a table or a column came has
|
|
1266
|
+
# none of it, and the report only reads the store, so it never adds them.
|
|
1267
|
+
# A number whose column the store lacks is not read. The lists of what
|
|
1268
|
+
# used the most need the readings' cores, the shares and the test runs,
|
|
1269
|
+
# and where the steps' time went needs the shares, and the splits to split
|
|
1270
|
+
# it.
|
|
1271
|
+
have=$(host_columns) || have=' '
|
|
1272
|
+
case $have in *' shares.'*) works=1 ;; esac
|
|
1273
|
+
case $have in *' splits.'*) splits=$works ;; esac
|
|
1274
|
+
case $have in *' readings.cores '*) case $have in *' test_runs.'*) ranks=$works ;; esac ;; esac
|
|
1275
|
+
store "$HOST_DB" "$(host_report_sql "$start" "$end" "$period")" || die "could not read $HOST_DB"
|
|
1276
|
+
store "$HOST_DB" "$(host_numbers_sql "$start" "$end" "$have")" || die "could not read $HOST_DB"
|
|
1277
|
+
if [ "$ranks" = 1 ]; then
|
|
1298
1278
|
store "$HOST_DB" "$(host_ranks_sql "$start" "$end")" || die "could not read $HOST_DB"
|
|
1299
1279
|
else
|
|
1300
1280
|
say ''
|
|
1301
1281
|
say 'No step, phase or test run was recorded in this period.'
|
|
1302
1282
|
fi
|
|
1303
1283
|
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
1284
|
}
|
|
1306
1285
|
|
|
1307
|
-
# The
|
|
1308
|
-
#
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1286
|
+
# The tables and the columns the readings' store has, each column as its
|
|
1287
|
+
# table and its name, like readings.cores, between spaces, from one query.
|
|
1288
|
+
host_columns() {
|
|
1289
|
+
store "$HOST_DB" "select ' ' || coalesce(group_concat(m.name || '.' || p.name, ' '), '') || ' '
|
|
1290
|
+
from sqlite_master m join pragma_table_info(m.name) p where m.type = 'table';"
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
# The top of the report, for the period from $1 to $2, named $3: how much of
|
|
1294
|
+
# it was recorded and how much is missing, then the same for each day. A
|
|
1295
|
+
# reading covers the secs before its at, so each one counts for the part of
|
|
1296
|
+
# that which falls in the period, and in each day.
|
|
1313
1297
|
host_report_sql() {
|
|
1314
|
-
local s=$1 e=$2 name=$3
|
|
1315
|
-
[ "${4:-0}" != 1 ] ||
|
|
1316
|
-
watch="coalesce(100.0 * (select sum(watch_secs) from test_runs where started >= $s and started < $e)
|
|
1317
|
-
/ (select nullif(max(cores), 0) from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e), 0)"
|
|
1298
|
+
local s=$1 e=$2 name=$3
|
|
1318
1299
|
cat <<EOF
|
|
1319
1300
|
with recursive
|
|
1320
1301
|
days(day, ds, de) as (
|
|
@@ -1326,216 +1307,156 @@ with recursive
|
|
|
1326
1307
|
cast(strftime('%s', date(day, '+1 day'), 'utc') as integer),
|
|
1327
1308
|
min($e, cast(strftime('%s', date(day, '+2 days'), 'utc') as integer))
|
|
1328
1309
|
from days where de < $e),
|
|
1329
|
-
parts(day, len, d
|
|
1330
|
-
select days.day, days.de - days.ds,
|
|
1331
|
-
max(0, min(at, days.de) - max(at - secs, days.ds)), cpu_busy, mem_pressure, disk_free_pct, cpu_self
|
|
1310
|
+
parts(day, len, d) as (
|
|
1311
|
+
select days.day, days.de - days.ds, max(0, min(at, days.de) - max(at - secs, days.ds))
|
|
1332
1312
|
from days left join readings on at > days.ds and at < days.de + $HOST_GAP and at - secs < days.de),
|
|
1333
|
-
byday(day, len, rec
|
|
1334
|
-
select day, len, cast(coalesce(sum(d), 0) as integer),
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
from parts group by day),
|
|
1340
|
-
total(len, rec, cpu, mem, disk, self) as (
|
|
1341
|
-
select $e - $s, sum(rec), sum(cpu), sum(mem), sum(disk),
|
|
1342
|
-
case when sum(self_d) > 0 then (sum(self_time) + $watch) / sum(self_d) end
|
|
1343
|
-
from byday),
|
|
1344
|
-
shown(len, rec, missing, cpu, mem, disk, self) as (
|
|
1345
|
-
select len, rec, max(0, len - rec), cpu, mem, disk, self from total),
|
|
1313
|
+
byday(day, len, rec) as (
|
|
1314
|
+
select day, len, cast(coalesce(sum(d), 0) as integer) from parts group by day),
|
|
1315
|
+
total(len, rec) as (
|
|
1316
|
+
select $e - $s, sum(rec) from byday),
|
|
1317
|
+
shown(len, rec, missing) as (
|
|
1318
|
+
select len, rec, max(0, len - rec) from total),
|
|
1346
1319
|
lines(n, k, line) as (
|
|
1347
1320
|
select 1, '', 'The host from ' || strftime('%Y-%m-%d %H:%M', $s, 'unixepoch', 'localtime') || ' to '
|
|
1348
1321
|
|| strftime('%Y-%m-%d %H:%M', $e, 'unixepoch', 'localtime') || ' ($name)' from shown
|
|
1349
1322
|
union all select 2, '', ' recorded ' || $(sql_took rec) || ' of ' || $(sql_took len) from shown
|
|
1350
1323
|
union all select 3, '', ' missing ' || $(sql_took missing) || ', shown as missing, not idle: no reading was taken then' from shown
|
|
1351
|
-
union all select 4, '', '
|
|
1352
|
-
|
|
1353
|
-
union all select 5, '', ' memory at its limit ' || $(sql_took mem) || ', ' || printf('%.1f%%', 100.0 * mem / rec)
|
|
1354
|
-
|| ' of the recorded time (memory pressure at warning or critical)' from shown
|
|
1355
|
-
union all select 6, '', ' disk at its limit ' || $(sql_took disk) || ', ' || printf('%.1f%%', 100.0 * disk / rec)
|
|
1356
|
-
|| ' of the recorded time (under 10% free on the disk holding the home folder)' from shown
|
|
1357
|
-
union all select 7, '', ' recording ' || case when self is null then 'its own use of the CPU was not read'
|
|
1358
|
-
else 'used ' || printf('%.2f%%', self) || ' of the CPU, all cores together, on average' end from shown
|
|
1359
|
-
union all select 8, '', '' union all select 9, '', 'By day:'
|
|
1360
|
-
union all select 10, day, ' ' || day || ' recorded ' || $(sql_took rec) || ', missing ' || $(sql_took "max(0, len - rec)")
|
|
1361
|
-
|| case when rec > 0 then '; at its limit: CPU ' || printf('%.1f%%', 100.0 * cpu / rec)
|
|
1362
|
-
|| ', memory ' || printf('%.1f%%', 100.0 * mem / rec) || ', disk ' || printf('%.1f%%', 100.0 * disk / rec)
|
|
1363
|
-
else '' end
|
|
1324
|
+
union all select 4, '', '' union all select 5, '', 'By day:'
|
|
1325
|
+
union all select 6, day, ' ' || day || ' recorded ' || $(sql_took rec) || ', missing ' || $(sql_took "max(0, len - rec)")
|
|
1364
1326
|
from byday)
|
|
1365
1327
|
select line from lines order by n, k;
|
|
1366
1328
|
EOF
|
|
1367
1329
|
}
|
|
1368
1330
|
|
|
1369
|
-
# The
|
|
1370
|
-
#
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
#
|
|
1378
|
-
#
|
|
1379
|
-
#
|
|
1331
|
+
# The numbers a reading holds of the host, in the order the report gives
|
|
1332
|
+
# them: CPU, memory, disk, network, and power and heat.
|
|
1333
|
+
HOST_NUMBERS='cpu_busy cpu_system cpu_agents cpu_rest cpu_self cpu_p cpu_e
|
|
1334
|
+
mem_pressure mem_used_mb mem_agents_mb mem_rest_mb compressed_mb swap_used_mb swap_ins swap_outs
|
|
1335
|
+
disk_read_kb disk_write_kb disk_free_pct
|
|
1336
|
+
net_in_kb net_out_kb net_wifi net_resent_pct wifi_rssi wifi_noise
|
|
1337
|
+
on_battery low_power thermal'
|
|
1338
|
+
|
|
1339
|
+
# The host's numbers from $1 to $2, under five headings: CPU, memory, disk,
|
|
1340
|
+
# network, and power and heat. They are read from r, the readings in the
|
|
1341
|
+
# period, each with d, the part of its secs in the period, as the report
|
|
1342
|
+
# counts a reading. Each number is summed up as what it is:
|
|
1343
|
+
# a level its average, each reading weighed by its d, over the readings
|
|
1344
|
+
# that hold it, and its highest in one reading, or its lowest
|
|
1345
|
+
# for the disk's free space and the Wi-Fi's signal (host_level)
|
|
1346
|
+
# an amount its total: the recorder writes what it grew by in each
|
|
1347
|
+
# reading, and one on the period's edge counts in proportion to
|
|
1348
|
+
# its d, as host_split_sql counts a split (host_amount)
|
|
1349
|
+
# a state how long each value lasted, and how long it was not read when
|
|
1350
|
+
# that is more than nothing (host_state)
|
|
1351
|
+
# A number no reading in the period holds says not read in place of its
|
|
1352
|
+
# figures, as SQLite's printf would print a null as 0, and sql_took of a
|
|
1353
|
+
# null is null. $3 lists the store's tables and columns, as host_columns
|
|
1354
|
+
# gives them, and a column the store lacks is read as null, so that its
|
|
1355
|
+
# number says not read too. Every line is worked out in one pass over the
|
|
1356
|
+
# readings, into one array, which gives them in its order.
|
|
1380
1357
|
#
|
|
1381
|
-
#
|
|
1382
|
-
#
|
|
1383
|
-
#
|
|
1384
|
-
#
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
|
|
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
|
|
1358
|
+
# Recording's average adds what watching the test runs that started in the
|
|
1359
|
+
# period used, as a share of the cores the readings counted, over the time
|
|
1360
|
+
# its own CPU was read. No reading holds that, so its most in one reading
|
|
1361
|
+
# is the recorder's own.
|
|
1362
|
+
host_numbers_sql() {
|
|
1363
|
+
local s=$1 e=$2 have=$3 c cols='' watch=''
|
|
1364
|
+
for c in $HOST_NUMBERS; do
|
|
1365
|
+
case $have in *" readings.$c "*) cols="$cols, $c" ;; *) cols="$cols, null as $c" ;; esac
|
|
1366
|
+
done
|
|
1367
|
+
case $have in
|
|
1368
|
+
*' readings.cores '*)
|
|
1369
|
+
case $have in
|
|
1370
|
+
*' test_runs.watch_secs '*)
|
|
1371
|
+
watch="coalesce(100.0 * (select sum(watch_secs) from test_runs where started >= $s and started < $e)
|
|
1372
|
+
/ (select nullif(max(cores), 0) from readings where at > $s and at < $e + $HOST_GAP and at - secs < $e), 0)"
|
|
1373
|
+
;;
|
|
1374
|
+
esac
|
|
1375
|
+
;;
|
|
1376
|
+
esac
|
|
1403
1377
|
cat <<EOF
|
|
1404
1378
|
with
|
|
1405
|
-
|
|
1406
|
-
select
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
select
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
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;
|
|
1379
|
+
r as (
|
|
1380
|
+
select max(0, min(at, $e) - max(at - secs, $s)) as d, secs$cols from readings
|
|
1381
|
+
where at > $s and at < $e + $HOST_GAP and at - secs < $e and secs > 0),
|
|
1382
|
+
numbers(lines) as (
|
|
1383
|
+
select json_array(
|
|
1384
|
+
'', 'CPU, as a share of all cores'' time:',
|
|
1385
|
+
$(host_level busy cpu_busy '%.1f%%'),
|
|
1386
|
+
$(host_level system cpu_system '%.1f%%'),
|
|
1387
|
+
$(host_level 'the agents' cpu_agents '%.1f%%'),
|
|
1388
|
+
$(host_level 'the rest' cpu_rest '%.1f%%'),
|
|
1389
|
+
$(host_level recording cpu_self '%.2f%%' '' most "$watch"),
|
|
1390
|
+
$(host_level 'performance cores' cpu_p '%.1f%%' 'busy on average'),
|
|
1391
|
+
$(host_level 'efficiency cores' cpu_e '%.1f%%' 'busy on average'),
|
|
1392
|
+
'', 'Memory:',
|
|
1393
|
+
$(host_state pressure mem_pressure 'not read' normal '< 2' warning 'between 2 and 3' critical '>= 4'),
|
|
1394
|
+
$(host_level used mem_used_mb '%.0f MB'),
|
|
1395
|
+
$(host_level 'the agents' mem_agents_mb '%.0f MB'),
|
|
1396
|
+
$(host_level 'the rest' mem_rest_mb '%.0f MB'),
|
|
1397
|
+
$(host_level compressed compressed_mb '%.0f MB'),
|
|
1398
|
+
$(host_level 'swap used' swap_used_mb '%.0f MB'),
|
|
1399
|
+
$(host_amount 'swapped in' swap_ins '%.0f pages'),
|
|
1400
|
+
$(host_amount 'swapped out' swap_outs '%.0f pages'),
|
|
1401
|
+
'', 'Disk:',
|
|
1402
|
+
$(host_amount read disk_read_kb '%.1f MB' 1024),
|
|
1403
|
+
$(host_amount written disk_write_kb '%.1f MB' 1024),
|
|
1404
|
+
$(host_level free disk_free_pct '%.1f%%' '' lowest),
|
|
1405
|
+
'', 'Network:',
|
|
1406
|
+
$(host_amount received net_in_kb '%.1f MB' 1024),
|
|
1407
|
+
$(host_amount sent net_out_kb '%.1f MB' 1024),
|
|
1408
|
+
$(host_state interface net_wifi 'offline or not read' Wi-Fi '= 1' another '= 0'),
|
|
1409
|
+
$(host_level 'sent again' net_resent_pct '%.1f%%' 'of TCP bytes on average'),
|
|
1410
|
+
$(host_level 'Wi-Fi signal' wifi_rssi '%.0f dBm' '' lowest),
|
|
1411
|
+
$(host_level 'Wi-Fi noise' wifi_noise '%.0f dBm'),
|
|
1412
|
+
'', 'Power and heat:',
|
|
1413
|
+
$(host_state power on_battery 'not read' 'on battery' '= 1' 'on power' '= 0'),
|
|
1414
|
+
$(host_state 'Low Power Mode' low_power 'not read' on '= 1' off '= 0'),
|
|
1415
|
+
$(host_state 'thermal state' thermal 'not read' nominal '= 0' fair '= 1' serious '= 2' critical '= 3'))
|
|
1416
|
+
from r)
|
|
1417
|
+
select value from numbers, json_each(numbers.lines) order by key;
|
|
1462
1418
|
EOF
|
|
1463
1419
|
}
|
|
1464
1420
|
|
|
1465
|
-
#
|
|
1466
|
-
#
|
|
1467
|
-
#
|
|
1468
|
-
#
|
|
1469
|
-
#
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
#
|
|
1479
|
-
#
|
|
1480
|
-
#
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
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
|
|
1421
|
+
# SQL for a line of the host's numbers on a level, over the readings r: the
|
|
1422
|
+
# label $1, then the average of the column $2, with the words $4 after it,
|
|
1423
|
+
# or "on average", and its highest in one reading, or its lowest with $5 as
|
|
1424
|
+
# lowest. $3 is the printf format of each figure. $6, when given, is added
|
|
1425
|
+
# to the readings' sum before it is divided by their seconds.
|
|
1426
|
+
host_level() {
|
|
1427
|
+
local peak="max($2)" most='at most'
|
|
1428
|
+
[ "${5:-}" != lowest ] || peak="min($2)" most='at the lowest'
|
|
1429
|
+
printf '%s' "' ' || printf('%-19s', '$1') || case when count($2) = 0 then 'not read'
|
|
1430
|
+
else printf('$3', (sum(1.0 * $2 * d)${6:+ + $6}) / sum(case when $2 is not null then d end))
|
|
1431
|
+
|| ' ${4:-on average}, ' || printf('$3', $peak) || ' $most' end"
|
|
1432
|
+
}
|
|
1433
|
+
|
|
1434
|
+
# SQL for a line of the host's numbers on an amount, over the readings r:
|
|
1435
|
+
# the label $1, then the total of the column $2, divided by $4 when it is
|
|
1436
|
+
# given, in the printf format $3. Each reading counts what it grew by for
|
|
1437
|
+
# its d in proportion to its secs.
|
|
1438
|
+
host_amount() {
|
|
1439
|
+
printf '%s' "' ' || printf('%-19s', '$1') || case when count($2) = 0 then 'not read'
|
|
1440
|
+
else printf('$3', sum(1.0 * $2 * d / secs)${4:+ / $4}) end"
|
|
1441
|
+
}
|
|
1442
|
+
|
|
1443
|
+
# SQL for a line of the host's numbers on a state, over the readings r: the
|
|
1444
|
+
# label $1, then how long the column $2 held each value, $4 onward, each a
|
|
1445
|
+
# name and the SQL that tests the column for it, like normal '< 2'. Then,
|
|
1446
|
+
# when it is more than nothing, how long it held none of them, which $3
|
|
1447
|
+
# names.
|
|
1448
|
+
host_state() {
|
|
1449
|
+
local label=$1 col=$2 none=$3 shown='' left='sum(d)' v
|
|
1450
|
+
shift 3
|
|
1451
|
+
while [ "$#" -ge 2 ]; do
|
|
1452
|
+
v="sum(case when $col $2 then d else 0 end)"
|
|
1453
|
+
[ -z "$shown" ] || shown="$shown || ', ' || "
|
|
1454
|
+
shown="$shown'$1 ' || $(sql_took "$v")"
|
|
1455
|
+
left="$left - $v"
|
|
1456
|
+
shift 2
|
|
1457
|
+
done
|
|
1458
|
+
printf '%s' "' ' || printf('%-19s', '$label') || case when count($col) = 0 then 'not read'
|
|
1459
|
+
else $shown || case when $left > 0 then ', $none ' || $(sql_took "($left)") else '' end end"
|
|
1539
1460
|
}
|
|
1540
1461
|
|
|
1541
1462
|
# The steps and the phases that used the most CPU time, and that held the
|
|
@@ -1663,131 +1584,166 @@ select line from lines order by k;
|
|
|
1663
1584
|
EOF
|
|
1664
1585
|
}
|
|
1665
1586
|
|
|
1666
|
-
# The
|
|
1667
|
-
#
|
|
1668
|
-
#
|
|
1669
|
-
#
|
|
1587
|
+
# The readings taken while each of a card's steps ran, as one line of JSON:
|
|
1588
|
+
# `host report --card <space> <card> --json`. Anything else it is asked is
|
|
1589
|
+
# refused on stderr, with nothing on stdout, so that a program never reads
|
|
1590
|
+
# words as JSON.
|
|
1670
1591
|
#
|
|
1671
|
-
# A
|
|
1672
|
-
#
|
|
1673
|
-
#
|
|
1674
|
-
#
|
|
1675
|
-
#
|
|
1676
|
-
#
|
|
1677
|
-
#
|
|
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.
|
|
1592
|
+
# A step is each time the card was in it: hand-offs of one step in a row,
|
|
1593
|
+
# from the hand-off before the first to the last, so the time it waited on
|
|
1594
|
+
# the human is inside it. The times are log_view's, as `task log` shows
|
|
1595
|
+
# them, so the two cannot disagree. A `new` or a `start` row has no time
|
|
1596
|
+
# there, so it has no entry here. The step under way runs to now and is
|
|
1597
|
+
# open: the one the log counts as under way (card_agent in agents.sh), or
|
|
1598
|
+
# one whose question still waits.
|
|
1681
1599
|
#
|
|
1682
|
-
#
|
|
1683
|
-
#
|
|
1684
|
-
#
|
|
1685
|
-
#
|
|
1686
|
-
#
|
|
1687
|
-
#
|
|
1688
|
-
#
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1706
|
-
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
1710
|
-
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
1716
|
-
|
|
1717
|
-
|
|
1718
|
-
|
|
1719
|
-
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
|
|
1776
|
-
|
|
1777
|
-
|
|
1778
|
-
|
|
1779
|
-
|
|
1780
|
-
|
|
1781
|
-
|
|
1782
|
-
|
|
1783
|
-
|
|
1784
|
-
|
|
1785
|
-
|
|
1786
|
-
|
|
1787
|
-
|
|
1788
|
-
|
|
1789
|
-
select
|
|
1790
|
-
|
|
1600
|
+
# A reading counts for its seconds inside the step, as the report counts
|
|
1601
|
+
# one in a period. A step with more than HOST_CARD_POINTS readings is cut
|
|
1602
|
+
# into that many equal parts, to the second, and each part with a reading in
|
|
1603
|
+
# it gives one point: the average CPU and memory over its recorded seconds,
|
|
1604
|
+
# and the worst memory pressure in it. Time with no reading gives no point,
|
|
1605
|
+
# so it is never a number. With recording off, or with no readings kept, the
|
|
1606
|
+
# steps are still listed, each with none.
|
|
1607
|
+
HOST_CARD_POINTS=60
|
|
1608
|
+
HOST_CARD_FORM='ocnus host report --card <space> <card> --json'
|
|
1609
|
+
host_card() {
|
|
1610
|
+
local name='' card='' json=0 asked=0
|
|
1611
|
+
while [ "$#" -gt 0 ]; do
|
|
1612
|
+
case $1 in
|
|
1613
|
+
--json)
|
|
1614
|
+
[ "$json" = 0 ] || die "--json is given once: $HOST_CARD_FORM"
|
|
1615
|
+
json=1
|
|
1616
|
+
;;
|
|
1617
|
+
--card)
|
|
1618
|
+
[ "$asked" = 0 ] || die "--card is given once, for one card: $HOST_CARD_FORM"
|
|
1619
|
+
asked=1
|
|
1620
|
+
case ${2:-} in '' | --*) die "--card takes a space and a card: $HOST_CARD_FORM" ;; esac
|
|
1621
|
+
case ${3:-} in '' | --*) die "--card takes a space and a card: $HOST_CARD_FORM" ;; esac
|
|
1622
|
+
name=$2 card=$3
|
|
1623
|
+
shift 2
|
|
1624
|
+
;;
|
|
1625
|
+
*)
|
|
1626
|
+
[ "$asked" = 1 ] || case " $* " in *' --card '*) asked=1 ;; esac
|
|
1627
|
+
[ "$asked" = 1 ] ||
|
|
1628
|
+
die "--json needs --card: only a card's readings come as JSON, with $HOST_CARD_FORM. The report on a period is in words."
|
|
1629
|
+
die "'$1' does not go with --card: a card's readings are those of its steps, whatever the period. Ask with: $HOST_CARD_FORM"
|
|
1630
|
+
;;
|
|
1631
|
+
esac
|
|
1632
|
+
shift
|
|
1633
|
+
done
|
|
1634
|
+
[ "$asked" = 1 ] ||
|
|
1635
|
+
die "--json needs --card: only a card's readings come as JSON, with $HOST_CARD_FORM. The report on a period is in words."
|
|
1636
|
+
[ "$json" = 1 ] || die "--card needs --json: a card's readings come as JSON alone. Ask with: $HOST_CARD_FORM"
|
|
1637
|
+
space_named "$name" || die "there is no ocnus space called '$name'. See: ocnus space ls"
|
|
1638
|
+
[[ $card =~ $CARD_RE ]] || die "'$card' is not a card ID like ABC-122."
|
|
1639
|
+
card=$(printf '%s' "$card" | tr '[:lower:]' '[:upper:]')
|
|
1640
|
+
have_sqlite || die "$SQLITE is not installed, and the hand-offs and the readings are kept with it."
|
|
1641
|
+
|
|
1642
|
+
local recording=false now uri attach='' out
|
|
1643
|
+
[ ! -d "$HOST_DIR" ] || recording=true
|
|
1644
|
+
# As `task log --json` with no store: the same keys, and no steps.
|
|
1645
|
+
if [ ! -e "$STORE" ]; then
|
|
1646
|
+
printf '{"space":"%s","card":"%s","recording":%s,"steps":[]}\n' "$(json_str "$name")" "$(json_str "$card")" "$recording"
|
|
1647
|
+
return
|
|
1648
|
+
fi
|
|
1649
|
+
now=$(date +%s)
|
|
1650
|
+
# With no readings kept, a table with none stands in for them.
|
|
1651
|
+
local readings='(select 0 as at, 0 as secs, null as cpu_busy, null as mem_used_mb, null as mem_pressure where 0)'
|
|
1652
|
+
if [ -e "$HOST_DB" ]; then
|
|
1653
|
+
# In a URI, % starts an escape, ? the options and # the end.
|
|
1654
|
+
uri=${HOST_DB//\%/%25}; uri=${uri//\?/%3F}; uri=${uri//\#/%23}
|
|
1655
|
+
attach="attach $(sql_str "file:$uri?mode=ro") as host;"
|
|
1656
|
+
readings=host.readings
|
|
1657
|
+
fi
|
|
1658
|
+
# Each table is worked out once, whatever the card's length:
|
|
1659
|
+
# flagged, grouped the card's rows, numbered by the time it was in a step
|
|
1660
|
+
# spans, latest each of those times' first and last row, and the
|
|
1661
|
+
# card's latest row with the step under way, if any
|
|
1662
|
+
# ended, steps the steps, in order, the one under way running to now
|
|
1663
|
+
# inside, counts each reading's seconds inside each step, and how
|
|
1664
|
+
# many readings a step has
|
|
1665
|
+
# spread, pieces for a step to thin, each reading's seconds in each of
|
|
1666
|
+
# the equal parts it reaches: the first and the last of
|
|
1667
|
+
# them are worked out, so no reading is tried against
|
|
1668
|
+
# every part
|
|
1669
|
+
# points, drawn each step's points, and all of them as one array
|
|
1670
|
+
# SQLite builds the JSON, so no value is escaped by hand.
|
|
1671
|
+
out=$(store "$STORE" "$attach
|
|
1672
|
+
$(log_view "$name" "$card"),
|
|
1673
|
+
flagged(id, run, step, kind, status, next, after, t, prev_t, first) as (
|
|
1674
|
+
select id, run, step, kind, status, next, after,
|
|
1675
|
+
cast(strftime('%s', at) as integer), cast(strftime('%s', prev_at) as integer),
|
|
1676
|
+
case when lag(step) over (order by id) is step then 0 else 1 end
|
|
1677
|
+
from shown),
|
|
1678
|
+
grouped(id, run, step, kind, status, next, after, t, prev_t, g) as (
|
|
1679
|
+
select id, run, step, kind, status, next, after, t, prev_t,
|
|
1680
|
+
sum(first) over (order by id rows between unbounded preceding and current row)
|
|
1681
|
+
from flagged),
|
|
1682
|
+
spans(g, first_id, last_id) as (
|
|
1683
|
+
select g, min(id), max(id) from grouped where kind != 'start' group by g),
|
|
1684
|
+
latest(run, step, t, under) as (
|
|
1685
|
+
select run, step, t, case when status in ('answered', 'needs-human') then step
|
|
1686
|
+
when status = 'done' and coalesce(next, '') not in ('', 'start', 'setup', 'merged') then next end
|
|
1687
|
+
from grouped where after is null),
|
|
1688
|
+
ended(o, run, step, s, e, open) as (
|
|
1689
|
+
select sp.g, l.run, l.step, coalesce(f.prev_t, f.t), l.t, l.after is null and l.step is u.under
|
|
1690
|
+
from spans sp join grouped f on f.id = sp.first_id join grouped l on l.id = sp.last_id left join latest u on 1
|
|
1691
|
+
union all
|
|
1692
|
+
select (select max(g) from grouped) + 1, run, under, t, t, 1 from latest
|
|
1693
|
+
where under is not null and under is not step),
|
|
1694
|
+
steps(n, run, step, s, e, open) as (
|
|
1695
|
+
select row_number() over (order by o), run, step, s, case when open then max($now, e) else e end, open from ended),
|
|
1696
|
+
inside(n, at, a, b, cpu, mem, pressure) as (
|
|
1697
|
+
select st.n, g.at, max(g.at - g.secs, st.s), min(g.at, st.e), g.cpu_busy, g.mem_used_mb, g.mem_pressure
|
|
1698
|
+
from steps st cross join $readings g
|
|
1699
|
+
on g.at > st.s and g.at < st.e + $HOST_GAP and g.at - g.secs < st.e
|
|
1700
|
+
where min(g.at, st.e) > max(g.at - g.secs, st.s)),
|
|
1701
|
+
counts(n, readings, recorded) as (select n, count(*), sum(b - a) from inside group by n),
|
|
1702
|
+
spread(n, k, last, s, len, a, b, cpu, mem, pressure) as (
|
|
1703
|
+
select p.n, ($HOST_CARD_POINTS * (p.a - st.s + 1) - 1) / (st.e - st.s), ($HOST_CARD_POINTS * (p.b - st.s) - 1) / (st.e - st.s),
|
|
1704
|
+
st.s, st.e - st.s, p.a, p.b, p.cpu, p.mem, p.pressure
|
|
1705
|
+
from inside p join counts c on c.n = p.n and c.readings > $HOST_CARD_POINTS join steps st on st.n = p.n
|
|
1706
|
+
union all
|
|
1707
|
+
select n, k + 1, last, s, len, a, b, cpu, mem, pressure from spread where k < last),
|
|
1708
|
+
pieces(n, k, lo, hi, d, cpu, mem, pressure) as (
|
|
1709
|
+
select n, k, lo, hi, min(b, hi) - max(a, lo), cpu, mem, pressure from (
|
|
1710
|
+
select n, k, s + len * k / $HOST_CARD_POINTS as lo, s + len * (k + 1) / $HOST_CARD_POINTS as hi, a, b, cpu, mem, pressure
|
|
1711
|
+
from spread)
|
|
1712
|
+
where min(b, hi) > max(a, lo)),
|
|
1713
|
+
points(n, o, a, b, d, cpu, mem, pressure) as (
|
|
1714
|
+
select p.n, p.at, p.a, p.b, p.b - p.a, p.cpu, p.mem, p.pressure
|
|
1715
|
+
from inside p join counts c on c.n = p.n and c.readings <= $HOST_CARD_POINTS
|
|
1716
|
+
union all
|
|
1717
|
+
select n, k, lo, hi, sum(d), 1.0 * sum(cpu * d) / sum(case when cpu is not null then d end),
|
|
1718
|
+
cast(round(1.0 * sum(mem * d) / sum(case when mem is not null then d end)) as integer), max(pressure)
|
|
1719
|
+
from pieces group by n, k),
|
|
1720
|
+
drawn(n, i, points) as (
|
|
1721
|
+
select n, row_number() over (partition by n order by o),
|
|
1722
|
+
json_group_array(json_object(
|
|
1723
|
+
'start', strftime('%Y-%m-%dT%H:%M:%SZ', a, 'unixepoch'),
|
|
1724
|
+
'end', strftime('%Y-%m-%dT%H:%M:%SZ', b, 'unixepoch'), 'seconds', d,
|
|
1725
|
+
'cpu_busy', round(cpu, 1), 'mem_used_mb', mem,
|
|
1726
|
+
'mem_pressure', case when pressure >= 4 then 'critical' when pressure >= 2 then 'warning'
|
|
1727
|
+
when pressure is not null then 'normal' end))
|
|
1728
|
+
over (partition by n order by o rows between unbounded preceding and unbounded following)
|
|
1729
|
+
from points)
|
|
1730
|
+
select json_object('space', $(sql_str "$name"), 'card', $(sql_str "$card"), 'recording', json('$recording'),
|
|
1731
|
+
'steps', json((select json_group_array(json(entry)) from (
|
|
1732
|
+
select json_object('run', st.run, 'step', st.step,
|
|
1733
|
+
'start', strftime('%Y-%m-%dT%H:%M:%SZ', st.s, 'unixepoch'),
|
|
1734
|
+
'end', strftime('%Y-%m-%dT%H:%M:%SZ', st.e, 'unixepoch'),
|
|
1735
|
+
'seconds', max(st.e - st.s, 0), 'open', json(case when st.open then 'true' else 'false' end),
|
|
1736
|
+
'readings', coalesce(c.readings, 0), 'recorded', coalesce(c.recorded, 0),
|
|
1737
|
+
'points', json(coalesce(d.points, '[]'))) as entry
|
|
1738
|
+
from steps st left join counts c on c.n = st.n left join drawn d on d.n = st.n and d.i = 1
|
|
1739
|
+
order by st.n))));") || {
|
|
1740
|
+
# Which of the two it could not read: the hand-offs alone are tried again.
|
|
1741
|
+
[ -n "$attach" ] && store "$STORE" 'select count(*) from handoffs where 0;' >/dev/null ||
|
|
1742
|
+
die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
1743
|
+
die "could not read the readings in $HOST_DB. They may not be the ones ocnus host records."
|
|
1744
|
+
}
|
|
1745
|
+
[ -n "$out" ] || die "could not read the hand-offs in $STORE. It may not be ocnus's store."
|
|
1746
|
+
say "$out"
|
|
1791
1747
|
}
|
|
1792
1748
|
|
|
1793
1749
|
cmd_host() {
|