-
Notifications
You must be signed in to change notification settings - Fork 607
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
Colorize weblist output #271
base: main
Are you sure you want to change the base?
Conversation
As you may have noticed I have some failing tests because of the different html output for weblist. Is there a way of updating the testdata easily? |
<span class=line> 5</span> <span class=nop> . . line5 </span> | ||
<span class=line> 6</span> <span class=nop> . . line6 </span> | ||
<span class=line> 7</span> <span class=nop> . . line7 </span> | ||
<span class=line> 3</span> <span class="nop "> . . line3 </span> |
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.
Trailing space shouldn't be there.
internal/report/source.go
Outdated
@@ -347,20 +347,40 @@ func printFunctionHeader(w io.Writer, name, path string, flatSum, cumSum int64, | |||
measurement.Percentage(cumSum, rpt.total)) | |||
} | |||
|
|||
func calculatePercentile(partial, sum int64) string { | |||
percentile := partial * 100 / sum |
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.
This is not percentile.
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.
Will change this. Misunderstood its meaning.
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.
@aalexand I have now implemented percentile. I'm not sure if my code (in terms of style and correctness) is fine, thus I have pushed a first version without tests, to get it reviewed. I will add tests soon.
I wonder if the percentiles functions should go into a different file or if they belong where they are.
Codecov Report
@@ Coverage Diff @@
## master #271 +/- ##
==========================================
+ Coverage 67.14% 67.25% +0.10%
==========================================
Files 78 78
Lines 14084 14130 +46
==========================================
+ Hits 9457 9503 +46
Misses 3792 3792
Partials 835 835
Continue to review full report at Codecov.
|
Looks like test fail at formatting check. |
@aalexand solved 😄 I was sleeping so I couldn't fix it straight away. |
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.
There are a bunch of style comments but also one important one on the what we actually want to do, please look at that first (it's the longest one).
internal/report/source.go
Outdated
} | ||
printFunctionClosing(w) | ||
} | ||
return nil | ||
} | ||
|
||
func getPercentileString(cumSum float64, percentiles map[float64]float64) string { |
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 this function can be simplified with a for loop, there is unnecessary repetition.
internal/report/source.go
Outdated
for _, fn := range fnodes { | ||
printFunctionSourceLine(w, fn, asm[fn.Info.Lineno], reader, rpt) | ||
printFunctionSourceLine(w, fn, asm[fn.Info.Lineno], reader, getPercentileString(float64(fn.Cum), percentiles), rpt) |
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.
getPercentileString
- this is not just string, this is CSS class name?
internal/report/source.go
Outdated
} | ||
printFunctionClosing(w) | ||
} | ||
return nil | ||
} | ||
|
||
func getPercentileString(cumSum float64, percentiles map[float64]float64) string { |
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.
Using float64 as the map key is quite unusual.
internal/report/source.go
Outdated
} | ||
printFunctionClosing(w) | ||
} | ||
return nil | ||
} | ||
|
||
func getPercentileString(cumSum float64, percentiles map[float64]float64) string { |
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'd suggest replacing "Percentile" with "Ptile" throughout. Using the full term makes the code unnecessarily verbose for the task.
internal/report/source.go
Outdated
return "" | ||
} | ||
|
||
// calculate percentile expects cumSums to be sorted and |
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.
Doc should start with function name.
internal/report/source_test.go
Outdated
"github.com/google/pprof/profile" | ||
) | ||
|
||
func TestCalculatePercentiles(t *testing.T) { | ||
for _, testCase := range []struct { | ||
fnodes graph.Nodes |
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 does "f" in "fnodes" stand for here?
internal/report/source_test.go
Outdated
func TestCalculatePercentiles(t *testing.T) { | ||
for _, testCase := range []struct { | ||
fnodes graph.Nodes | ||
output map[float64]float64 |
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.
output
-> want
internal/report/source.go
Outdated
return "" | ||
} | ||
switch { | ||
case cumSum >= percentiles[80]: |
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.
Why did you choose the specific percentiles of 10, 20, 40, 60 and 80?
Looking at the whole PR, I think that we should start with something simpler.
- Let's start with just two colors: pink and red.
- Percentiles which are calculated off unique set built of float64 numbers look weird, frankly, so not sure it was a good idea. I think the easier to understand thing is to base the coloring on the max value among of the source lines.
- Color as pink values that are > 80% of the max value.
- Color as red values that are > 95% of the max value.
- Leave all other values as white.
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 have implemented these changes. The code now calculates the percentile on the array of cum values, instead of a set. I'm not using float64s anymore, instead I use int64. This last change meant that I had to implement the Sort Interface for int64.
internal/report/source.go
Outdated
return cumSums[int64(rank)] | ||
} | ||
|
||
func getSetOfCumValues(fnodes graph.Nodes) []float64 { |
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.
This should explain what this function is doing and why. E.g. the choice of deduplicating the different values before computing the percentile values is non-obvious, we should clearly explain the tactics and document the rationale.
"github.com/google/pprof/profile" | ||
) | ||
|
||
func TestCalculatePercentiles(t *testing.T) { | ||
for _, testCase := range []struct { |
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 there should be at least these additional test cases:
- Duplicate values.
- All equal values.
@Maaarcocr Could you address the PR comments? |
@aalexand Sorry for the delay. I've been ill and I had a lot of coursework in the meanwhile, I will address the comments either today or tomorrow. |
@aalexand I've changed the code based on your suggested changes. I was wondering if I should change the background-color in a different way, such as: |
Hi! I would love to get this merged if it is still something that the project need 😄 |
@aalexand any progress this PR...? would be great feature I think. |
@zchee the branch is out of date so the author will need to rebase it first. |
@aalexand Ah, your correct. @Maaarcocr could you rebase it? |
Sorry for the very delayed answer. Will try to rebase when I have some free time, hopefully this weekend! |
still not merged? |
This is my first try at solving #218 (and also first time contributing here 😄)
This is how it looks:
I have added 5 new CSS classes whose background-colors are from a red to yellow gradient (please feel free to criticize my color choices)
I am not sure if I should use flatSum or cumSum in order to calculate the percentile, so if you have any opinion on this, please let me know.
I can add some basics tests for the calculatePercentile function, if needed.