Imported Upstream version 5.3.21
[platform/upstream/libdb.git] / util / db_printlog / logstat.awk
1 # $Id$
2 #
3 # Output accumulated log record count/size statistics.
4 BEGIN {
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
23 END {
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 }