#!/usr/bin/awk -f
# vim: ft=awk ts=4 sw=4 et
#
# This script summarizes the contents of the MAKE_DEPS_CACHE_STATS
# files generated by the conditionally-enabled statistics-gathering code
# at the end of compiler/make.deps_cache.m.
#

NF == 3 {
        cache = $1;
        cur_lookups = $2;
        cur_misses = $3;
        cur_hits =  cur_lookups - cur_misses;

        caches[cache] += 1;
        lookups[cache] += cur_lookups;
        misses[cache] += cur_misses;
        hits[cache] += cur_hits;

        overall_lookups += cur_lookups;
        overall_hits += cur_hits;
        overall_misses += cur_misses;
        # printf "EXEC %s %d\n", cache, caches[cache];
    }
END {
        overall_hits = overall_lookups - overall_misses;
        overall_hit_rate = (100 * overall_hits) / overall_lookups;
        printf "number of lookups:      %12d\n", overall_lookups;
        printf "number of hits:         %12d\n", overall_hits;
        printf "number of misses:       %12d\n", overall_misses;
        printf "hit %:                        %6.2f\n\n", overall_hit_rate;

        printf "----------------------------------------------------------\n\n";

        printf "%-30s %6s %8s %8s %8s %6s\n\n",
            "cache", "#exec", "#lookup", "#hit", "#miss", "hit%";
        for (cache in caches) {
            hit_rate[cache] = (100 * hits[cache]) / lookups[cache];
            printf "%-30s %6d %8d %8d %8d %6.2f\n",
                cache, caches[cache], lookups[cache],
                hits[cache], misses[cache], hit_rate[cache];
        }
    }
