Skip to content
Merged
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
14 changes: 13 additions & 1 deletion gprofiler/profilers/java.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ def __init__(
mcache: int = 0,
collect_meminfo: bool = True,
include_method_modifiers: bool = False,
java_line_numbers: str = "none",
):
self.process = process
self._profiler_state = profiler_state
Expand Down Expand Up @@ -498,6 +499,7 @@ def __init__(
self._mcache = mcache
self._collect_meminfo = collect_meminfo
self._include_method_modifiers = ",includemm" if include_method_modifiers else ""
self._include_line_numbers = ",includeln" if java_line_numbers == "line-of-function" else ""

def _find_rw_exec_dir(self) -> str:
"""
Expand Down Expand Up @@ -632,7 +634,7 @@ def _get_extra_ap_args(self) -> str:
def _get_ap_output_args(self) -> str:
return (
f",file={self._output_path_process},{self.OUTPUT_FORMAT},"
+ f"{self.FORMAT_PARAMS}{self._include_method_modifiers}"
+ f"{self.FORMAT_PARAMS}{self._include_method_modifiers}{self._include_line_numbers}"
)

def _get_interval_arg(self, interval: int) -> str:
Expand Down Expand Up @@ -862,6 +864,13 @@ def read_output(self) -> Optional[str]:
default=False,
help="Add method modifiers to profiling data",
),
ProfilerArgument(
"--java-line-numbers",
dest="java_line_numbers",
choices=["none", "line-of-function"],
default="none",
help="Select if async-profiler should add line numbers to frames",
),
],
supported_profiling_modes=["cpu", "allocation"],
)
Expand Down Expand Up @@ -904,6 +913,7 @@ def __init__(
java_collect_jvm_flags: str,
java_full_hserr: bool,
java_include_method_modifiers: bool,
java_line_numbers: str,
):
assert java_mode == "ap", "Java profiler should not be initialized, wrong java_mode value given"
super().__init__(frequency, duration, profiler_state)
Expand Down Expand Up @@ -943,6 +953,7 @@ def __init__(
self._report_meminfo = java_async_profiler_report_meminfo
self._java_full_hserr = java_full_hserr
self._include_method_modifiers = java_include_method_modifiers
self._java_line_numbers = java_line_numbers

def _init_ap_mode(self, profiling_mode: str, ap_mode: str) -> None:
assert profiling_mode in ("cpu", "allocation"), "async-profiler support only cpu/allocation profiling modes"
Expand Down Expand Up @@ -1183,6 +1194,7 @@ def _profile_process(self, process: Process, duration: int, spawned: bool) -> Pr
self._ap_mcache,
self._report_meminfo,
self._include_method_modifiers,
self._java_line_numbers,
) as ap_proc:
stackcollapse = self._profile_ap_process(ap_proc, comm, duration)

Expand Down
4 changes: 2 additions & 2 deletions scripts/async_profiler_build_shared.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#
set -euo pipefail

VERSION=v2.10g1
GIT_REV="b3baf6010e31378679a28fe1cd30168f51cc1ade"
VERSION=v2.10g2
GIT_REV="40b850a4101756bc398051661d1adbbe5d7e2211"

git clone --depth 1 -b "$VERSION" https://github.com/Granulate/async-profiler.git && cd async-profiler && git reset --hard "$GIT_REV"
make all
Expand Down
18 changes: 18 additions & 0 deletions tests/test_java.py
Original file line number Diff line number Diff line change
Expand Up @@ -1164,3 +1164,21 @@ def test_including_method_modifiers(
assert is_function_in_collapsed("private static Fibonacci.fibonacci(I)J_[j]", collapsed)
else:
assert not is_function_in_collapsed("private static Fibonacci.fibonacci(I)J_[j]", collapsed)


@pytest.mark.parametrize("java_line_numbers", ["none", "line-of-function"])
@pytest.mark.parametrize("in_container", [True])
def test_including_line_numbers(
application_pid: int,
profiler_state: ProfilerState,
java_line_numbers: str,
) -> None:
function_with_line_numbers = "Fibonacci.fibonacci:9(I)J_[j]"
with make_java_profiler(profiler_state, java_line_numbers=java_line_numbers) as profiler:
collapsed = snapshot_pid_collapsed(profiler, application_pid)
if java_line_numbers == "line-of-function":
assert is_function_in_collapsed(function_with_line_numbers, collapsed)
else:
assert java_line_numbers == "none"
assert is_function_in_collapsed("Fibonacci.fibonacci(I)J_[j]", collapsed)
assert not is_function_in_collapsed(function_with_line_numbers, collapsed)
2 changes: 2 additions & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def make_java_profiler(
java_collect_jvm_flags: str = JavaFlagCollectionOptions.DEFAULT,
java_full_hserr: bool = False,
java_include_method_modifiers: bool = False,
java_line_numbers: str = "none",
) -> JavaProfiler:
return JavaProfiler(
frequency=frequency,
Expand All @@ -232,6 +233,7 @@ def make_java_profiler(
java_collect_jvm_flags=java_collect_jvm_flags,
java_full_hserr=java_full_hserr,
java_include_method_modifiers=java_include_method_modifiers,
java_line_numbers=java_line_numbers,
)


Expand Down