Skip to content

Commit

Permalink
cache: print cache for easier debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
emranemran committed Oct 20, 2022
1 parent dfffccd commit 86806ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion cache/segmenting.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package cache

import (
"sync"

"github.com/kylelemons/godebug/pretty"
)

type SegmentingCache struct {
Expand All @@ -22,6 +24,7 @@ func (c *SegmentingCache) Remove(streamName string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.cache, streamName)
c.debugPrint("remove", streamName)
}

func (c *SegmentingCache) GetCallbackUrl(streamName string) string {
Expand All @@ -46,6 +49,7 @@ func (c *SegmentingCache) Get(streamName string) StreamInfo {

func (c *SegmentingCache) Store(streamName string, streamInfo StreamInfo) {
c.mutex.Lock()
defer c.mutex.Unlock()
c.cache[streamName] = StreamInfo{
SourceFile: streamInfo.SourceFile,
CallbackURL: streamInfo.CallbackURL,
Expand All @@ -54,5 +58,10 @@ func (c *SegmentingCache) Store(streamName string, streamInfo StreamInfo) {
TranscodeAPIUrl: streamInfo.TranscodeAPIUrl,
HardcodedBroadcasters: streamInfo.HardcodedBroadcasters,
}
c.mutex.Unlock()
c.debugPrint("add", streamName)
}

func (c *SegmentingCache) debugPrint(action, streamName string) {
var id string = action + " " + streamName + ": SegmentingCache"
pretty.Print(id, c.cache)
}
10 changes: 9 additions & 1 deletion cache/transcoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"sync"
"time"

"github.com/kylelemons/godebug/pretty"
"github.com/livepeer/catalyst-api/clients"
"github.com/livepeer/catalyst-api/config"
)
Expand Down Expand Up @@ -114,6 +115,7 @@ func (c *TranscodingCache) Remove(streamName string) {
c.mutex.Lock()
defer c.mutex.Unlock()
delete(c.pushes, streamName)
c.debugPrint("remove", streamName)
}

func (c *TranscodingCache) Get(streamName string) *SegmentInfo {
Expand All @@ -134,7 +136,13 @@ func (c *TranscodingCache) GetAll() map[string]*SegmentInfo {

func (c *TranscodingCache) Store(streamName string, info SegmentInfo) {
c.mutex.Lock()
defer c.mutex.Unlock()
info.updatedAt = time.Now()
c.pushes[streamName] = &info
c.mutex.Unlock()
c.debugPrint("add", streamName)
}

func (c *TranscodingCache) debugPrint(action, streamName string) {
var id string = action + " " + streamName + ": TranscodingCache"
pretty.Print(id, c.pushes)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require (
github.com/hashicorp/go-memdb v1.3.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/jmespath/go-jmespath v0.4.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfn
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/livepeer/go-tools v0.0.0-20220926110222-2ebcbb5685b4 h1:xsXgYoJ7GL1Vpg20cqZB06BDgNCc0qVxEip9ZcaeiPA=
github.com/livepeer/go-tools v0.0.0-20220926110222-2ebcbb5685b4/go.mod h1:aLVS1DT0ur9kpr0IlNI4DNcm9vVjRRUjDnwuEUm0BdQ=
github.com/livepeer/livepeer-data v0.4.22 h1:7XMnGFfxBXWiwB4QC5doiNrxEqV4vzORhYpB+ZDnUv8=
Expand Down

0 comments on commit 86806ee

Please sign in to comment.