summaryrefslogtreecommitdiff
path: root/dist/stat.py
blob: b43a189a4b68e43030cb287825d43de5ded87dd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Read the source files and output the statistics #defines and allocation code.

import re, string, sys
from operator import attrgetter
from dist import compare_srcfile
from dist import source_paths_list

# Read the source files.
from stat_data import btree_stats, connection_stats

# print_def --
#	Print the structures for the stat.h file.
def print_struct(title, name, list):
	f.write('/*\n')
	f.write(' * Statistics entries for ' + title + ' handle.\n')
	f.write(' */\n')
	f.write('struct __wt_' + name + '_stats {\n')

	# Sort the structure fields by their description, so the eventual
	# disply is sorted by string.
	for l in sorted(list, key=attrgetter('desc')):
		f.write('\tWT_STATS ' + l.name + ';\n')

	f.write('\tWT_STATS __end;\n')
	f.write('};\n\n')

# Update the #defines in the stat.h file.
tmp_file = '__tmp'
f = open(tmp_file, 'w')
skip = 0
for line in open('../src/include/stat.h', 'r'):
	if not skip:
		f.write(line)
	if line.count('Statistics section: END'):
		f.write(line)
		skip = 0
	elif line.count('Statistics section: BEGIN'):
		f.write('\n')
		skip = 1
		print_struct('BTREE', 'btree', btree_stats)
		print_struct('CONNECTION', 'connection', connection_stats)
f.close()
compare_srcfile(tmp_file, '../src/include/stat.h')

# print_func --
#	Print the functions for the stat.c file.
def print_func(name, list):
	f.write('''
int
__wt_stat_alloc_''' + name + '''_stats(WT_SESSION_IMPL *session, WT_''' +
	    name.upper() + '''_STATS **statsp)
{
\tWT_''' + name.upper() + '''_STATS *stats;

\tWT_RET(__wt_calloc_def(session, 1, &stats));

''')

	for l in sorted(list):
		f.write('\tstats->' + l.name + '.name = "' + l.name + '";\n')
		o = '\tstats->' + l.name + '.desc = "' + l.desc + '";\n'
		if len(o) + 7  > 80:
			o = o.replace('= ', '=\n\t    ')
		f.write(o)
	f.write('''
\t*statsp = stats;
\treturn (0);
}
''')

	f.write('''
void
__wt_stat_clear_''' + name + '''_stats(WT_STATS *stats_arg)
{
\tWT_''' + name.upper() + '''_STATS *stats;

\tstats = (WT_''' + name.upper() + '''_STATS *)stats_arg;
''')
	for l in sorted(list):
		# Items marked permanent aren't cleared by the stat clear
		# methods.
		if not l.config.count('perm'):
			f.write('\tstats->' + l.name + '.v = 0;\n');
	f.write('}\n')

# Write the stat allocation and clear routines to the stat.c file.
f = open(tmp_file, 'w')
f.write('/* DO NOT EDIT: automatically built by dist/stat.py. */\n\n')
f.write('#include "wt_internal.h"\n')

print_func('btree', btree_stats)
print_func('connection', connection_stats)

f.close()

compare_srcfile(tmp_file, '../src/support/stat.c')

# print_dox --
#	Print the tables for the dox file.
def print_dox(name, list):
	f.write('<table>\n')
	f.write('@hrow{' + name + ' Statistics}\n')

	# Sort the structure fields by their description, so the eventual
	# disply is sorted by string.
	for l in sorted(list, key=attrgetter('desc')):
		f.write('@row{' + l.desc + '}\n')
	f.write('</table>\n\n')

# Update dox file
tmp_file = '__tmp'
f = open(tmp_file, 'w')
skip = 0
for line in open('../docs/src/stat-desc.dox', 'r'):
	if not skip:
		f.write(line)
	if line.count('connection statistics section: END'):
		f.write(line)
		skip = 0
	elif line.count('connection statistics section: BEGIN'):
		f.write('\n')
		skip = 1
		print_dox('Connection', connection_stats)
	if line.count('file statistics section: END'):
		f.write(line)
		skip = 0
	elif line.count('file statistics section: BEGIN'):
		f.write('\n')
		skip = 1
		print_dox('File', btree_stats)
f.close()
compare_srcfile(tmp_file, '../docs/src/stat-desc.dox')