Skip to content

Commit

Permalink
Add a global option to print memory usage
Browse files Browse the repository at this point in the history
This option, -print-memory-usage, will print memory usage every second while
the program is running.
  • Loading branch information
gilbertchen committed Oct 16, 2021
1 parent cacf661 commit 68b6049
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
8 changes: 8 additions & 0 deletions duplicacy/duplicacy_main.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func setGlobalOptions(context *cli.Context) {
duplicacy.SetLoggingLevel(duplicacy.DEBUG)
}

if context.GlobalBool("print-memory-usage") {
go duplicacy.PrintMemoryUsage()
}

ScriptEnabled = true
if context.GlobalBool("no-script") {
ScriptEnabled = false
Expand Down Expand Up @@ -2180,6 +2184,10 @@ func main() {
Usage: "suppress logs with the specified id",
Argument: "<id>",
},
cli.BoolFlag{
Name: "print-memory-usage",
Usage: "print memory usage every second",
},
}

app.HideVersion = true
Expand Down
14 changes: 14 additions & 0 deletions src/duplicacy_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"strconv"
"strings"
"time"
"runtime"

"github.com/gilbertchen/gopass"
"golang.org/x/crypto/pbkdf2"
Expand Down Expand Up @@ -460,3 +461,16 @@ func AtoSize(sizeString string) int {

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)
}
}

1 comment on commit 68b6049

@gilbertchen
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commit has been mentioned on Duplicacy Forum. There might be relevant details there:

https://forum.duplicacy.com/t/duplicacy-killed-during-copy/5213/8

Please sign in to comment.