Skip to content

Commit

Permalink
Remove dependency on collect command in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriPavela committed Sep 30, 2024
1 parent 276895c commit 3fb27d9
Show file tree
Hide file tree
Showing 72 changed files with 567 additions and 481 deletions.
2 changes: 1 addition & 1 deletion docs/_static/templates/degradation_api.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""..."""

from perun.utils.structs import DegradationInfo
from perun.utils.structs.common_structs import DegradationInfo


def my_degradation_checker(baseline_profile, target_profile):
Expand Down
2 changes: 1 addition & 1 deletion perun/check/detection_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from perun.postprocess.regression_analysis import regression_models
from perun.profile import query
from perun.utils.common import common_kit
from perun.utils.structs import (
from perun.utils.structs.common_structs import (
PerformanceChange,
DegradationInfo,
ModelRecord,
Expand Down
2 changes: 1 addition & 1 deletion perun/check/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
polynomial_regression,
)
from perun.utils import decorators, log
from perun.utils.structs import (
from perun.utils.structs.common_structs import (
DetectionChangeResult,
DegradationInfo,
PerformanceChange,
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/abstract_base_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Perun Imports
if TYPE_CHECKING:
from perun.profile.factory import Profile
from perun.utils.structs import DegradationInfo
from perun.utils.structs.common_structs import DegradationInfo


class AbstractBaseChecker(ABC):
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/average_amount_threshold.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.profile import convert
from perun.utils.common import common_kit
from perun.utils.structs import DegradationInfo, PerformanceChange
from perun.utils.structs.common_structs import DegradationInfo, PerformanceChange

if TYPE_CHECKING:
from perun.profile.factory import Profile
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/best_model_order_equality.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@

# Perun Imports
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.utils.structs import DegradationInfo, PerformanceChange
from perun.utils.structs.common_structs import DegradationInfo, PerformanceChange
import perun.check.detection_kit as detection

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/exclusive_time_outliers.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.logic import config
from perun.profile import convert
from perun.utils.structs import DegradationInfo, PerformanceChange
from perun.utils.structs.common_structs import DegradationInfo, PerformanceChange

if TYPE_CHECKING:
from perun.profile.factory import Profile
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/fast_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
# Perun Imports
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.logic import runner
from perun.utils.structs import DegradationInfo, ClassificationMethod
from perun.utils.structs.common_structs import DegradationInfo, ClassificationMethod
import perun.check.detection_kit as detect

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/integral_comparison.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from perun.check import factory, nonparam_kit as nparam_helpers
from perun.postprocess.regression_analysis import regression_models
from perun.utils.common import common_kit
from perun.utils.structs import DegradationInfo, ModelRecord, DetectionChangeResult
from perun.utils.structs.common_structs import DegradationInfo, ModelRecord, DetectionChangeResult

if TYPE_CHECKING:
from perun.profile.factory import Profile
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/linear_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from perun.check.methods import fast_check
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.utils.common import common_kit
from perun.utils.structs import DegradationInfo, ModelRecord, ClassificationMethod
from perun.utils.structs.common_structs import DegradationInfo, ModelRecord, ClassificationMethod

if TYPE_CHECKING:
import numpy
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/local_statistics.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.profile.factory import Profile
from perun.utils.common import common_kit
from perun.utils.structs import DegradationInfo, ModelRecord, DetectionChangeResult
from perun.utils.structs.common_structs import DegradationInfo, ModelRecord, DetectionChangeResult
import perun.check.nonparam_kit as nparam_helpers

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion perun/check/methods/polynomial_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

# Perun Imports
from perun.check.methods.abstract_base_checker import AbstractBaseChecker
from perun.utils.structs import DegradationInfo, ClassificationMethod
from perun.utils.structs.common_structs import DegradationInfo, ClassificationMethod
import perun.check.detection_kit as detect

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion perun/check/nonparam_kit.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
# Perun Imports
from perun.postprocess.regression_analysis import data_provider
from perun.utils import log
from perun.utils.structs import PerformanceChange, ModelRecord
from perun.utils.structs.common_structs import PerformanceChange, ModelRecord
import perun.check.detection_kit as methods
import perun.postprocess.regressogram.methods as rg_methods

Expand Down
205 changes: 25 additions & 180 deletions perun/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@

from __future__ import annotations

import cProfile, pstats, io
import atexit

pr = cProfile.Profile()
pr.enable()


def terminate_profiling():
pr.disable()
s = io.StringIO()
sortby = pstats.SortKey.CUMULATIVE
ps = pstats.Stats(pr, stream=s).sort_stats(sortby)
ps.print_stats("perun/collect")
# ps.print_stats(100)
print(s.getvalue())


atexit.register(terminate_profiling)


# Standard Imports
from typing import Optional, Any
import os
Expand All @@ -50,17 +70,12 @@
import click

# Perun Imports
from perun.cli_groups import check_cli, config_cli, run_cli, utils_cli, import_cli
from perun.cli_groups import check_cli, collect_cli, config_cli, run_cli, utils_cli, import_cli
import perun.collect
from perun.logic import commands, pcs, config as perun_config
from perun.utils import exceptions, log as perun_log
from perun.utils.common import cli_kit, common_kit
from perun.utils.external import commands as external_commands
from perun.collect.trace.optimizations.structs import (
Pipeline,
Optimizations,
CallGraphTypes,
)
from perun.collect.trace.optimizations.structs import Parameters
from perun.profile.factory import Profile
from perun.utils.exceptions import (
UnsupportedModuleException,
Expand All @@ -69,8 +84,7 @@
MissingConfigSectionException,
ExternalEditorErrorException,
)
from perun.utils.structs import Executable
import perun.collect
from perun.utils.structs.common_structs import Executable
import perun.fuzz.factory as fuzz
import perun.postprocess
import perun.profile.helpers as profiles
Expand Down Expand Up @@ -831,176 +845,6 @@ def postprocessby(ctx: click.Context, profile: Profile, **_: Any) -> None:
ctx.obj = profile


@cli.group()
@click.option(
"--output-file",
"-o",
nargs=1,
required=False,
multiple=False,
type=click.Path(writable=True),
help="Specifies the full path to where the profile will be stored.",
)
@click.option(
"--profile-name",
"-pn",
nargs=1,
required=False,
multiple=False,
type=str,
help="Specifies the name of the profile, which will be collected, e.g. profile.perf. The profile will be stored in .perun/jobs",
)
@click.option(
"--minor-version",
"-m",
"minor_version_list",
nargs=1,
multiple=True,
callback=cli_kit.minor_version_list_callback,
default=["HEAD"],
help="Specifies the head minor version, for which the profiles will be collected.",
)
@click.option(
"--crawl-parents",
"-cp",
is_flag=True,
default=False,
is_eager=True,
help=(
"If set to true, then for each specified minor versions, profiles for parents"
" will be collected as well"
),
)
@click.option(
"--cmd",
"-c",
nargs=1,
required=False,
multiple=True,
default=[""],
help=(
"Command that is being profiled. Either corresponds to some"
" script, binary or command, e.g. ``./mybin`` or ``perun``."
),
)
@click.option(
"--args",
"-a",
nargs=1,
required=False,
multiple=True,
help="Additional parameters for <cmd>. E.g. ``status`` or ``-al`` is command parameter.",
)
@click.option(
"--workload",
"-w",
nargs=1,
required=False,
multiple=True,
default=[""],
help="Inputs for <cmd>. E.g. ``./subdir`` is possible workload for ``ls`` command.",
)
@click.option(
"--params",
"-p",
nargs=1,
required=False,
multiple=True,
callback=cli_kit.single_yaml_param_callback,
help="Additional parameters for called collector read from file in YAML format.",
)
@click.option(
"--output-filename-template",
"-ot",
default=None,
callback=cli_kit.set_config_option_from_flag(
perun_config.runtime, "format.output_profile_template", str
),
help=(
"Specifies the template for automatic generation of output filename"
" This way the file with collected data will have a resulting filename w.r.t "
" to this parameter. Refer to :ckey:`format.output_profile_template` for more"
" details about the format of the template."
),
)
@click.option(
"--optimization-pipeline",
"-op",
type=click.Choice(Pipeline.supported()),
default=Pipeline.default(),
callback=cli_kit.set_optimization,
help="Pre-configured combinations of collection optimization methods.",
)
@click.option(
"--optimization-on",
"-on",
type=click.Choice(Optimizations.supported()),
multiple=True,
callback=cli_kit.set_optimization,
help="Enable the specified collection optimization method.",
)
@click.option(
"--optimization-off",
"-off",
type=click.Choice(Optimizations.supported()),
multiple=True,
callback=cli_kit.set_optimization,
help="Disable the specified collection optimization method.",
)
@click.option(
"--optimization-args",
"-oa",
type=(click.Choice(Parameters.supported()), str),
multiple=True,
callback=cli_kit.set_optimization_param,
help="Set parameter values for various optimizations.",
)
@click.option(
"--optimization-cache-off",
is_flag=True,
callback=cli_kit.set_optimization_cache,
help="Ignore cached optimization data (e.g., cached call graph).",
)
@click.option(
"--optimization-reset-cache",
is_flag=True,
default=False,
callback=cli_kit.reset_optimization_cache,
help="Remove the cached optimization resources and data.",
)
@click.option(
"--use-cg-type",
"-cg",
type=(click.Choice(CallGraphTypes.supported())),
default=CallGraphTypes.default(),
callback=cli_kit.set_call_graph_type,
)
@click.pass_context
def collect(ctx: click.Context, **kwargs: Any) -> None:
"""Generates performance profile using selected collector.
Runs the single collector unit (registered in Perun) on given profiled
command (optionally with given arguments and workloads) and generates
performance profile. The generated profile is then stored in
``.perun/jobs/`` directory as a file, by default with filename in form of::
bin-collector-workload-timestamp.perf
Generated profiles will not be postprocessed in any way. Consult ``perun
postprocessby --help`` in order to postprocess the resulting profile.
The configuration of collector can be specified in external YAML file given
by the ``-p``/``--params`` argument.
For a thorough list and description of supported collectors refer to
:ref:`collectors-list`. For a more subtle running of profiling jobs and
more complex configuration consult either ``perun run matrix --help`` or
``perun run job --help``.
"""
commands.try_init()
ctx.obj = kwargs


@cli.command("fuzz")
@click.option("--cmd", "-b", nargs=1, required=True, help="The command which will be fuzzed.")
@click.option(
Expand Down Expand Up @@ -1319,7 +1163,7 @@ def init_unit_commands(lazy_init: bool = True) -> None:
(perun.view_diff, showdiff, "showdiff"),
(perun.view, show, "show"),
(perun.postprocess, postprocessby, "postprocessby"),
(perun.collect, collect, "collect"),
(perun.collect, collect_cli.collect, "collect"),
]:
if lazy_init and cli_arg not in sys.argv:
continue
Expand All @@ -1330,6 +1174,7 @@ def init_unit_commands(lazy_init: bool = True) -> None:
# Initialization of other stuff
init_unit_commands()
cli.add_command(check_cli.check_group)
cli.add_command(collect_cli.collect)
cli.add_command(config_cli.config)
cli.add_command(run_cli.run)
cli.add_command(utils_cli.utils_group)
Expand Down
Loading

0 comments on commit 3fb27d9

Please sign in to comment.