| 1 | #!/usr/bin/env bash
|
| 2 | #
|
| 3 | # Stats about build artifacts.
|
| 4 | #
|
| 5 | # Usage:
|
| 6 | # ./metrics.sh <function name>
|
| 7 |
|
| 8 | set -o nounset
|
| 9 | set -o pipefail
|
| 10 | set -o errexit
|
| 11 |
|
| 12 | source 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 |
|
| 33 | linecount-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 |
|
| 42 | readonly 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 |
|
| 49 | linecount-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 |
|
| 64 | linecount-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 |
|
| 102 | linecount-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
|
| 122 | bundle-size() {
|
| 123 | ls -l _build/*/bytecode-*.zip _build/*/ovm _bin/*.ovm
|
| 124 | }
|
| 125 |
|
| 126 | pyc-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]
|
| 132 | pyc-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.
|
| 144 | hello-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:
|
| 150 | oil-tar-lines() {
|
| 151 | _tar-lines oil
|
| 152 | }
|
| 153 |
|
| 154 | "$@"
|