1
0
Fork 0
mirror of https://github.com/postmannen/ctrl.git synced 2025-03-05 06:46:48 +00:00

created flags for profiling

This commit is contained in:
postmannen 2024-12-02 07:19:33 +01:00
parent 693e3e9fe5
commit fc2d1da165
3 changed files with 18 additions and 11 deletions

View file

@ -21,20 +21,25 @@ import (
var version string
func main() {
defer profile.Start(profile.BlockProfile).Stop()
//defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
//defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
//defer profile.Start(profile.MemProfile, profile.MemProfileRate(1)).Stop()
c := ctrl.NewConfiguration()
// err := c.CheckFlags(version)
// if err != nil {
// log.Printf("%v\n", err)
// return
// }
// Start profiling if profiling port is specified
if c.ProfilingPort != "" {
switch c.Profiling {
case "block":
defer profile.Start(profile.BlockProfile).Stop()
case "cpu":
defer profile.Start(profile.CPUProfile, profile.ProfilePath(".")).Stop()
case "trace":
defer profile.Start(profile.TraceProfile, profile.ProfilePath(".")).Stop()
case "mem":
defer profile.Start(profile.MemProfile, profile.MemProfileRate(1)).Stop()
default:
log.Fatalf("error: profiling port defined, but no valid profiling type defined. Check --help. Got: %v\n", c.Profiling)
}
go func() {
http.ListenAndServe("localhost:"+c.ProfilingPort, nil)
}()

View file

@ -46,6 +46,8 @@ type Configuration struct {
KeysUpdateInterval int `comment:"KeysUpdateInterval in seconds"`
// AclUpdateInterval in seconds
AclUpdateInterval int `comment:"AclUpdateInterval in seconds"`
// The type of profiling
Profiling string
// The number of the profiling port
ProfilingPort string `comment:"The number of the profiling port"`
// Host and port for prometheus listener, e.g. localhost:2112
@ -163,6 +165,7 @@ func NewConfiguration() *Configuration {
flag.IntVar(&c.NatsReconnectJitterTLS, "natsReconnectJitterTLS", CheckEnv("NATS_RECONNECT_JITTER_TLS", c.NatsReconnectJitterTLS).(int), "default nats ReconnectJitterTLS interval in seconds.")
flag.IntVar(&c.KeysUpdateInterval, "keysUpdateInterval", CheckEnv("KEYS_UPDATE_INTERVAL", c.KeysUpdateInterval).(int), "default interval in seconds for asking the central for public keys")
flag.IntVar(&c.AclUpdateInterval, "aclUpdateInterval", CheckEnv("ACL_UPDATE_INTERVAL", c.AclUpdateInterval).(int), "default interval in seconds for asking the central for acl updates")
flag.StringVar(&c.Profiling, "profiling", CheckEnv("PROFILING", c.Profiling).(string), "type of profiling: cpu/block/trace/mem/heap")
flag.StringVar(&c.ProfilingPort, "profilingPort", CheckEnv("PROFILING_PORT", c.ProfilingPort).(string), "The number of the profiling port")
flag.StringVar(&c.PromHostAndPort, "promHostAndPort", CheckEnv("PROM_HOST_AND_PORT", c.PromHostAndPort).(string), "host and port for prometheus listener, e.g. localhost:2112")
flag.StringVar(&c.JetstreamsConsume, "jetstreamsConsume", CheckEnv("JETSTREAMS_CONSUME", c.JetstreamsConsume).(string), "Comma separated list of Jetstrams to consume from")
@ -240,6 +243,7 @@ func newConfigurationDefaults() Configuration {
NatsReconnectJitterTLS: 1,
KeysUpdateInterval: 60,
AclUpdateInterval: 60,
Profiling: "",
ProfilingPort: "",
PromHostAndPort: "",
JetstreamsConsume: "",

View file

@ -368,8 +368,6 @@ func (s *server) readFolder() {
}
fh.Close()
fmt.Printf("------- DEBUG: %v\n", b)
b = bytes.Trim(b, "\x00")
// unmarshal the JSON into a struct