photoprism/internal/config/runtime.go
Michael Mayer 1c53a565a7 Configure on-demand rendering of regular thumbnail sizes #294
Can be enabled by setting PHOTOPRISM_RESAMPLE_UNCACHED to true

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
2020-05-05 15:42:54 +02:00

38 lines
930 B
Go

package config
import (
"fmt"
"runtime"
"github.com/dustin/go-humanize"
)
// RuntimeInfo represents memory and cpu usage statistics.
type RuntimeInfo struct {
Cores int `json:"cores"`
Routines int `json:"routines"`
Memory struct {
Used uint64 `json:"used"`
Reserved uint64 `json:"reserved"`
Info string `json:"info"`
} `json:"memory"`
}
// NewRuntimeInfo returns a new RuntimeInfo instance.
func NewRuntimeInfo() (r RuntimeInfo) {
r = RuntimeInfo{}
r.Refresh()
return r
}
// Refresh updates runtime info values like number of goroutines and memory usage.
func (r *RuntimeInfo) Refresh() {
r.Cores = runtime.NumCPU()
r.Routines = runtime.NumGoroutine()
var mem runtime.MemStats
runtime.ReadMemStats(&mem)
r.Memory.Used = mem.Alloc
r.Memory.Reserved = mem.Sys
r.Memory.Info = fmt.Sprintf("Used %s / Reserved %s", humanize.Bytes(r.Memory.Used), humanize.Bytes(r.Memory.Reserved))
}