import os.path
import isystem.connect as ic
EXAMPLE_TRD_FILE_NAME = "sdk_example.trd"
EXAMPLE_XML_PROFILER_FILE_NAME = "example_profiler_data.xml"
EXAMPLE_BIN_PROFILER_FILE_NAME = f"{EXAMPLE_XML_PROFILER_FILE_NAME}.BIN"
def export_data(conn_mgr: ic.ConnectionMgr) -> str:
"""
Export sdk_example.trd data to profiler XML and binary data, 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)
xml_file_path = os.path.join(workspace_dir, EXAMPLE_XML_PROFILER_FILE_NAME)
bin_file_path = os.path.join(workspace_dir, EXAMPLE_BIN_PROFILER_FILE_NAME)
if os.path.exists(xml_file_path) and os.path.exists(bin_file_path):
print("Profiler data files already exists, nothing to do...")
else:
print("Exporting .trd data to profiler XML and binary file...")
export_cfg = ic.CProfilerExportConfig()
export_cfg.setFileName(xml_file_path)
fmt = ic.CProfilerXMLExportFormat()
fmt.setTimelineBinary(True)
export_cfg.setFormatter(fmt)
export_cfg.setSaveTimeline(True)
prof_ctrl = ic.CProfilerController2(conn_mgr, EXAMPLE_TRD_FILE_NAME, "u")
prof_ctrl.waitUntilLoaded(10000, isThrow=True)
prof_ctrl.exportData(export_cfg)
prof_ctrl.closeDiscard()
assert os.path.exists(xml_file_path)
assert os.path.exists(bin_file_path)
print(f"\t{xml_file_path}\n\t{bin_file_path}")
return xml_file_path