def _main(args): events = get_trace_events_from_file(args.databases, args.input_file) json_lines = trace.generate_trace_json(events) with open(args.output_file, 'w') as output_file: for line in json_lines: output_file.write("%s,\n" % line)
def _main(args): token_database = \ database.load_token_database(args.trace_token_database, domain="trace") _LOG.info(database.database_summary(token_database)) client = get_hdlc_rpc_client(**vars(args)) data = get_trace_data_from_device(client) events = trace_tokenized.get_trace_events([token_database], data) json_lines = trace.generate_trace_json(events) trace_tokenized.save_trace_file(json_lines, args.trace_output_file)
def test_generate_single_json_event(self): event = trace.TraceEvent(event_type=trace.TraceType.Instantaneous, module="module", label="label", timestamp_us=10) json_lines = trace.generate_trace_json([event]) self.assertEqual(1, len(json_lines)) self.assertEqual(json.loads(json_lines[0]), { "ph": "I", "pid": "module", "name": "label", "ts": 10, "s": "p" })
def test_generate_json_data_arg_label(self): event = trace.TraceEvent( event_type=trace.TraceType.Instantaneous, module="module", label="", # Is replaced by data string timestamp_us=10, has_data=True, data_fmt="@pw_arg_label", data=bytes("arg", "utf-8")) json_lines = trace.generate_trace_json([event]) self.assertEqual(1, len(json_lines)) self.assertEqual(json.loads(json_lines[0]), { "ph": "I", "pid": "module", "name": "arg", "ts": 10, "s": "p" })
def test_generate_json_data_struct_fmt_single(self): event = trace.TraceEvent(event_type=trace.TraceType.Instantaneous, module="module", label="counter", timestamp_us=10, has_data=True, data_fmt="@pw_py_struct_fmt:H", data=(5).to_bytes(2, byteorder="little")) json_lines = trace.generate_trace_json([event]) self.assertEqual(1, len(json_lines)) self.assertEqual( json.loads(json_lines[0]), { "ph": "I", "pid": "module", "name": "counter", "ts": 10, "s": "p", "args": { "data_0": 5 } })
def test_generate_json_data_struct_fmt_multi(self): event = trace.TraceEvent(event_type=trace.TraceType.Instantaneous, module="module", label="counter", timestamp_us=10, has_data=True, data_fmt="@pw_py_struct_fmt:Hl", data=struct.pack("Hl", 5, 2)) json_lines = trace.generate_trace_json([event]) self.assertEqual(1, len(json_lines)) self.assertEqual( json.loads(json_lines[0]), { "ph": "I", "pid": "module", "name": "counter", "ts": 10, "s": "p", "args": { "data_0": 5, "data_1": 2 } })
def test_generate_multiple_json_events(self): json_lines = trace.generate_trace_json(test_events) self.assertEqual(len(test_json), len(json_lines)) for actual, expected in zip(json_lines, test_json): self.assertEqual(expected, json.loads(actual))
def _main(args): events = get_trace_events_from_file(args.databases, args.input_file) json_lines = trace.generate_trace_json(events) save_trace_file(json_lines, args.output_file)