1
2
3
4
5"""
6This script demonstrates usage of profiler with isystem.connect API.
7"""
8
9from __future__ import print_function
10
11import os
12import time
13import isystem.connect as ic
14
15
16if __name__ == '__main__':
17 winidea_id = ''
18
19
20 print('isystem.connect version: ' + ic.getModuleVersion())
21
22 cmgr = ic.ConnectionMgr()
23 cmgr.connect(ic.CConnectionConfig().instanceId(winidea_id))
24
25 debugCtrl = ic.CDebugFacade(cmgr)
26 ideCtrl = ic.CIDEController(cmgr)
27
28 debugCtrl.download()
29 debugCtrl.runUntilFunction("main")
30 debugCtrl.waitUntilStopped()
31
32
33 profiler = ic.CProfilerController2(cmgr, 'sample_profiler.trd', 'w')
34
35
36
37 profiler.removeTrigger('testTrigger')
38 triggerIdx = profiler.createTrigger('testTrigger')
39
40
41 profiler.select(triggerIdx)
42
43
44 profiler.setProfilingSections(triggerIdx, True, True, False, False);
45
46
47 profiler.setTriggerOption(triggerIdx, 'HW.Recorder.BufferSize', '32 MB')
48
49
50 profiler.setFunctionTrigger(triggerIdx, "target_init")
51
52
53 profiler.addFunction(triggerIdx, "get_random")
54 profiler.addFunction(triggerIdx, "fibonacci")
55
56 profiler.addVariable(triggerIdx, "main_loop_counter", ic.CProfilerController2.EDATRegular)
57 profiler.addStateVariable(triggerIdx,
58 "g_enumA",
59 ic.CProfilerController2.EStateDefEnum,
60 "enumA")
61
62 print('Target is running, profiler is recording data...')
63 profiler.waitUntilLoaded()
64
65 profiler.start()
66 debugCtrl.run()
67 time.sleep(3)
68 debugCtrl.stop()
69
70 print('Target stopped, loading profiler data...')
71 profiler.waitUntilLoaded()
72
73 exportCfg = ic.CProfilerExportConfig()
74 exportCfg.setFileName('profilerSample-1.xml') \
75 .setAreaScope(ic.CProfilerExportConfig.EAreaAll) \
76 .setAreaExportSections(True, True, True) \
77 .setSaveTimeline(True)
78
79 print('-------------------------\nWriting export file with settings:\n')
80 print(exportCfg.toString())
81 print('-------------------------\n\n')
82 profiler.exportData(exportCfg)
83
84 exportCfg.setFileName('profilerSample-bin.xml')
85 formatter = ic.CProfilerXMLExportFormat()
86 formatter.setTimelineBinary(True)
87 formatter.setUseIndent(False)
88 exportCfg.setFormatter(formatter)
89 print('Writing XML export file with binary timeline ...')
90 profiler.exportData(exportCfg)
91
92 debugCtrl.reset()
93 debugCtrl.runUntilFunction("main")
94 debugCtrl.waitUntilStopped()
95
96 print('One function and variable will be removed from trigger configuration.')
97 profiler.removeFunction(triggerIdx, "get_random")
98 profiler.removeVariable(triggerIdx, "fibonacci")
99
100
101 print('New recording started: Target is running, profiler is recording data ...')
102 profiler.start()
103 debugCtrl.run()
104 time.sleep(3)
105 debugCtrl.stop()
106
107 print('Target stopped, loading profiler data...')
108 profiler.waitUntilLoaded()
109
110 exportCfg = ic.CProfilerExportConfig()
111 exportFile = 'profilerSample-2.csv'
112 exportCfg.setFileName(exportFile) \
113 .setSaveTimeline(True) \
114 .setAreaScope(ic.CProfilerExportConfig.EAreaFilter) \
115 .setFunctionsFilter('*') \
116 .setVariablesFilter('*')
117
118
119 exportCfg.setFileName('profilerSample.btf')
120 formatter = ic.CProfilerBTFExportFormat()
121 exportCfg.setFormatter(formatter)
122
123 print('Writing BTF export file with binary timeline ...')
124 profiler.exportData(exportCfg)
125
126
127 print('Demonstration of some other profiler methods:')
128 print(' Number of triggers: ', profiler.getNumberOfTriggers())
129
130
131
132 print(" Profiler recording start: ", profiler.getTriggerOption(triggerIdx, 'HW.Recorder.Start'))
133
134
135 print('\n\n\nProfiler measurements')
136
137 profilerExportFile = 'profilerSample-3.xml'
138 profilerData = ic.CProfilerData2.createInstance(profiler,
139 profilerExportFile,
140 True,
141 '*', '*')
142
143
144 warnings = profilerData.getParserWarnings()
145 if warnings:
146 print('WARNING(S): ', warnings)
147
148
149 def printAreas(profilerData, areaType):
150
151 areaIterator = profilerData.getAreaIterator(areaType)
152
153 while areaIterator.hasNext():
154 area = areaIterator.next()
155 print('Area:')
156 print(' Id: ', hex(area.getAreaId()))
157 print(' Handle: ', area.getHandle())
158 print(' Path: ', area.getPath())
159 print(' Name: ', area.getAreaName())
160 print(' Value: ', area.getValue())
161 print(' Value Unit:', area.getValueUnit())
162 print(' Value Type:', area.getValueType())
163 print(' Parent h.: ', area.getParentHandle())
164 print(' Parent a.: ', area.getParentAreaName())
165
166
167 print('\nFunction areas: ')
168 printAreas(profilerData, ic.CProfilerArea2.EFunctions)
169
170 print('\nVariable areas: ')
171 printAreas(profilerData, ic.CProfilerArea2.EVariables)
172
173 print('\nTimeline: ')
174 timeIter = profilerData.getTimelineIterator()
175 counter = 0
176 while timeIter.hasNext():
177 timeEvent = timeIter.next()
178 print(' time: ', timeEvent.getTime())
179 if counter > 100:
180 break
181 counter += 1
182
183
184 profilerData.closeParser()
185
186 print("\n\n\nRun script 'profilerData.py' to print ALL the recorded results.")