mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-15 07:43:21 +00:00
restored original stats output, enabled option to switch to tabular
This commit is contained in:
@@ -896,90 +896,145 @@ func (manager *SnapshotManager) CheckSnapshots(snapshotID string, revisionsToChe
|
|||||||
snapshotIDIndex += 1
|
snapshotIDIndex += 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if showTabular {
|
||||||
|
manager.ShowStatisticsTabular(snapshotMap, chunkSizeMap, chunkUniqueMap, chunkSnapshotMap)
|
||||||
|
} else if showStatistics {
|
||||||
|
manager.ShowStatistics(snapshotMap, chunkSizeMap, chunkUniqueMap, chunkSnapshotMap)
|
||||||
|
}
|
||||||
|
|
||||||
if showStatistics {
|
return true
|
||||||
tableBuffer := new(bytes.Buffer)
|
}
|
||||||
tableWriter := tabwriter.NewWriter(tableBuffer, 0, 0, 1, ' ', tabwriter.AlignRight|tabwriter.Debug)
|
|
||||||
|
|
||||||
for snapshotID, snapshotList := range snapshotMap {
|
// Print snapshot and revision statistics
|
||||||
fmt.Fprintln(tableWriter, "")
|
func (manager *SnapshotManager) ShowStatistics(snapshotMap map[string] [] *Snapshot, chunkSizeMap map[string]int64, chunkUniqueMap map[string]bool,
|
||||||
fmt.Fprintln(tableWriter, " snap \trev \t \tfiles \tbytes \tchunks \tbytes \tuniq \tbytes \tnew \tbytes \t")
|
chunkSnapshotMap map[string]int) {
|
||||||
snapshotChunks := make(map[string]bool)
|
for snapshotID, snapshotList := range snapshotMap {
|
||||||
|
|
||||||
earliestSeenChunks := make(map[string]int)
|
snapshotChunks := make(map[string]bool)
|
||||||
|
|
||||||
for _, snapshot := range snapshotList {
|
for _, snapshot := range snapshotList {
|
||||||
for _, chunkID := range manager.GetSnapshotChunks(snapshot) {
|
|
||||||
if earliestSeenChunks[chunkID] == 0 {
|
chunks := make(map[string]bool)
|
||||||
earliestSeenChunks[chunkID] = math.MaxInt64
|
for _, chunkID := range manager.GetSnapshotChunks(snapshot) {
|
||||||
}
|
chunks[chunkID] = true
|
||||||
earliestSeenChunks[chunkID] = MinInt(earliestSeenChunks[chunkID], snapshot.Revision)
|
snapshotChunks[chunkID] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var totalChunkSize int64
|
||||||
|
var uniqueChunkSize int64
|
||||||
|
|
||||||
|
for chunkID, _ := range chunks {
|
||||||
|
chunkSize := chunkSizeMap[chunkID]
|
||||||
|
totalChunkSize += chunkSize
|
||||||
|
if chunkUniqueMap[chunkID] {
|
||||||
|
uniqueChunkSize += chunkSize
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, snapshot := range snapshotList {
|
files := ""
|
||||||
|
if snapshot.FileSize != 0 && snapshot.NumberOfFiles != 0 {
|
||||||
|
files = fmt.Sprintf("%d files (%s bytes), ", snapshot.NumberOfFiles, PrettyNumber(snapshot.FileSize))
|
||||||
|
}
|
||||||
|
LOG_INFO("SNAPSHOT_CHECK", "Snapshot %s at revision %d: %s%s total chunk bytes, %s unique chunk bytes",
|
||||||
|
snapshot.ID, snapshot.Revision, files, PrettyNumber(totalChunkSize), PrettyNumber(uniqueChunkSize))
|
||||||
|
}
|
||||||
|
|
||||||
chunks := make(map[string]bool)
|
var totalChunkSize int64
|
||||||
for _, chunkID := range manager.GetSnapshotChunks(snapshot) {
|
var uniqueChunkSize int64
|
||||||
chunks[chunkID] = true
|
for chunkID, _ := range snapshotChunks {
|
||||||
snapshotChunks[chunkID] = true
|
chunkSize := chunkSizeMap[chunkID]
|
||||||
|
totalChunkSize += chunkSize
|
||||||
|
|
||||||
|
if chunkSnapshotMap[chunkID] != -1 {
|
||||||
|
uniqueChunkSize += chunkSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
LOG_INFO("SNAPSHOT_CHECK", "Snapshot %s all revisions: %s total chunk bytes, %s unique chunk bytes",
|
||||||
|
snapshotID, PrettyNumber(totalChunkSize), PrettyNumber(uniqueChunkSize))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Print snapshot and revision statistics in tabular format
|
||||||
|
func (manager *SnapshotManager) ShowStatisticsTabular(snapshotMap map[string] [] *Snapshot, chunkSizeMap map[string]int64, chunkUniqueMap map[string]bool,
|
||||||
|
chunkSnapshotMap map[string]int) {
|
||||||
|
tableBuffer := new(bytes.Buffer)
|
||||||
|
tableWriter := tabwriter.NewWriter(tableBuffer, 0, 0, 1, ' ', tabwriter.AlignRight|tabwriter.Debug)
|
||||||
|
|
||||||
|
for snapshotID, snapshotList := range snapshotMap {
|
||||||
|
fmt.Fprintln(tableWriter, "")
|
||||||
|
fmt.Fprintln(tableWriter, " snap \trev \t \tfiles \tbytes \tchunks \tbytes \tuniq \tbytes \tnew \tbytes \t")
|
||||||
|
snapshotChunks := make(map[string]bool)
|
||||||
|
|
||||||
|
earliestSeenChunks := make(map[string]int)
|
||||||
|
|
||||||
|
for _, snapshot := range snapshotList {
|
||||||
|
for _, chunkID := range manager.GetSnapshotChunks(snapshot) {
|
||||||
|
if earliestSeenChunks[chunkID] == 0 {
|
||||||
|
earliestSeenChunks[chunkID] = math.MaxInt64
|
||||||
}
|
}
|
||||||
|
earliestSeenChunks[chunkID] = MinInt(earliestSeenChunks[chunkID], snapshot.Revision)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var totalChunkSize int64
|
for _, snapshot := range snapshotList {
|
||||||
var uniqueChunkSize int64
|
|
||||||
var totalChunkCount int64
|
|
||||||
var uniqueChunkCount int64
|
|
||||||
var newChunkCount int64
|
|
||||||
var newChunkSize int64
|
|
||||||
|
|
||||||
for chunkID, _ := range chunks {
|
chunks := make(map[string]bool)
|
||||||
chunkSize := chunkSizeMap[chunkID]
|
for _, chunkID := range manager.GetSnapshotChunks(snapshot) {
|
||||||
totalChunkSize += chunkSize
|
chunks[chunkID] = true
|
||||||
totalChunkCount += 1
|
snapshotChunks[chunkID] = true
|
||||||
if earliestSeenChunks[chunkID] == snapshot.Revision {
|
|
||||||
newChunkCount += 1
|
|
||||||
newChunkSize += chunkSize
|
|
||||||
}
|
|
||||||
if chunkUniqueMap[chunkID] {
|
|
||||||
uniqueChunkSize += chunkSize
|
|
||||||
uniqueChunkCount += 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
files := " \t "
|
|
||||||
if snapshot.FileSize != 0 && snapshot.NumberOfFiles != 0 {
|
|
||||||
files = fmt.Sprintf("%d \t%s", snapshot.NumberOfFiles, PrettyNumber(snapshot.FileSize))
|
|
||||||
}
|
|
||||||
creationTime := time.Unix(snapshot.StartTime, 0).Format("2006-01-02 15:04")
|
|
||||||
fmt.Fprintln(tableWriter, fmt.Sprintf(
|
|
||||||
"%s \t%d \t@ %s %5s \t%s \t%d \t%s \t%d \t%s \t%d \t%s \t",
|
|
||||||
snapshotID, snapshot.Revision, creationTime, snapshot.Options, files, totalChunkCount, PrettyNumber(totalChunkSize), uniqueChunkCount, PrettyNumber(uniqueChunkSize), newChunkCount, PrettyNumber(newChunkSize)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var totalChunkSize int64
|
var totalChunkSize int64
|
||||||
var uniqueChunkSize int64
|
var uniqueChunkSize int64
|
||||||
var totalChunkCount int64
|
var totalChunkCount int64
|
||||||
var uniqueChunkCount int64
|
var uniqueChunkCount int64
|
||||||
for chunkID, _ := range snapshotChunks {
|
var newChunkCount int64
|
||||||
|
var newChunkSize int64
|
||||||
|
|
||||||
|
for chunkID, _ := range chunks {
|
||||||
chunkSize := chunkSizeMap[chunkID]
|
chunkSize := chunkSizeMap[chunkID]
|
||||||
totalChunkSize += chunkSize
|
totalChunkSize += chunkSize
|
||||||
totalChunkCount += 1
|
totalChunkCount += 1
|
||||||
|
if earliestSeenChunks[chunkID] == snapshot.Revision {
|
||||||
if chunkSnapshotMap[chunkID] != -1 {
|
newChunkCount += 1
|
||||||
|
newChunkSize += chunkSize
|
||||||
|
}
|
||||||
|
if chunkUniqueMap[chunkID] {
|
||||||
uniqueChunkSize += chunkSize
|
uniqueChunkSize += chunkSize
|
||||||
uniqueChunkCount += 1
|
uniqueChunkCount += 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
files := " \t "
|
||||||
|
if snapshot.FileSize != 0 && snapshot.NumberOfFiles != 0 {
|
||||||
|
files = fmt.Sprintf("%d \t%s", snapshot.NumberOfFiles, PrettyNumber(snapshot.FileSize))
|
||||||
|
}
|
||||||
|
creationTime := time.Unix(snapshot.StartTime, 0).Format("2006-01-02 15:04")
|
||||||
fmt.Fprintln(tableWriter, fmt.Sprintf(
|
fmt.Fprintln(tableWriter, fmt.Sprintf(
|
||||||
"%s \tall \t \t \t \t%d \t%s \t%d \t%s \t \t \t",
|
"%s \t%d \t@ %s %5s \t%s \t%d \t%s \t%d \t%s \t%d \t%s \t",
|
||||||
snapshotID, totalChunkCount, PrettyNumber(totalChunkSize), uniqueChunkCount, PrettyNumber(uniqueChunkSize)))
|
snapshotID, snapshot.Revision, creationTime, snapshot.Options, files, totalChunkCount, PrettyNumber(totalChunkSize), uniqueChunkCount, PrettyNumber(uniqueChunkSize), newChunkCount, PrettyNumber(newChunkSize)))
|
||||||
}
|
}
|
||||||
tableWriter.Flush()
|
|
||||||
LOG_INFO("SNAPSHOT_CHECK", tableBuffer.String())
|
var totalChunkSize int64
|
||||||
|
var uniqueChunkSize int64
|
||||||
|
var totalChunkCount int64
|
||||||
|
var uniqueChunkCount int64
|
||||||
|
for chunkID, _ := range snapshotChunks {
|
||||||
|
chunkSize := chunkSizeMap[chunkID]
|
||||||
|
totalChunkSize += chunkSize
|
||||||
|
totalChunkCount += 1
|
||||||
|
|
||||||
|
if chunkSnapshotMap[chunkID] != -1 {
|
||||||
|
uniqueChunkSize += chunkSize
|
||||||
|
uniqueChunkCount += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fmt.Fprintln(tableWriter, fmt.Sprintf(
|
||||||
|
"%s \tall \t \t \t \t%d \t%s \t%d \t%s \t \t \t",
|
||||||
|
snapshotID, totalChunkCount, PrettyNumber(totalChunkSize), uniqueChunkCount, PrettyNumber(uniqueChunkSize)))
|
||||||
}
|
}
|
||||||
|
tableWriter.Flush()
|
||||||
return true
|
LOG_INFO("SNAPSHOT_CHECK", tableBuffer.String())
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ConvertSequence converts a sequence of chunk hashes into a sequence of chunk ids.
|
// ConvertSequence converts a sequence of chunk hashes into a sequence of chunk ids.
|
||||||
|
|||||||
Reference in New Issue
Block a user