Skip to content

Commit

Permalink
Startup performance logging (#2145)
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeSullivan7 authored Mar 25, 2024
2 parents 6a23dea + b9b5baf commit 3d59e0c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions mantidimaging/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later
from __future__ import annotations
import time

process_start_time = time.monotonic()

if __name__ == '__main__':
from multiprocessing import freeze_support
Expand Down
7 changes: 7 additions & 0 deletions mantidimaging/core/parallel/manager.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (C) 2024 ISIS Rutherford Appleton Laboratory UKRI
# SPDX - License - Identifier: GPL-3.0-or-later
from __future__ import annotations

import time
from multiprocessing import get_context
import os
import uuid
Expand All @@ -20,19 +22,24 @@
CURRENT_PID = psutil.Process().pid

LOG = getLogger(__name__)
perf_logger = getLogger("perf." + __name__)

cores: int = 1
pool: Pool | None = None


def create_and_start_pool():
LOG.info('Creating process pool')
t0 = time.monotonic()
context = get_context('spawn')
global cores
cores = context.cpu_count()
global pool
pool = context.Pool(cores, initializer=worker_setup)

if perf_logger.isEnabledFor(1):
perf_logger.info(f"Process pool started in {time.monotonic() - t0}")


def worker_setup():
# Required to import modules for running operations
Expand Down
8 changes: 8 additions & 0 deletions mantidimaging/gui/windows/main/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import uuid
from logging import getLogger
from pathlib import Path
import time
from typing import TYPE_CHECKING
from uuid import UUID

Expand Down Expand Up @@ -42,6 +43,7 @@
from mantidimaging.gui.windows.stack_visualiser import StackVisualiserView
from mantidimaging.gui.windows.welcome_screen.presenter import WelcomeScreenPresenter
from mantidimaging.gui.windows.wizard.presenter import WizardPresenter
from mantidimaging.__main__ import process_start_time

if TYPE_CHECKING:
from mantidimaging.core.data.dataset import MixedDataset
Expand All @@ -50,6 +52,7 @@
SINO_TEXT = "Sinograms"

LOG = getLogger(__name__)
perf_logger = getLogger("perf." + __name__)


class QTreeDatasetWidgetItem(QTreeWidgetItem):
Expand Down Expand Up @@ -164,6 +167,11 @@ def __init__(self, open_dialogs: bool = True):

self.tabifiedDockWidgetActivated.connect(self._on_tab_bar_clicked)

def _window_ready(self) -> None:
if perf_logger.isEnabledFor(1):
perf_logger.info(f"Mantid Imaging ready in {time.monotonic() - process_start_time}")
super()._window_ready()

def setup_shortcuts(self):
self.actionLoadDataset.triggered.connect(self.show_image_load_dialog)
self.actionLoadImages.triggered.connect(self.load_image_stack)
Expand Down
2 changes: 1 addition & 1 deletion mantidimaging/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def initialise_logging(arg_level: str) -> None:
perf_logger = logging.getLogger('perf')
perf_logger.setLevel(100)
perf_logger.propagate = False
if settings.value("logging/performance_log", defaultValue=False):
if settings.value("logging/performance_log", defaultValue=False, type=bool):
perf_logger.setLevel(1)
perf_logger.addHandler(console_handler)
if log_directory != Path(""):
Expand Down

0 comments on commit 3d59e0c

Please sign in to comment.