diff --git a/autosubmit/autosubmit.py b/autosubmit/autosubmit.py index 10f7a7be3574e5e1d2a2726f26eb7940f774b241..d1a7b00c99c6d94c799efaa2eec742e92f810522 100644 --- a/autosubmit/autosubmit.py +++ b/autosubmit/autosubmit.py @@ -2017,7 +2017,7 @@ class Autosubmit: :param start_time: the time at which the experiment should start :param start_after: the expid after which the experiment should start :param run_only_members: the members to run - :param profile: if True, the whole experiment will be profiled + :param profile: if True, the function will be profiled :return: None """ diff --git a/autosubmit/profiler/profiler.py b/autosubmit/profiler/profiler.py index 789402b4d9130faf67addbd3a179f2078e9a6788..b73ccea09f2aba409167ad292082d2ffd02e650f 100644 --- a/autosubmit/profiler/profiler.py +++ b/autosubmit/profiler/profiler.py @@ -46,24 +46,26 @@ class Profiler: # Error handling flags self._started = False + self._finished = False def start(self) -> None: """Function to start the profiling process.""" if self._started: raise AutosubmitCritical('The profiling process was already started.', 7074) + self._started = True self._profiler.enable() self._mem_init += _get_current_memory() - self._started = True def stop(self) -> None: """Function to finish the profiling process.""" - if not self._started: + if not self._started or self._finished: raise AutosubmitCritical('Cannot stop the profiler because was not running.', 7074) self._profiler.disable() self._mem_final += _get_current_memory() self._report() + self._finished = True def _report(self) -> None: """Function to print the final report into the stdout, log and filesystem.""" diff --git a/test/unit/test_profiler.py b/test/unit/test_profiler.py index 4d474d572a23a029be09fe099565fd9edbf40f13..cf99067eaaf349f507a6c59f53063d45493cd9e8 100644 --- a/test/unit/test_profiler.py +++ b/test/unit/test_profiler.py @@ -1,7 +1,6 @@ from unittest import TestCase, mock from autosubmit.profiler.profiler import Profiler from log.log import AutosubmitCritical -from pathlib import Path class TestProfiler(TestCase): @@ -15,11 +14,6 @@ class TestProfiler(TestCase): # | # stop ----> report --->0 - # Status coverage - def test_status_machine(self): - self.profiler.start() - self.profiler.stop() - # Transition coverage def test_transitions(self): # __init__ -> start @@ -36,6 +30,10 @@ class TestProfiler(TestCase): self.profiler.start() self.assertRaises(AutosubmitCritical, self.profiler.start) + # stop -> stop + self.profiler.stop() + self.assertRaises(AutosubmitCritical, self.profiler.stop) + # White box tests @mock.patch("os.access") def test_writing_permission_check_fails(self, mock_response):