From 182809a86274e2b450c72bda1cfe3a75fc7b00ce Mon Sep 17 00:00:00 2001 From: Chuddah Date: Tue, 18 Feb 2020 00:23:19 +0000 Subject: [PATCH 1/2] Added profiling info --- jellyfin_kodi/full_sync.py | 3 ++- jellyfin_kodi/helper/debug.py | 37 ++++++++++++++++++++++++++++++ jellyfin_kodi/objects/kodi/kodi.py | 11 +++++++++ 3 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 jellyfin_kodi/helper/debug.py 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: From 09288c542b66fa39876755305a01eabc070a8cc5 Mon Sep 17 00:00:00 2001 From: Chuddah Date: Tue, 18 Feb 2020 02:31:47 +0000 Subject: [PATCH 2/2] Revert local cache of people. A better solution was found. --- jellyfin_kodi/objects/kodi/kodi.py | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/jellyfin_kodi/objects/kodi/kodi.py b/jellyfin_kodi/objects/kodi/kodi.py index cc503516..e34d57d2 100644 --- a/jellyfin_kodi/objects/kodi/kodi.py +++ b/jellyfin_kodi/objects/kodi/kodi.py @@ -15,16 +15,6 @@ 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): @@ -165,7 +155,6 @@ class Kodi(object): return person_id - @cache def get_person(self, *args): try: