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

log error message when negative samples appear in non-diff_base profiles #391

Closed
wants to merge 5 commits into from

Conversation

nolanmar511
Copy link
Contributor

@nolanmar511 nolanmar511 commented Jun 22, 2018

This is the last change needed for improving diff mode, so fixes #323.

@codecov-io
Copy link

codecov-io commented Jun 22, 2018

Codecov Report

Merging #391 into master will increase coverage by 0.02%.
The diff coverage is 76.92%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
internal/driver/webui.go 58.47% <0%> (ø) ⬆️
internal/driver/driver.go 68.92% <0%> (ø) ⬆️
internal/report/report.go 31.77% <90.9%> (+0.48%) ⬆️

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 ef43755...ad55e97. Read the comment docs.

@aalexand aalexand changed the title log error message when negatice samples appear in non-diff_base profiles log error message when negative samples appear in non-diff_base profiles Jun 27, 2018
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.")
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nolanmar511 nolanmar511 force-pushed the neg-warn branch 2 times, most recently from c1f2196 to 9b1cf87 Compare June 27, 2018 23:43
@nolanmar511
Copy link
Contributor Author

PTAL

@@ -213,6 +238,41 @@ var testProfile = &profile.Profile{
Mapping: testM,
}

var testProfile2 = &profile.Profile{
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

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)
Copy link
Collaborator

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"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

OutputFormat: Dot,
CallTree: true,
Symbol: regexp.MustCompile(`.`),
TrimPath: "/some/path",
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this.

rpt: New(
testProfile2.Copy(),
&Options{
OutputFormat: Dot,
Copy link
Collaborator

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?

Copy link
Contributor Author

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)
Copy link
Collaborator

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.

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

Copy link
Contributor Author

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.

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.")
Copy link
Collaborator

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...

Copy link
Contributor Author

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.

total int64
options *Options
formatValue func(int64) string
unexpNegSamples bool
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nolanmar511 nolanmar511 force-pushed the neg-warn branch 3 times, most recently from 234e004 to c789498 Compare June 28, 2018 17:54
@nolanmar511
Copy link
Contributor Author

PTAL

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.")
Copy link
Collaborator

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?

Copy link
Contributor Author

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:

  1. Call report.Generate() with a boolean indicating if -base was used to specify a base profile. This requires also passing that boolean into interactive() and generateReport() or extending plugin.Options with a field for specifying if there is a -base profile.
  2. Add a boolean to profile.Profile to track if a base profile was specified with the base.
  3. 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)

Copy link
Collaborator

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?

Copy link
Contributor Author

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.

Copy link
Collaborator

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.

@nolanmar511
Copy link
Contributor Author

PTAL at response to comment.

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.")
Copy link
Collaborator

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."

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -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.
Copy link
Collaborator

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nolanmar511
Copy link
Contributor Author

PTAL

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.")
Copy link
Collaborator

@aalexand aalexand Jul 19, 2018

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.

Copy link
Collaborator

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..

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@nolanmar511
Copy link
Contributor Author

PTAL

@nolanmar511
Copy link
Contributor Author

Closing because we do not want to submit this.
The message currently appears in situations when we would not want the message to appear.

@aalexand
Copy link
Collaborator

Actually closing the PR. Also to clarify, the exact reason for why the change shouldn't go in is golang/go#26638.

@aalexand aalexand closed this Jul 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix percentage calculation in diff mode (-base) and remove -positive_percentages
4 participants