1
0
Fork 0
mirror of https://github.com/restic/restic.git synced 2025-03-30 00:00:14 +01:00

prune: Unify statistics computation

+ prepare JSON output
This commit is contained in:
Alexander Weiss 2020-11-30 15:22:04 +01:00 committed by Dark Dragon
parent da47967316
commit ae0835f12d
2 changed files with 53 additions and 36 deletions

View file

@ -232,24 +232,19 @@ func printPruneStats(printer progress.Printer, stats repository.PruneStats) erro
if stats.Size.Unref > 0 { if stats.Size.Unref > 0 {
printer.V("unreferenced: %s\n", ui.FormatBytes(stats.Size.Unref)) printer.V("unreferenced: %s\n", ui.FormatBytes(stats.Size.Unref))
} }
totalBlobs := stats.Blobs.Used + stats.Blobs.Unused + stats.Blobs.Duplicate printer.V("total: %10d blobs / %s\n", stats.Blobs.Total, ui.FormatBytes(stats.Size.Total))
totalSize := stats.Size.Used + stats.Size.Duplicate + stats.Size.Unused + stats.Size.Unref printer.V("unused size: %s of total size\n", ui.FormatPercent(stats.Size.Unused, stats.Size.Total))
unusedSize := stats.Size.Duplicate + stats.Size.Unused
printer.V("total: %10d blobs / %s\n", totalBlobs, ui.FormatBytes(totalSize))
printer.V("unused size: %s of total size\n", ui.FormatPercent(unusedSize, totalSize))
printer.P("\nto repack: %10d blobs / %s\n", stats.Blobs.Repack, ui.FormatBytes(stats.Size.Repack)) printer.P("\nto repack: %10d blobs / %s\n", stats.Blobs.Repack, ui.FormatBytes(stats.Size.Repack))
printer.P("this removes: %10d blobs / %s\n", stats.Blobs.Repackrm, ui.FormatBytes(stats.Size.Repackrm)) printer.P("this removes: %10d blobs / %s\n", stats.Blobs.Repackrm, ui.FormatBytes(stats.Size.Repackrm))
printer.P("to delete: %10d blobs / %s\n", stats.Blobs.Remove, ui.FormatBytes(stats.Size.Remove+stats.Size.Unref)) printer.P("to delete: %10d blobs / %s\n", stats.Blobs.Remove, ui.FormatBytes(stats.Size.Remove+stats.Size.Unref))
totalPruneSize := stats.Size.Remove + stats.Size.Repackrm + stats.Size.Unref printer.P("total prune: %10d blobs / %s\n", stats.Blobs.RemoveTotal, ui.FormatBytes(stats.Size.RemoveTotal))
printer.P("total prune: %10d blobs / %s\n", stats.Blobs.Remove+stats.Blobs.Repackrm, ui.FormatBytes(totalPruneSize))
if stats.Size.Uncompressed > 0 { if stats.Size.Uncompressed > 0 {
printer.P("not yet compressed: %s\n", ui.FormatBytes(stats.Size.Uncompressed)) printer.P("not yet compressed: %s\n", ui.FormatBytes(stats.Size.Uncompressed))
} }
printer.P("remaining: %10d blobs / %s\n", totalBlobs-(stats.Blobs.Remove+stats.Blobs.Repackrm), ui.FormatBytes(totalSize-totalPruneSize)) printer.P("remaining: %10d blobs / %s\n", stats.Blobs.Remain, ui.FormatBytes(stats.Size.Remain))
unusedAfter := unusedSize - stats.Size.Remove - stats.Size.Repackrm
printer.P("unused size after prune: %s (%s of remaining size)\n", printer.P("unused size after prune: %s (%s of remaining size)\n",
ui.FormatBytes(unusedAfter), ui.FormatPercent(unusedAfter, totalSize-totalPruneSize)) ui.FormatBytes(stats.Size.RemainUnused), ui.FormatPercent(stats.Size.RemainUnused, stats.Size.Remain))
printer.P("\n") printer.P("\n")
printer.V("totally used packs: %10d\n", stats.Packs.Used) printer.V("totally used packs: %10d\n", stats.Packs.Used)
printer.V("partly used packs: %10d\n", stats.Packs.PartlyUsed) printer.V("partly used packs: %10d\n", stats.Packs.PartlyUsed)

