Skip to content

Conversation

@mpozniak95
Copy link
Contributor

It wraps function get_elf_id(), if that function throws FileNotFound exception then wrapper checks if not found file is /proc/{pid}/*, if it is, wrapper changes exception to NoSuchProcess.

Connected to: intel/gprofiler#503

@mpozniak95
Copy link
Contributor Author

@Jongy please review :)

Copy link
Contributor

@Jongy Jongy left a comment

Choose a reason for hiding this comment

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

Done reviewing :) Also please note the linting failures.

@mpozniak95 mpozniak95 requested a review from Jongy October 10, 2022 10:53
pid_max = int(pid_max_file.read())
if pid <= pid_max:
# Check if pid is running
if not psutil.pid_exists(pid):
Copy link
Contributor

Choose a reason for hiding this comment

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

It is true though, that pid_exists is a better check than what we have in read_proc_file - we use os.path.exists("/proc/pid"), but this will return True also if pid is a tid of another process (e.g due to reuse). pid_exists uses different means to check, to avoid this confusion. Note @d3dave .

Copy link
Contributor

@d3dave d3dave Oct 10, 2022

Choose a reason for hiding this comment

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

I assume that in read_proc_file we do not want to support PIDs only. I can see value in reading a specific thread's mountinfo, ns/*, stat, etc.

Copy link
Contributor

@d3dave d3dave Oct 10, 2022

Choose a reason for hiding this comment

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

Also, instead of exists(/proc/pid) should have just kill(pid, 0). (Hmmm, pretty sure I copied that from psutil...)

Copy link
Contributor

Choose a reason for hiding this comment

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

pid_exists does extra checks because they claim os.kill is bad as well :dumb:

Copy link
Contributor

@Jongy Jongy left a comment

Choose a reason for hiding this comment

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

1 more question, and fix linters :)

@Jongy
Copy link
Contributor

Jongy commented Oct 10, 2022

Btw, did you verify that mypy accepts the typing tricks for the decorator? (i.e that get_elf_id still has the typing specs as it had)

@mpozniak95
Copy link
Contributor Author

mypy granulate_utils/linux/elf.py
Success: no issues found in 1 source file

@Jongy
Copy link
Contributor

Jongy commented Oct 12, 2022

Looks good!

@Jongy Jongy merged commit 724d3e8 into intel:master Oct 12, 2022
Jongy pushed a commit to intel/gprofiler that referenced this pull request Oct 14, 2022
This PR updates granulate-utils post the changes in intel/granulate-utils#73,
and includes a few other updates from the utils repo as well, one of them is intel/granulate-utils#87 which fixes #503.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants