add 'profile': log individual starting times, and use them on next run to estimate...
authorFelix Domke <tmbinc@elitedvb.net>
Thu, 7 Feb 2008 23:53:58 +0000 (23:53 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Thu, 7 Feb 2008 23:53:58 +0000 (23:53 +0000)
lib/python/Tools/Makefile.am
lib/python/Tools/Profile.py [new file with mode: 0644]
mytest.py

index 0bc82009efba2cfd0f6d750602b2600c42fc6813..0050ee34aa5c297a039076925a1359199b3006b5 100644 (file)
@@ -4,4 +4,4 @@ install_PYTHON = \
        FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py \
        KeyBindings.py BoundFunction.py ISO639.py Notifications.py __init__.py \
        RedirectOutput.py DreamboxHardware.py Import.py Event.py CList.py \
        FuzzyDate.py XMLTools.py Directories.py NumericalTextInput.py \
        KeyBindings.py BoundFunction.py ISO639.py Notifications.py __init__.py \
        RedirectOutput.py DreamboxHardware.py Import.py Event.py CList.py \
-       RedirectTime.py LoadPixmap.py
+       RedirectTime.py LoadPixmap.py Profile.py
diff --git a/lib/python/Tools/Profile.py b/lib/python/Tools/Profile.py
new file mode 100644 (file)
index 0000000..1c44bc8
--- /dev/null
@@ -0,0 +1,42 @@
+import time
+from Directories import resolveFilename, SCOPE_SYSETC
+
+PERCENTAGE_START = 50
+PERCENTAGE_END = 100
+
+profile_start = time.time()
+
+profile_data = {}
+total_time = 1
+
+try:
+       profile_old = open(resolveFilename(SCOPE_SYSETC, "profile"), "r").readlines()
+
+       t = None
+       for line in profile_old:
+               (t, id) = line[:-1].split('\t')
+               t = float(t)
+               total_time = t
+               profile_data[id] = t
+except:
+       print "no profile data available"
+
+profile_file = open(resolveFilename(SCOPE_SYSETC, "profile"), "w")
+
+def profile(id):
+       now = time.time() - profile_start
+       if profile_file:
+               profile_file.write("%.2f\t%s\n" % (now, id))
+       if id in profile_data:
+               t = profile_data[id]
+               perc = t * (PERCENTAGE_END - PERCENTAGE_START) / total_time + PERCENTAGE_START
+               try:
+                       open("/proc/progress", "w").write("%d \n" % perc)
+               except IOError:
+                       pass
+
+def profile_final():
+       global profile_file
+       if profile_file is not None:
+               profile_file.close()
+               profile_file = None
index 3bdbcf2d63b94edad399440df75d202937f19a55..627d16fbf5990f2baa84fc3333f38647b740befc 100644 (file)
--- a/mytest.py
+++ b/mytest.py
@@ -1,7 +1,13 @@
+from Tools.Profile import profile, profile_final
+
+profile("PYTHON_START")
+
 from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, eDVBVolumecontrol, \
        getDesktop, ePythonConfigQuery, eAVSwitch, eWindow, eServiceEvent
 from tools import *
 
 from enigma import runMainloop, eDVBDB, eTimer, quitMainloop, eDVBVolumecontrol, \
        getDesktop, ePythonConfigQuery, eAVSwitch, eWindow, eServiceEvent
 from tools import *
 
+profile("LANGUAGE")
+
 from Components.Language import language
 
 def setEPGLanguage():
 from Components.Language import language
 
 def setEPGLanguage():
@@ -11,25 +17,33 @@ def setEPGLanguage():
 language.addCallback(setEPGLanguage)
 
 from traceback import print_exc
 language.addCallback(setEPGLanguage)
 
 from traceback import print_exc
+profile("LOAD:InfoBar")
 import Screens.InfoBar
 from Screens.SimpleSummary import SimpleSummary
 
 from sys import stdout, exc_info
 
 import Screens.InfoBar
 from Screens.SimpleSummary import SimpleSummary
 
 from sys import stdout, exc_info
 
+profile("ParentalControl")
 from Components.ParentalControl import InitParentalControl
 InitParentalControl()
 
 from Components.ParentalControl import InitParentalControl
 InitParentalControl()
 
+profile("LOAD:Navigation")
 from Navigation import Navigation
 
 from Navigation import Navigation
 
+profile("LOAD:skin")
 from skin import readSkin, applyAllAttributes
 
 from skin import readSkin, applyAllAttributes
 
+profile("LOAD:Tools")
 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from Components.config import config, configfile, ConfigText, ConfigSubsection, ConfigInteger
 InitFallbackFiles()
 from Tools.Directories import InitFallbackFiles, resolveFilename, SCOPE_PLUGINS, SCOPE_SKIN_IMAGE
 from Components.config import config, configfile, ConfigText, ConfigSubsection, ConfigInteger
 InitFallbackFiles()
+
+profile("ReloadProfiles")
 eDVBDB.getInstance().reloadBouquets()
 
 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
 
 eDVBDB.getInstance().reloadBouquets()
 
 config.misc.radiopic = ConfigText(default = resolveFilename(SCOPE_SKIN_IMAGE)+"radio.mvi")
 
+profile("Twisted")
 try:
        import twisted.python.runtime
        twisted.python.runtime.platform.supportsThreads = lambda: False
 try:
        import twisted.python.runtime
        twisted.python.runtime.platform.supportsThreads = lambda: False
@@ -46,9 +60,12 @@ except ImportError:
        def runReactor():
                runMainloop()
 
        def runReactor():
                runMainloop()
 
+profile("LOAD:Plugin")
+
 # initialize autorun plugins and plugin menu entries
 from Components.PluginComponent import plugins
 
 # initialize autorun plugins and plugin menu entries
 from Components.PluginComponent import plugins
 
+profile("LOAD:Wizard")
 from Screens.Wizard import wizardManager
 from Screens.ImageWizard import *
 from Screens.StartWizard import *
 from Screens.Wizard import wizardManager
 from Screens.ImageWizard import *
 from Screens.StartWizard import *
@@ -56,6 +73,7 @@ from Screens.TutorialWizard import *
 from Tools.BoundFunction import boundFunction
 from Plugins.Plugin import PluginDescriptor
 
 from Tools.BoundFunction import boundFunction
 from Plugins.Plugin import PluginDescriptor
 
+profile("misc")
 had = dict()
 
 def dump(dir, p = ""):
 had = dict()
 
 def dump(dir, p = ""):
@@ -79,23 +97,17 @@ def dump(dir, p = ""):
 class OutputDevice:
        def create(self, screen): pass
 
 class OutputDevice:
        def create(self, screen): pass
 
-# display: HTML
-
-class HTMLOutputDevice(OutputDevice):
-       def create(self, comp):
-               print comp.produceHTML()
-
-html = HTMLOutputDevice()
-
 class GUIOutputDevice(OutputDevice):
        parent = None
        def create(self, comp, desktop):
                comp.createGUIScreen(self.parent, desktop)
 
 class GUIOutputDevice(OutputDevice):
        parent = None
        def create(self, comp, desktop):
                comp.createGUIScreen(self.parent, desktop)
 
+profile("LOAD:ScreenGlobals")
 from Screens.Globals import Globals
 from Screens.SessionGlobals import SessionGlobals
 from Screens.Screen import Screen
 
 from Screens.Globals import Globals
 from Screens.SessionGlobals import SessionGlobals
 from Screens.Screen import Screen
 
+profile("Screen")
 Screen.global_screen = Globals()
 
 # Session.open:
 Screen.global_screen = Globals()
 
 # Session.open:
@@ -320,6 +332,7 @@ from Screens.Volume import Volume
 from Screens.Mute import Mute
 from GlobalActions import globalActionMap
 
 from Screens.Mute import Mute
 from GlobalActions import globalActionMap
 
+profile("VolumeControl")
 #TODO .. move this to a own .py file
 class VolumeControl:
        """Volume control, handles volUp, volDown, volMute actions and display
 #TODO .. move this to a own .py file
 class VolumeControl:
        """Volume control, handles volUp, volDown, volMute actions and display
@@ -392,6 +405,7 @@ class VolumeControl:
                                self.muteDialog.hide()
                                self.volumeDialog.setValue(vol)
 
                                self.muteDialog.hide()
                                self.volumeDialog.setValue(vol)
 
+profile("Standby,PowerKey")
 import Screens.Standby
 from Screens.Menu import MainMenu, mdom
 import xml.dom.minidom
 import Screens.Standby
 from Screens.Menu import MainMenu, mdom
 import xml.dom.minidom
@@ -450,6 +464,7 @@ class PowerKey:
                if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
                        self.session.open(Screens.Standby.Standby)
 
                if not Screens.Standby.inStandby and self.session.current_dialog and self.session.current_dialog.ALLOW_SUSPEND:
                        self.session.open(Screens.Standby.Standby)
 
+profile("Scart")
 from Screens.Scart import Scart
 
 class AutoScartControl:
 from Screens.Scart import Scart
 
 class AutoScartControl:
@@ -475,12 +490,15 @@ class AutoScartControl:
                        else:
                                self.scartDialog.switchToTV()
 
                        else:
                                self.scartDialog.switchToTV()
 
+profile("Load:CI")
 from enigma import eDVBCIInterfaces
 from Screens.Ci import CiHandler
 
 def runScreenTest():
 from enigma import eDVBCIInterfaces
 from Screens.Ci import CiHandler
 
 def runScreenTest():
+       profile("readPluginList")
        plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
 
        plugins.readPluginList(resolveFilename(SCOPE_PLUGINS))
 
+       profile("Init:Session")
        session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
 
        CiHandler.setSession(session)
        session = Session(desktop = getDesktop(0), summary_desktop = getDesktop(1), navigation = Navigation())
 
        CiHandler.setSession(session)
@@ -490,6 +508,7 @@ def runScreenTest():
        for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
                screensToRun.append(p.__call__)
 
        for p in plugins.getPlugins(PluginDescriptor.WHERE_WIZARD):
                screensToRun.append(p.__call__)
 
+       profile("wizards")
        screensToRun += wizardManager.getWizards()
 
        screensToRun.append(Screens.InfoBar.InfoBar)
        screensToRun += wizardManager.getWizards()
 
        screensToRun.append(Screens.InfoBar.InfoBar)
@@ -516,16 +535,21 @@ def runScreenTest():
 
        runNextScreen(session, screensToRun)
 
 
        runNextScreen(session, screensToRun)
 
+       profile("Init:VolumeControl")
        vol = VolumeControl(session)
        vol = VolumeControl(session)
+       profile("Init:PowerKey")
        power = PowerKey(session)
 
        # we need session.scart to access it from within menu.xml
        session.scart = AutoScartControl(session)
 
        power = PowerKey(session)
 
        # we need session.scart to access it from within menu.xml
        session.scart = AutoScartControl(session)
 
+       profile("RunReactor")
+       profile_final()
        runReactor()
        runReactor()
-
+       profile("configfile.save")
        configfile.save()
 
        configfile.save()
 
+       profile("wakeup")
        from time import time
        from Tools.DreamboxHardware import setFPWakeuptime
        #get currentTime
        from time import time
        from Tools.DreamboxHardware import setFPWakeuptime
        #get currentTime
@@ -544,41 +568,54 @@ def runScreenTest():
                        setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
                else:
                        setFPWakeuptime(startTime - 300)
                        setFPWakeuptime(nowTime + 30) # so switch back on in 30 seconds
                else:
                        setFPWakeuptime(startTime - 300)
+       profile("stopService")
        session.nav.stopService()
        session.nav.stopService()
+       profile("nav shutdown")
        session.nav.shutdown()
 
        return 0
 
        session.nav.shutdown()
 
        return 0
 
+profile("Init:skin")
 import skin
 skin.loadSkinData(getDesktop(0))
 
 import skin
 skin.loadSkinData(getDesktop(0))
 
+profile("InputDevice")
 import Components.InputDevice
 Components.InputDevice.InitInputDevices()
 
 import Components.InputDevice
 Components.InputDevice.InitInputDevices()
 
+profile("AVSwitch")
 import Components.AVSwitch
 Components.AVSwitch.InitAVSwitch()
 
 import Components.AVSwitch
 Components.AVSwitch.InitAVSwitch()
 
+profile("RecordingConfig")
 import Components.RecordingConfig
 Components.RecordingConfig.InitRecordingConfig()
 
 import Components.RecordingConfig
 Components.RecordingConfig.InitRecordingConfig()
 
+profile("UsageConfig")
 import Components.UsageConfig
 Components.UsageConfig.InitUsageConfig()
 
 import Components.UsageConfig
 Components.UsageConfig.InitUsageConfig()
 
+profile("keymapparser")
 import keymapparser
 keymapparser.readKeymap(config.usage.keymap.value)
 
 import keymapparser
 keymapparser.readKeymap(config.usage.keymap.value)
 
+profile("Network")
 import Components.Network
 Components.Network.InitNetwork()
 
 import Components.Network
 Components.Network.InitNetwork()
 
+profile("LCD")
 import Components.Lcd
 Components.Lcd.InitLcd()
 
 import Components.Lcd
 Components.Lcd.InitLcd()
 
+profile("SetupDevices")
 import Components.SetupDevices
 Components.SetupDevices.InitSetupDevices()
 
 import Components.SetupDevices
 Components.SetupDevices.InitSetupDevices()
 
+profile("RFMod")
 import Components.RFmod
 Components.RFmod.InitRFmod()
 
 import Components.RFmod
 Components.RFmod.InitRFmod()
 
+profile("Init:CI")
 import Screens.Ci
 Screens.Ci.InitCiConfig()
 
 import Screens.Ci
 Screens.Ci.InitCiConfig()