View file

@ -32,32 +32,42 @@ type PruneOptions struct {
type PruneStats struct { type PruneStats struct {
Blobs struct { Blobs struct {
Used uint Used uint `json:"used"`
Duplicate uint Duplicate uint `json:"duplicate"`
Unused uint Unused uint `json:"unused"`
Remove uint Total uint `json:"total"`
Repack uint Repack uint `json:"repack"`
Repackrm uint Repackrm uint `json:"repack_remove"`
} Remove uint `json:"remove"`
RemoveTotal uint `json:"remove_total"`
Remain uint `json:"remaining"`
RemainUnused uint `json:"remaining_unused"`
} `json:"blobs"`
Size struct { Size struct {
Used uint64 Used uint64 `json:"used"`
Duplicate uint64 Duplicate uint64 `json:"duplicate"`
Unused uint64 Unused uint64 `json:"unused"`
Remove uint64 Unref uint64 `json:"unreferenced"`
Repack uint64 Uncompressed uint64 `json:"uncompressed"`
Repackrm uint64 Total uint64 `json:"total"`
Unref uint64 Repack uint64 `json:"repack"`
Uncompressed uint64 Repackrm uint64 `json:"repack_remove"`
} Remove uint64 `json:"remove"`
RemoveTotal uint64 `json:"remove_total"`
Remain uint64 `json:"remaining"`
RemainUnused uint64 `json:"remaining_unused"`
} `json:"bytes"`
Packs struct { Packs struct {
Used uint Used uint `json:"used"`
Unused uint Unused uint `json:"unused"`
PartlyUsed uint PartlyUsed uint `json:"partly_used"`
Unref uint Unref uint `json:"unreferenced"`
Keep uint Total uint `json:"total"`
Repack uint Keep uint `json:"keep"`
Remove uint Repack uint `json:"repack"`
} Remove uint `json:"remove"`
RemoveTotal uint `json:"remove_total"`
} `json:"packfiles"`
} }
type PrunePlan struct { type PrunePlan struct {
@ -141,6 +151,18 @@ func PlanPrune(ctx context.Context, opts PruneOptions, repo *Repository, getUsed
} }
plan.keepBlobs = keepBlobs plan.keepBlobs = keepBlobs
// calculate totals for statistics
stats.Blobs.Total = stats.Blobs.Used + stats.Blobs.Unused + stats.Blobs.Duplicate
stats.Blobs.RemoveTotal = stats.Blobs.Remove + stats.Blobs.Repackrm
stats.Blobs.Remain = stats.Blobs.Total - stats.Blobs.RemoveTotal
stats.Size.Total = stats.Size.Used + stats.Size.Duplicate + stats.Size.Unused + stats.Size.Unref
stats.Size.Unused = stats.Size.Duplicate + stats.Size.Unused
stats.Size.RemoveTotal = stats.Size.Remove + stats.Size.Repackrm + stats.Size.Unref
stats.Size.Remain = stats.Size.Total - stats.Size.RemoveTotal
stats.Size.RemainUnused = stats.Size.Unused - stats.Size.Remove - stats.Size.Repackrm
stats.Packs.Total = stats.Packs.Used + stats.Packs.PartlyUsed + stats.Packs.Unused + stats.Packs.Unref
stats.Packs.RemoveTotal = stats.Packs.Unref + stats.Packs.Remove
plan.repo = repo plan.repo = repo
plan.stats = stats plan.stats = stats
plan.opts = opts plan.opts = opts