mirror of
https://github.com/rclone/rclone.git
synced 2024-12-23 07:29:35 +01:00
test: consider global option for printing human-readable sizes and avoid unsigned integer overflow
This commit is contained in:
parent
8c4b06da79
commit
8500d95579
@ -24,6 +24,7 @@ var commandDefinition = &cobra.Command{
|
|||||||
fsrc := cmd.NewFsSrc(args)
|
fsrc := cmd.NewFsSrc(args)
|
||||||
cmd.Run(false, false, command, func() error {
|
cmd.Run(false, false, command, func() error {
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
ci := fs.GetConfig(context.Background())
|
||||||
objects, _, err := operations.Count(ctx, fsrc)
|
objects, _, err := operations.Count(ctx, fsrc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -43,9 +44,52 @@ var commandDefinition = &cobra.Command{
|
|||||||
}
|
}
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
runtime.ReadMemStats(&after)
|
runtime.ReadMemStats(&after)
|
||||||
usedMemory := after.Alloc - before.Alloc
|
var allocChange int64
|
||||||
fs.Logf(nil, "%d objects took %d bytes, %.1f bytes/object", len(objs), usedMemory, float64(usedMemory)/float64(len(objs)))
|
if after.Alloc >= before.Alloc {
|
||||||
fs.Logf(nil, "System memory changed from %d to %d bytes a change of %d bytes", before.Sys, after.Sys, after.Sys-before.Sys)
|
allocChange = int64(after.Alloc - before.Alloc)
|
||||||
|
} else {
|
||||||
|
allocChange = -int64(before.Alloc - after.Alloc)
|
||||||
|
}
|
||||||
|
var sysChange int64
|
||||||
|
if after.Sys >= before.Sys {
|
||||||
|
sysChange = int64(after.Sys - before.Sys)
|
||||||
|
} else {
|
||||||
|
sysChange = -int64(before.Sys - after.Sys)
|
||||||
|
}
|
||||||
|
if ci.HumanReadable {
|
||||||
|
objString := fs.CountSuffix(int64(len(objs)))
|
||||||
|
var usedString string
|
||||||
|
if after.Alloc >= before.Alloc {
|
||||||
|
usedString = fs.SizeSuffix(int64(after.Alloc - before.Alloc)).ByteUnit()
|
||||||
|
} else {
|
||||||
|
usedString = "-" + fs.SizeSuffix(int64(before.Alloc-after.Alloc)).ByteUnit()
|
||||||
|
}
|
||||||
|
avgString := fs.SizeSuffix(allocChange / int64(len(objs))).ByteUnit()
|
||||||
|
fs.Logf(nil, "%s objects took %s, %s/object", objString, usedString, avgString)
|
||||||
|
|
||||||
|
var sysBeforeString string
|
||||||
|
if before.Sys <= fs.SizeSuffixMaxValue {
|
||||||
|
sysBeforeString = fs.SizeSuffix(int64(before.Sys)).String()
|
||||||
|
} else {
|
||||||
|
sysBeforeString = ">" + fs.SizeSuffixMax.String()
|
||||||
|
}
|
||||||
|
var sysAfterString string
|
||||||
|
if after.Sys <= fs.SizeSuffixMaxValue {
|
||||||
|
sysAfterString = fs.SizeSuffix(int64(after.Sys)).ByteUnit()
|
||||||
|
} else {
|
||||||
|
sysAfterString = ">" + fs.SizeSuffixMax.ByteUnit()
|
||||||
|
}
|
||||||
|
var sysUsedString string
|
||||||
|
if after.Sys >= before.Sys {
|
||||||
|
sysUsedString = fs.SizeSuffix(int64(after.Sys - before.Sys)).ByteUnit()
|
||||||
|
} else {
|
||||||
|
sysUsedString = "-" + fs.SizeSuffix(int64(before.Sys-after.Sys)).ByteUnit()
|
||||||
|
}
|
||||||
|
fs.Logf(nil, "System memory changed from %s to %s a change of %s", sysBeforeString, sysAfterString, sysUsedString)
|
||||||
|
} else {
|
||||||
|
fs.Logf(nil, "%d objects took %d bytes, %.1f bytes/object", len(objs), allocChange, float64(allocChange)/float64(len(objs)))
|
||||||
|
fs.Logf(nil, "System memory changed from %d to %d bytes a change of %d bytes", before.Sys, after.Sys, sysChange)
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user