-
Notifications
You must be signed in to change notification settings - Fork 612
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
log error message when negative samples appear in non-diff_base profiles #391
Conversation
Codecov Report
@@ Coverage Diff @@
## master #391 +/- ##
==========================================
+ Coverage 67.67% 67.69% +0.02%
==========================================
Files 36 36
Lines 7535 7540 +5
==========================================
+ Hits 5099 5104 +5
Misses 2031 2031
Partials 405 405
Continue to review full report at Codecov.
|
internal/report/report.go
Outdated
if diffTotal > 0 { | ||
total = diffTotal | ||
div = diffDiv | ||
} else if negSamples { | ||
ui.PrintErr("Negative sample values appeared in the profile.\nIf using the -base flag to compare profiles, consider using the -diff_base flag instead.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit strange that printing out this user interface messages goes down as deeply as to this code that computes the total. As well as that report.New has to take the UI now. I think it would be better to make computeTotal return a boolean (in addition to the int64 like now) indicating whether negative values were seen, store that in the report object, and print the message in Generate() making that function take UI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
c1f2196
to
9b1cf87
Compare
PTAL |
internal/report/report_test.go
Outdated
@@ -213,6 +238,41 @@ var testProfile = &profile.Profile{ | |||
Mapping: testM, | |||
} | |||
|
|||
var testProfile2 = &profile.Profile{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be easier to massage testProfile where needed in the test to produce this profile. As far as I can tell, it's just negating the value in one of the samples.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
I negated all samples for simplicity, but this works.
internal/report/report_test.go
Outdated
t.Errorf("got total %d, want %v", gotTotal, tc.wantTotal) | ||
} | ||
if gotUnexpNegSamples != tc.wantUnexpNegSamples { | ||
t.Errorf("got unexpected negative samples %v, want %v", gotUnexpNegSamples, tc.wantUnexpNegSamples) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: double space after "got"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
internal/report/report_test.go
Outdated
OutputFormat: Dot, | ||
CallTree: true, | ||
Symbol: regexp.MustCompile(`.`), | ||
TrimPath: "/some/path", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you specify TrimPath in this test for?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this.
internal/report/report_test.go
Outdated
rpt: New( | ||
testProfile2.Copy(), | ||
&Options{ | ||
OutputFormat: Dot, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this test, is Dot format really necessary? Which kind of issues would it help to catch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switched to list
@@ -1202,8 +1206,8 @@ func New(prof *profile.Profile, o *Options) *Report { | |||
} | |||
return measurement.ScaledLabel(v, o.SampleUnit, o.OutputUnit) | |||
} | |||
return &Report{prof, computeTotal(prof, o.SampleValue, o.SampleMeanDivisor), | |||
o, format} | |||
total, unexpNegSamples := computeTotal(prof, o.SampleValue, o.SampleMeanDivisor) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unexpNegSamples -> hasNegativeSamples, here and in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Not sure if this could be confusing, because -diff_base profiles will have negative samples, but this will be false.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Well, maybe leave the old name then. Up to you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Switching back to old name.
internal/report/report.go
Outdated
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error { | ||
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool, ui plugin.UI) error { | ||
if rpt.unexpNegSamples { | ||
ui.PrintErr("Negative sample values appeared in the profile.\nIf using the -base flag to compare profiles, consider using the -diff_base flag instead.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to shorten the message a bit (without any loss of information), but I couldn't come up with a good version...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about it still... not sure if I'll come up with something.
internal/report/report.go
Outdated
total int64 | ||
options *Options | ||
formatValue func(int64) string | ||
unexpNegSamples bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe move it up to be after "total" since these are related.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
234e004
to
c789498
Compare
PTAL |
internal/report/report.go
Outdated
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error { | ||
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool, ui plugin.UI) error { | ||
if rpt.unexpNegSamples { | ||
ui.PrintErr("Profile has negative sample values.\nIf using the -base flag to compare profiles, consider using the -diff_base flag instead.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we check if -base
flag was actually used and print this warning (or this part of the warning) only in that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's possible, but I don't think it's trivial.
I see a few possible options:
- Call
report.Generate()
with a boolean indicating if-base
was used to specify a base profile. This requires also passing that boolean intointeractive()
andgenerateReport()
or extendingplugin.Options
with a field for specifying if there is a-base
profile. - Add a boolean to profile.Profile to track if a base profile was specified with the
base
. - Start tracking -base somehow in
pprofVariables
(this seems undesirable, because I think specifying a base profile from the interactive mode would fail silently).
Any other ideas or preferences?
(There's also the smaller complication of what to name a boolean indicating the a profile has a "base: profile but not a "diff base" profile)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if it would make more sense to print out this warning in fetchProfiles around where pbase and s.DiffBase are checked. The complication is that at that point the sample index is not known, but we could print a warning if any of the metrics has a negative sample and mention all such metrics in the message. The advantage of placing it there is that the message would be printed only once as opposed to for every report in the interactive mode. What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm happy with that solution.
It may lead to the message printing out when people are using -base to look at cumulative profiles, but I think that'll be okay.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point, we don't want the message to be printed out when someone is doing pprof -sample_index=alloc_space profile1.pb.gz -base profile2.pb.gz
.
PTAL at response to comment. |
internal/report/report.go
Outdated
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error { | ||
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool, ui plugin.UI) error { | ||
if rpt.unexpNegSamples { | ||
ui.PrintErr("Profile has negative sample values.\nIf using the -base flag to compare profiles, consider using the -diff_base flag instead.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe shorten the message a bit to have it one line: "Profile has negative values. If using -base, consider using -diff_base instead."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
internal/report/report.go
Outdated
@@ -1246,20 +1254,23 @@ func computeTotal(prof *profile.Profile, value, meanDiv func(v []int64) int64) i | |||
if diffTotal > 0 { | |||
total = diffTotal | |||
div = diffDiv | |||
// negative samples are expected in diff base profiles. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: "Negative" (capitalize documentation sentences)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
PTAL |
internal/report/report.go
Outdated
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool) error { | ||
func Generate(w io.Writer, rpt *Report, obj plugin.ObjTool, ui plugin.UI) error { | ||
if rpt.unexpNegSamples { | ||
ui.PrintErr("Profile has negative values. If using -base, consider using -diff_base instead.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, let's do one more tweak to clarify why someone would need to consider using -diff_base instead. How about
Profile has negative values, percentage values may be incorrect. If using -base, consider using -diff_base instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edited the comment, I had a mistake there. The right version is Profile has negative values, percentage values may be incorrect. If using -base, consider using -diff_base instead.
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
PTAL |
Closing because we do not want to submit this. |
Actually closing the PR. Also to clarify, the exact reason for why the change shouldn't go in is golang/go#26638. |
This is the last change needed for improving diff mode, so fixes #323.