Skip to content

Commit

Permalink
[refactor] Add test/tsv-lib.sh
Browse files Browse the repository at this point in the history
Still need to consolidate more
  • Loading branch information
Andy C committed Feb 17, 2022
1 parent f304908 commit fac83ef
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 49 deletions.
1 change: 1 addition & 0 deletions benchmarks/common.sh
Expand Up @@ -57,6 +57,7 @@ csv2html() {
web/table/csv2html.py --css-class-pattern 'special ^osh' "$@"
}

# TODO: Conslidate with test/tsv-lib.sh
tsv2html() {
web/table/csv2html.py --tsv "$@"
}
Expand Down
12 changes: 7 additions & 5 deletions benchmarks/compute.sh
Expand Up @@ -30,6 +30,7 @@ set -o pipefail
set -o errexit

source benchmarks/common.sh # filter-provenance
source test/tsv-lib.sh

readonly BASE_DIR=_tmp/compute
readonly OSH_CC=_bin/osh_eval.opt.stripped
Expand Down Expand Up @@ -275,7 +276,12 @@ task-all() {
mkdir -p $tmp_dir $raw_dir/$task_name

# header
echo $'status\telapsed_secs\tuser_secs\tsys_secs\tmax_rss_KiB\tstdout_md5sum\thost_name\thost_hash\truntime_name\truntime_hash\ttask_name\targ1\targ2' > $times_tsv
tsv-row \
status elapsed_secs user_secs sys_secs max_rss_KiB \
stdout_md5sum \
host_name host_hash \
runtime_name runtime_hash \
task_name arg1 arg2 > $times_tsv

local task_id=0

Expand Down Expand Up @@ -418,10 +424,6 @@ stage1() {
wc -l $times_tsv
}

tsv2html() {
csv2html --tsv "$@"
}

print-report() {
local in_dir=$1

Expand Down
11 changes: 7 additions & 4 deletions benchmarks/ovm-build.sh
Expand Up @@ -36,6 +36,7 @@ set -o errexit

source benchmarks/common.sh # for log, etc.
source build/common.sh # for $CLANG
source test/tsv-lib.sh

readonly BASE_DIR=_tmp/ovm-build
readonly TAR_DIR=$PWD/_deps/ovm-build # Make it absolute
Expand Down Expand Up @@ -96,7 +97,7 @@ extract-oil() {

sizes-tsv() {
# host_label matches the times.tsv file output by report.R
echo $'host_label\tnum_bytes\tpath'
tsv-row host_label num_bytes path
local host=$(hostname)
find "$@" -maxdepth 0 -printf "$host\t%s\t%p\n"
}
Expand Down Expand Up @@ -315,7 +316,6 @@ oil-historical-tasks() {
}

# action is 'configure', a target name, etc.
readonly HEADER=$'status\telapsed_secs\thost_name\thost_hash\tcompiler_path\tcompiler_hash\tsrc_dir\taction'
readonly NUM_COLUMNS=7 # 5 from provenence, then tarball/target

measure() {
Expand All @@ -334,8 +334,11 @@ measure() {

# TODO: the $times_out calculation is duplicated in build-task()

# Write Header of the CSV file that is appended to.
echo "$HEADER" > $times_out
# Write header of the TSV file that is appended to.
tsv-row \
status elapsed_secs \
host_name host_hash compiler_path compiler_hash \
src_dir action > $times_out

local t1=$BASE_DIR/oil-tasks.txt
local t2=$BASE_DIR/other-shell-tasks.txt
Expand Down
9 changes: 4 additions & 5 deletions metrics/source-code.sh
Expand Up @@ -9,6 +9,9 @@ set -o nounset
set -o pipefail
set -o errexit

source test/common.sh
source test/tsv-lib.sh

filter-py() {
grep -E -v '__init__.py$|_gen.py|_test.py|_tests.py$'
}
Expand Down Expand Up @@ -310,10 +313,6 @@ metrics-html-head() {
html-head --title "$title" "$base_url/base.css" "$base_url/table/table-sort.css" "$base_url/line-counts.css"
}

tsv2html() {
web/table/csv2html.py --tsv "$@"
}

counts-html() {
local name=$1
local title=$2
Expand All @@ -323,7 +322,7 @@ counts-html() {
rm -r -f -v $tmp_dir >& 2
mkdir -v -p $tmp_dir >& 2

echo $'category\tcategory_HREF\ttotal_lines\tnum_files' > $tmp_dir/INDEX.tsv
tsv-row category category_HREF total_lines num_files > $tmp_dir/INDEX.tsv

echo $'column_name\ttype
category\tstring
Expand Down
7 changes: 2 additions & 5 deletions soil/worker.sh
Expand Up @@ -10,10 +10,7 @@ set -o pipefail
set -o errexit

source soil/common.sh

time-tsv() {
benchmarks/time_.py --tsv "$@"
}
source test/tsv-lib.sh

dump-timezone() {

Expand Down Expand Up @@ -279,7 +276,7 @@ run-tasks() {
# show the last line

echo
echo $'status\telapsed\ttask\tscript\taction\tresult_html'
tsv-row status elapsed task script action result_html
tail -n 1 $tsv
echo
log "status=$status max_status=$max_status"
Expand Down
32 changes: 32 additions & 0 deletions test/tsv-lib.sh
@@ -0,0 +1,32 @@
# TSV utiltiies
#
# Usage:
# source test/tsv-lib.sh

time-tsv() {
### Run a task and output TSV
benchmarks/time_.py --tsv "$@"
}

tsv2html() {
### Convert TSV to an HTML table
web/table/csv2html.py --tsv "$@"
}

tsv-row() {
### Usage: tsv-row a b c
local i=0
for cell in "$@"; do
if test $i -ne 0; then
echo -n $'\t'
fi

# note: if this were QTT, then it would be quoted
echo -n "$cell"

i=$((i + 1))
done

echo # newline
}

31 changes: 1 addition & 30 deletions test/unit.sh
Expand Up @@ -17,6 +17,7 @@ set -o errexit
shopt -s strict:all 2>/dev/null || true # dogfood for OSH

source test/common.sh
source test/tsv-lib.sh

export PYTHONPATH='.:vendor' # repo root and vendor subdir

Expand Down Expand Up @@ -138,36 +139,6 @@ all-in-one() {
# NOTE: Show options like this:
# python -m unittest discover -h

#
# TODO: Move to test/common.sh
#

time-tsv() {
benchmarks/time_.py --tsv "$@"
}

tsv-row() {
### Usage: tsv-row a b c
local i=0
for cell in "$@"; do
if test $i -ne 0; then
echo -n $'\t'
fi

# note: if this were QTT, then it would be quoted
echo -n "$cell"

i=$((i + 1))
done

echo # newline
}

tsv2html() {
web/table/csv2html.py --tsv "$@"
}


#
# For _release/VERSION
#
Expand Down

0 comments on commit fac83ef

Please sign in to comment.