Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add argument to specify the number of jobs being used for interfile #10230

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cli/src/semgrep/commands/scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,10 @@ def convert(
"--jobs",
type=int,
),
optgroup.option(
"--interfile-jobs",
type=int,
),
optgroup.option(
"--max-memory",
type=int,
Expand Down Expand Up @@ -511,6 +515,7 @@ def scan(
exclude_rule: Optional[Tuple[str, ...]],
force_color: bool,
include: Optional[Tuple[str, ...]],
interfile_jobs: Optional[int],
jobs: Optional[int],
lang: Optional[str],
matching_explanations: bool,
Expand Down Expand Up @@ -719,6 +724,7 @@ def scan(
try:
metacheck_errors = CoreRunner(
jobs=jobs,
interfile_jobs=interfile_jobs,
engine_type=engine_type,
timeout=timeout,
max_memory=max_memory,
Expand Down Expand Up @@ -775,6 +781,7 @@ def scan(
lang=lang,
configs=(config or ["auto"]),
no_rewrite_rule_ids=(not rewrite_rule_ids),
interfile_jobs=interfile_jobs,
jobs=jobs,
include=include,
exclude={product: (exclude or ()) for product in ALL_PRODUCTS},
Expand Down
3 changes: 3 additions & 0 deletions cli/src/semgrep/core_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ class CoreRunner:
def __init__(
self,
jobs: Optional[int],
interfile_jobs: Optional[int],
engine_type: EngineType,
timeout: int,
max_memory: int,
Expand All @@ -489,6 +490,7 @@ def __init__(
):
self._binary_path = engine_type.get_binary_path()
self._jobs = jobs or engine_type.default_jobs
self._interfile_jobs = jobs or engine_type.default_interfile_jobs
self._engine_type = engine_type
self._timeout = timeout
self._max_memory = max_memory
Expand Down Expand Up @@ -899,6 +901,7 @@ def _run_rules_direct_to_semgrep_core_helper(
"-timeout_for_interfile_analysis",
str(self._interfile_timeout),
]
cmd += ["-interfile_jobs", str(self._interfile_jobs)]
cmd += [root]
elif engine is EngineType.PRO_INTRAFILE:
cmd += ["-deep_intra_file"]
Expand Down
6 changes: 4 additions & 2 deletions cli/src/semgrep/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@ def get_cpu_count() -> int:

@property
def default_jobs(self) -> int:
if self == EngineType.PRO_INTERFILE:
return 1
# Maxing out number of cores used to 16 if more not requested to not overload on large machines
return min(16, self.get_cpu_count())

@property
def default_interfile_jobs(self) -> int:
return 1

@property
def default_max_memory(self) -> int:
"""Interfile uses a lot of memory, so it should have a safe default limit."""
Expand Down
2 changes: 2 additions & 0 deletions cli/src/semgrep/run_scan.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def run_scan(
str
], # NOTE: Since the `ci` command reuses this function, we intentionally do not set a default at this level.
no_rewrite_rule_ids: bool = False,
interfile_jobs: Optional[int] = None,
jobs: Optional[int] = None,
include: Optional[Sequence[str]] = None,
exclude: Optional[Mapping[Product, Sequence[str]]] = None,
Expand Down Expand Up @@ -552,6 +553,7 @@ def run_scan(
core_start_time = time.time()
core_runner = CoreRunner(
jobs=jobs,
interfile_jobs=interfile_jobs,
engine_type=engine_type,
timeout=timeout,
max_memory=max_memory,
Expand Down
Loading