diff options
| author | Joey Jiao <joeyjiaojg@gmail.com> | 2021-04-28 09:05:58 +0800 |
|---|---|---|
| committer | Dmitry Vyukov <dvyukov@google.com> | 2021-05-03 15:07:48 +0200 |
| commit | ad61f3714f0a5e8f7ce062d54f310df1f5e0d351 (patch) | |
| tree | 2eefaa5cc89e7e8e5f190c1acfb22679436b6502 /pkg/cover/html.go | |
| parent | ced327b28d431dad85971aec1c2df58d7dfdc9db (diff) | |
pkg/cover: show stat of PCs in covered function
Diffstat (limited to 'pkg/cover/html.go')
| -rw-r--r-- | pkg/cover/html.go | 73 |
1 files changed, 50 insertions, 23 deletions
diff --git a/pkg/cover/html.go b/pkg/cover/html.go index 6b99060b8..f1cd96205 100644 --- a/pkg/cover/html.go +++ b/pkg/cover/html.go @@ -105,14 +105,16 @@ func (rg *ReportGenerator) DoHTML(w io.Writer, progs []Prog) error { } type fileStats struct { - Name string - CoveredLines int - TotalLines int - CoveredPCs int - TotalPCs int - TotalFunctions int - CoveredPCsInFunctions int - TotalPCsInFunctions int + Name string + CoveredLines int + TotalLines int + CoveredPCs int + TotalPCs int + TotalFunctions int + CoveredFunctions int + CoveredPCsInFunctions int + TotalPCsInCoveredFunctions int + TotalPCsInFunctions int } var csvFilesHeader = []string{ @@ -124,6 +126,7 @@ var csvFilesHeader = []string{ "TotalFunctions", "CoveredPCsInFunctions", "TotalPCsInFunctions", + "TotalPCsInCoveredFunctions", } func (rg *ReportGenerator) convertToStats(progs []Prog) ([]fileStats, error) { @@ -142,8 +145,14 @@ func (rg *ReportGenerator) convertToStats(progs []Prog) ([]fileStats, error) { totalFuncs := len(file.functions) var coveredInFunc int var pcsInFunc int + var pcsInCoveredFunc int + var coveredFunc int for _, function := range file.functions { coveredInFunc += function.covered + if function.covered != 0 { + pcsInCoveredFunc += function.pcs + coveredFunc++ + } pcsInFunc += function.pcs } totalLines := len(lines) @@ -154,14 +163,16 @@ func (rg *ReportGenerator) convertToStats(progs []Prog) ([]fileStats, error) { } } data = append(data, fileStats{ - Name: fname, - CoveredLines: coveredLines, - TotalLines: totalLines, - CoveredPCs: file.coveredPCs, - TotalPCs: file.totalPCs, - TotalFunctions: totalFuncs, - CoveredPCsInFunctions: coveredInFunc, - TotalPCsInFunctions: pcsInFunc, + Name: fname, + CoveredLines: coveredLines, + TotalLines: totalLines, + CoveredPCs: file.coveredPCs, + TotalPCs: file.totalPCs, + TotalFunctions: totalFuncs, + CoveredFunctions: coveredFunc, + CoveredPCsInFunctions: coveredInFunc, + TotalPCsInFunctions: pcsInFunc, + TotalPCsInCoveredFunctions: pcsInCoveredFunc, }) } @@ -195,6 +206,7 @@ func (rg *ReportGenerator) DoCSVFiles(w io.Writer, progs []Prog) error { strconv.Itoa(dt.TotalFunctions), strconv.Itoa(dt.CoveredPCsInFunctions), strconv.Itoa(dt.TotalPCsInFunctions), + strconv.Itoa(dt.TotalPCsInCoveredFunctions), }) } return writer.WriteAll(d) @@ -209,11 +221,15 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste var coveredPCsInFile int var totalPCsInFile int var totalFuncs int + var coveredFuncs int var coveredPCsInFuncs int + var pcsInCoveredFuncs int var pcsInFuncs int var percentLines float64 var percentPCsInFile float64 var percentPCsInFunc float64 + var percentPCsInCoveredFunc float64 + var percentCoveredFunc float64 for _, path := range subsystem.Paths { for _, data := range datas { @@ -225,8 +241,10 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste coveredPCsInFile += data.CoveredPCs totalPCsInFile += data.TotalPCs totalFuncs += data.TotalFunctions + coveredFuncs += data.CoveredFunctions coveredPCsInFuncs += data.CoveredPCsInFunctions pcsInFuncs += data.TotalPCsInFunctions + pcsInCoveredFuncs += data.TotalPCsInCoveredFunctions } } @@ -239,13 +257,20 @@ func groupCoverByFilePrefixes(datas []fileStats, subsystems []mgrconfig.Subsyste if pcsInFuncs != 0 { percentPCsInFunc = 100.0 * float64(coveredPCsInFuncs) / float64(pcsInFuncs) } + if pcsInCoveredFuncs != 0 { + percentPCsInCoveredFunc = 100.0 * float64(coveredPCsInFuncs) / float64(pcsInCoveredFuncs) + } + if totalFuncs != 0 { + percentCoveredFunc = 100.0 * float64(coveredFuncs) / float64(totalFuncs) + } d[subsystem.Name] = map[string]string{ - "subsystem": subsystem.Name, - "lines": fmt.Sprintf("%v / %v / %.2f%%", coveredLines, totalLines, percentLines), - "PCsInFiles": fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFile, totalPCsInFile, percentPCsInFile), - "totalFuncs": strconv.Itoa(totalFuncs), - "PCsInFuncs": fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFuncs, pcsInFuncs, percentPCsInFunc), + "subsystem": subsystem.Name, + "lines": fmt.Sprintf("%v / %v / %.2f%%", coveredLines, totalLines, percentLines), + "PCsInFiles": fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFile, totalPCsInFile, percentPCsInFile), + "Funcs": fmt.Sprintf("%v / %v / %.2f%%", coveredFuncs, totalFuncs, percentCoveredFunc), + "PCsInFuncs": fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFuncs, pcsInFuncs, percentPCsInFunc), + "PCsInCoveredFuncs": fmt.Sprintf("%v / %v / %.2f%%", coveredPCsInFuncs, pcsInCoveredFuncs, percentPCsInCoveredFunc), } } @@ -762,7 +787,8 @@ var coverTableTemplate = template.Must(template.New("coverTable").Parse(` <th>Covered / Total Lines / %</th> <th>Covered / Total PCs in File / %</th> <th>Covered / Total PCs in Function / %</th> - <th>Covered Functions</th> + <th>Covered / Total PCs in Covered Function / %</th> + <th>Covered / Total Functions / %</th> </tr> </thead> <tbody id="content"> @@ -772,7 +798,8 @@ var coverTableTemplate = template.Must(template.New("coverTable").Parse(` <td>{{$p.lines}}</td> <td>{{$p.PCsInFiles}}</td> <td>{{$p.PCsInFuncs}}</td> - <td>{{$p.totalFuncs}}</td> + <td>{{$p.PCsInCoveredFuncs}}</td> + <td>{{$p.Funcs}}</td> </tr> {{end}} </tbody> |
