From 5b85b2b71a90ccd193be1f827891a1c536308049 Mon Sep 17 00:00:00 2001 From: croneter Date: Fri, 9 Nov 2018 09:08:04 +0100 Subject: [PATCH] Enable cProfiling for full sync --- resources/lib/library_sync/process_metadata.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/resources/lib/library_sync/process_metadata.py b/resources/lib/library_sync/process_metadata.py index c3f9fd55..5482c353 100644 --- a/resources/lib/library_sync/process_metadata.py +++ b/resources/lib/library_sync/process_metadata.py @@ -3,6 +3,10 @@ from __future__ import absolute_import, division, unicode_literals from logging import getLogger import xbmcgui +from cProfile import Profile +from pstats import Stats +from StringIO import StringIO + from . import common from .. import backgroundthread, utils @@ -80,6 +84,8 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin): self.current = 1 self.total = section.total self.section_name = section.name + profile = Profile() + profile.enable() with section.context(self.last_sync) as context: while not self.isCanceled(): # grabs item from queue. This will block! @@ -104,6 +110,12 @@ class ProcessMetadata(backgroundthread.KillableThread, common.libsync_mixin): context.plexconn.commit() context.kodiconn.commit() self.queue.task_done() + profile.disable() + string_io = StringIO() + stats = Stats(profile, stream=string_io).sort_stats('cumulative') + stats.print_stats() + LOG.info('cProfile result: ') + LOG.info(string_io.getvalue()) finally: if self.dialog: self.dialog.close()