Skip to content
GitLab
Projects Groups Topics Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in
  • autosubmit autosubmit
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributor statistics
    • Graph
    • Compare revisions
  • Issues 338
    • Issues 338
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 21
    • Merge requests 21
  • Deployments
    • Deployments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Commits
  • Issue Boards
Collapse sidebar
  • Earth SciencesEarth Sciences
  • autosubmitautosubmit
  • Issues
  • #1094
Closed
Open
Issue created Jul 26, 2023 by Pablo Goitia@pgoitiaMaintainer

Enhancement: Integrate a decorator into the Autosubmit's profiler

Hi!

I will leave here my proposal to integrate a decorator in the Autosubmit's profiler. I consider that is the easiest way to profile a complete function, such as run_experiment(), monitor() or expid(), just adding the tag/decorator @profile above it.

Implementing this functionality only requires copy/pasting this fragments of code in the following files:

  • profiler.py
from functools import wraps

def profile(func=None):
    """
    Decorator that will run and profile a whole function

    """
    if func is None:
        Log.error('The decorator requires to be placed right above the function definition.')
        raise AutosubmitCritical(
            'The decorator requires to be placed right above the function definition.', 0000)

    @wraps(wrapped=func)
    def wrapper(*args, **kwargs):
        if ProfilerConfig.as_profile_flag:
            profiler = Profiler()
            profiler.start()
        value = func(*args, **kwargs)
        if ProfilerConfig.as_profile_flag:
            profiler.stop()
            profiler.report(func.__name__)
        return value
    return wrapper
  • profiler_config.py
class ProfilerConfig:
    # Class attributes
    [more class attributes...]
    as_profile_flag = False

    @staticmethod
    def __init__(expid=None):
        [previous code...]

        # Set profiler status to activated
        ProfilerConfig.as_profile_flag = True

Just adding this, the decorator will be functional.

But it is necessary to test it, so the following black box cases should be added to the test_profiler.py (naturally, importing the profile decorator):

from autosubmit.profiler.profiler import profile

@profile
def decorator_function():
    return

class TestProfiler(TestCase):

    def test_profile_decorator(self):
        decorator_function()

    def test_profile_decorator_fail_case(self):
        self.assertRaises(AutosubmitCritical, profile, None)
Edited Jul 26, 2023 by Pablo Goitia
Assignee
Assign to
Time tracking