from pyfbsdk import *
import os
import tempfile
import time
gApp = FBApplication()
gProfiler = FBProfiler()
gPlayer = FBPlayerControl()
gProfiler.ActiveSampling = True
gPlayer.Goto( FBTime(0,0,0,0) )
gPlayer.Play()
while FBSystem().LocalTime.GetFrame() < 50:
gApp.FlushEventQueue()
gPlayer.Stop()
while gPlayer.IsPlaying:
gApp.FlushEventQueue()
gProfiler.ActiveSampling = False
lSamplesCount = gProfiler.GetEventSampleCount()
print "Number of samples collected: %d\n" % lSamplesCount
if lSamplesCount > 0:
logPath = os.path.join( tempfile.gettempdir(), "EventsLog.txt" )
f = open(logPath, 'wt')
for i in range(lSamplesCount):
lEvent = gProfiler.GetEventSample(i)
lEndEvent = gProfiler.GetEndEventSample(i)
lColor = lEvent.GetColor()
if lEvent.IsSingleEvent():
lString = "%s;%s;%f %f %f %d %d\n" % (lEvent.GetComment(),lEvent.GetTypeName(),lColor[0],lColor[1],lColor[2],lEvent.GetThreadID(), lEvent.GetTime().Get())
f.write(lString)
elif lEndEvent:
lString = "%s;%s;%f %f %f %d %d %d\n" % (lEvent.GetComment(),lEvent.GetTypeName(),lColor[0],lColor[1],lColor[2],lEvent.GetThreadID(), lEvent.GetTime().Get(), lEndEvent.GetTime().Get())
f.write(lString)
f.close()
print "File successfully saved to %s" % logPath