winIDEA SDK
export_trace_data.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import os
6import isystem.connect as ic
7from typing import Tuple
8
9EXAMPLE_TRD_FILE = "example.trd"
10EXAMPLE_XML_TRACE_FILE_NAME = "example_trace_data.xml"
11EXAMPLE_BIN_TRACE_FILE_NAME = f"{EXAMPLE_XML_TRACE_FILE_NAME}.BIN"
12
13
14def export_data(conn_mgr: ic.ConnectionMgr) -> Tuple[str, str]:
15 """
16 Export example .trd data to trace XML, and return path to a created XML file.
17 NOTE: Only export files if they do not exists yet.
18 """
19 ide_ctrl = ic.CIDEController(conn_mgr)
20 workspace_dir = ide_ctrl.getPath(ic.CIDEController.WORKSPACE_DIR)
21
22 trd_file_path = EXAMPLE_TRD_FILE
23 xml_file_path = os.path.join(workspace_dir, EXAMPLE_XML_TRACE_FILE_NAME)
24 bin_file_path = os.path.join(workspace_dir, EXAMPLE_BIN_TRACE_FILE_NAME)
25
26 if os.path.exists(xml_file_path) and os.path.exists(bin_file_path):
27 print("Trace data files already exists, nothing to do...")
28 else:
29 print("Exporting .trd data to trace XML...")
30
31 trace_ctrl = ic.CTraceController(conn_mgr, trd_file_path, "u")
32 trace_ctrl.waitUntilLoaded(10000, isThrow=True)
33
34 trace_data = ic.CTraceData.createInstance(trace_ctrl, xml_file_path, 0, 0, False)
35 trace_data.closeParser()
36 assert os.path.exists(xml_file_path)
37
38 trace_data = ic.CTraceData.createInstance(trace_ctrl, bin_file_path, 0, 0, True)
39 trace_data.closeParser()
40 assert os.path.exists(bin_file_path)
41 trace_ctrl.closeDiscard()
42 print(f"\t{xml_file_path}\n\t{bin_file_path}")
43
44 return xml_file_path, bin_file_path