1# $Id: logstat.awk,v 12.0 2004/11/17 03:43:25 bostic Exp $
2#
3# Output accumulated log record count/size statistics.
4BEGIN {
5	l_file = 0;
6	l_offset = 0;
7}
8
9/^\[/{
10	gsub("[][:	 ]", " ", $1)
11	split($1, a)
12
13	if (a[1] == l_file) {
14		l[a[3]] += a[2] - l_offset
15		++n[a[3]]
16	} else
17		++s[a[3]]
18
19	l_file = a[1]
20	l_offset = a[2]
21}
22
23END {
24	# We can't figure out the size of the first record in each log file,
25	# use the average for other records we found as an estimate.
26	for (i in s)
27		if (s[i] != 0 && n[i] != 0) {
28			l[i] += s[i] * (l[i]/n[i])
29			n[i] += s[i]
30			delete s[i]
31		}
32	for (i in l)
33		printf "%s: %d (n: %d, avg: %.2f)\n", i, l[i], n[i], l[i]/n[i]
34	for (i in s)
35		printf "%s: unknown (n: %d, unknown)\n", i, s[i]
36}
37