| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Old code that might be useful for analysis.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # regtest/aports-old.sh <function name>
|
| 7 |
|
| 8 | : ${LIB_OSH=stdlib/osh}
|
| 9 | source $LIB_OSH/bash-strict.sh
|
| 10 | source $LIB_OSH/task-five.sh
|
| 11 |
|
| 12 | alter-sql() {
|
| 13 | ### unused
|
| 14 | if false; then
|
| 15 | echo '
|
| 16 | .mode columns
|
| 17 |
|
| 18 | -- not using this now
|
| 19 | ALTER TABLE tasks DROP COLUMN xargs_slot;
|
| 20 |
|
| 21 | -- elapsed is enough; this was for graphing
|
| 22 | alter table tasks DROP COLUMN start_time;
|
| 23 | alter table tasks DROP COLUMN end_time;
|
| 24 |
|
| 25 | alter table tasks ADD COLUMN user_elapsed_ratio;
|
| 26 | update tasks set user_elapsed_ratio = user_secs / elapsed_secs;
|
| 27 | alter table tasks DROP COLUMN user_secs;
|
| 28 |
|
| 29 | alter table tasks ADD COLUMN max_rss_MB;
|
| 30 | update tasks set max_rss_MB = max_rss_KiB * 1024 / 1e6;
|
| 31 | alter table tasks DROP COLUMN max_rss_KiB;
|
| 32 | '
|
| 33 | fi
|
| 34 | }
|
| 35 |
|
| 36 | # workaround for old VM
|
| 37 | # old sqlite doesn't have 'drop column'!
|
| 38 | #if sqlite3 --version | grep -q '2018-'; then
|
| 39 | if false; then
|
| 40 | sqlite3() {
|
| 41 | ~/src/sqlite-autoconf-3500300/sqlite3 "$@"
|
| 42 | }
|
| 43 | fi
|
| 44 |
|
| 45 | log-sizes() {
|
| 46 | local config=${1:-baseline}
|
| 47 |
|
| 48 | tsv-row 'num_bytes' 'path'
|
| 49 | find $CHROOT_HOME_DIR/oils/_tmp/aports-guest/$config \
|
| 50 | -name '*.log.txt' -a -printf '%s\t%P\n'
|
| 51 | }
|
| 52 |
|
| 53 | log-sizes-schema() {
|
| 54 | here-schema-tsv <<EOF
|
| 55 | column_name type
|
| 56 | num_bytes integer
|
| 57 | path string
|
| 58 | EOF
|
| 59 | }
|
| 60 |
|
| 61 | big-logs() {
|
| 62 | local config=${1:-baseline}
|
| 63 |
|
| 64 | local dir=$BASE_DIR/big
|
| 65 |
|
| 66 | mkdir -p $dir
|
| 67 |
|
| 68 | concat-task-tsv > $dir/tasks.tsv
|
| 69 | tasks-schema > $dir/tasks.schema.tsv
|
| 70 |
|
| 71 | log-sizes > $dir/log_sizes.tsv
|
| 72 | log-sizes-schema > $dir/log_sizes.schema.tsv
|
| 73 |
|
| 74 | { typed-tsv-to-sql $dir/tasks.tsv
|
| 75 | typed-tsv-to-sql $dir/log_sizes.tsv
|
| 76 | echo '.mode table'
|
| 77 | if true; then
|
| 78 | echo 'select * from tasks order by elapsed_secs limit 10;'
|
| 79 | echo 'select * from log_sizes order by num_bytes limit 10;'
|
| 80 | echo 'select elapsed, start_time, end_time from tasks order by elapsed_secs limit 10;'
|
| 81 |
|
| 82 | echo '
|
| 83 | create table big_logs as
|
| 84 | select * from log_sizes where num_bytes > 1e6 order by num_bytes;
|
| 85 |
|
| 86 | SELECT "--";
|
| 87 |
|
| 88 | select sum(num_bytes) / 1e6 from log_sizes;
|
| 89 |
|
| 90 | -- this is more than half the logs
|
| 91 | select sum(num_bytes) / 1e6 from big_logs;
|
| 92 |
|
| 93 | select * from big_logs;
|
| 94 |
|
| 95 | -- 22 hours, but there was a big pause in the middle
|
| 96 | select ( max(end_time)-min(start_time) ) / 60 / 60 from tasks;
|
| 97 |
|
| 98 | -- SELECT status, pkg FROM tasks WHERE status != 0;
|
| 99 |
|
| 100 | -- SELECT * from tasks limit 10;
|
| 101 | '
|
| 102 | fi
|
| 103 | } | sqlite3 :memory:
|
| 104 | }
|
| 105 |
|
| 106 | concat-tables() {
|
| 107 | sqlite3 $db <<EOF
|
| 108 | -- Attach the source databases
|
| 109 | ATTACH DATABASE 'baseline/packages.db' AS baseline;
|
| 110 | ATTACH DATABASE 'osh-as-sh/packages.db' AS osh_as_sh;
|
| 111 |
|
| 112 | -- Create the new table by copying the structure and adding config column
|
| 113 | -- interesting trick from Claude: where 1 = 0;
|
| 114 | -- CREATE TABLE packages AS SELECT 'baseline' AS config, * FROM baseline.packages WHERE 1=0;
|
| 115 |
|
| 116 | -- Insert data from baseline database
|
| 117 | -- INSERT INTO packages SELECT 'baseline', * FROM baseline.packages;
|
| 118 |
|
| 119 | -- Insert data from osh-as-sh database
|
| 120 | -- INSERT INTO packages SELECT 'osh-as-sh', * FROM osh_as_sh.packages;
|
| 121 | EOF
|
| 122 | }
|
| 123 |
|
| 124 | diff-report() {
|
| 125 | local dir=$REPORT_DIR/$EPOCH
|
| 126 |
|
| 127 | { typed-tsv-to-sql $dir/baseline/tasks.tsv baseline
|
| 128 | typed-tsv-to-sql $dir/osh-as-sh/tasks.tsv osh_as_sh
|
| 129 | echo '
|
| 130 | .mode column
|
| 131 | select count(*) from baseline;
|
| 132 | select count(*) from osh_as_sh;
|
| 133 | select * from pragma_table_info("baseline");
|
| 134 | select * from pragma_table_info("osh_as_sh");
|
| 135 |
|
| 136 | -- 22 hours, but there was a big pause in the middle
|
| 137 | select ( max(end_time)-min(start_time) ) / 60 / 60 from baseline;
|
| 138 |
|
| 139 | SELECT status, pkg FROM baseline WHERE status != 0;
|
| 140 | '
|
| 141 | } | sqlite3 :memory:
|
| 142 | }
|
| 143 |
|
| 144 |
|
| 145 | task-five "$@"
|