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

performance utilities #331

Open
robnagler opened this issue Dec 21, 2022 · 0 comments
Open

performance utilities #331

robnagler opened this issue Dec 21, 2022 · 0 comments

Comments

@robnagler
Copy link
Member

robnagler commented Dec 21, 2022

This one is useful to compute memory used by a process (on Linux only):

def mem():
    with open('/proc/self/status') as f:
        m = f.read().split('VmRSS:')[1].split('\n')[0][:-3]
        return f"{int(m.strip()) // 1024:-3d}M"

This one is good for logging time of some arbitrary code in a with:

    @contextlib.contextmanager
    def time_and_log(self, name):
        s = time.perf_counter()
        yield
        r = time.perf_counter() - s
        self.log(
            "{} seconds={:.2}", name, r, pkdebug_frame=inspect.currentframe().f_back
        )

pykern.perf or some other module name should be created to support these operations. Maybe even a "how much does this operation use in DRS".

@robnagler robnagler changed the title 20220331 performance utilities performance utilities Apr 17, 2023
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

No branches or pull requests

1 participant