mirror of
https://github.com/celogeek/go-comic-converter.git
synced 2025-05-24 15:52:38 +02:00
add memory usage
This commit is contained in:
parent
a254fc446f
commit
fc6885fabc
60
main.go
60
main.go
@ -6,6 +6,7 @@ import (
|
|||||||
"go-comic-converter/internal/epub"
|
"go-comic-converter/internal/epub"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -53,14 +54,15 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Option struct {
|
type Option struct {
|
||||||
Input string
|
Input string
|
||||||
Output string
|
Output string
|
||||||
Profile string
|
Profile string
|
||||||
Author string
|
Author string
|
||||||
Title string
|
Title string
|
||||||
Quality int
|
Quality int
|
||||||
NoCrop bool
|
NoCrop bool
|
||||||
LimitMb int
|
LimitMb int
|
||||||
|
PrintMem bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Option) String() string {
|
func (o *Option) String() string {
|
||||||
@ -80,14 +82,15 @@ func (o *Option) String() string {
|
|||||||
return fmt.Sprintf(`Go Comic Converter
|
return fmt.Sprintf(`Go Comic Converter
|
||||||
|
|
||||||
Options:
|
Options:
|
||||||
Input : %s
|
Input : %s
|
||||||
Output : %s
|
Output : %s
|
||||||
Profile: %s - %s - %dx%d
|
Profile : %s - %s - %dx%d
|
||||||
Author : %s
|
Author : %s
|
||||||
Title : %s
|
Title : %s
|
||||||
Quality: %d
|
Quality : %d
|
||||||
Crop : %v
|
Crop : %v
|
||||||
LimitMb: %s
|
LimitMb : %s
|
||||||
|
PrintMem: %v
|
||||||
`,
|
`,
|
||||||
o.Input,
|
o.Input,
|
||||||
o.Output,
|
o.Output,
|
||||||
@ -100,6 +103,27 @@ Options:
|
|||||||
o.Quality,
|
o.Quality,
|
||||||
!o.NoCrop,
|
!o.NoCrop,
|
||||||
limitmb,
|
limitmb,
|
||||||
|
o.PrintMem,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
func PrintMemUsage() {
|
||||||
|
var m runtime.MemStats
|
||||||
|
runtime.ReadMemStats(&m)
|
||||||
|
|
||||||
|
bToMb := func(b uint64) uint64 { return b / 1024 / 1024 }
|
||||||
|
|
||||||
|
// For info on each, see: https://golang.org/pkg/runtime/#MemStats
|
||||||
|
fmt.Printf(`Memory Usage:
|
||||||
|
Alloc : %v MiB
|
||||||
|
TotalAlloc: %v MiB
|
||||||
|
Sys : %v MiB
|
||||||
|
NumGC : %v
|
||||||
|
`,
|
||||||
|
bToMb(m.Alloc),
|
||||||
|
bToMb(m.TotalAlloc),
|
||||||
|
bToMb(m.Sys),
|
||||||
|
m.NumGC,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +147,7 @@ func main() {
|
|||||||
flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image")
|
flag.IntVar(&opt.Quality, "quality", 85, "Quality of the image")
|
||||||
flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping")
|
flag.BoolVar(&opt.NoCrop, "nocrop", false, "Disable cropping")
|
||||||
flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
flag.IntVar(&opt.LimitMb, "limitmb", 0, "Limit size of the ePub: Default nolimit (0), Minimum 20")
|
||||||
|
flag.BoolVar(&opt.PrintMem, "printmem", false, "Print memory usage")
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
if opt.Input == "" {
|
if opt.Input == "" {
|
||||||
@ -183,5 +208,8 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if opt.PrintMem {
|
||||||
|
PrintMemUsage()
|
||||||
|
}
|
||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user