mirror of
https://github.com/jkl1337/duplicacy.git
synced 2026-01-06 21:54:38 -06:00
Add a global option to print memory usage
This option, -print-memory-usage, will print memory usage every second while the program is running.
This commit is contained in:
@@ -147,6 +147,10 @@ func setGlobalOptions(context *cli.Context) {
|
|||||||
duplicacy.SetLoggingLevel(duplicacy.DEBUG)
|
duplicacy.SetLoggingLevel(duplicacy.DEBUG)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if context.GlobalBool("print-memory-usage") {
|
||||||
|
go duplicacy.PrintMemoryUsage()
|
||||||
|
}
|
||||||
|
|
||||||
ScriptEnabled = true
|
ScriptEnabled = true
|
||||||
if context.GlobalBool("no-script") {
|
if context.GlobalBool("no-script") {
|
||||||
ScriptEnabled = false
|
ScriptEnabled = false
|
||||||
@@ -2180,6 +2184,10 @@ func main() {
|
|||||||
Usage: "suppress logs with the specified id",
|
Usage: "suppress logs with the specified id",
|
||||||
Argument: "<id>",
|
Argument: "<id>",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "print-memory-usage",
|
||||||
|
Usage: "print memory usage every second",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
app.HideVersion = true
|
app.HideVersion = true
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
"github.com/gilbertchen/gopass"
|
"github.com/gilbertchen/gopass"
|
||||||
"golang.org/x/crypto/pbkdf2"
|
"golang.org/x/crypto/pbkdf2"
|
||||||
@@ -460,3 +461,16 @@ func AtoSize(sizeString string) int {
|
|||||||
|
|
||||||
return size
|
return size
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PrintMemoryUsage() {
|
||||||
|
|
||||||
|
for {
|
||||||
|
var m runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&m)
|
||||||
|
|
||||||
|
LOG_INFO("MEMORY_STATS", "Currently allocated: %s, total allocated: %s, system memory: %s, number of GCs: %d",
|
||||||
|
PrettySize(int64(m.Alloc)), PrettySize(int64(m.TotalAlloc)), PrettySize(int64(m.Sys)), m.NumGC)
|
||||||
|
|
||||||
|
time.Sleep(time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user