Skip to content

G-UTILS-GPROFILER REWORK (2): Rework complex files #261

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
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

granulatedekel
Copy link

@granulatedekel granulatedekel commented Sep 18, 2024

Part of the G-UTILS-GPROFILER REWORK saga - which aims to move away shared code from gprofiler to the g-utils project:
#263 #261 intel/gprofiler#925 intel/gprofiler#926 intel/gprofiler#926

This ultimate PR (for this repo) is responsible for logical changes and "trimming" of complex files to be untied from the gprofiler platform

@granulatedekel granulatedekel changed the base branch from master to add-unedited-gprofiler-files-in September 23, 2024 21:45
@granulatedekel granulatedekel force-pushed the refactor-gprofiler-utils-in branch from c092236 to 40b789f Compare September 23, 2024 21:46
@granulatedekel granulatedekel changed the title add gprofiler utils GPROFILER REWORK (1): Rework complex files Sep 23, 2024
@granulatedekel granulatedekel changed the title GPROFILER REWORK (1): Rework complex files G-UTILS-GPROFILER REWORK (2): Rework complex files Sep 23, 2024
@granulatedekel granulatedekel added the g-utils-gprofiler-rework PRs related to the G-UTILS-GPROFILER saga label Sep 23, 2024
@granulatedekel granulatedekel marked this pull request as ready for review September 23, 2024 22:51
@YoniKF YoniKF requested review from roi-granulate and removed request for YoniKF October 1, 2024 10:15
@@ -247,6 +244,7 @@ def _kill_and_reap_process(process: Popen, kill_signal: signal.Signals) -> Tuple

def run_process(
cmd: Union[str, List[str]],
logger: Union[logging.LoggerAdapter, logging.Logger],
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason we don’t want to enforce this as keyword argument?

@Jongy
Copy link
Contributor

Jongy commented Oct 20, 2024

I'm changing the source branch to master so we can see the total diff.

@Jongy Jongy changed the base branch from add-unedited-gprofiler-files-in to master October 20, 2024 15:29
return wrapper


def start_process(
Copy link
Contributor

Choose a reason for hiding this comment

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

start_process, run_process et al are very coupled to gProfiler at several points:

  • the logging of command + output
  • staticx
  • removal of LD_LIBRARY_PATH
    and add some optional features that we want for gProfiler but not for other callers:
  • pdeathsig

Let's keep it in gProfiler, alongside all relevant logic:

  • get_staticx_dir
  • start_process
  • run_process
  • set_child_termination_on_parent_death
  • prctl
  • (and any other function not used in this PR after the removal of that function).

os.unlink(f)


def wait_for_file_by_prefix(
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused? Move back to gProfiler.

return Path(output_files[0])


def reap_process(process: Popen) -> Tuple[int, bytes, bytes]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be moved back.

return result


def pgrep_maps(match: str, logger: Union[logging.LoggerAdapter, logging.Logger]) -> List[Process]:
Copy link
Contributor

Choose a reason for hiding this comment

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

Can be moved back.

Comment on lines +406 to +416
_INSTALLED_PROGRAMS_CACHE: List[str] = []


def assert_program_installed(program: str) -> None:
if program in _INSTALLED_PROGRAMS_CACHE:
return

if shutil.which(program) is not None:
_INSTALLED_PROGRAMS_CACHE.append(program)
else:
raise ProgramMissingException(program)
Copy link
Contributor

Choose a reason for hiding this comment

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

Move back

)


class JattachJcmdRunner:
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert this to accept a run_process callable, gProfiler will use its run_process function and other components will pass their own wrappers.

The type of the callable should be defined in granulate-utils.

self._libap_path_glibc = libap_path_glibc
self._libap_path_musl = libap_path_musl

# assert mode in ("cpu", "itimer", "alloc"), f"unexpected mode: {mode}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Need to bring this assert back (potentially with other event types you wish to support)

def _run_async_profiler(self, cmd: List[str]) -> str:
try:
# kill jattach with SIGTERM if it hangs. it will go down
run_process(
Copy link
Contributor

Choose a reason for hiding this comment

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

As commented for JattachJcmdRunner, please have a parameter for this class to control the callable to run processes with. When instantiating JattachJcmdRunner, you'll pass the same value from this class.

Copy link
Contributor

Choose a reason for hiding this comment

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

These can be moved back to gProfiler

Copy link
Contributor

Choose a reason for hiding this comment

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

Most of these can be moved back to gProfiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
g-utils-gprofiler-rework PRs related to the G-UTILS-GPROFILER saga
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants