diff options
Diffstat (limited to 'src/third_party/wiredtiger/dist/stat.py')
-rw-r--r-- | src/third_party/wiredtiger/dist/stat.py | 128 |
1 files changed, 86 insertions, 42 deletions
diff --git a/src/third_party/wiredtiger/dist/stat.py b/src/third_party/wiredtiger/dist/stat.py index 2a87d4425e6..c9684665a53 100644 --- a/src/third_party/wiredtiger/dist/stat.py +++ b/src/third_party/wiredtiger/dist/stat.py @@ -12,12 +12,11 @@ def print_struct(title, name, base, stats): f.write('/*\n') f.write(' * Statistics entries for ' + title + '.\n') f.write(' */\n') - f.write( - '#define\tWT_' + name.upper() + '_STATS_BASE\t' + str(base) + '\n') + f.write('#define\tWT_' + name.upper() + '_STATS_BASE\t' + str(base) + '\n') f.write('struct __wt_' + name + '_stats {\n') for l in stats: - f.write('\tWT_STATS ' + l.name + ';\n') + f.write('\tint64_t ' + l.name + ';\n') f.write('};\n\n') # Update the #defines in the stat.h file. @@ -90,67 +89,113 @@ for line in open('../src/include/wiredtiger.in', 'r'): f.close() compare_srcfile(tmp_file, '../src/include/wiredtiger.in') -def print_func(name, list): - '''Print the functions for the stat.c file.''' +def print_func(name, handle, list): + '''Print the structures/functions for the stat.c file.''' + f.write('\n') + f.write('static const char * const __stats_' + name + '_desc[] = {\n') + for l in list: + f.write('\t"' + l.desc + '",\n') + f.write('};\n') + + f.write(''' +const char * +__wt_stat_''' + name + '''_desc(int slot) +{ +\treturn (__stats_''' + name + '''_desc[slot]); +} +''') + f.write(''' void -__wt_stat_init_''' + name + '''_stats(WT_''' + name.upper() + '''_STATS *stats) +__wt_stat_''' + name + '_init_single(WT_' + name.upper() + '''_STATS *stats) { -\t/* Clear, so can also be called for reinitialization. */ \tmemset(stats, 0, sizeof(*stats)); - -''') - for l in sorted(list): - o = '\tstats->' + l.name + '.desc = "' + l.desc + '";\n' - if len(o) + 7 > 80: - o = o.replace('= ', '=\n\t ') - f.write(o) - f.write('''} +} ''') f.write(''' void -__wt_stat_refresh_''' + name + '''_stats(void *stats_arg) +__wt_stat_''' + name + '_init(' + handle + ''' *handle) { -\tWT_''' + name.upper() + '''_STATS *stats; +\tint i; + +\tfor (i = 0; i < WT_COUNTER_SLOTS; ++i) { +\t\thandle->stats[i] = &handle->stat_array[i]; +\t\t__wt_stat_''' + name + '''_init_single(handle->stats[i]); +\t} +} +''') -\tstats = (WT_''' + name.upper() + '''_STATS *)stats_arg; + f.write(''' +void +__wt_stat_''' + name + '_clear_single(WT_' + name.upper() + '''_STATS *stats) +{ ''') for l in sorted(list): # no_clear: don't clear the value. - if not 'no_clear' in l.flags: - f.write('\tstats->' + l.name + '.v = 0;\n'); + if 'no_clear' in l.flags: + f.write('\t\t/* not clearing ' + l.name + ' */\n') + else: + f.write('\tstats->' + l.name + ' = 0;\n') f.write('}\n') - # Aggregation is only interesting for data-source statistics. - # Complain if any aggregation flags are set. - if name == 'connection': + f.write(''' +void +__wt_stat_''' + name + '_clear_all(WT_' + name.upper() + '''_STATS **stats) +{ +\tu_int i; + +\tfor (i = 0; i < WT_COUNTER_SLOTS; ++i) +\t\t__wt_stat_''' + name + '''_clear_single(stats[i]); +} +''') + + # Single structure aggregation is currently only used by data sources. + if name == 'dsrc': + f.write(''' +void +__wt_stat_''' + name + '''_aggregate_single( + WT_''' + name.upper() + '_STATS *from, WT_' + name.upper() + '''_STATS *to) +{ +''') for l in sorted(list): - if 'no_aggregate' in l.flags or 'max_aggregate' in l.flags: - print >>sys.stdout,\ - "Aggregation configuration for " +\ - name + "." + l.name + " statistics not supported" - return; + if 'no_aggregate' in l.flags: + o = '\tto->' + l.name + ' = from->' + l.name + ';\n' + elif 'max_aggregate' in l.flags: + o = '\tif (from->' + l.name + ' > to->' + l.name + ')\n' +\ + '\t\tto->' + l.name + ' = from->' + l.name + ';\n' + else: + o = '\tto->' + l.name + ' += from->' + l.name + ';\n' + if len(o) > 72: # Account for the leading tab. + o = o.replace(' += ', ' +=\n\t ') + f.write(o) + f.write('}\n') f.write(''' void -__wt_stat_aggregate_''' + name + -'''_stats(const void *child, const void *parent) +__wt_stat_''' + name + '''_aggregate( + WT_''' + name.upper() + '_STATS **from, WT_' + name.upper() + '''_STATS *to) { -\tWT_''' + name.upper() + '''_STATS *c, *p; - -\tc = (WT_''' + name.upper() + '''_STATS *)child; -\tp = (WT_''' + name.upper() + '''_STATS *)parent; ''') + # Connection level aggregation does not currently have any computation + # of a maximum value; I'm leaving in support for it, but don't declare + # a temporary variable until it's needed. + for l in sorted(list): + if 'max_aggregate' in l.flags: + f.write('\tint64_t v;\n\n') + break; for l in sorted(list): if 'no_aggregate' in l.flags: - continue; + o = '\tto->' + l.name + ' = from[0]->' + l.name + ';\n' elif 'max_aggregate' in l.flags: - o = 'if (c->' + l.name + '.v > p->' + l.name +\ - '.v)\n\t p->' + l.name + '.v = c->' + l.name + '.v;' + o = '\tif ((v = WT_STAT_READ(from, ' + l.name + ')) >\n' +\ + '\t to->' + l.name + ')\n' +\ + '\t\tto->' + l.name + ' = v;\n' else: - o = 'p->' + l.name + '.v += c->' + l.name + '.v;' - f.write('\t' + o + '\n') + o = '\tto->' + l.name + ' += WT_STAT_READ(from, ' + l.name + ');\n' + if len(o) > 72: # Account for the leading tab. + o = o.replace(' += ', ' +=\n\t ') + f.write(o) f.write('}\n') # Write the stat initialization and refresh routines to the stat.c file. @@ -158,12 +203,11 @@ 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('dsrc', dsrc_stats) -print_func('connection', connection_stats) +print_func('dsrc', 'WT_DATA_HANDLE', dsrc_stats) +print_func('connection', 'WT_CONNECTION_IMPL', connection_stats) f.close() compare_srcfile(tmp_file, '../src/support/stat.c') - # Update the statlog file with the entries we can scale per second. scale_info = 'no_scale_per_second_list = [\n' clear_info = 'no_clear_list = [\n' |