Samples/Profiling/CreateProfilingEventsLog.py
 
 
 
Samples/Profiling/CreateProfilingEventsLog.py
# Copyright 2012 Autodesk, Inc.  All rights reserved.
# Use of this software is subject to the terms of the Autodesk license agreement
# provided at the time of installation or download, or which otherwise accompanies
# this software in either electronic or hard copy form.
#
# Script description:
# Demonstrates usage of FBProfiler to collect time events information. 
#
# Topic: FBProfiler, FBPlayerControl 
#
from pyfbsdk import *
import os
import tempfile
import time

gApp = FBApplication()
gProfiler = FBProfiler()
gPlayer = FBPlayerControl()

# Activate collection of time events information
gProfiler.ActiveSampling = True

# Play for 50 frames
gPlayer.Goto( FBTime(0,0,0,0) )
gPlayer.Play()
while FBSystem().LocalTime.GetFrame() < 50:
    gApp.FlushEventQueue()

# Wait for playing to stop
gPlayer.Stop()
while gPlayer.IsPlaying:
    gApp.FlushEventQueue()
                
# Deactivate collection of time events information
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