tools/function-stats.sh (see #905)
parent
7f561e8571
commit
80c66d5d7a
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,133 @@
|
||||
#/usr/bin/env bash
|
||||
#
|
||||
# This script generates lists of functions generated by bindgen, on one side,
|
||||
# and static inline functions in notcurses.h on the other, grouped by prefix.
|
||||
# It also generates some statistics.
|
||||
#
|
||||
|
||||
PATH_SOURCE_FILE="../include/notcurses/notcurses.h"
|
||||
|
||||
# this is the path to the latest bindgen generated rust sources
|
||||
PATH_BINDGEN_LATEST="function-stats.bindgen_20200823.rs"
|
||||
|
||||
# these are the main function prefixes used in notcurses (before the first `_`) for STATS_FILE
|
||||
PREFIX_LIST="cell channel ncblit ncdirect ncdplot ncfadectx ncfdplane nckey ncmenu ncmetric ncmultiselector ncpixel ncplane ncreader ncreel ncselector ncsubproc nctablet ncuplot ncvisual notcurses palette"
|
||||
|
||||
|
||||
OUTPUT_DIR_ROOT="function-stats-output/"
|
||||
#DATE="$(date +%Y%m%d_%H%M%S)" # with time
|
||||
DATE="$(date +%Y%m%d)"
|
||||
OUTPUT_DIR="$OUTPUT_DIR_ROOT/$DATE"
|
||||
OUTPUT_DIR_BG="$OUTPUT_DIR/bindgen" # (bindgen generated)
|
||||
OUTPUT_DIR_SI="$OUTPUT_DIR/static" # (static inline)
|
||||
STATS_FILE="$OUTPUT_DIR/STATS"
|
||||
# TODO: add to the STATS_FILE and/or OUTPUT_DIR a prefix of the source_file
|
||||
|
||||
TERM="static inline"
|
||||
|
||||
GREP="/bin/grep"
|
||||
CUT="/usr/bin/cut"
|
||||
SED="/bin/sed"
|
||||
WC="/usr/bin/wc"
|
||||
UNIQ="/usr/bin/uniq"
|
||||
REV="/usr/bin/rev"
|
||||
SORT="/usr/bin/sort"
|
||||
|
||||
# show the list of functions that are static inline
|
||||
listfn() {
|
||||
"$GREP" "$TERM" "$PATH_SOURCE_FILE" -A 1 | $GREP -v -- "--" | $SED /^static.*/d | $CUT -d '(' -f1
|
||||
}
|
||||
listfn_bindgen() {
|
||||
"$GREP" "pub fn" "$PATH_BINDGEN_LATEST" | $CUT -d'(' -f1 | $REV | $CUT -d' ' -f1 | $REV
|
||||
}
|
||||
|
||||
# show the number of different prefixes there are
|
||||
listprefixes() {
|
||||
listfn | $CUT -d'_' -f1 | $SORT | $UNIQ
|
||||
}
|
||||
listprefixes_bindgen() {
|
||||
listfn_bindgen | $CUT -d'_' -f1 | $GREP -v '^$' | $SORT | $UNIQ
|
||||
}
|
||||
|
||||
|
||||
generate() {
|
||||
|
||||
mkdir -p "$OUTPUT_DIR_BG"
|
||||
mkdir -p "$OUTPUT_DIR_SI"
|
||||
|
||||
echo "GENERAL" | tee $STATS_FILE
|
||||
echo "-------"| tee -a $STATS_FILE
|
||||
echo -n "bindgen generated functions (bg): " | tee -a $STATS_FILE
|
||||
listfn_bindgen | $WC -l | tee -a $STATS_FILE
|
||||
echo -n "static inline functions (si): " | tee -a $STATS_FILE
|
||||
listfn | $WC -l | tee -a $STATS_FILE
|
||||
echo | tee -a $STATS_FILE
|
||||
|
||||
|
||||
echo "grouped by the following prefixes:" | tee -a $STATS_FILE
|
||||
echo $PREFIX_LIST | tee -a $STATS_FILE
|
||||
echo "--------------------------" | tee -a $STATS_FILE
|
||||
echo -e " (bg, si)\n" | tee -a $STATS_FILE
|
||||
|
||||
for prefix in $PREFIX_LIST; do
|
||||
printf "%.12s" "$prefix: " | tee -a $STATS_FILE
|
||||
echo -en "(" | tee -a $STATS_FILE
|
||||
listfn_bindgen | $GREP "^$prefix" | $UNIQ -u | $WC -l | tr -d '\n' | tee -a $STATS_FILE
|
||||
echo -en ", " | tee -a $STATS_FILE
|
||||
listfn | $GREP "^$prefix" | $UNIQ -u | $WC -l | tr -d '\n' | tee -a $STATS_FILE
|
||||
echo ")" | tee -a $STATS_FILE
|
||||
|
||||
# create the files
|
||||
listfn_bindgen | $GREP "^$prefix" | $UNIQ -u | $SORT > "$OUTPUT_DIR_BG/$prefix" | tee -a $STATS_FILE
|
||||
listfn | $GREP "^$prefix" | $UNIQ -u | $SORT > "$OUTPUT_DIR_SI/$prefix" | tee -a $STATS_FILE
|
||||
|
||||
filterout="$filterout^$prefix|"
|
||||
done
|
||||
|
||||
# DEBUG: show filtered out
|
||||
filterout="${filterout::-1}"
|
||||
#echo -e "$filterout" # DEBUG
|
||||
|
||||
# show/save the rest not prefixed
|
||||
echo -en "\nrest of the functions (bg/si):" | tee -a $STATS_FILE
|
||||
echo -en "(" | tee -a $STATS_FILE
|
||||
listfn | $GREP -vE "$filterout" | $WC -l | tr -d '\n' | tee -a $STATS_FILE
|
||||
echo -en ", " | tee -a $STATS_FILE
|
||||
listfn_bindgen | $GREP -vE "$filterout" | $WC -l | tr -d '\n' | tee -a $STATS_FILE
|
||||
echo ")" | tee -a $STATS_FILE
|
||||
|
||||
listfn_bindgen | $GREP -vE "$filterout" | $UNIQ -u | $SORT > "$OUTPUT_DIR_BG/_NON_FILTERED" | tee -a $STATS_FILE
|
||||
listfn | $GREP -vE "$filterout" | $UNIQ -u | $SORT > "$OUTPUT_DIR_SI/_NON_FILTERED" | tee -a $STATS_FILE
|
||||
|
||||
|
||||
}
|
||||
|
||||
usage() {
|
||||
|
||||
if [[ $1 == "p" ]]; then
|
||||
listprefixes
|
||||
elif [[ $1 == "f" ]]; then
|
||||
listfn
|
||||
elif [[ $1 == "pbind" ]]; then
|
||||
listprefixes_bindgen
|
||||
elif [[ $1 == "fbind" ]]; then
|
||||
listfn_bindgen
|
||||
elif [[ $1 == "generate" ]]; then
|
||||
generate
|
||||
else
|
||||
echo -e "I need an argument:"
|
||||
echo -e "\tp list static inline uniq fn prefixes"
|
||||
echo -e "\tf list static inline functions"
|
||||
echo
|
||||
echo -e "\tpbind list bindgen generated uniq fn prefixes"
|
||||
echo -e "\tfbind list bindgen generated functions"
|
||||
echo
|
||||
echo -e "\tgenerate"
|
||||
echo -e " create an output subfolder with today's date and save in there"
|
||||
echo -e " a series of textfiles named by prefix, with the list of functions:"
|
||||
echo -e " 1) generated by bindgen, and 2) static inline ones in notcurses.h"
|
||||
echo
|
||||
fi
|
||||
}
|
||||
|
||||
usage $1
|
Loading…
Reference in New Issue