winIDEA SDK
export_profiler_data.py
1# This script is licensed under BSD License, see file LICENSE.txt.
2#
3# (c) TASKING Germany GmbH, 2023
4
5import os.path
6import isystem.connect as ic
7
8EXAMPLE_TRD_FILE_NAME = "example.trd"
9EXAMPLE_XML_PROFILER_FILE_NAME = "example_profiler_data.xml"
10EXAMPLE_BIN_PROFILER_FILE_NAME = f"{EXAMPLE_XML_PROFILER_FILE_NAME}.BIN"
11
12
13def export_data(conn_mgr: ic.ConnectionMgr) -> str:
14 """
15 Export example.trd data to profiler XML and binary data, and return path to a created XML file.
16 NOTE: Only export files if they do not exists yet.
17 """
18 ide_ctrl = ic.CIDEController(conn_mgr)
19 workspace_dir = ide_ctrl.getPath(ic.CIDEController.WORKSPACE_DIR)
20 xml_file_path = os.path.join(workspace_dir, EXAMPLE_XML_PROFILER_FILE_NAME)
21 bin_file_path = os.path.join(workspace_dir, EXAMPLE_BIN_PROFILER_FILE_NAME)
22
23 if os.path.exists(xml_file_path) and os.path.exists(bin_file_path):
24 print("Profiler data files already exists, nothing to do...")
25 else:
26 print("Exporting .trd data to profiler XML and binary file...")
27 export_cfg = ic.CProfilerExportConfig()
28 export_cfg.setFileName(xml_file_path)
29 fmt = ic.CProfilerXMLExportFormat()
30 fmt.setTimelineBinary(True) # this setting creates file 'bin_file_path'
31 export_cfg.setFormatter(fmt)
32 export_cfg.setSaveTimeline(True)
33
34 prof_ctrl = ic.CProfilerController2(conn_mgr, EXAMPLE_TRD_FILE_NAME, "u")
35 prof_ctrl.waitUntilLoaded(10000, isThrow=True)
36 prof_ctrl.exportData(export_cfg)
37 prof_ctrl.closeDiscard()
38
39 assert os.path.exists(xml_file_path)
40 assert os.path.exists(bin_file_path)
41 print(f"\t{xml_file_path}\n\t{bin_file_path}")
42
43 return xml_file_path
44