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

Implement --deterministic, for chaotic but repeatable color selection #190

Merged
merged 10 commits into from
Oct 5, 2020

Conversation

saethlin
Copy link
Contributor

From the runs I've tried out with this so far it seems like the color selection is a bit biased towards darker shades, which is unfortunate. Not entirely sure what to do about that.

@codecov
Copy link

codecov bot commented Sep 27, 2020

Codecov Report

Merging #190 into master will increase coverage by 0.05%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #190      +/-   ##
==========================================
+ Coverage   90.31%   90.36%   +0.05%     
==========================================
  Files          17       17              
  Lines        2219     2231      +12     
==========================================
+ Hits         2004     2016      +12     
  Misses        215      215              
Impacted Files Coverage Δ
src/flamegraph/color/mod.rs 83.55% <100.00%> (+1.03%) ⬆️
src/flamegraph/mod.rs 96.45% <100.00%> (+0.03%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 86302c8...e65e6e2. Read the comment docs.

src/bin/flamegraph.rs Outdated Show resolved Hide resolved
src/bin/flamegraph.rs Outdated Show resolved Hide resolved
src/bin/flamegraph.rs Outdated Show resolved Hide resolved
src/flamegraph/color/mod.rs Outdated Show resolved Hide resolved
src/flamegraph/color/mod.rs Outdated Show resolved Hide resolved
@jonhoo
Copy link
Owner

jonhoo commented Sep 27, 2020

Thanks, this looks pretty good! Left some comments inline. I'm not sure why the colors are generally dark, though the second hash trick I mentioned might help. I'd also like to see a new test case for this.

@saethlin
Copy link
Contributor Author

I'd love to add some tests, but... how? The existing test suite doesn't run on its own, it seems like maybe it's missing some files?

---- collapse::dtrace::tests::test_collapse_multi_dtrace_simple stdout ----
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
thread 'collapse::dtrace::tests::test_collapse_multi_dtrace_simple' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:192:5
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

---- collapse::dtrace::tests::test_collapse_multi_dtrace stdout ----
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
thread 'collapse::dtrace::tests::test_collapse_multi_dtrace' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:192:5

---- collapse::perf::tests::test_collapse_multi_perf stdout ----
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
thread 'collapse::perf::tests::test_collapse_multi_perf' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:192:5

---- collapse::perf::tests::test_collapse_multi_perf_simple stdout ----
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }
thread 'collapse::perf::tests::test_collapse_multi_perf_simple' panicked at 'assertion failed: `(left == right)`
  left: `1`,
 right: `0`: the test returned a termination value with a non-zero status code (1) which indicates a failure', /home/ben/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/test/src/lib.rs:192:5

@jonhoo
Copy link
Owner

jonhoo commented Sep 28, 2020

Ah, yes, it also runs a bunch of tests from the upstream Perl flamegraph repository, which has to be checked out with

$ git submodule update --init

src/flamegraph/color/mod.rs Outdated Show resolved Hide resolved
@saethlin
Copy link
Contributor Author

saethlin commented Oct 3, 2020

@jonhoo The test I've added passes on my machine, I would really appreciate some assistance here. I don't know why it's not working in the CI or whether this is even the test we want.

jonhoo
jonhoo previously approved these changes Oct 3, 2020
@jonhoo
Copy link
Owner

jonhoo commented Oct 3, 2020

Hmm, looking at the test output, it seems like the test run generates a different color than the committed test file. Even more interestingly, different runs of the test produce different values, which suggest that the generated color is not actually deterministic. Are you sure the test is actually being run on your computer? The failure seems to be consistent across all the different OSes.

Separately, you have to use std::u64::MAX, not u64::MAX, otherwise the code will not compile on Rust 1.40.

src/flamegraph/color/mod.rs Outdated Show resolved Hide resolved
@saethlin saethlin requested a review from jonhoo October 5, 2020 13:57
@@ -342,7 +342,8 @@ pub(super) fn color(
(name_hash, reverse_name_hash, reverse_name_hash)
} else if deterministic {
use std::hash::Hasher;
let mut hasher = ahash::AHasher::default();
// Do not use AHasher::default; it is seeded with a compile-time RNG
Copy link
Owner

Choose a reason for hiding this comment

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

Ah, good catch!

@jonhoo jonhoo merged commit 519cccc into jonhoo:master Oct 5, 2020
@jonhoo
Copy link
Owner

jonhoo commented Oct 5, 2020

Excellent, thank you!

@jonhoo
Copy link
Owner

jonhoo commented Oct 6, 2020

Released in 0.10.1.

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.

2 participants