OILS / metrics / tarball.sh View on Github | oilshell.org

154 lines, 101 significant
1#!/usr/bin/env bash
2#
3# Stats about build artifacts.
4#
5# Usage:
6# ./metrics.sh <function name>
7
8set -o nounset
9set -o pipefail
10set -o errexit
11
12source metrics/source-code.sh # for ASDL counts
13
14_banner() {
15 echo
16 echo "$@"
17 echo
18}
19
20_cloc-header() {
21 _banner 'SIGNIFICANT LINES OF CODE'
22}
23
24_wc-header() {
25 _banner 'PHYSICAL LINES OF CODE'
26}
27
28_native-deps() {
29 local app_name=${1:-oil}
30 find _tmp/${app_name}-tar-test -type f -a -name '*.[ch]'
31}
32
33linecount-nativedeps() {
34 _cloc-header
35 _native-deps | xargs cloc
36 echo
37
38 _wc-header
39 _native-deps | xargs wc -l | sort -n
40}
41
42readonly BYTECODE='bytecode-opy'
43
44_py-deps() {
45 local app_name=${1:-oil}
46 awk '/\.py$/ { print $1 }' _build/$app_name/${BYTECODE}-manifest.txt
47}
48
49linecount-pydeps() {
50 _cloc-header
51 _py-deps | xargs cloc
52 echo
53
54 _wc-header
55 _py-deps | sort | uniq | xargs wc -l | sort -n
56
57}
58
59_oils-cpp() {
60 # The CI runs devtools/release-native.sh test-tar
61 find . \( -name '*.cc' -o -name '*.h' \) -a -printf '%P\n'
62}
63
64linecount-oils-cpp() {
65 local first=_tmp/native-tar-test
66
67 # The release runs extract-for-benchmarks
68 local version
69 version=$(head -n 1 oil-version.txt)
70 local second="../benchmark-data/src/oils-for-unix-$version"
71
72 local dir
73 if test -d "$first"; then
74 dir=$first
75 elif test -d "$second"; then
76 dir=$second
77 else
78 die "Couldn't find $first or $second"
79 fi
80
81 pushd $dir > /dev/null
82
83 if command -v cloc; then # CI might not have it
84 _cloc-header
85 _oils-cpp | xargs cloc
86 echo
87 fi
88
89 _wc-header
90 _oils-cpp | sort | uniq | xargs wc -l | sort -n
91
92 popd > /dev/null
93}
94
95# Without generated code. This is a fair comparison against bash, because
96# we include everything shipped with the tarball, but count source files
97# rather than generated code.
98_py-deps-src-only() {
99 metrics/tarball.sh _py-deps | grep -v _devbuild
100}
101
102linecount-pydeps-src-only() {
103 _cloc-header
104 _py-deps-src-only | xargs cloc
105
106 # Copied from osh-cloc in metrics/source-code.sh
107 echo
108 echo 'ASDL SCHEMAS (non-blank non-comment lines)'
109 asdl-cloc "${ASDL_FILES[@]}"
110
111 echo
112 _wc-header
113 _py-deps-src-only | sort | uniq | xargs wc -l | sort -n
114
115 echo
116 echo 'ASDL SCHEMAS'
117 wc -l "${ASDL_FILES[@]}"
118}
119
120# hello: 1.41 MB native + 145 KB = 1.56 MB bundle
121# oil: 1.65 MB native + 642 KB = 2.30 MB bundle
122bundle-size() {
123 ls -l _build/*/bytecode-*.zip _build/*/ovm _bin/*.ovm
124}
125
126pyc-files() {
127 local app_name=${1:-oil}
128 awk '/\.pyc$/ { print $1 }' _build/$app_name/${BYTECODE}-manifest.txt
129}
130
131# Print table of [md5 pyc path]
132pyc-md5() {
133 pyc-files "$@" | xargs bin/opyc dis-md5
134}
135
136_tar-lines() {
137 linecount-nativedeps "$@"
138 echo
139 linecount-pydeps "$@"
140}
141
142# 144.6 K lines of C
143# 6.4 K lines Python.
144hello-tar-lines() {
145 _tar-lines hello
146}
147
148# 165.8 K lines of C (biggest: posixmodule.c, unicodeobject.c)
149# 30.8 K lines Python (biggest:
150oil-tar-lines() {
151 _tar-lines oil
152}
153
154"$@"