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

Add support for profiling benchmarks #134

Merged
merged 6 commits into from
Jul 14, 2022
Merged

Conversation

mdboom
Copy link
Collaborator

@mdboom mdboom commented Jun 3, 2022

This should make it much easier to collect profiles for benchmarks in the pyperformance suite.

Implements #133.

TODO:

  • Tests

@mdboom mdboom closed this Jun 3, 2022
@mdboom mdboom reopened this Jun 3, 2022
@mdboom mdboom marked this pull request as draft June 3, 2022 16:52
@vstinner
Copy link
Member

vstinner commented Jun 6, 2022

Tests don't pass.

How does merge_profile_stats() work? Does it compute the average of N processes timings? Or does it accumulate time?

Is it more reliable than running a single process?

@mdboom
Copy link
Collaborator Author

mdboom commented Jun 6, 2022

Tests don't pass.

Noted. Wanted to get some feedback about the general concept here first.

How does merge_profile_stats() work? Does it compute the average of N processes timings? Or does it accumulate time?

Is it more reliable than running a single process?

Yes, it just accumulates timings from multiple profiling runs. It produces more accurate results, in the same way that running the benchmarks multiple times does.

@mdboom mdboom marked this pull request as ready for review June 13, 2022 20:19
max_rss = 0
range_it = range(loops)
start_time = time.perf_counter()

if profile_filename:
with tempfile.NamedTemporaryFile(suffix=".profile", delete=False) as fh:
temp_profile_filename = fh.name
Copy link
Member

Choose a reason for hiding this comment

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

IMO tempfile.mktemp() would be better than using NamedTemporaryFile() here.

Copy link
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

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

Would it be possible to create the temporary file in pyperf/_manager.py and pass it to worker processes? A worker is more likely to crash, and so it's harder to make sure that the temporary file is removed in case of a crash.

Maybe the profiling data could be written into a pipe by the worker, and the manager would be responsible to merge data? I don't really if pyperf uses pipes or not on Windows.

@mdboom
Copy link
Collaborator Author

mdboom commented Jun 16, 2022

I'm not sure I understand the request.

The temporary file only comes into play when using bench_process. In that case, the temporary filename is generated in parent process and passed to the child process being benchmarked specifically to make it easier to clean up because it could crash. (The temporary file is deleted whether the worker process succeeds or fails).

For other kinds of benchmarks, there is no temporary file involved -- each child worker process merges their results directly into the output file. That has a separate problem in that there is a race condition if multiple workers update that file at the same time, but the whole design here is to not benchmark things in parallel, so that should be ok.

This certainly could use a pipe to communicate all the profiling data to the parent process -- all platforms already use that to communicate benchmark results from the worker processes. But it would add complexity to a bunch of places since the "protocol", which right now dumps things directly into the master benchmarking results, would have to split things out into separate files for the profiling results.

@vstinner
Copy link
Member

cc @corona10

@mdboom mdboom requested a review from vstinner June 23, 2022 13:47
@vstinner
Copy link
Member

cc @pablogsal

@corona10 corona10 self-requested a review July 4, 2022 03:06
@corona10
Copy link
Member

corona10 commented Jul 6, 2022

I will left review by this weekend cc @vstinner

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

pyperf/tests/test_runner.py Outdated Show resolved Hide resolved
@corona10
Copy link
Member

I am going to release the new version of pyperf in 7days after this PR is merged.
cc @vstinner

@mdboom
Copy link
Collaborator Author

mdboom commented Jul 14, 2022

Please update the following documentation.

https://github.com/psf/pyperf/blob/6eb6de7427c5ac8939a21c0c68014be1167847de/doc/cli.rst#pyperf-timeit

@corona10: I already did that in this PR. Is there something specific missing there that you'd like to see?

Copy link
Member

@corona10 corona10 left a comment

Choose a reason for hiding this comment

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

@mdboom

@corona10: I already did that in this PR. Is there something specific missing there that you'd like to see?

Oops sorry, I may miss something at that time.
LGTM, I will release the next version by this weekend.

@corona10 corona10 merged commit f06d3bf into psf:main Jul 14, 2022
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