Skip to content

Commit

Permalink
better precision of elapsed.
Browse files Browse the repository at this point in the history
  • Loading branch information
thushan committed Nov 26, 2023
1 parent 72a74a8 commit 215f382
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
18 changes: 16 additions & 2 deletions internal/report/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ type RunSummary struct {

func PrintRunSummary(rs RunSummary, ignoreEmptyFiles bool) {
theme.StyleHeading.Println("---| Analysis Summary")
duration := time.Duration(rs.ElapsedTime)
theme.Println(writeCategory("Total Time:"), theme.ColourTime(duration.Round(time.Second).String()))

theme.Println(writeCategory("Total Time:"), theme.ColourTime(calcTotalTime(rs.ElapsedTime)))
theme.Println(writeCategory("Total Analysed:"), theme.ColourNumber(rs.TotalFiles))
theme.Println(writeCategory("Total Unique:"), theme.ColourNumber(rs.UniqueFiles), "(excludes empty files)")
if rs.TotalFileErrors > 0 {
Expand All @@ -35,6 +35,20 @@ func PrintRunSummary(rs RunSummary, ignoreEmptyFiles bool) {
theme.Println(writeCategory("Space Reclaimable:"), theme.ColourFileSizeA(rs.DuplicateFileSizeF), "(approx)")
}
}
func calcTotalTime(elapsedNs int64) string {
duration := time.Duration(elapsedNs)
switch {
case duration >= 60*time.Minute:
return duration.Round(time.Minute).String()
case duration >= 1*time.Minute:
return duration.Round(time.Second).String()
case duration <= 1*time.Second:
return duration.Round(time.Millisecond).String()
default:
return duration.Round(time.Second).String()
}
}

func writeCategory(category string) string {
return fmt.Sprintf("%20s", category)
}
26 changes: 26 additions & 0 deletions internal/report/summary_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package report

import (
"strings"
"testing"
)

func TestCalcTotalTime(t *testing.T) {
var data = []struct {

Check failure on line 9 in internal/report/summary_test.go

View workflow job for this annotation

GitHub Actions / golangci

fieldalignment: struct with 16 pointer bytes could be 8 (govet)
elapsedNs int64
expected string
}{
{12660100, "13ms"},
{22592034100, "23s"},
{60592034100, "1m1s"},
{360592034100, "6m1s"},
{8960592034100, "2h29m0s"},
}

for _, item := range data {
actual := calcTotalTime(item.elapsedNs)
if !strings.EqualFold(actual, item.expected) {
t.Errorf("expected time %s, got %s", item.expected, actual)
}
}
}
13 changes: 11 additions & 2 deletions internal/smash/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@ func (app *App) printConfiguration() {
theme.StyleHeading.Println("---| Configuration")

if app.Flags.Verbose {
theme.Println(b.Sprint("Concurrency: "), theme.ColourConfig(f.MaxWorkers), "workers |", theme.ColourConfig(f.MaxThreads), "threads")
config = "(Slices: " + theme.ColourConfig(slicer.DefaultSlices) + " | Size: " + theme.ColourConfig(humanize.Bytes(slicer.DefaultSliceSize)) + " | Threshold: " + theme.ColourConfig(humanize.Bytes(slicer.DefaultThreshold)) + ")"
slices := theme.ColourConfig(slicer.DefaultSlices)
size := theme.ColourConfig(humanize.Bytes(slicer.DefaultSliceSize))
threshold := theme.ColourConfig(humanize.Bytes(slicer.DefaultThreshold))

config = "(Slices: " + slices + " | Size: " + size + " | Threshold: " + threshold + ")"

maxThreads := theme.ColourConfig(f.MaxThreads)
maxWorkers := theme.ColourConfig(f.MaxWorkers)

theme.Println(b.Sprint("Concurrency: "), maxWorkers, "workers |", maxThreads, "threads")

} else {
config = ""
}
Expand Down

0 comments on commit 215f382

Please sign in to comment.