1
2
3
4
5"""
6This script reads data recorded by profiler and prints it to stdout.
7It demonstrates usage of class CProfilerData2 and related classes.
8"""
9
10from __future__ import print_function
11
12import sys
13import isystem.connect as ic
14
15
16def printTimes(stats, timeType):
17 print(' total: ', stats.getTotalTime(timeType))
18 print(' min: ', stats.getMinTime(timeType))
19 print(' minStart:', stats.getMinStartTime(timeType))
20 print(' minEnd: ', stats.getMinEndTime(timeType))
21 print(' max: ', stats.getMaxTime(timeType))
22 print(' maxStart:', stats.getMaxStartTime(timeType))
23 print(' maxEnd: ', stats.getMaxEndTime(timeType))
24 print(' average: ', stats.getAverageTime(timeType))
25
26
27def printStatistics(stats):
28 print(' Statistics:')
29 print(' Id: ', hex(stats.getAreaId()))
30 print(' Handle: ', stats.getHandle())
31 print(' Name: ', stats.getAreaName())
32 print(' Value: ', stats.getAreaValue())
33 print(' Num hits: ', stats.getNumHits())
34 print(' Net times: ')
35 printTimes(stats, ic.CProfilerStatistics2.ENetTimes)
36 print(' Gross times:')
37 printTimes(stats, ic.CProfilerStatistics2.EGrossTimes)
38 print(' Call times:')
39 printTimes(stats, ic.CProfilerStatistics2.ECallTimes)
40 print(' Period:')
41 printTimes(stats, ic.CProfilerStatistics2.EPeriodTimes)
42 print(' Outside times:')
43 printTimes(stats, ic.CProfilerStatistics2.EOutsideTimes)
44 print(' Value statistics:')
45 print(' Average:', stats.getValueAverage())
46 print(' Min:', stats.getValueMin())
47 print(' Max:', stats.getValueMax())
48 print(' TimeOfMin:', stats.getValueTimeOfMin())
49 print(' TimeOfMax:', stats.getValueTimeOfMax())
50
51
52
53def printArea(area):
54 print('Area:')
55 print(' Id: ', hex(area.getAreaId()))
56 print(' Handle: ', area.getHandle())
57 print(' Path: ', area.getPath())
58 print(' Name: ', area.getAreaName())
59 print(' Value: ', area.getValue())
60 print(' Value type:', area.getValueType())
61 print(' Line num.: ', area.getLineNumber())
62 print(' Parent h.: ', area.getParentHandle())
63 print(' Parent a.: ', area.getParentAreaName())
64
65
66def printAreas(profilerData, areaType):
67
68 areaIterator = profilerData.getAreaIterator(areaType)
69
70 while areaIterator.hasNext():
71 area = areaIterator.next()
72 printArea(area)
73
74 if (profilerData.hasStatisticsForArea(area.getAreaId())):
75 stats = profilerData.getStatistics(area.getAreaId())
76 printStatistics(stats)
77 else:
78 print('No statistic for area ', hex(area.getAreaId()), 'found.')
79
80def uhex(val, bits):
81 return hex(val if val >= 0 else (1 << bits) + val)
82
83
84def printTimeEvent(timeEvent, valueType):
85 print('TimeEvent: ')
86 print(' handle: ', hex(timeEvent.getHandle()))
87 print(' evType: ', timeEvent.getEventType())
88
89 if valueType == 'F32':
90 print(' value F: ', timeEvent.getFloatValue())
91 elif valueType == 'I32' or valueType == 'I64':
92 print(' value I: ', uhex(timeEvent.getValue(), 64))
93 elif valueType == 'S32' or valueType == 'S64':
94 print(' value S: ', timeEvent.getSignedValue())
95 else:
96 raise Exception('Unknown area value type: ', valueType)
97
98 print(' time: ', timeEvent.getTime())
99 print(' eventSrc:', timeEvent.getEventSource())
100
101
102def iterateEvents(timeIter, profilerData):
103 counter = 0
104 while timeIter.hasNext():
105 timeEvent = timeIter.next()
106 area = profilerData.getArea(timeEvent.getHandle())
107 printTimeEvent(timeEvent, area.getValueType())
108 counter += 1
109 if counter > 30:
110 break
111
112if __name__ == '__main__':
113 profilerExportFile = '../../targetProjects/profilerSample-1.xml'
114
115 if len(sys.argv) > 1:
116 profilerExportFile = sys.argv[1]
117
118 profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
119
120
121 warnings = profilerData.getParserWarnings()
122 if warnings:
123 print('WARNING(S): ', warnings)
124
125 print('\nProfiler session time:', profilerData.getTotalSessionTimeNs())
126 print('\n--------------- Function areas ---------------\n')
127 printAreas(profilerData, ic.CProfilerArea2.EFunctions)
128
129 print('\n--------------- Variable areas ---------------\n')
130 printAreas(profilerData, ic.CProfilerArea2.EVariables)
131
132 print('\n--------------- State Variable areas ---------------\n')
133 printAreas(profilerData, ic.CProfilerArea2.EStateVariables)
134
135 print('\n--------------- Inspector areas ---------------\n')
136 printAreas(profilerData, ic.CProfilerArea2.EInspector)
137
138 print('\n--------------- State Filter areas ---------------\n')
139 printAreas(profilerData, ic.CProfilerArea2.EStateInspector)
140
141 print('\n\n\n--------------- All time-line Events ---------------\n')
142 timeIter = profilerData.getTimelineIterator()
143 iterateEvents(timeIter, profilerData)
144
145 print('\n\n\nExamples of getArea() method, if we know area Id:')
146 area = profilerData.getArea(0)
147 printArea(area)
148 area = profilerData.getArea(0x20000000)
149 printArea(area)
150 area = profilerData.getArea(0x30000001)
151 printArea(area)
152
153
154 print('\n\n\nExamples of getArea() method, if we know area name:')
155 area = profilerData.getArea(ic.CProfilerArea2.EFunctions, 'fibonacci')
156 printArea(area)
157 area = profilerData.getArea(ic.CProfilerArea2.EVariables, 'main_loop_counter')
158 printArea(area)
159
160 area = profilerData.getArea(ic.CProfilerArea2.EStateVariables, 'E_ONE')
161 printArea(area)
162
163 area = profilerData.getArea(ic.CProfilerArea2.EStateVariables, 'g_enumA', 0)
164 printArea(area)
165
166 contexts = ic.StrVector()
167 profilerData.getContexts(contexts)
168 print('\n\nAvailable contexts:\n', end=' ')
169 for ctx in contexts:
170 print(ctx)
171
172 print('\n\n\nExamples of getStatistics() methods:')
173
174
175 if profilerData.hasStatisticsForArea(ic.CProfilerArea2.EFunctions, 'fibonacci'):
176 stats = profilerData.getStatistics(ic.CProfilerArea2.EFunctions, 'fibonacci')
177 printStatistics(stats)
178 else:
179 print('No statistics for function fibonacci found.')
180
181
182 if profilerData.hasStatisticsForFunction(0, 'Neutral'):
183 stats = profilerData.getStatisticsForFunction(0, 'Neutral')
184 printStatistics(stats)
185 else:
186 print('No statistics for function with handle 0 and context Neutral found.')
187
188
189 if (profilerData.hasStatisticsForFunction(ic.CProfilerArea2.EFunctions,
190 'fibonacci', 'Neutral')):
191 stats = profilerData.getStatisticsForFunction(ic.CProfilerArea2.EFunctions,
192 'fibonacci', 'Neutral')
193 printStatistics(stats)
194 else:
195 print('No statistics for function named fibonacci with context Neutral found')
196
197 stats = profilerData.getStatistics(ic.CProfilerArea2.EVariables, 'main_loop_counter')
198 printStatistics(stats)
199
200 stats = profilerData.getStatistics(ic.CProfilerArea2.EVariables, 'g_enumA')
201 printStatistics(stats)
202
203
204 if profilerData.hasStatisticsForStateArea(ic.CProfilerArea2.EStateVariables, 'g_enumA', 2):
205 stats = profilerData.getStatistics(ic.CProfilerArea2.EStateVariables, 'g_enumA', 2)
206 printStatistics(stats)
207 else:
208 print('No statistics for state area g_enumA[2] found.')
209
210
211
212 print('\n\n\nAll time-line Events:\n')
213 timeIter = profilerData.getTimelineIterator()
214 iterateEvents(timeIter, profilerData)
215 profilerData.closeParser()
216
217
218
219
220 print('\n\n\nWrite Events:\n')
221 profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
222 timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite)
223 iterateEvents(timeIter, profilerData)
224 profilerData.closeParser()
225
226
227
228
229
230 print("\n\n\n'Enter' Events for function 'fibonacci':\n")
231 profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
232 typeSimpleArea = profilerData.getArea(ic.CProfilerArea2.EFunctions, 'fibonacci')
233 timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvAny,
234 typeSimpleArea.getHandle())
235 iterateEvents(timeIter, profilerData)
236
237 profilerData.closeParser()
238
239
240
241
242
243 print("\n\n\n'Write' Events for variable 'main_loop_counter':\n")
244 profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
245 iCounterArea = profilerData.getArea(ic.CProfilerArea2.EVariables, 'main_loop_counter')
246 timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
247 iCounterArea.getHandle())
248 iterateEvents(timeIter, profilerData)
249
250 profilerData.closeParser()
251
252
253
254
255
256 print("\n\n\n'Write' Events for variable 'g_enumA', value 3:\n")
257 profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
258 stateArea = profilerData.getArea(ic.CProfilerArea2.EVariables, 'g_enumA')
259 timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
260 stateArea.getHandle(),
261 3)
262 iterateEvents(timeIter, profilerData)
263
264 profilerData.closeParser()
265
266
267
268
269
270 print("\n\n\nWrite Events for variable 'g_enumA', all values:\n")
271 profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
272 varArea = profilerData.getArea(ic.CProfilerArea2.EVariables, 'g_enumA')
273 timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
274 varArea.getHandle())
275 iterateEvents(timeIter, profilerData)
276
277 profilerData.closeParser()
278
279
280 print("\n\n\nParse data from binary export:")
281 print("Write Events for variable 'g_enumA', all values:\n")
282 profilerData = ic.CProfilerData2.createInstance('../../targetProjects/profilerSample-bin.xml', True)
283 varArea = profilerData.getArea(ic.CProfilerArea2.EVariables, 'g_enumA')
284 timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
285 varArea.getHandle())
286 iterateEvents(timeIter, profilerData)
287
288 profilerData.closeParser()
289 print('Done!')
290