def main(output, *filenames): # Load the event data. if len(filenames) > 1: raise Exception('We don\'t support loading from more than one file.') events = parse_events.load_events(filenames[0]) # Write the scalar data file. print(banner, file=output) print(file_header, file=output) # Write the extra keys table. string_table = StringTable() extra_table = write_extra_table(events, output, string_table) print("", file=output) # Write a table with the common event data. write_common_event_table(events, output, string_table, extra_table) print("", file=output) # Write the data for individual events. write_event_table(events, output, string_table) print("", file=output) # Write the string table. string_table_name = "gEventsStringTable" string_table.writeDefinition(output, string_table_name) static_assert(output, "sizeof(%s) <= UINT32_MAX" % string_table_name, "index overflow") print("", file=output) print(file_footer, file=output)
def main(output, *filenames): # Load the event data. if len(filenames) > 1: raise Exception('We don\'t support loading from more than one file.') try: events = parse_events.load_events(filenames[0]) except ParserError as ex: print("\nError processing events:\n" + str(ex) + "\n") sys.exit(1) # Write the scalar data file. print(banner, file=output) print(file_header, file=output) # Write the extra keys table. string_table = StringTable() extra_table = write_extra_table(events, output, string_table) print("", file=output) # Write a table with the common event data. write_common_event_table(events, output, string_table, extra_table) print("", file=output) # Write the data for individual events. write_event_table(events, output, string_table) print("", file=output) # Write the string table. string_table_name = "gEventsStringTable" string_table.writeDefinition(output, string_table_name) static_assert(output, "sizeof(%s) <= UINT32_MAX" % string_table_name, "index overflow") print("", file=output) print(file_footer, file=output)
def write_histogram_table(output, histograms): table = StringTable() print("const HistogramInfo gHistograms[] = {", file=output) for histogram in histograms: name_index = table.stringIndex(histogram.name()) exp_index = table.stringIndex(histogram.expiration()) print_array_entry(output, histogram, name_index, exp_index) print("};", file=output) strtab_name = "gHistogramStringTable" table.writeDefinition(output, strtab_name) static_assert(output, "sizeof(%s) <= UINT32_MAX" % strtab_name, "index overflow")
def write_histogram_table(output, histograms): string_table = StringTable() label_table = [] label_count = 0 print("const HistogramInfo gHistograms[] = {", file=output) for histogram in histograms: name_index = string_table.stringIndex(histogram.name()) exp_index = string_table.stringIndex(histogram.expiration()) labels = histogram.labels() label_index = 0 if len(labels) > 0: label_index = label_count label_table.append( (histogram.name(), string_table.stringIndexes(labels))) label_count += len(labels) print_array_entry(output, histogram, name_index, exp_index, label_index, len(labels)) print("};\n", file=output) strtab_name = "gHistogramStringTable" string_table.writeDefinition(output, strtab_name) static_assert(output, "sizeof(%s) <= UINT32_MAX" % strtab_name, "index overflow") print("\nconst uint32_t gHistogramLabelTable[] = {", file=output) for name, indexes in label_table: print("/* %s */ %s," % (name, ", ".join(map(str, indexes))), file=output) print("};", file=output)
def write_scalar_tables(scalars, output): """Writes the scalar and strings tables to an header file. :param scalars: a list of ScalarType instances describing the scalars. :param output: the output stream. """ string_table = StringTable() print("const ScalarInfo gScalars[] = {", file=output) for s in scalars: # We add both the scalar label and the expiration string to the strings # table. name_index = string_table.stringIndex(s.label) exp_index = string_table.stringIndex(s.expires) # Write the scalar info entry. write_scalar_info(s, output, name_index, exp_index) print("};", file=output) string_table_name = "gScalarsStringTable" string_table.writeDefinition(output, string_table_name) static_assert(output, "sizeof(%s) <= UINT32_MAX" % string_table_name, "index overflow")
def write_histogram_table(output, histograms): string_table = StringTable() label_table = [] label_count = 0 print("const HistogramInfo gHistograms[] = {", file=output) for histogram in histograms: name_index = string_table.stringIndex(histogram.name()) exp_index = string_table.stringIndex(histogram.expiration()) labels = histogram.labels() label_index = 0 if len(labels) > 0: label_index = label_count label_table.append((histogram.name(), string_table.stringIndexes(labels))) label_count += len(labels) print_array_entry(output, histogram, name_index, exp_index, label_index, len(labels)) print("};\n", file=output) strtab_name = "gHistogramStringTable" string_table.writeDefinition(output, strtab_name) static_assert(output, "sizeof(%s) <= UINT32_MAX" % strtab_name, "index overflow") print("\nconst uint32_t gHistogramLabelTable[] = {", file=output) for name,indexes in label_table: print("/* %s */ %s," % (name, ", ".join(map(str, indexes))), file=output) print("};", file=output)