Skip to content

Conversation

@adi-benz
Copy link
Contributor

@adi-benz adi-benz commented Jan 16, 2022

Make get_process_nspid() work with old kernels

Tested on Ubuntu 14.04 3.13.0-170-generic

@adi-benz adi-benz added the enhancement New feature or request label Jan 16, 2022
@adi-benz adi-benz requested a review from Jongy January 16, 2022 14:26
Adi Benziony added 4 commits January 16, 2022 17:03
This happend when the process dies between us opening the sched file
and us reading it. Appearently procfs returns ESRCH when trying to read
a procfs file of a dead process, and Python converts it to
a ProcessLookupError
@adi-benz adi-benz requested a review from Jongy January 16, 2022 15:47
@adi-benz
Copy link
Contributor Author

Following your suggestions to use asserts (in intel/gprofiler#269), now that get_process_nspid() fails only if the process isn't running, should we make the function raise instead of returning None?

@Jongy
Copy link
Contributor

Jongy commented Jan 16, 2022

Following your suggestions to use asserts (in Granulate/gprofiler#269), now that get_process_nspid() fails only if the process isn't running, should we make the function raise instead of returning None?

Yes. Let's, instead of returning None, ensure that the PID now really doesn't run - and then raise psutil.NoSuchProcess. If it does run and we haven't found, raise another exception (that's probably a bug in our code)

Adi Benziony added 3 commits January 16, 2022 20:05
Also, make sure we raise NoSuchProcess in all places instead of weird,
un-indicative errors
@adi-benz adi-benz requested a review from Jongy January 18, 2022 07:45

is_the_same_ns = get_process_ns_inode(process, nstype) == get_process_ns_inode(process2, nstype)

# If one of the processes isn't running, we checked the wrong one
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do this check again, if already done in get_process_ns_inode?

Copy link
Contributor Author

@adi-benz adi-benz Jan 19, 2022

Choose a reason for hiding this comment

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

get_process_ns_inode() doesn't make sure this is the same process.
get_process_ns_inode() might return True, but actually, it was for the wrong process.

But now I'm moving this check into get_process_ns_inode() 🙃

@adi-benz adi-benz requested a review from Jongy January 19, 2022 10:23
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.

.

adi-benz and others added 2 commits January 19, 2022 15:53
Co-authored-by: Yonatan Goldschmidt <yonatan.goldschmidt@granulate.io>
Co-authored-by: Yonatan Goldschmidt <yonatan.goldschmidt@granulate.io>
@adi-benz adi-benz requested a review from Jongy January 19, 2022 13:54
@adi-benz adi-benz merged commit 83dd35e into master Jan 19, 2022
@adi-benz adi-benz deleted the get-process-nspid-support-old-kernels branch January 19, 2022 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants