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

Use proc_events on Java processes #208

Merged
merged 27 commits into from Nov 26, 2021
Merged
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
118340b
Add proc_events
YishaiZinkin Nov 14, 2021
c795706
Run lint.sh
YishaiZinkin Nov 21, 2021
a122366
Remove unused import
YishaiZinkin Nov 21, 2021
4697752
Move to class and done some fixes
YishaiZinkin Nov 22, 2021
fe2373e
Add stop functionality
YishaiZinkin Nov 22, 2021
5513350
Integrate with java profiler
YishaiZinkin Nov 22, 2021
916ace5
select -> selectors
YishaiZinkin Nov 22, 2021
77088e8
Merge branch 'master' into feature/track-java-processes-termination
YishaiZinkin Nov 22, 2021
ffe742e
Typo
YishaiZinkin Nov 23, 2021
6dc4140
Raise in case of error in socket.bind
YishaiZinkin Nov 23, 2021
6d3f4c1
Add tid to callback
YishaiZinkin Nov 23, 2021
2032625
Fix: Don't call socket.close while in select()
YishaiZinkin Nov 23, 2021
728c9c8
Remove ProcEventsListener object from the API
YishaiZinkin Nov 23, 2021
c8b2097
Typo
YishaiZinkin Nov 24, 2021
b68c289
Cleanup properly
YishaiZinkin Nov 24, 2021
7520777
Differ thread start to first registration
YishaiZinkin Nov 24, 2021
8f7d5ce
Merge branch 'master' into feature/track-java-processes-termination
YishaiZinkin Nov 24, 2021
b06b654
Add unregister
YishaiZinkin Nov 24, 2021
2cc5df1
Add type hints
YishaiZinkin Nov 24, 2021
def3098
Add type hints
YishaiZinkin Nov 24, 2021
2b22419
Add module doc
YishaiZinkin Nov 24, 2021
4675511
Use granulate-utils
YishaiZinkin Nov 25, 2021
c4e3a4c
Fix linting
YishaiZinkin Nov 25, 2021
02f4cf0
Log the error code of the main thread only
YishaiZinkin Nov 25, 2021
7cdc3d4
Add git to Dockerfile
YishaiZinkin Nov 25, 2021
dfca758
Add package name in requirements.txt
YishaiZinkin Nov 25, 2021
99a1b59
Merge branch 'master' into feature/track-java-processes-termination
YishaiZinkin Nov 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions gprofiler/profilers/java.py
Expand Up @@ -13,6 +13,7 @@
from typing import List, Optional, Set

import psutil
from granulate_utils.linux import proc_events
from granulate_utils.linux.oom import get_oom_entry
from granulate_utils.linux.signals import get_signal_entry
from packaging.version import Version
Expand Down Expand Up @@ -114,6 +115,23 @@ def get_ap_log(self) -> str:
return self._ap_log


class AsyncProfiledProcessMonitor:
def __init__(self):
self._attached_processes: List[int] = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're now tracking processes both here and in JavaProfiler._profiled_processes :(

proc_events.register_exit_callback(self._proc_exit_callback)

def _proc_exit_callback(self, tid: int, pid: int, exit_code: int):
# Notice that we only check the exit code of the main thread here.
# It's assumed that an error in any of the Java threads will be reflected in the exit code of the main thread.
if tid in self._attached_processes:
if exit_code != 0:
Jongy marked this conversation as resolved.
Show resolved Hide resolved
logger.warning(f"Async-profiled Java process {tid} exited with error code: {hex(exit_code)}")
self._attached_processes.remove(tid)

def register_process(self, pid: int):
self._attached_processes.append(pid)


@functools.lru_cache(maxsize=1)
def jattach_path() -> str:
return resource_path("java/jattach")
Expand Down Expand Up @@ -538,6 +556,7 @@ def __init__(
self._mode = java_async_profiler_mode
self._safemode = java_async_profiler_safemode
self._saved_mlock: Optional[int] = None
self._process_monitor = AsyncProfiledProcessMonitor()
self._java_safemode = java_safemode
if self._java_safemode:
logger.debug("Java safemode enabled")
Expand Down Expand Up @@ -663,6 +682,7 @@ def _profile_process(self, process: Process) -> Optional[StackToSampleCount]:
with AsyncProfiledProcess(
process, self._storage_dir, self._buildids, self._mode, self._safemode, self._java_safemode
) as ap_proc:
self._process_monitor.register_process(process.pid)
Jongy marked this conversation as resolved.
Show resolved Hide resolved
return self._profile_ap_process(ap_proc)

def _profile_ap_process(self, ap_proc: AsyncProfiledProcess) -> Optional[StackToSampleCount]:
Expand Down