def main(argv):
    filenames = argv

    all_histograms = OrderedDict()

    for histogram in parse_histograms.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.
        parse_histograms.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 parse_histograms.DefinitionException:
            continue

        all_histograms.update({name: parameters})

    print json.dumps({'histograms': all_histograms})
Ejemplo n.º 2
0
def main(output, *filenames):
    """
    Generate a Perfect Hash Table for the Histogram name -> Histogram ID lookup.
    The table is immutable once generated and we can avoid any dynamic memory allocation.
    """

    output.write(banner)
    output.write(header)

    try:
        histograms = list(parse_histograms.from_files(filenames))
        histograms = [
            h for h in histograms
            if h.record_on_os(buildconfig.substs["OS_TARGET"])
        ]
    except ParserError as ex:
        print("\nError processing histograms:\n" + str(ex) + "\n")
        sys.exit(1)

    histograms = [(bytearray(hist.name(), 'ascii'), idx)
                  for (idx, hist) in enumerate(histograms)]
    name_phf = PerfectHash(histograms, PHFSIZE)

    output.write(
        name_phf.cxx_codegen(name='HistogramIDByNameLookup',
                             entry_type="uint32_t",
                             lower_entry=lambda (_, v): str(v),
                             key_type="const nsACString&",
                             key_bytes="aKey.BeginReading()",
                             key_length="aKey.Length()"))

    output.write(footer)
Ejemplo n.º 3
0
def main(output, *filenames):
    try:
        histograms = list(parse_histograms.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)
Ejemplo n.º 4
0
def main(output, *filenames):
    try:
        histograms = list(parse_histograms.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 test_current_histogram(self):
        HISTOGRAMS_PATH = path.join(TELEMETRY_ROOT_PATH, "Histograms.json")
        all_histograms = list(
            parse_histograms.from_files([HISTOGRAMS_PATH],
                                        strict_type_checks=False))
        test_histogram = [
            i for i in all_histograms if i.name() == 'TELEMETRY_TEST_FLAG'
        ][0]

        self.assertEqual(test_histogram.expiration(), 'never')
        self.assertEqual(test_histogram.kind(), 'flag')
        self.assertEqual(test_histogram.record_in_processes(),
                         ["main", "content"])
        self.assertEqual(test_histogram.keyed(), False)
def main(argv):
    filenames = argv

    all_histograms = OrderedDict()

    for histogram in parse_histograms.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.
        parse_histograms.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 parse_histograms.DefinitionException:
            continue

        all_histograms.update({name: parameters})

    print json.dumps({'histograms': all_histograms})
Ejemplo n.º 7
0
def main(output, *filenames):
    # Print header.
    print(banner, file=output)
    print(header, file=output)

    # Load the histograms.
    try:
        all_histograms = list(parse_histograms.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 parse_histograms.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)
Ejemplo n.º 8
0
def main(output, *filenames):
    # Print header.
    print(banner, file=output)
    print(header, file=output)

    # Load the histograms.
    try:
        all_histograms = list(parse_histograms.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 parse_histograms.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:
            if histogram.record_on_os(buildconfig.substs["OS_TARGET"]):
                print("  %s," % histogram.name(), 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)