Skip to content

Commit

Permalink
Merge pull request #546 from oliver-sanders/profiler
Browse files Browse the repository at this point in the history
add a profiler
  • Loading branch information
oliver-sanders authored Jan 8, 2024
2 parents d28cc23 + d93f1e3 commit 864d1b0
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cylc/uiserver/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
from tornado import ioloop
from tornado.web import RedirectHandler
from traitlets import (
Bool,
Dict,
Float,
Int,
Expand All @@ -75,12 +76,14 @@
default,
validate,
)
from types import SimpleNamespace

from jupyter_server.extension.application import ExtensionApp

from cylc.flow.network.graphql import (
CylcGraphQLBackend, IgnoreFieldMiddleware
)
from cylc.flow.profiler import Profiler
from cylc.uiserver import (
__file__ as uis_pkg,
)
Expand Down Expand Up @@ -324,6 +327,16 @@ class CylcUIServer(ExtensionApp):
''',
default_value=1
)
profile = Bool(
config=True,
help='''
Turn on Python profiling.
The profile results will be saved to ~/.cylc/uiserver/profile.prof
in cprofile format.
''',
default_value=False,
)

@validate('ui_build_dir')
def _check_ui_build_dir_exists(self, proposed):
Expand Down Expand Up @@ -403,6 +416,8 @@ def initialize_settings(self):
self.settings.update({'<trait>':...})
"""
super().initialize_settings()

# startup messages
self.log.info("Starting Cylc UI Server")
self.log.info(f'Serving UI from: {self.ui_path}')
self.log.debug(
Expand All @@ -411,6 +426,16 @@ def initialize_settings(self):
for key, value in self.config['CylcUIServer'].items()
)
)

# start profiling
self.profiler = Profiler(
# the profiler is designed to attach to a Cylc scheduler
schd=SimpleNamespace(workflow_log_dir=USER_CONF_ROOT),
# profiling is turned on via the "profile" traitlet
enabled=self.profile,
)
self.profiler.start()

# start the async scan task running (do this on server start not init)
ioloop.IOLoop.current().add_callback(
self.workflows_mgr.run
Expand Down Expand Up @@ -540,3 +565,4 @@ async def stop_extension(self):
self.data_store_mgr.executor.shutdown(wait=False)
# Destroy ZeroMQ context of all sockets
self.workflows_mgr.context.destroy()
self.profiler.stop()

0 comments on commit 864d1b0

Please sign in to comment.