6This script demonstrates usage of profiler with isystem.connect API.
9from __future__
import print_function
13import isystem.connect
as ic
19print(
'isystem.connect version: ' + ic.getModuleVersion())
21cmgr = ic.ConnectionMgr()
22cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
24debugCtrl = ic.CDebugFacade(cmgr)
25ideCtrl = ic.CIDEController(cmgr)
28debugCtrl.runUntilFunction(
"main")
29debugCtrl.waitUntilStopped()
32profiler = ic.CProfilerController2(cmgr,
'sample_profiler.trd',
'w')
36profiler.removeTrigger(
'testTrigger')
37triggerIdx = profiler.createTrigger(
'testTrigger')
40profiler.select(triggerIdx)
43profiler.setProfilingSections(triggerIdx,
True,
True,
False,
False);
46profiler.setTriggerOption(triggerIdx,
'HW.Recorder.BufferSize',
'32 MB')
49profiler.setFunctionTrigger(triggerIdx,
"target_init")
52profiler.addFunction(triggerIdx,
"get_random")
53profiler.addFunction(triggerIdx,
"fibonacci")
55profiler.addVariable(triggerIdx,
"main_loop_counter", ic.CProfilerController2.EDATRegular)
56profiler.addStateVariable(triggerIdx,
58 ic.CProfilerController2.EStateDefEnum,
61print(
'Target is running, profiler is recording data...')
62profiler.waitUntilLoaded()
69print(
'Target stopped, loading profiler data...')
70profiler.waitUntilLoaded()
72exportCfg = ic.CProfilerExportConfig()
73exportCfg.setFileName(
'profilerSample-1.xml') \
74 .setAreaScope(ic.CProfilerExportConfig.EAreaAll) \
75 .setAreaExportSections(
True,
True,
True) \
76 .setSaveTimeline(
True)
78print(
'-------------------------\nWriting export file with settings:\n')
79print(exportCfg.toString())
80print(
'-------------------------\n\n')
81profiler.exportData(exportCfg)
83exportCfg.setFileName(
'profilerSample-bin.xml')
84formatter = ic.CProfilerXMLExportFormat()
85formatter.setTimelineBinary(
True)
86formatter.setUseIndent(
False)
87exportCfg.setFormatter(formatter)
88print(
'Writing XML export file with binary timeline ...')
89profiler.exportData(exportCfg)
92debugCtrl.runUntilFunction(
"main")
93debugCtrl.waitUntilStopped()
95print(
'One function and variable will be removed from trigger configuration.')
96profiler.removeFunction(triggerIdx,
"get_random")
97profiler.removeVariable(triggerIdx,
"fibonacci")
100print(
'New recording started: Target is running, profiler is recording data ...')
106print(
'Target stopped, loading profiler data...')
107profiler.waitUntilLoaded()
109exportCfg = ic.CProfilerExportConfig()
110exportFile =
'profilerSample-2.csv'
111exportCfg.setFileName(exportFile) \
112 .setSaveTimeline(
True) \
113 .setAreaScope(ic.CProfilerExportConfig.EAreaFilter) \
114 .setFunctionsFilter(
'*') \
115 .setVariablesFilter(
'*')
118exportCfg.setFileName(
'profilerSample.btf')
119formatter = ic.CProfilerBTFExportFormat()
120exportCfg.setFormatter(formatter)
122print(
'Writing BTF export file with binary timeline ...')
123profiler.exportData(exportCfg)
126print(
'Demonstration of some other profiler methods:')
127print(
' Number of triggers: ', profiler.getNumberOfTriggers())
131print(
" Profiler recording start: ", profiler.getTriggerOption(triggerIdx,
'HW.Recorder.Start'))
134print(
'\n\n\nProfiler measurements')
136profilerExportFile =
'profilerSample-3.xml'
137profilerData = ic.CProfilerData2.createInstance(profiler,
143warnings = profilerData.getParserWarnings()
145 print(
'WARNING(S): ', warnings)
148def printAreas(profilerData, areaType):
150 areaIterator = profilerData.getAreaIterator(areaType)
152 while areaIterator.hasNext():
153 area = areaIterator.next()
155 print(
' Id: ', hex(area.getAreaId()))
156 print(
' Handle: ', area.getHandle())
157 print(
' Path: ', area.getPath())
158 print(
' Name: ', area.getAreaName())
159 print(
' Value: ', area.getValue())
160 print(
' Value Unit:', area.getValueUnit())
161 print(
' Value Type:', area.getValueType())
162 print(
' Parent h.: ', area.getParentHandle())
163 print(
' Parent a.: ', area.getParentAreaName())
166print(
'\nFunction areas: ')
167printAreas(profilerData, ic.CProfilerArea2.EFunctions)
169print(
'\nVariable areas: ')
170printAreas(profilerData, ic.CProfilerArea2.EVariables)
173timeIter = profilerData.getTimelineIterator()
175while timeIter.hasNext():
176 timeEvent = timeIter.next()
177 print(
' time: ', timeEvent.getTime())
183profilerData.closeParser()
185print(
"\n\n\nRun script 'profilerData.py' to print ALL the recorded results.")