def main(output, *filenames): histograms = list(histogram_tools.from_files(filenames)) print(banner, file=output) write_histogram_table(output, histograms) write_histogram_static_asserts(output, histograms) write_debug_histogram_ranges(output, histograms)
def main(argv): filenames = argv all_histograms = OrderedDict() for histogram in histogram_tools.from_files(filenames): name = histogram.name() parameters = OrderedDict() table = { 'boolean': '2', 'flag': '3', 'enumerated': '1', 'linear': '1', 'exponential': '0', 'count': '4', } # Use __setitem__ because Python lambdas are so limited. histogram_tools.table_dispatch(histogram.kind(), table, lambda k: parameters.__setitem__('kind', k)) if histogram.low() == 0: parameters['min'] = 1 else: parameters['min'] = histogram.low() try: buckets = histogram.ranges() parameters['buckets'] = buckets parameters['max'] = buckets[-1] parameters['bucket_count'] = len(buckets) except histogram_tools.DefinitionException: continue all_histograms.update({ name: parameters }) print json.dumps({ 'histograms': all_histograms})
def main(argv): filenames = argv all_histograms = OrderedDict() for histogram in histogram_tools.from_files(filenames): name = histogram.name() parameters = OrderedDict() table = { 'boolean': '2', 'flag': '3', 'enumerated': '1', 'linear': '1', 'exponential': '0', 'count': '4', } # Use __setitem__ because Python lambdas are so limited. histogram_tools.table_dispatch(histogram.kind(), table, lambda k: parameters.__setitem__('kind', k)) if histogram.low() == 0: parameters['min'] = 1 else: parameters['min'] = histogram.low() try: buckets = histogram.ranges() parameters['buckets'] = buckets parameters['max'] = buckets[-1] parameters['bucket_count'] = len(buckets) except histogram_tools.DefinitionException: continue all_histograms.update({ name: parameters }); print json.dumps({ 'histograms': all_histograms})
def main(argv): filenames = argv all_histograms = OrderedDict() for histogram in histogram_tools.from_files(filenames): name = histogram.name() parameters = OrderedDict() table = {"boolean": "2", "flag": "3", "enumerated": "1", "linear": "1", "exponential": "0", "count": "4"} # Use __setitem__ because Python lambdas are so limited. histogram_tools.table_dispatch(histogram.kind(), table, lambda k: parameters.__setitem__("kind", k)) if histogram.low() == 0: parameters["min"] = 1 else: parameters["min"] = histogram.low() try: buckets = histogram.ranges() parameters["buckets"] = buckets parameters["max"] = buckets[-1] parameters["bucket_count"] = len(buckets) except histogram_tools.DefinitionException: continue all_histograms.update({name: parameters}) if startup_histogram_re.search(name) is not None: all_histograms.update({"STARTUP_" + name: parameters}) print json.dumps({"histograms": all_histograms})
def main(argv): filenames = argv histograms = list(histogram_tools.from_files(filenames)) print banner write_histogram_table(histograms) write_histogram_static_asserts(histograms) write_debug_histogram_ranges(histograms)
def main(output, *filenames): try: histograms = list(histogram_tools.from_files(filenames)) except ParserError as ex: print("\nError processing histograms:\n" + str(ex) + "\n") sys.exit(1) print(banner, file=output) write_histogram_table(output, histograms) write_histogram_ranges(output, histograms) write_histogram_static_asserts(output, histograms)
def main(output, *filenames): try: histograms = list(histogram_tools.from_files(filenames)) except ParserError as ex: print("\nError processing histograms:\n" + str(ex) + "\n") sys.exit(1) print(banner, file=output) write_histogram_table(output, histograms) write_histogram_static_asserts(output, histograms) write_debug_histogram_ranges(output, histograms)
def main(output, *filenames): print(banner, file=output) print("#ifndef mozilla_TelemetryHistogramEnums_h", file=output) print("#define mozilla_TelemetryHistogramEnums_h", file=output) print("namespace mozilla {", file=output) print("namespace Telemetry {", file=output) print("enum ID : uint32_t {", file=output) groups = itertools.groupby(histogram_tools.from_files(filenames), lambda h: h.name().startswith("USE_COUNTER2_")) seen_use_counters = False # Note that histogram_tools.py guarantees that all of the USE_COUNTER2_* # histograms are defined in a contiguous block. We therefore assume # that there's at most one group for which use_counter_group is true. for (use_counter_group, histograms) in groups: if use_counter_group: seen_use_counters = True # The HistogramDUMMY* enum variables are used to make the computation # of Histogram{First,Last}UseCounter easier. Otherwise, we'd have to # special case the first and last histogram in the group. if use_counter_group: print(" HistogramFirstUseCounter,", file=output) print(" HistogramDUMMY1 = HistogramFirstUseCounter - 1,", file=output) for histogram in histograms: cpp_guard = histogram.cpp_guard() if cpp_guard: print("#if defined(%s)" % cpp_guard, file=output) print(" %s," % histogram.name(), file=output) if cpp_guard: print("#endif", file=output) if use_counter_group: print(" HistogramDUMMY2,", file=output) print(" HistogramLastUseCounter = HistogramDUMMY2 - 1,", file=output) print(" HistogramCount,", file=output) if seen_use_counters: print( " HistogramUseCounterCount = HistogramLastUseCounter - HistogramFirstUseCounter + 1", file=output) else: print(" HistogramFirstUseCounter = 0,", file=output) print(" HistogramLastUseCounter = 0,", file=output) print(" HistogramUseCounterCount = 0", file=output) print("};", file=output) print("} // namespace mozilla", file=output) print("} // namespace Telemetry", file=output) print("#endif // mozilla_TelemetryHistogramEnums_h", file=output)
def main(output, *filenames): print(banner, file=output) print("#ifndef mozilla_TelemetryHistogramEnums_h", file=output); print("#define mozilla_TelemetryHistogramEnums_h", file=output); print("namespace mozilla {", file=output) print("namespace Telemetry {", file=output) print("enum ID : uint32_t {", file=output) groups = itertools.groupby(histogram_tools.from_files(filenames), lambda h: h.name().startswith("USE_COUNTER2_")) seen_use_counters = False # Note that histogram_tools.py guarantees that all of the USE_COUNTER2_* # histograms are defined in a contiguous block. We therefore assume # that there's at most one group for which use_counter_group is true. for (use_counter_group, histograms) in groups: if use_counter_group: seen_use_counters = True # The HistogramDUMMY* enum variables are used to make the computation # of Histogram{First,Last}UseCounter easier. Otherwise, we'd have to # special case the first and last histogram in the group. if use_counter_group: print(" HistogramFirstUseCounter,", file=output) print(" HistogramDUMMY1 = HistogramFirstUseCounter - 1,", file=output) for histogram in histograms: cpp_guard = histogram.cpp_guard() if cpp_guard: print("#if defined(%s)" % cpp_guard, file=output) print(" %s," % histogram.name(), file=output) if cpp_guard: print("#endif", file=output) if use_counter_group: print(" HistogramDUMMY2,", file=output) print(" HistogramLastUseCounter = HistogramDUMMY2 - 1,", file=output) print(" HistogramCount,", file=output) if seen_use_counters: print(" HistogramUseCounterCount = HistogramLastUseCounter - HistogramFirstUseCounter + 1", file=output) else: print(" HistogramFirstUseCounter = 0,", file=output) print(" HistogramLastUseCounter = 0,", file=output) print(" HistogramUseCounterCount = 0", file=output) print("};", file=output) print("} // namespace mozilla", file=output) print("} // namespace Telemetry", file=output) print("#endif // mozilla_TelemetryHistogramEnums_h", file=output);
def main(argv): filenames = argv print banner print "enum ID : uint32_t {" groups = itertools.groupby(histogram_tools.from_files(filenames), lambda h: h.name().startswith("USE_COUNTER_")) seen_use_counters = False # Note that histogram_tools.py guarantees that all of the USE_COUNTER_* # histograms are defined in a contiguous block. We therefore assume # that there's at most one group for which use_counter_group is true. for (use_counter_group, histograms) in groups: if use_counter_group: seen_use_counters = True # The HistogramDUMMY* enum variables are used to make the computation # of Histogram{First,Last}UseCounter easier. Otherwise, we'd have to # special case the first and last histogram in the group. if use_counter_group: print " HistogramFirstUseCounter," print " HistogramDUMMY1 = HistogramFirstUseCounter - 1," for histogram in histograms: cpp_guard = histogram.cpp_guard() if cpp_guard: print "#if defined(%s)" % cpp_guard print " %s," % histogram.name() if cpp_guard: print "#endif" if use_counter_group: print " HistogramDUMMY2," print " HistogramLastUseCounter = HistogramDUMMY2 - 1," print " HistogramCount," if seen_use_counters: print " HistogramUseCounterCount = HistogramLastUseCounter - HistogramFirstUseCounter + 1" else: print " HistogramFirstUseCounter = 0," print " HistogramLastUseCounter = 0," print " HistogramUseCounterCount = 0" print "};"
def main(argv): filenames = argv print banner print "enum ID : uint32_t {" groups = itertools.groupby(histogram_tools.from_files(filenames), lambda h: h.name().startswith("USE_COUNTER_")) seen_use_counters = False # Note that histogram_tools.py guarantees that all of the USE_COUNTER_* # histograms are defined in a contiguous block. We therefore assume # that there's at most one group for which use_counter_group is true. for (use_counter_group, histograms) in groups: if use_counter_group: seen_use_counters = True # The HistogramDUMMY* enum variables are used to make the computation # of Histogram{First,Last}UseCounter easier. Otherwise, we'd have to # special case the first and last histogram in the group. if use_counter_group: print " HistogramFirstUseCounter," print " HistogramDUMMY1 = HistogramFirstUseCounter - 1," for histogram in histograms: cpp_guard = histogram.cpp_guard() if cpp_guard: print "#if defined(%s)" % cpp_guard print " %s," % histogram.name() if cpp_guard: print "#endif" if use_counter_group: print " HistogramDUMMY2," print " HistogramLastUseCounter = HistogramDUMMY2 - 1," print " HistogramCount," if seen_use_counters: print " HistogramUseCounterCount = HistogramLastUseCounter - HistogramFirstUseCounter + 1" else: print " HistogramUseCounterCount = 0" print "};"
def main(output, *filenames): # Print header. print(banner, file=output) print(header, file=output) # Load the histograms. try: all_histograms = list(histogram_tools.from_files(filenames)) except ParserError as ex: print("\nError processing histograms:\n" + str(ex) + "\n") sys.exit(1) groups = itertools.groupby(all_histograms, lambda h: h.name().startswith("USE_COUNTER2_")) # Print the histogram enums. # Note that histogram_tools.py guarantees that all of the USE_COUNTER2_* # histograms are defined in a contiguous block. We therefore assume # that there's at most one group for which use_counter_group is true. print("enum HistogramID : uint32_t {", file=output) seen_use_counters = False for (use_counter_group, histograms) in groups: if use_counter_group: seen_use_counters = True # The HistogramDUMMY* enum variables are used to make the computation # of Histogram{First,Last}UseCounter easier. Otherwise, we'd have to # special case the first and last histogram in the group. if use_counter_group: print(" HistogramFirstUseCounter,", file=output) print(" HistogramDUMMY1 = HistogramFirstUseCounter - 1,", file=output) for histogram in histograms: cpp_guard = histogram.cpp_guard() if cpp_guard: print("#if defined(%s)" % cpp_guard, file=output) print(" %s," % histogram.name(), file=output) if cpp_guard: print("#endif", file=output) if use_counter_group: print(" HistogramDUMMY2,", file=output) print(" HistogramLastUseCounter = HistogramDUMMY2 - 1,", file=output) print(" HistogramCount,", file=output) if seen_use_counters: print( " HistogramUseCounterCount = HistogramLastUseCounter -" " HistogramFirstUseCounter + 1", file=output) else: print(" HistogramFirstUseCounter = 0,", file=output) print(" HistogramLastUseCounter = 0,", file=output) print(" HistogramUseCounterCount = 0", file=output) print("};", file=output) # Write categorical label enums. categorical = filter(lambda h: h.kind() == "categorical", all_histograms) enums = [("LABELS_" + h.name(), h.labels(), h.name()) for h in categorical] for name, labels, _ in enums: print("\nenum class %s : uint32_t {" % name, file=output) print(" %s" % ",\n ".join(labels), file=output) print("};", file=output) print("\ntemplate<class T> struct IsCategoricalLabelEnum : FalseType {};", file=output) for name, _, _ in enums: print("template<> struct IsCategoricalLabelEnum<%s> : TrueType {};" % name, file=output) print("\ntemplate<class T> struct CategoricalLabelId {};", file=output) for name, _, id in enums: print("template<> struct CategoricalLabelId<%s> : " "IntegralConstant<uint32_t, %s> {};" % (name, id), file=output) # Footer. print(footer, file=output)
def main(output, *filenames): # Print header. print(banner, file=output) print(header, file=output) # Load the histograms. all_histograms = list(histogram_tools.from_files(filenames)) groups = itertools.groupby(all_histograms, lambda h: h.name().startswith("USE_COUNTER2_")) # Print the histogram enums. # Note that histogram_tools.py guarantees that all of the USE_COUNTER2_* # histograms are defined in a contiguous block. We therefore assume # that there's at most one group for which use_counter_group is true. print("enum ID : uint32_t {", file=output) seen_use_counters = False for (use_counter_group, histograms) in groups: if use_counter_group: seen_use_counters = True # The HistogramDUMMY* enum variables are used to make the computation # of Histogram{First,Last}UseCounter easier. Otherwise, we'd have to # special case the first and last histogram in the group. if use_counter_group: print(" HistogramFirstUseCounter,", file=output) print(" HistogramDUMMY1 = HistogramFirstUseCounter - 1,", file=output) for histogram in histograms: cpp_guard = histogram.cpp_guard() if cpp_guard: print("#if defined(%s)" % cpp_guard, file=output) print(" %s," % histogram.name(), file=output) if cpp_guard: print("#endif", file=output) if use_counter_group: print(" HistogramDUMMY2,", file=output) print(" HistogramLastUseCounter = HistogramDUMMY2 - 1,", file=output) print(" HistogramCount,", file=output) if seen_use_counters: print(" HistogramUseCounterCount = HistogramLastUseCounter - HistogramFirstUseCounter + 1", file=output) else: print(" HistogramFirstUseCounter = 0,", file=output) print(" HistogramLastUseCounter = 0,", file=output) print(" HistogramUseCounterCount = 0", file=output) print("};", file=output) # Write categorical label enums. categorical = filter(lambda h: h.kind() == "categorical", all_histograms) enums = [("LABELS_" + h.name(), h.labels(), h.name()) for h in categorical] for name,labels,_ in enums: print("\nenum class %s : uint32_t {" % name, file=output) print(" %s" % ",\n ".join(labels), file=output) print("};", file=output) print("\ntemplate<class T> struct IsCategoricalLabelEnum : FalseType {};", file=output) for name,_,_ in enums: print("template<> struct IsCategoricalLabelEnum<%s> : TrueType {};" % name, file=output) print("\ntemplate<class T> struct CategoricalLabelId {};", file=output) for name,_,id in enums: print("template<> struct CategoricalLabelId<%s> : IntegralConstant<uint32_t, %s> {};" % (name, id), file=output) # Footer. print(footer, file=output)