Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions pyperf/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,16 @@ def write(self, tune):
self.log_action("CPU scaling governor of CPUs %s %s" % (cpus, action))


def parse_linux_version(release):
"""Get the version from a Linux kernel release string, such as (6, 8, 0)
from '6.8.0-45-generic' or (7, 3, 4) from Debian's '7.3.4+deb14-amd64'.
Return None if the string does not start with a version."""
match = re.match(r'\d+(?:\.\d+)*', release)
if match is None:
return None
return tuple(map(int, match.group().split('.')))


class LinuxScheduler(Operation):
"""
Check isolcpus=cpus and rcu_nocbs=cpus parameters of the Linux kernel
Expand All @@ -446,10 +456,8 @@ def show(self):
return

release = os.uname()[2]
try:
version_txt = release.split('-', 1)[0]
self.linux_version = tuple(map(int, version_txt.split('.')))
except ValueError:
self.linux_version = parse_linux_version(release)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

linux_version is only needed to check if the running Linux kernel is Linux 3.8 or newer. Linux 3.8 was released 13 years ago. Maybe we can just remove the test and makes the assumption that the current Linux is more recent than that.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's moderately convenient to my usecase to have pyperf system show capture the Linux kernel version for my benchmark records, but I also support not making pointless checks. I'm sure some older kernels are out there, but I'm dubious they're running a contemporary pyperf.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's moderately convenient to my usecase to have pyperf system show capture the Linux kernel version for my benchmark records

Would you mind to elaborate? Currently, os.uname()[2] is only logged if parsing the Linux fails (your issue). On success, self.linux_version is not logged.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

linux_version is only needed to check if the running Linux kernel is Linux 3.8 or newer. Linux 3.8 was released 13 years ago. Maybe we can just remove the test and makes the assumption that the current Linux is more recent than that.

We can drop the check.

Linux 3.7 was EOL in March 2013.

https://en.wikipedia.org/wiki/Linux_kernel_version_history

That's around the time Python 2.6 and 3.1 went EOL.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's moderately convenient to my usecase to have pyperf system show capture the Linux kernel version for my benchmark records

Would you mind to elaborate? Currently, os.uname()[2] is only logged if parsing the Linux fails (your issue). On success, self.linux_version is not logged.

Ah: shows how much experience I have with pyperf! There's no need to keep it from my end, then---my benchmarking will get that information elsewhere.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm happy to put up a "take out the version" check PR, but y'all seem to have this well in hand. Feel free to close this PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you want to open a new PR to drop this Linux version check?

If you want to log os.uname(), you should look at pyperf/_collect_metadata.py, but it should be done in a separated PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, thing, if it saves you trouble! I'll put up those two later this evening.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

#281 drops the version check. Apparently the Linux kernel version will show up in the platform metadata already, so no second PR (I don't need full uname, just the version). Thanks!

if self.linux_version is None:
self.error("Failed to get the Linux version: release=%r" % release)
return

Expand Down
15 changes: 15 additions & 0 deletions pyperf/tests/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import unittest

from pyperf._system import parse_linux_version
from pyperf.tests import get_output


Expand All @@ -22,6 +23,20 @@ def test_show(self):
# is not available
self.assertIn(proc.returncode, (0, 1, 2), msg=proc)

def test_parse_linux_version(self):
for release, version in (
('6.8.0-45-generic', (6, 8, 0)),
('7.3.4+deb14-amd64', (7, 3, 4)),
('7.0.0-1020-azure', (7, 0, 0)),
('6.12.10-arch1-1', (6, 12, 10)),
('6.1', (6, 1)),
('5.15.167.4-microsoft-standard-WSL2', (5, 15, 167, 4)),
('', None),
('custom', None),
):
with self.subTest(release=release):
self.assertEqual(parse_linux_version(release), version)


if __name__ == "__main__":
unittest.main()