Skip to content

Commit

Permalink
Add debugging helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
1lann committed Jul 10, 2016
1 parent 8a7f12b commit 05c3c6f
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
85 changes: 85 additions & 0 deletions debugger/debugger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package main

import (
"bytes"
"fmt"
"os"
"strconv"
"time"

"github.com/1lann/lol-replay/recording"
)

func main() {
if len(os.Args) < 2 {
fmt.Println("GLR File Debugger")
fmt.Println("This utility dumps information for debugging recordings")
fmt.Println("Usage: " + os.Args[0] + " recording.glr")
return
}

file, err := os.OpenFile(os.Args[1], os.O_RDWR, 0666)
if err != nil {
fmt.Println("failed to open file:", err)
return
}

rec, err := recording.NewRecording(file)
if err != nil {
fmt.Println("failed to read recording:", err)
file.Close()
return
}

fmt.Println("--- Recording properties ---")
fmt.Println("Has game metadata:", rec.HasGameMetadata())
fmt.Println("Has user metadata:", rec.HasUserMetadata())
fmt.Println("Is recording complete:", rec.IsComplete())
fmt.Println("")

fmt.Println("--- Game information ---")
gameInfo := rec.RetrieveGameInfo()
fmt.Println("Platform:", gameInfo.Platform)
fmt.Println("Game version:", gameInfo.Version)
fmt.Println("Record time", gameInfo.RecordTime.Format(time.RFC1123Z))
fmt.Println("Encryption key:", gameInfo.EncryptionKey)
fmt.Println("")

buf := new(bytes.Buffer)

fmt.Println("--- Metadata information ---")
rec.RetrieveGameMetadataTo(buf)
fmt.Println(buf.String())

fmt.Println("--- Chunk information ---")
buf.Reset()
rec.RetrieveFirstChunkInfo().WriteTo(buf)
fmt.Println("First chunk information:")
fmt.Println(buf.String())
buf.Reset()
rec.RetrieveLastChunkInfo().WriteTo(buf)
fmt.Println("Last chunk information:")
fmt.Println(buf.String())
fmt.Println("")

fmt.Println("--- Chunk and key frame data ---")
fmt.Println("Chunks found:")
for i := 0; i < 1000; i++ {
if rec.HasChunk(i) {
buf.Reset()
rec.RetrieveChunkTo(i, buf)
fmt.Println(" " + strconv.Itoa(i) + ": size: " + strconv.Itoa(buf.Len()))
}
}

fmt.Println("Key frames found:")
for i := 0; i < 1000; i++ {
if rec.HasKeyFrame(i) {
buf.Reset()
rec.RetrieveKeyFrameTo(i, buf)
fmt.Println(" " + strconv.Itoa(i) + ": size: " + strconv.Itoa(buf.Len()))
}
}
fmt.Println("")
fmt.Println("--- End of report ---")
}
31 changes: 31 additions & 0 deletions record/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ package record

import (
"bytes"
"log"
"os"
"time"

"github.com/1lann/lol-replay/recording"
Expand Down Expand Up @@ -32,6 +34,8 @@ type recorder struct {
gaps bool
}

var showDebug = os.Getenv("GLR_DEBUG") != ""

// Record starts a new recording that writes into a *recording.Recording
// and blocks until the recording ends or an error occurs. Note that partial
// data may be written to the recording, even if the recording was
Expand Down Expand Up @@ -73,10 +77,22 @@ func Record(platform, gameID, encryptionKey string,
return err
}

if showDebug {
log.Println("recording game " + gameID + " on platform " + platform +
" on version " + version + " with encryption key " + encryptionKey)
}

if err := thisRecorder.waitForFirstChunk(); err != nil {
if showDebug {
log.Println("waitForFirstChunk error:", err)
}
return err
}

if showDebug {
log.Println("got first chunk")
}

if err := thisRecorder.recordFrames(resumption); err != nil {
return err
}
Expand All @@ -94,6 +110,10 @@ func Record(platform, gameID, encryptionKey string,
}

func (r *recorder) getStartupFrames(meta metadata) error {
if showDebug {
log.Println("getting startup chunks to", meta.StartupChunk)
}

// Get the startup frames
for i := 1; i <= meta.StartupChunk; i++ {
for {
Expand Down Expand Up @@ -182,6 +202,13 @@ func (r *recorder) handleResumption(chunk recording.ChunkInfo) {

func (r *recorder) storeChunksAndFrames(chunk recording.ChunkInfo, lastChunkID,
firstChunkID, lastKeyFrame, firstKeyFrame int) error {

if showDebug {
log.Println("storeChunksAndFrames lastChunkID:", lastChunkID,
"firstChunkID:", firstChunkID, "lastKeyFrame:", lastKeyFrame,
"firstKeyFrame:", firstKeyFrame)
}

if chunk.CurrentChunk > lastChunkID {
for i := lastChunkID + 1; i <= chunk.CurrentChunk; i++ {
if err := r.storeChunk(i); err != nil {
Expand Down Expand Up @@ -258,6 +285,10 @@ func (r *recorder) recordFrames(resumption bool) error {
lastChunkID = chunk.CurrentChunk
lastKeyFrame = chunk.CurrentKeyFrame

if showDebug {
log.Println("resuming recording")
}

r.handleResumption(chunk)

resumption = false
Expand Down
9 changes: 9 additions & 0 deletions record/retrieve.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io"
"io/ioutil"
"log"
"net/http"
"strconv"
"time"
Expand Down Expand Up @@ -132,6 +133,10 @@ func (r *recorder) storeChunk(frame int) error {
return nil
}

if showDebug {
log.Println("getting chunk:", frame)
}

resp, err := requestURL(r.platformURL +
"/observer-mode/rest/consumer/getGameDataChunk/" + r.platform + "/" +
r.gameID + "/" + strconv.Itoa(frame) + "/token")
Expand All @@ -154,6 +159,10 @@ func (r *recorder) storeKeyFrame(frame int) error {
return nil
}

if showDebug {
log.Println("getting key frame:", frame)
}

resp, err := requestURL(r.platformURL +
"/observer-mode/rest/consumer/getKeyFrame/" + r.platform + "/" +
r.gameID + "/" + strconv.Itoa(frame) + "/token")
Expand Down
4 changes: 4 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ func main() {
loadRecordings(dir, config.RecordingsDirectory)
}

if len(config.Players) == 0 {
log.Fatal("you cannot start the server without any monitored players")
}

internal := &internalServer{replay.Router(retrieve)}

c := make(chan os.Signal, 1)
Expand Down

0 comments on commit 05c3c6f

Please sign in to comment.