diff --git a/debug/debug.go b/debug/debug.go deleted file mode 100644 index eaf18012..00000000 --- a/debug/debug.go +++ /dev/null @@ -1,2 +0,0 @@ -// Package debug provides interfaces for service debugging -package debug diff --git a/debug/stats/memory/memory.go b/debug/stats/memory/memory.go deleted file mode 100644 index 7c63c7ca..00000000 --- a/debug/stats/memory/memory.go +++ /dev/null @@ -1,89 +0,0 @@ -package stats - -import ( - "runtime" - "sync" - "time" - - "github.com/unistack-org/micro/v3/debug/stats" - "github.com/unistack-org/micro/v3/util/ring" -) - -type memoryStats struct { - // used to store past stats - buffer *ring.Buffer - - sync.RWMutex - started int64 - requests uint64 - errors uint64 -} - -func (s *memoryStats) snapshot() *stats.Stat { - s.RLock() - defer s.RUnlock() - - var mstat runtime.MemStats - runtime.ReadMemStats(&mstat) - - now := time.Now().Unix() - - return &stats.Stat{ - Timestamp: now, - Started: s.started, - Uptime: now - s.started, - Memory: mstat.Alloc, - GC: mstat.PauseTotalNs, - Threads: uint64(runtime.NumGoroutine()), - Requests: s.requests, - Errors: s.errors, - } -} - -func (s *memoryStats) Read() ([]*stats.Stat, error) { - buf := s.buffer.Get(s.buffer.Size()) - var buffer []*stats.Stat - - // get a value from the buffer if it exists - for _, b := range buf { - stat, ok := b.Value.(*stats.Stat) - if !ok { - continue - } - buffer = append(buffer, stat) - } - - // get a snapshot - buffer = append(buffer, s.snapshot()) - - return buffer, nil -} - -func (s *memoryStats) Write(stat *stats.Stat) error { - s.buffer.Put(stat) - return nil -} - -func (s *memoryStats) Record(err error) error { - s.Lock() - defer s.Unlock() - - // increment the total request count - s.requests++ - - // increment the error count - if err != nil { - s.errors++ - } - - return nil -} - -// NewStats returns a new in memory stats buffer -// TODO add options -func NewStats() stats.Stats { - return &memoryStats{ - started: time.Now().Unix(), - buffer: ring.New(1), - } -} diff --git a/debug/stats/stats.go b/debug/stats/stats.go deleted file mode 100644 index 7c714c56..00000000 --- a/debug/stats/stats.go +++ /dev/null @@ -1,32 +0,0 @@ -// Package stats provides runtime stats -package stats - -// Stats provides stats interface -type Stats interface { - // Read stat snapshot - Read() ([]*Stat, error) - // Write a stat snapshot - Write(*Stat) error - // Record a request - Record(error) error -} - -// A runtime stat -type Stat struct { - // Timestamp of recording - Timestamp int64 - // Start time as unix timestamp - Started int64 - // Uptime in seconds - Uptime int64 - // Memory usage in bytes - Memory uint64 - // Threads aka go routines - Threads uint64 - // Garbage collection in nanoseconds - GC uint64 - // Total requests - Requests uint64 - // Total errors - Errors uint64 -} diff --git a/debug/profile/http/http.go b/profiler/http/http.go similarity index 100% rename from debug/profile/http/http.go rename to profiler/http/http.go diff --git a/debug/profile/pprof/pprof.go b/profiler/pprof/pprof.go similarity index 100% rename from debug/profile/pprof/pprof.go rename to profiler/pprof/pprof.go diff --git a/debug/profile/profile.go b/profiler/profile.go similarity index 100% rename from debug/profile/profile.go rename to profiler/profile.go