Skip to content
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

PMEM: Optimization of enabled namespace methods #5873

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 7 additions & 8 deletions avocado/utils/pmem.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,10 @@ def enable_region(self, name="all"):
def disable_namespace(self, namespace="all", region="", bus="", verbose=False):
richtja marked this conversation as resolved.
Show resolved Hide resolved
"""
Disable namespaces

Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please return the new lines into this docstring. It improves the readability, and it will be in respect to PEP 257

:param namespace: name of the namespace to be disabled
:param region: Filter namespace by region
:param bus: Filter namespace by bus
:param verbose: Enable True command with debug information

Copy link
Contributor

Choose a reason for hiding this comment

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

same here

:return: True on success
:raise: :class:`PMemException`, if command fails.
"""
Expand Down Expand Up @@ -302,16 +300,17 @@ def enable_namespace(self, namespace="all", region="", bus="", verbose=False):
"""
args = namespace
if region:
args = f"{args} -r {region}"
args += f" -r {region}"
if bus:
args = f"{args} -b {bus}"
args += f" -b {bus}"
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, you're adding on operation here. Initially you have one "f string" operation (with two variables). Now you have both, one "f string" and a string concatenation.

I'm sorry but this is not an optimization.

Even worse, there's a consensus around the fact that usually string concatenations are slower than "f string" operations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not a very good optimization, thank you for your comment

if verbose:
args = f"{args} -v"
args += " -v"

if process.system(
f"{self.ndctl} enable-namespace {args}", shell=True, ignore_status=True
):
cmd = f"{self.ndctl} enable-namespace {args}"

if process.system(cmd, shell=True, ignore_status=False) != 0:
raise PMemException(f'Namespace enable failed for "{namespace}"')

return True

def create_namespace(
Expand Down