diff --git a/jellyfin_kodi/full_sync.py b/jellyfin_kodi/full_sync.py index a3226a65..da75812c 100644 --- a/jellyfin_kodi/full_sync.py +++ b/jellyfin_kodi/full_sync.py @@ -11,7 +11,7 @@ from kodi_six import xbmc import downloader as server import helper.xmls as xmls from database import Database, get_sync, save_sync, jellyfin_db -from helper import translate, settings, window, progress, dialog, LibraryException +from helper import translate, settings, window, progress, dialog, LibraryException, debug from helper.utils import get_screensaver, set_screensaver ################################################################################################## @@ -249,6 +249,7 @@ class FullSync(object): raise @progress() + @debug.profile def movies(self, library, dialog): ''' Process movies from a single library. diff --git a/jellyfin_kodi/helper/debug.py b/jellyfin_kodi/helper/debug.py new file mode 100644 index 00000000..f73dc2e0 --- /dev/null +++ b/jellyfin_kodi/helper/debug.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- + +################################################################################################## + +import cProfile +import json +import logging +import pstats +import StringIO + +################################################################################################## + +LOG = logging.getLogger("JELLYFIN." + __name__) + +class JsonDebugPrinter(object): + + def __init__(self, json): + self.json = json + + def __str__(self): + return json.dumps(self.json, indent=4) + +def profile(fn): + def profiling_wrapper(*args, **kargs): + pr = cProfile.Profile() + pr.enable() + + fn(*args, **kargs) + + pr.disable() + s = StringIO.StringIO() + sortby = 'cumulative' + ps = pstats.Stats(pr, stream=s).sort_stats(sortby) + ps.print_stats() + LOG.debug(s.getvalue()) + return profiling_wrapper + diff --git a/jellyfin_kodi/objects/kodi/kodi.py b/jellyfin_kodi/objects/kodi/kodi.py index e34d57d2..cc503516 100644 --- a/jellyfin_kodi/objects/kodi/kodi.py +++ b/jellyfin_kodi/objects/kodi/kodi.py @@ -15,6 +15,16 @@ LOG = logging.getLogger("JELLYFIN." + __name__) ################################################################################################## +def cache(fn): + CACHE = {} + def cache_wrapper(*args): + try: + result = CACHE[args] + except KeyError: + result = fn(*args) + CACHE[args] = result + return result + return cache_wrapper class Kodi(object): @@ -155,6 +165,7 @@ class Kodi(object): return person_id + @cache def get_person(self, *args): try: