2015-07-11 07:51:30 +02:00
|
|
|
#!/usr/bin/env python
|
2018-06-12 11:43:13 +02:00
|
|
|
from __future__ import print_function
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2014-07-30 04:00:14 +02:00
|
|
|
counter_types = {}
|
|
|
|
|
|
|
|
f = open('../include/libtorrent/performance_counters.hpp')
|
|
|
|
|
|
|
|
counter_type = ''
|
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
for line in f:
|
2015-12-20 08:02:09 +01:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
# ignore anything after //
|
|
|
|
if '//' in line:
|
|
|
|
line = line.split('//')[0]
|
2015-12-20 08:02:09 +01:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
line = line.strip()
|
2014-07-30 04:00:14 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if line.startswith('#'):
|
|
|
|
continue
|
|
|
|
if line == '':
|
|
|
|
continue
|
2014-07-30 04:00:14 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if 'enum stats_counter_t' in line:
|
|
|
|
counter_type = 'counter'
|
|
|
|
continue
|
2014-07-30 04:00:14 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if 'enum stats_gauge_t' in line:
|
|
|
|
counter_type = 'gauge'
|
|
|
|
continue
|
2014-07-30 04:00:14 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if '{' in line or '}' in line or 'struct' in line or 'namespace' in line:
|
|
|
|
continue
|
|
|
|
if counter_type == '':
|
|
|
|
continue
|
|
|
|
if not line.endswith(','):
|
|
|
|
continue
|
2014-07-30 04:00:14 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
# strip off trailing comma
|
|
|
|
line = line[:-1]
|
|
|
|
if '=' in line:
|
|
|
|
line = line[:line.index('=')].strip()
|
2014-07-30 04:00:14 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
counter_types[line] = counter_type
|
2015-07-11 07:51:30 +02:00
|
|
|
|
2014-07-30 04:00:14 +02:00
|
|
|
f.close()
|
|
|
|
|
2014-07-09 01:44:34 +02:00
|
|
|
f = open('../src/session_stats.cpp')
|
|
|
|
|
|
|
|
out = open('stats_counters.rst', 'w+')
|
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
|
2014-07-09 01:44:34 +02:00
|
|
|
def print_field(str, width):
|
2018-06-12 11:43:13 +02:00
|
|
|
return '%s%s' % (str, ' ' * (width - len(str)))
|
|
|
|
|
2014-07-09 01:44:34 +02:00
|
|
|
|
|
|
|
def render_section(names, description, types):
|
2018-06-12 11:43:13 +02:00
|
|
|
max_name_len = max(len(max(names, key=len)), len('name'))
|
|
|
|
max_type_len = max(len(max(types, key=len)), len('type'))
|
|
|
|
|
|
|
|
if description == '':
|
|
|
|
for n in names:
|
|
|
|
print('WARNING: no description for "%s"' % n)
|
|
|
|
|
|
|
|
# add link targets for the rest of the manual to reference
|
|
|
|
for n in names:
|
|
|
|
print('.. _%s:\n' % n, file=out)
|
|
|
|
|
|
|
|
if len(names) > 0:
|
|
|
|
print('.. raw:: html\n', file=out)
|
|
|
|
for n in names:
|
|
|
|
print('\t<a name="%s"></a>' % n, file=out)
|
|
|
|
print('', file=out)
|
|
|
|
|
|
|
|
separator = '+-' + ('-' * max_name_len) + '-+-' + ('-' * max_type_len) + '-+'
|
|
|
|
|
|
|
|
# build a table for the settings, their type and default value
|
|
|
|
print(separator, file=out)
|
|
|
|
print('| %s | %s |' % (print_field('name', max_name_len), print_field('type', max_type_len)), file=out)
|
|
|
|
print(separator.replace('-', '='), file=out)
|
|
|
|
for i in range(len(names)):
|
|
|
|
print('| %s | %s |' % (print_field(names[i], max_name_len), print_field(types[i], max_type_len)), file=out)
|
|
|
|
print(separator, file=out)
|
|
|
|
print(file=out)
|
|
|
|
print(description, file=out)
|
|
|
|
print('', file=out)
|
|
|
|
|
2014-07-09 01:44:34 +02:00
|
|
|
|
|
|
|
mode = ''
|
|
|
|
|
|
|
|
description = ''
|
|
|
|
names = []
|
|
|
|
types = []
|
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
for line in f:
|
|
|
|
description_line = line.lstrip().startswith('//')
|
2016-02-18 03:38:50 +01:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
line = line.strip()
|
2014-07-09 01:44:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if mode == 'ignore':
|
|
|
|
if '#endif' in line:
|
|
|
|
mode = ''
|
|
|
|
continue
|
2016-10-25 14:02:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if 'TORRENT_ABI_VERSION == 1' in line:
|
|
|
|
mode = 'ignore'
|
|
|
|
continue
|
2016-10-25 14:02:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if description_line:
|
|
|
|
if len(names) > 0:
|
|
|
|
render_section(names, description, types)
|
|
|
|
description = ''
|
|
|
|
names = []
|
|
|
|
types = []
|
2014-07-09 01:44:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
description += '\n' + line[3:]
|
2014-07-09 01:44:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if '#define' in line:
|
|
|
|
continue
|
2014-07-09 01:44:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
if 'METRIC(' in line:
|
|
|
|
args = line.split('(')[1].split(')')[0].split(',')
|
2014-07-09 01:44:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
# args: category, name, type
|
2014-07-09 01:44:34 +02:00
|
|
|
|
2018-06-12 11:43:13 +02:00
|
|
|
args[1] = args[1].strip()
|
|
|
|
names.append(args[0].strip() + '.' + args[1].strip())
|
|
|
|
types.append(counter_types[args[1]])
|
2014-07-09 01:44:34 +02:00
|
|
|
|
|
|
|
if len(names) > 0:
|
2018-06-12 11:43:13 +02:00
|
|
|
render_section(names, description, types)
|
2014-07-09 01:44:34 +02:00
|
|
|
|
|
|
|
out.close()
|
|
|
|
f.close()
|