Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/sh
- # ref: http://unix.stackexchange.com/questions/223746/why-is-the-linux-kernel-15-million-lines-of-code/223770#223770
- # create a json to be used with this js bubble chart http://bl.ocks.org/mbostock/4063269
- # 1. build the kernel with the chosen config
- # 2. use the script with this argument $(find -name "*.cmd" | grep -v "/scripts/" )
- wrap() {
- xargs=""
- deps=""
- out=""
- set -- $1
- while [ $# -gt 0 ]; do
- arg="$1"
- case "$arg" in
- -o) shift; out="$1.c" ;;
- *\.c) deps="$deps $arg" ;;
- esac
- shift
- done
- for dep in $deps; do
- cat "$dep" >"$dep-dep.c"
- size=$(wc -l <"$dep-dep.c")
- printf "%s %s %s\n" "$(dirname "$dep")" \
- "$(basename "$dep")" "$size" >> wc-data.tmp
- done
- }
- printf "" >wc-data.tmp
- while [ $# -gt 0 ]; do
- args="$(sed -n 's/^.*\.o := gcc//p' "$1")"
- if [ ! -z "$args" ]; then
- wrap "$args"
- fi
- shift
- done
- printf "{\n \"name\": \"tinyconfig\",\n" > graph.json
- printf " \"children\": [\n" >> graph.json
- sort < wc-data.tmp | while read -r DIR NAME SIZE; do
- # printf " $DIR $NAME $SIZE\n" >> grap.json
- if test "$line0" = "" ; then
- line0=1
- printf " { \"name\": \"%s\",\n" "$DIR" >> graph.json
- printf " \"children\": [\n" >> graph.json
- ODIR="$DIR"
- elif test "$DIR" != "$ODIR" ; then
- printf "\n ]\n },\n" >> graph.json
- printf " { \"name\": \"%s\",\n" "$DIR" >> graph.json
- printf " \"children\": [\n" >> graph.json
- ODIR="$DIR"
- else
- printf ",\n" >> graph.json
- fi
- printf " { \"name\": \"%s\", \"size\": %s }" "$DIR/$NAME" "$SIZE" >> graph.json
- done
- printf " ]\n }\n" >> graph.json
- printf " ]\n}\n" >> graph.json
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement