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

Run perf continuously #113

Merged
merged 16 commits into from
Jul 18, 2021
Merged

Run perf continuously #113

merged 16 commits into from
Jul 18, 2021

Conversation

Jongy
Copy link
Contributor

@Jongy Jongy commented Jun 20, 2021

Description

This PR changes SystemProfiler (which runs perf) to run in true continuous mode (like PyPerf & phpspy, and more to come, hopefully).
Continuous mode produces more accurate results because we don't miss anything - we're always sampling. Also, avoiding the re-starts of perf should yield better performance.

Supersedes #103.
Based on #89.

Motivation and Context

Performance & accuracy.

How Has This Been Tested?

  • Basic sanity works.
  • I ran it for 30 mins, then ran master for 30 mins, and compared the results - they were very much the same (on the same machine with similar load)

I will decide on more elaborate tests & preferably add them to our test suite.

Checklist:

  • I have read the CONTRIBUTING document.
  • I have updated the relevant documentation.
  • I have added tests for new logic.
  • Test performance effect - does it really help in benchmarks & do we see less perf in the flamegraph now :) I ran master and this branch on the same machine, and compared the numbers of --log-cpu-usage & how much of perf I see in the graph. Both went down.
  • Complete all TODOs in code
  • Time to get rid of the --profiling-interval option? With perf now being continuous, there's no sense in allowing duration != interval.

@Jongy Jongy added the enhancement New feature or request label Jun 20, 2021
Base automatically changed from no-perf to master June 20, 2021 12:43
@Jongy Jongy force-pushed the continuous-perf-2 branch from 15a8374 to 01aec64 Compare June 20, 2021 12:47
Jongy added 3 commits June 21, 2021 15:37
This is done for 2 reasons:
1. More correct & accurate: collect samples *all* the time, without excluding any interval.
2. For performance reasons - this still has to be benched, but we believe that avoiding
   the start-stop-start-stop-... of "perf record" will be beneficial.
We now profile foreverrrr
@Jongy
Copy link
Contributor Author

Jongy commented Jun 21, 2021

Time to get rid of the --profiling-interval option? With perf now being continuous, there's no sense in allowing duration != interval.

We have decided to get rid of it, in favor of true continuity.

@Jongy Jongy force-pushed the continuous-perf-2 branch from 01aec64 to 770a28b Compare June 21, 2021 19:46
@Jongy Jongy marked this pull request as ready for review July 15, 2021 16:09
@Jongy Jongy requested a review from michelhe July 15, 2021 16:09
buildid recording & cache is enabled by default in perf, but disabled in
"switch output" mode (see explanation in Linux commit 0c1d46a8796e830).
We had it enabled (and specifically handled it in #17) because I had in mind that
it's required for perf to properly resolve symbols across namespaces.
I have proved this incorrect by testing, so there's no reason to keep these
flags on - we run "script" right after record is done, it's okay to access
files just by path.
@Jongy Jongy requested a review from guybortnikov July 15, 2021 22:29
@Jongy Jongy mentioned this pull request Jul 15, 2021
10 tasks

logger = get_logger_adapter(__name__)

PERF_BUILDID_DIR = os.path.join(TEMPORARY_STORAGE_PATH, "perf-buildids")

class PerfProcess:

Choose a reason for hiding this comment

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

Looks like your can derive from ProfilerBase here and get away with much of the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not really. It's not the same API. For example, its result isn't ProcessToStackSampleCounters but plain perf script.

def stop(self) -> None:
if self._process is not None:
self._process.terminate() # okay to call even if process is already dead
self._process.wait()

Choose a reason for hiding this comment

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

timeout?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

terminate sends SIGTERM, which kills perf.

But I agree timeouts are nice nonetheless

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But we'll add timeouts somewhen else (we have plenty of other missing timeouts - for example, when running py-spy, I happened to see it hang). So in another PR. There's an issue open (or I will open one)

@michelhe
Copy link

Changes LGTM

@Jongy Jongy requested a review from michelhe July 18, 2021 15:38
@Jongy
Copy link
Contributor Author

Jongy commented Jul 18, 2021

I'll update the README

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.

2 participants