OILS / regtest / aports / old.sh View on Github | oils.pub

145 lines, 52 significant
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}
9source $LIB_OSH/bash-strict.sh
10source $LIB_OSH/task-five.sh
11
12alter-sql() {
13 ### unused
14 if false; then
15 echo '
16.mode columns
17
18-- not using this now
19ALTER TABLE tasks DROP COLUMN xargs_slot;
20
21-- elapsed is enough; this was for graphing
22alter table tasks DROP COLUMN start_time;
23alter table tasks DROP COLUMN end_time;
24
25alter table tasks ADD COLUMN user_elapsed_ratio;
26update tasks set user_elapsed_ratio = user_secs / elapsed_secs;
27alter table tasks DROP COLUMN user_secs;
28
29alter table tasks ADD COLUMN max_rss_MB;
30update tasks set max_rss_MB = max_rss_KiB * 1024 / 1e6;
31alter 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
39if false; then
40 sqlite3() {
41 ~/src/sqlite-autoconf-3500300/sqlite3 "$@"
42 }
43fi
44
45log-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
53log-sizes-schema() {
54 here-schema-tsv <<EOF
55column_name type
56num_bytes integer
57path string
58EOF
59}
60
61big-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 '
83create table big_logs as
84select * from log_sizes where num_bytes > 1e6 order by num_bytes;
85
86SELECT "--";
87
88select sum(num_bytes) / 1e6 from log_sizes;
89
90-- this is more than half the logs
91select sum(num_bytes) / 1e6 from big_logs;
92
93select * from big_logs;
94
95-- 22 hours, but there was a big pause in the middle
96select ( 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
106concat-tables() {
107 sqlite3 $db <<EOF
108-- Attach the source databases
109ATTACH DATABASE 'baseline/packages.db' AS baseline;
110ATTACH 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;
121EOF
122}
123
124diff-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
131select count(*) from baseline;
132select count(*) from osh_as_sh;
133select * from pragma_table_info("baseline");
134select * from pragma_table_info("osh_as_sh");
135
136-- 22 hours, but there was a big pause in the middle
137select ( max(end_time)-min(start_time) ) / 60 / 60 from baseline;
138
139SELECT status, pkg FROM baseline WHERE status != 0;
140'
141 } | sqlite3 :memory:
142}
143
144
145task-five "$@"