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

Replace use of Result.env in profiling code #1404

Merged
merged 4 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
17 changes: 12 additions & 5 deletions asv/commands/profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,22 @@ def run(cls, conf, benchmark, revision=None, gui=None, output=None,
conf.results_dir, machine_name):
if hash_equal(commit_hash, result.commit_hash):
if result.has_profile(benchmark):
env_matched = any(result.env.name == env.name
for env in environments)
# Only take the first one
env_matched = next(
(
env
for env in environments
if result.env_name == env.name
),
None,
)
if env_matched:
if result.env.name not in checked_out:
if result.env_name not in checked_out:
# We need to checkout the correct commit so that
# the line numbers in the profile data match up with
# what's in the source tree.
result.env.checkout_project(repo, commit_hash)
checked_out.add(result.env.name)
env_matched.checkout_project(repo, commit_hash)
checked_out.add(result.env_name)
profile_data = result.get_profile(benchmark)
break

Expand Down
2 changes: 1 addition & 1 deletion asv/results.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def has_profile(self, benchmark_name):
"""
Does the given benchmark data have profiling information?
"""
return benchmark_name in self._profiles
return self._profiles.get(benchmark_name)
HaoZeke marked this conversation as resolved.
Show resolved Hide resolved

def save(self, result_dir):
"""
Expand Down
32 changes: 32 additions & 0 deletions test/test_profile.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import re

from asv import util

from . import tools


Expand All @@ -17,3 +19,33 @@ def test_profile_python_same(capsys, basic_conf):
# Check that it did not clone or install
assert "Cloning" not in text
assert "Installing" not in text


def test_profile_python_commit(capsys, basic_conf):

tmpdir, local, conf, machine_file = basic_conf

# Create initial results with no profile results
tools.run_asv_with_conf(conf, 'run', "--quick", "--bench=time_secondary.track_value",
f'{util.git_default_branch()}^!', _machine_file=machine_file)
text, err = capsys.readouterr()

assert "Installing" in text

# Query the previous empty results results; there should be no issues here
tools.run_asv_with_conf(conf, 'profile', "time_secondary.track_value",
f'{util.git_default_branch()}', _machine_file=machine_file)
text, err = capsys.readouterr()

assert "Profile data does not already exist" in text

tools.run_asv_with_conf(conf, 'run', "--quick", "--profile",
"--bench=time_secondary.track_value",
f'{util.git_default_branch()}^!', _machine_file=machine_file)

# Profile results should be present now
tools.run_asv_with_conf(conf, 'profile', "time_secondary.track_value",
f'{util.git_default_branch()}', _machine_file=machine_file)
text, err = capsys.readouterr()

assert "Profile data does not already exist" not in text
Loading