Guest User

linux build line count bubble graph generator

a guest
Aug 19th, 2015
457
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2. # ref: http://unix.stackexchange.com/questions/223746/why-is-the-linux-kernel-15-million-lines-of-code/223770#223770
  3. # create a json to be used with this js bubble chart http://bl.ocks.org/mbostock/4063269
  4. # 1. build the kernel with the chosen config
  5. # 2. use the script with this argument $(find -name "*.cmd" | grep -v "/scripts/" )
  6. wrap() {
  7.     xargs=""
  8.     deps=""
  9.     out=""
  10.     set -- $1
  11.     while [ $# -gt 0 ]; do
  12.         arg="$1"
  13.         case "$arg" in
  14.             -o) shift; out="$1.c" ;;
  15.             *\.c) deps="$deps $arg" ;;
  16.         esac
  17.         shift
  18.     done
  19.     for dep in $deps; do
  20.         cat "$dep" >"$dep-dep.c"
  21.         size=$(wc -l <"$dep-dep.c")
  22.         printf "%s %s %s\n" "$(dirname "$dep")" \
  23.                "$(basename "$dep")" "$size" >> wc-data.tmp
  24.     done
  25. }
  26. printf "" >wc-data.tmp
  27. while [ $# -gt 0 ]; do
  28.     args="$(sed -n 's/^.*\.o := gcc//p' "$1")"
  29.     if [ ! -z "$args" ]; then
  30.         wrap "$args"
  31.     fi
  32.     shift
  33. done
  34. printf "{\n   \"name\": \"tinyconfig\",\n" > graph.json
  35. printf "   \"children\": [\n" >> graph.json
  36. sort < wc-data.tmp | while read -r DIR NAME SIZE; do
  37.     # printf "      $DIR $NAME $SIZE\n" >> grap.json
  38.     if test "$line0" = "" ; then
  39.         line0=1
  40.         printf "         { \"name\": \"%s\",\n" "$DIR" >> graph.json
  41.         printf "           \"children\": [\n" >> graph.json
  42.         ODIR="$DIR"
  43.     elif test "$DIR" != "$ODIR" ; then
  44.         printf "\n            ]\n         },\n" >> graph.json
  45.         printf "         { \"name\": \"%s\",\n" "$DIR" >> graph.json       
  46.         printf "           \"children\": [\n" >> graph.json
  47.         ODIR="$DIR"
  48.     else
  49.         printf ",\n" >> graph.json
  50.     fi
  51.     printf "            { \"name\": \"%s\", \"size\": %s }" "$DIR/$NAME" "$SIZE" >> graph.json
  52. done
  53. printf "            ]\n         }\n" >> graph.json
  54. printf "   ]\n}\n" >> graph.json
RAW Paste Data