mirror of
https://github.com/wagoodman/dive
synced 2026-03-14 14:25:50 +01:00
fix: report reclaimable bytes for inefficiencies
This commit is contained in:
parent
91fda993a3
commit
51c0446df6
5 changed files with 15 additions and 4 deletions
|
|
@ -20,7 +20,7 @@
|
|||
"sizeBytes": 6405
|
||||
}
|
||||
],
|
||||
"inefficientBytes": 32025,
|
||||
"inefficientBytes": 19215,
|
||||
"sizeBytes": 1220598
|
||||
},
|
||||
"layer": [
|
||||
|
|
|
|||
|
|
@ -86,7 +86,7 @@ func (v *ImageDetails) Render() error {
|
|||
var wastedSpace int64
|
||||
for idx := 0; idx < len(v.inefficiencies); idx++ {
|
||||
data := v.inefficiencies[len(v.inefficiencies)-1-idx]
|
||||
wastedSpace += data.CumulativeSize
|
||||
wastedSpace += data.WastedSize()
|
||||
|
||||
inefficiencyReport += fmt.Sprintf(analysisTemplate, strconv.Itoa(len(data.Nodes)), humanize.Bytes(uint64(data.CumulativeSize)), data.Path)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,6 +14,17 @@ type EfficiencyData struct {
|
|||
minDiscoveredSize int64
|
||||
}
|
||||
|
||||
// WastedSize is the estimated reclaimable size for this path.
|
||||
// Exactly one discovered copy must remain, so only bytes beyond the smallest
|
||||
// discovered copy count as removable.
|
||||
func (data *EfficiencyData) WastedSize() int64 {
|
||||
wasted := data.CumulativeSize - data.minDiscoveredSize
|
||||
if wasted < 0 {
|
||||
return 0
|
||||
}
|
||||
return wasted
|
||||
}
|
||||
|
||||
// EfficiencySlice represents an ordered set of EfficiencyData data structures.
|
||||
type EfficiencySlice []*EfficiencyData
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func Analyze(ctx context.Context, img *Image) (*Analysis, error) {
|
|||
|
||||
var wastedBytes uint64
|
||||
for _, file := range inefficiencies {
|
||||
wastedBytes += uint64(file.CumulativeSize)
|
||||
wastedBytes += uint64(file.WastedSize())
|
||||
}
|
||||
|
||||
return &Analysis{
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ func Test_Analysis(t *testing.T) {
|
|||
wastedPercent float64
|
||||
path string
|
||||
}{
|
||||
"docker-image": {0.9844212134184309, 1220598, 66237, 32025, 0.4834911001404049, "../../../.data/test-docker-image.tar"},
|
||||
"docker-image": {0.9844212134184309, 1220598, 66237, 19215, 0.29009466008424295, "../../../.data/test-docker-image.tar"},
|
||||
}
|
||||
|
||||
for name, test := range table {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue