winIDEA SDK
Loading...
Searching...
No Matches
export_profiler_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.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) # this setting creates file 'bin_file_path'
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