winIDEA SDK
Loading...
Searching...
No Matches
export_trace_data.py
# This script is licensed under BSD License, see file LICENSE.txt, or search for `License` in the SDK online help.
#
# (c) TASKING Germany GmbH, 2023
import os
import isystem.connect as ic
from typing import Tuple
EXAMPLE_TRD_FILE = "sdk_example.trd"
EXAMPLE_XML_TRACE_FILE_NAME = "example_trace_data.xml"
EXAMPLE_BIN_TRACE_FILE_NAME = f"{EXAMPLE_XML_TRACE_FILE_NAME}.BIN"
def export_data(conn_mgr: ic.ConnectionMgr) -> Tuple[str, str]:
"""
Export example .trd data to trace XML, and return path to a created XML file.
NOTE: Only export files if they do not exists yet.
"""
ide_ctrl = ic.CIDEController(conn_mgr)
workspace_dir = ide_ctrl.getPath(ic.CIDEController.WORKSPACE_DIR)
trd_file_path = EXAMPLE_TRD_FILE
xml_file_path = os.path.join(workspace_dir, EXAMPLE_XML_TRACE_FILE_NAME)
bin_file_path = os.path.join(workspace_dir, EXAMPLE_BIN_TRACE_FILE_NAME)
if os.path.exists(xml_file_path) and os.path.exists(bin_file_path):
print("Trace data files already exists, nothing to do...")
else:
print("Exporting .trd data to trace XML...")
trace_ctrl = ic.CTraceController(conn_mgr, trd_file_path, "u")
trace_ctrl.waitUntilLoaded(10000, isThrow=True)
trace_data = ic.CTraceData.createInstance(trace_ctrl, xml_file_path, 0, 0, False)
trace_data.closeParser()
assert os.path.exists(xml_file_path)
trace_data = ic.CTraceData.createInstance(trace_ctrl, bin_file_path, 0, 0, True)
trace_data.closeParser()
assert os.path.exists(bin_file_path)
trace_ctrl.closeDiscard()
print(f"\t{xml_file_path}\n\t{bin_file_path}")
return xml_file_path, bin_file_path