From af63360079bb9b365196c9287f26e42928d7c10a Mon Sep 17 00:00:00 2001 From: aler9 <46489434+aler9@users.noreply.github.com> Date: Thu, 28 Oct 2021 17:33:43 +0200 Subject: [PATCH] remove count of readers and publishers from log lines --- internal/core/core.go | 24 +----------------------- internal/core/path.go | 21 +-------------------- internal/core/path_manager.go | 4 ---- internal/core/stats.go | 23 ----------------------- 4 files changed, 2 insertions(+), 70 deletions(-) delete mode 100644 internal/core/stats.go diff --git a/internal/core/core.go b/internal/core/core.go index 3c951592..cd18c319 100644 --- a/internal/core/core.go +++ b/internal/core/core.go @@ -5,7 +5,6 @@ import ( "fmt" "os" "reflect" - "sync/atomic" "github.com/aler9/gortsplib" "github.com/gin-gonic/gin" @@ -26,7 +25,6 @@ type Core struct { confPath string conf *conf.Conf confFound bool - stats *stats logger *logger.Logger metrics *metrics pprof *pprof @@ -118,12 +116,7 @@ func (p *Core) Wait() { // Log is the main logging function. func (p *Core) Log(level logger.Level, format string, args ...interface{}) { - countPublishers := atomic.LoadInt64(p.stats.CountPublishers) - countReaders := atomic.LoadInt64(p.stats.CountReaders) - - p.logger.Log(level, "[%d/%d] "+format, append([]interface{}{ - countPublishers, countReaders, - }, args...)...) + p.logger.Log(level, format, args...) } func (p *Core) run() { @@ -180,10 +173,6 @@ outer: func (p *Core) createResources(initial bool) error { var err error - if p.stats == nil { - p.stats = newStats() - } - if p.logger == nil { p.logger, err = logger.New( logger.Level(p.conf.LogLevel), @@ -232,7 +221,6 @@ func (p *Core) createResources(initial bool) error { p.conf.ReadBufferCount, p.conf.ReadBufferSize, p.conf.Paths, - p.stats, p.metrics, p) } @@ -367,11 +355,6 @@ func (p *Core) createResources(initial bool) error { } func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { - closeStats := false - if newConf == nil { - closeStats = true - } - closeLogger := false if newConf == nil || !reflect.DeepEqual(newConf.LogDestinations, p.conf.LogDestinations) || @@ -400,7 +383,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { newConf.WriteTimeout != p.conf.WriteTimeout || newConf.ReadBufferCount != p.conf.ReadBufferCount || newConf.ReadBufferSize != p.conf.ReadBufferSize || - closeStats || closeMetrics { closePathManager = true } else if !reflect.DeepEqual(newConf.Paths, p.conf.Paths) { @@ -538,10 +520,6 @@ func (p *Core) closeResources(newConf *conf.Conf, calledByAPI bool) { p.logger.Close() p.logger = nil } - - if closeStats && p.stats != nil { - p.stats.close() - } } func (p *Core) reloadConf(newConf *conf.Conf, calledByAPI bool) error { diff --git a/internal/core/path.go b/internal/core/path.go index 8f3de98c..3db122c3 100644 --- a/internal/core/path.go +++ b/internal/core/path.go @@ -6,7 +6,6 @@ import ( "net" "strings" "sync" - "sync/atomic" "time" "github.com/aler9/gortsplib" @@ -190,7 +189,6 @@ type path struct { conf *conf.PathConf name string wg *sync.WaitGroup - stats *stats parent pathParent ctx context.Context @@ -234,7 +232,6 @@ func newPath( conf *conf.PathConf, name string, wg *sync.WaitGroup, - stats *stats, parent pathParent) *path { ctx, ctxCancel := context.WithCancel(parentCtx) @@ -248,7 +245,6 @@ func newPath( conf: conf, name: name, wg: wg, - stats: stats, parent: parent, ctx: ctx, ctxCancel: ctxCancel, @@ -431,10 +427,7 @@ outer: req.Res <- pathReaderSetupPlayRes{Err: fmt.Errorf("terminated")} } - for rp, state := range pa.readers { - if state == pathReaderStatePlay { - atomic.AddInt64(pa.stats.CountReaders, -1) - } + for rp := range pa.readers { rp.close() } @@ -447,9 +440,6 @@ outer: source.close() pa.sourceStaticWg.Wait() } else if source, ok := pa.source.(publisher); ok { - if pa.sourceReady { - atomic.AddInt64(pa.stats.CountPublishers, -1) - } source.close() } } @@ -634,7 +624,6 @@ func (pa *path) doReaderRemove(r reader) { state := pa.readers[r] if state == pathReaderStatePlay { - atomic.AddInt64(pa.stats.CountReaders, -1) pa.stream.readerRemove(r) } @@ -643,8 +632,6 @@ func (pa *path) doReaderRemove(r reader) { func (pa *path) doPublisherRemove() { if pa.sourceReady { - atomic.AddInt64(pa.stats.CountPublishers, -1) - if pa.isOnDemand() && pa.onDemandState != pathOnDemandStateInitial { pa.onDemandCloseSource() } else { @@ -738,8 +725,6 @@ func (pa *path) handlePublisherRecord(req pathPublisherRecordReq) { return } - atomic.AddInt64(pa.stats.CountPublishers, 1) - req.Author.onPublisherAccepted(len(req.Tracks)) pa.sourceSetReady(req.Tracks) @@ -758,8 +743,6 @@ func (pa *path) handlePublisherRecord(req pathPublisherRecordReq) { func (pa *path) handlePublisherPause(req pathPublisherPauseReq) { if req.Author == pa.source && pa.sourceReady { - atomic.AddInt64(pa.stats.CountPublishers, -1) - if pa.isOnDemand() && pa.onDemandState != pathOnDemandStateInitial { pa.onDemandCloseSource() } else { @@ -815,7 +798,6 @@ func (pa *path) handleReaderSetupPlayPost(req pathReaderSetupPlayReq) { } func (pa *path) handleReaderPlay(req pathReaderPlayReq) { - atomic.AddInt64(pa.stats.CountReaders, 1) pa.readers[req.Author] = pathReaderStatePlay pa.stream.readerAdd(req.Author) @@ -827,7 +809,6 @@ func (pa *path) handleReaderPlay(req pathReaderPlayReq) { func (pa *path) handleReaderPause(req pathReaderPauseReq) { if state, ok := pa.readers[req.Author]; ok && state == pathReaderStatePlay { - atomic.AddInt64(pa.stats.CountReaders, -1) pa.readers[req.Author] = pathReaderStatePrePlay pa.stream.readerRemove(req.Author) } diff --git a/internal/core/path_manager.go b/internal/core/path_manager.go index 8e76daea..8153d657 100644 --- a/internal/core/path_manager.go +++ b/internal/core/path_manager.go @@ -27,7 +27,6 @@ type pathManager struct { readBufferCount int readBufferSize int pathConfs map[string]*conf.PathConf - stats *stats metrics *metrics parent pathManagerParent @@ -56,7 +55,6 @@ func newPathManager( readBufferCount int, readBufferSize int, pathConfs map[string]*conf.PathConf, - stats *stats, metrics *metrics, parent pathManagerParent) *pathManager { ctx, ctxCancel := context.WithCancel(parentCtx) @@ -68,7 +66,6 @@ func newPathManager( readBufferCount: readBufferCount, readBufferSize: readBufferSize, pathConfs: pathConfs, - stats: stats, metrics: metrics, parent: parent, ctx: ctx, @@ -285,7 +282,6 @@ func (pm *pathManager) createPath(confName string, conf *conf.PathConf, name str conf, name, &pm.wg, - pm.stats, pm) } diff --git a/internal/core/stats.go b/internal/core/stats.go deleted file mode 100644 index dcef6dd1..00000000 --- a/internal/core/stats.go +++ /dev/null @@ -1,23 +0,0 @@ -package core - -func ptrInt64() *int64 { - v := int64(0) - return &v -} - -type stats struct { - // use pointers to avoid a crash on 32bit platforms - // https://github.com/golang/go/issues/9959 - CountPublishers *int64 - CountReaders *int64 -} - -func newStats() *stats { - return &stats{ - CountPublishers: ptrInt64(), - CountReaders: ptrInt64(), - } -} - -func (s *stats) close() { -}