6This script reads data recorded by profiler and prints it to stdout.
7It demonstrates usage of class CProfilerData2 and related classes.
10from __future__
import print_function
13import isystem.connect
as ic
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))
27def printStatistics(stats):
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())
35 printTimes(stats, ic.CProfilerStatistics2.ENetTimes)
36 print(
' Gross times:')
37 printTimes(stats, ic.CProfilerStatistics2.EGrossTimes)
39 printTimes(stats, ic.CProfilerStatistics2.ECallTimes)
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())
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())
66def printAreas(profilerData, areaType):
68 areaIterator = profilerData.getAreaIterator(areaType)
70 while areaIterator.hasNext():
71 area = areaIterator.next()
74 if (profilerData.hasStatisticsForArea(area.getAreaId())):
75 stats = profilerData.getStatistics(area.getAreaId())
76 printStatistics(stats)
78 print(
'No statistic for area ', hex(area.getAreaId()),
'found.')
81 return hex(val
if val >= 0
else (1 << bits) + val)
84def printTimeEvent(timeEvent, valueType):
86 print(
' handle: ', hex(timeEvent.getHandle()))
87 print(
' evType: ', timeEvent.getEventType())
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())
96 raise Exception(
'Unknown area value type: ', valueType)
98 print(
' time: ', timeEvent.getTime())
99 print(
' eventSrc:', timeEvent.getEventSource())
102def iterateEvents(timeIter, profilerData):
104 while timeIter.hasNext():
105 timeEvent = timeIter.next()
106 area = profilerData.getArea(timeEvent.getHandle())
107 printTimeEvent(timeEvent, area.getValueType())
112profilerExportFile =
'../../targetProjects/profilerSample-1.xml'
115 profilerExportFile = sys.argv[1]
117profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
120warnings = profilerData.getParserWarnings()
122 print(
'WARNING(S): ', warnings)
124print(
'\nProfiler session time:', profilerData.getTotalSessionTimeNs())
125print(
'\n--------------- Function areas ---------------\n')
126printAreas(profilerData, ic.CProfilerArea2.EFunctions)
128print(
'\n--------------- Variable areas ---------------\n')
129printAreas(profilerData, ic.CProfilerArea2.EVariables)
131print(
'\n--------------- State Variable areas ---------------\n')
132printAreas(profilerData, ic.CProfilerArea2.EStateVariables)
134print(
'\n--------------- Inspector areas ---------------\n')
135printAreas(profilerData, ic.CProfilerArea2.EInspector)
137print(
'\n--------------- State Filter areas ---------------\n')
138printAreas(profilerData, ic.CProfilerArea2.EStateInspector)
140print(
'\n\n\n--------------- All time-line Events ---------------\n')
141timeIter = profilerData.getTimelineIterator()
142iterateEvents(timeIter, profilerData)
144print(
'\n\n\nExamples of getArea() method, if we know area Id:')
145area = profilerData.getArea(0)
147area = profilerData.getArea(0x20000000)
149area = profilerData.getArea(0x30000001)
153print(
'\n\n\nExamples of getArea() method, if we know area name:')
154area = profilerData.getArea(ic.CProfilerArea2.EFunctions,
'fibonacci')
156area = profilerData.getArea(ic.CProfilerArea2.EVariables,
'main_loop_counter')
159area = profilerData.getArea(ic.CProfilerArea2.EStateVariables,
'E_ONE')
162area = profilerData.getArea(ic.CProfilerArea2.EStateVariables,
'g_enumA', 0)
165contexts = ic.StrVector()
166profilerData.getContexts(contexts)
167print(
'\n\nAvailable contexts:\n', end=
' ')
171print(
'\n\n\nExamples of getStatistics() methods:')
174if profilerData.hasStatisticsForArea(ic.CProfilerArea2.EFunctions,
'fibonacci'):
175 stats = profilerData.getStatistics(ic.CProfilerArea2.EFunctions,
'fibonacci')
176 printStatistics(stats)
178 print(
'No statistics for function fibonacci found.')
181if profilerData.hasStatisticsForFunction(0,
'Neutral'):
182 stats = profilerData.getStatisticsForFunction(0,
'Neutral')
183 printStatistics(stats)
185 print(
'No statistics for function with handle 0 and context Neutral found.')
188if (profilerData.hasStatisticsForFunction(ic.CProfilerArea2.EFunctions,
189 'fibonacci',
'Neutral')):
190 stats = profilerData.getStatisticsForFunction(ic.CProfilerArea2.EFunctions,
191 'fibonacci',
'Neutral')
192 printStatistics(stats)
194 print(
'No statistics for function named fibonacci with context Neutral found')
196stats = profilerData.getStatistics(ic.CProfilerArea2.EVariables,
'main_loop_counter')
197printStatistics(stats)
199stats = profilerData.getStatistics(ic.CProfilerArea2.EVariables,
'g_enumA')
200printStatistics(stats)
203if profilerData.hasStatisticsForStateArea(ic.CProfilerArea2.EStateVariables,
'g_enumA', 2):
204 stats = profilerData.getStatistics(ic.CProfilerArea2.EStateVariables,
'g_enumA', 2)
205 printStatistics(stats)
207 print(
'No statistics for state area g_enumA[2] found.')
211print(
'\n\n\nAll time-line Events:\n')
212timeIter = profilerData.getTimelineIterator()
213iterateEvents(timeIter, profilerData)
214profilerData.closeParser()
219print(
'\n\n\nWrite Events:\n')
220profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
221timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite)
222iterateEvents(timeIter, profilerData)
223profilerData.closeParser()
229print(
"\n\n\n'Enter' Events for function 'fibonacci':\n")
230profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
231typeSimpleArea = profilerData.getArea(ic.CProfilerArea2.EFunctions,
'fibonacci')
232timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvAny,
233 typeSimpleArea.getHandle())
234iterateEvents(timeIter, profilerData)
236profilerData.closeParser()
242print(
"\n\n\n'Write' Events for variable 'main_loop_counter':\n")
243profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
244iCounterArea = profilerData.getArea(ic.CProfilerArea2.EVariables,
'main_loop_counter')
245timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
246 iCounterArea.getHandle())
247iterateEvents(timeIter, profilerData)
249profilerData.closeParser()
255print(
"\n\n\n'Write' Events for variable 'g_enumA', value 3:\n")
256profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
257stateArea = profilerData.getArea(ic.CProfilerArea2.EVariables,
'g_enumA')
258timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
259 stateArea.getHandle(),
261iterateEvents(timeIter, profilerData)
263profilerData.closeParser()
269print(
"\n\n\nWrite Events for variable 'g_enumA', all values:\n")
270profilerData = ic.CProfilerData2.createInstance(profilerExportFile)
271varArea = profilerData.getArea(ic.CProfilerArea2.EVariables,
'g_enumA')
272timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
274iterateEvents(timeIter, profilerData)
276profilerData.closeParser()
279print(
"\n\n\nParse data from binary export:")
280print(
"Write Events for variable 'g_enumA', all values:\n")
281profilerData = ic.CProfilerData2.createInstance(
'../../targetProjects/profilerSample-bin.xml',
True)
282varArea = profilerData.getArea(ic.CProfilerArea2.EVariables,
'g_enumA')
283timeIter = profilerData.getTimelineIterator(ic.CProfilerTimeEvent.EEvWrite,
285iterateEvents(timeIter, profilerData)
287profilerData.closeParser()