-
Notifications
You must be signed in to change notification settings - Fork 10
Add HeapTrack Research tool #932
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
Open
LuAbelt
wants to merge
4
commits into
vara-dev
Choose a base branch
from
f-HeapTrackTool
base: vara-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| """Module for the KDE tool heaptrack that describes the heaptrack code base | ||
| layout and implements automatic configuration and setup.""" | ||
| import shutil | ||
| import typing as tp | ||
| from pathlib import Path | ||
|
|
||
| from plumbum import local | ||
| from PyQt5.QtCore import QProcess | ||
|
|
||
| from varats.tools.research_tools.cmake_util import set_cmake_var | ||
| from varats.tools.research_tools.research_tool import ( | ||
| CodeBase, | ||
| SubProject, | ||
| ResearchTool, | ||
| Dependencies, | ||
| Distro, | ||
| ) | ||
| from varats.tools.research_tools.vara_manager import ( | ||
| BuildType, | ||
| ProcessManager, | ||
| run_process_with_output, | ||
| ) | ||
| from varats.utils.exceptions import ProcessTerminatedError | ||
| from varats.utils.logger_util import log_without_linesep | ||
| from varats.utils.settings import vara_cfg, save_config | ||
|
|
||
|
|
||
| class HeapTrackCodeBase(CodeBase): | ||
| """Layout of the heaptrack code base.""" | ||
|
|
||
| def __init__(self, base_dir: Path) -> None: | ||
| sub_projects = [ | ||
| SubProject( | ||
| base_dir, "heaptrack", | ||
| "https://invent.kde.org/sdk/heaptrack.git", "origin", | ||
| "heaptrack" | ||
| ) | ||
| ] | ||
|
|
||
| super().__init__(base_dir, sub_projects) | ||
|
|
||
|
|
||
| class HeapTrack(ResearchTool[HeapTrackCodeBase]): | ||
|
Check warning on line 43 in varats/varats/tools/research_tools/heaptrack.py
|
||
| """Heaptrack is a tool for tracking and analyzing heap memory usage in | ||
| applications.""" | ||
| __DEPENDENCIES = Dependencies({ | ||
| Distro.DEBIAN: [ | ||
| "zlib1g-dev", "zstd", "elfutils", "libc6-dev", | ||
| " libpthread-stubs0-dev", "libunwind-dev", "cmake", | ||
| "libboost-iostreams-dev", "libboost-program-options-dev", "cmake", | ||
| "ninja-build" | ||
| ], | ||
| }) | ||
|
|
||
| def __init__(self, base_dir: Path) -> None: | ||
| super().__init__( | ||
| "heaptrack", [BuildType.DEV], HeapTrackCodeBase(base_dir) | ||
| ) | ||
| vara_cfg()["heaptrack"]["source_dir"] = str(base_dir) | ||
| save_config() | ||
|
|
||
| @classmethod | ||
| def get_dependencies(cls) -> Dependencies: | ||
| return cls.__DEPENDENCIES | ||
|
|
||
| @staticmethod | ||
| def source_location() -> Path: | ||
| """Get the source location of heaptrack.""" | ||
| return Path(vara_cfg()["heaptrack"]["source_dir"].value) | ||
|
|
||
| @staticmethod | ||
| def has_source_location() -> bool: | ||
| """Check if a source location for heaptrack is configured.""" | ||
| return vara_cfg()["heaptrack"]["source_dir"].value is not None | ||
|
|
||
| @staticmethod | ||
| def install_location() -> Path: | ||
| """Return the install location of heaptrack.""" | ||
| return Path(vara_cfg()["heaptrack"]["install_dir"].value) | ||
|
|
||
| @staticmethod | ||
| def has_install_location() -> bool: | ||
| """Check if an install location for heaptrack is configured.""" | ||
| return vara_cfg()["heaptrack"]["install_dir"].value is not None | ||
|
|
||
| def is_up_to_date(self) -> bool: | ||
| """Check if heaptrack is up to date.""" | ||
| return True | ||
|
|
||
| def setup( | ||
| self, source_folder: tp.Optional[Path], install_prefix: Path, | ||
| version: tp.Optional[int] | ||
| ) -> None: | ||
| """ | ||
| Setup the HeapTrack with it's code base. This method sets up all | ||
| relevant config variables, downloads repositories via the ``CodeBase``, | ||
| checkouts the correct branches and prepares the research tool to be | ||
| built. | ||
|
|
||
| Args: | ||
| source_folder: location to store the code base in | ||
| install_prefix: Installation prefix path | ||
| version: Version to setup | ||
| """ | ||
| cfg = vara_cfg() | ||
| if source_folder: | ||
| cfg["phasar"]["source_dir"] = str(source_folder) | ||
| cfg["phasar"]["install_dir"] = str(install_prefix) | ||
| save_config() | ||
|
|
||
| print(f"Setting up heaptrack in {self.source_location()}") | ||
|
|
||
| self.code_base.clone(self.source_location()) | ||
|
|
||
| # Checkout the correct version if specified ? | ||
|
|
||
| def upgrade(self) -> None: | ||
| """Upgrade heaptrack to the latest version.""" | ||
| self.code_base.get_sub_project("heaptrack").pull() | ||
|
|
||
| def build( | ||
| self, build_type: BuildType, install_location: Path, | ||
| build_folder_suffix: tp.Optional[str] | ||
| ) -> None: | ||
| """Build and installs heaptrack in the specified build type.""" | ||
|
|
||
| build_path = self.code_base.base_dir / self.code_base.get_sub_project( | ||
| "heaptrack" | ||
| ).path / "build" | ||
| build_path /= build_type.build_folder(build_folder_suffix) | ||
|
|
||
| print(" - Setting up build directory") | ||
|
|
||
| if not build_path.exists(): | ||
| build_path.mkdir(parents=True, exist_ok=True) | ||
|
|
||
| try: | ||
| with ProcessManager.create_process( | ||
| "cmake", | ||
| ["-G", "Ninja", "-DCMAKE_BUILD_TYPE=Release", "../.."], | ||
| workdir=build_path | ||
| ) as proc: | ||
| proc.setProcessChannelMode(QProcess.MergedChannels) | ||
| proc.readyReadStandardOutput.connect( | ||
| lambda: run_process_with_output( | ||
| proc, log_without_linesep(print) | ||
| ) | ||
| ) | ||
| except ProcessTerminatedError as error: | ||
| print(" - Error during CMake") | ||
| shutil.rmtree(build_path) | ||
| raise error | ||
| print(" - Finished setting up build directory") | ||
|
|
||
| with local.cwd(build_path): | ||
| vara_cfg()["heaptrack"]["install_dir"] = str(install_location) | ||
| set_cmake_var( | ||
| "CMAKE_INSTALL_PREFIX", str(install_location), | ||
| log_without_linesep(print) | ||
| ) | ||
| print(" - Finished extra cmake config.") | ||
|
|
||
| print(" - Building heaptrack") | ||
| with ProcessManager.create_process( | ||
| "ninja", ["install"], workdir=build_path | ||
| ) as proc: | ||
| proc.setProcessChannelMode(QProcess.MergedChannels) | ||
| proc.readyReadStandardOutput.connect( | ||
| lambda: | ||
| run_process_with_output(proc, log_without_linesep(print)) | ||
| ) | ||
|
|
||
| def get_install_binaries(self) -> tp.List[str]: | ||
| return ["bin/heaptrack", "bin/heaptrack_print"] | ||
|
|
||
| def verify_build( | ||
| self, build_type: BuildType, build_folder_suffix: tp.Optional[str] | ||
| ) -> bool: | ||
| return True | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.