8000 P2PMatchingReport: rollback timing fields, logged by LBS by inada-s-ai[bot] · Pull Request #438 · inada-s/gdxsv · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 101 additions & 30 deletions gdxsv/lbs_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
pb "google.golang.org/protobuf/proto"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"golang.org/x/mod/semver"
"golang.org/x/text/encoding/japanese"
"golang.org/x/text/width"
Expand Down Expand Up @@ -1815,37 +1816,9 @@ var _ = register(lbsP2PMatchingReport, func(p *LbsPeer, m *LbsMessage) {
spectatorRegistry.Close(report.BattleCode, report.CloseReason, report.DisconnectedPeerId)

if report.CloseReason == "game_end" {
p.logger.Info("P2PMatchingReport",
zap.String("close_reason", report.CloseReason),
zap.String("battle_code", report.BattleCode),
zap.Int32("session_id", report.SessionId),
zap.Int32("player_count", report.PlayerCount),
zap.Int32("peer_id", report.PeerId),
zap.Int32("frame_count", report.FrameCount),
zap.Int32("disconnected_peer_id", report.DisconnectedPeerId),
zap.Float32s("fps_history", report.FpsHistory),
zap.Int32("total_timesync", report.TotalTimesync),
zap.Int32("input_block_count_0", report.InputBlockCount_0),
zap.Int32("input_block_count_1", report.InputBlockCount_1),
zap.Int32("input_block_count_2", report.InputBlockCount_2),
zap.String("before_log", report.BeforeLog),
zap.String("after_log", report.AfterLog))
p.logger.Info("P2PMatchingReport", p2pMatchingReportFields(&report)...)
} else {
p.logger.Warn("P2PMatchingReport",
zap.String("close_reason", report.CloseReason),
zap.String("battle_code", report.BattleCode),
zap.Int32("session_id", report.SessionId),
zap.Int32("player_count", report.PlayerCount),
zap.Int32("peer_id", report.PeerId),
zap.Int32("frame_count", report.FrameCount), 8000
zap.Int32("disconnected_peer_id", report.DisconnectedPeerId),
zap.Float32s("fps_history", report.FpsHistory),
zap.Int32("total_timesync", report.TotalTimesync),
zap.Int32("input_block_count_0", report.InputBlockCount_0),
zap.Int32("input_block_count_1", report.InputBlockCount_1),
zap.Int32("input_block_count_2", report.InputBlockCount_2),
zap.String("before_log", report.BeforeLog),
zap.String("after_log", report.AfterLog))
p.logger.Warn("P2PMatchingReport", p2pMatchingReportFields(&report)...)

if strings.HasPrefix(report.CloseReason, "player_disconnect") && report.PlayerCount == 4 {
WebhookPostSimpleText(fmt.Sprintf(":oncoming_police_car: battle_code:%v %v", report.BattleCode, report.CloseReason))
Expand Down Expand Up @@ -1905,3 +1878,101 @@ var _ = register(lbsP2PMatchingReport, func(p *LbsPeer, m *LbsMessage) {
}
}
})

// p2pMatchingReportFields: the log fields of a report, named as in the proto.
func p2pMatchingReportFields(r *proto.P2PMatchingReport) []zap.Field {
return []zap.Field{
zap.String("close_reason", r.CloseReason),
zap.String("battle_code", r.BattleCode),
zap.Int32("session_id", r.SessionId),
zap.Int32("player_count", r.PlayerCount),
zap.Int32("peer_id", r.PeerId),
zap.Int32("frame_count", r.FrameCount),
zap.Int32("disconnected_peer_id", r.DisconnectedPeerId),
zap.Float32s("fps_history", r.FpsHistory),
zap.Int32("total_timesync", r.TotalTimesync),
zap.Int32("input_block_count_0", r.InputBlockCount_0),
zap.Int32("input_block_count_1", r.InputBlockCount_1),
zap.Int32("input_block_count_2", r.InputBlockCount_2),
zap.String("before_log", r.BeforeLog),
zap.String("after_log", r.AfterLog),
zap.Int32("input_delay", r.InputDelay),
renderSettingsField("render", r.Render),
timingStatsField("socket_read_gap", r.SocketReadGap),
zap.Int32("rollback_count", r.RollbackCount),
zap.Int32s("rollback_depth_hist", r.RollbackDepthHist),
zap.Int32("rollback_max_us", r.RollbackMaxUs),
zap.Int32("late_frames_1", r.LateFrames_1),
zap.Int32("late_frames_1_5", r.LateFrames_1_5),
zap.Int32("late_frames_2", r.LateFrames_2),
zap.Int32("dropped_frames", r.DroppedFrames),
zap.Array("remote_peers", remotePeerReports(r.RemotePeers)),
zap.Int32("relay_forwarded", r.RelayForwarded),
zap.Int32s("timesync_frames", r.TimesyncFrames),
timingStatsField("input_read_interval", r.InputReadInterval),
timingStatsField("input_send_interval", r.InputSendInterval),
timingStatsField("present_interval", r.PresentInterval),
timingStatsField("rollback_budget", r.RollbackBudget),
zap.Int32("budget_exhausted_frames", r.BudgetExhaustedFrames),
zap.Int32s("budget_exhausted_depth_hist", r.BudgetExhaustedDepthHist),
}
}

type timingStatsLog struct{ s *proto.TimingStats }

func (l timingStatsLog) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddInt32("count", l.s.Count)
e.AddInt32("mean_us", l.s.MeanUs)
e.AddInt32("min_us", l.s.MinUs)
e.AddInt32("p1_us", l.s.P1Us)
e.AddInt32("p5_us", l.s.P5Us)
e.AddInt32("p99_us", l.s.P99Us)
e.AddInt32("max_us", l.s.MaxUs)
e.AddInt32("off_period", l.s.OffPeriod)
return nil
}

// timingStatsField: skipped when an older client did not send it.
func timingStatsField(key string, s *proto.TimingStats) zap.Field {
if s == nil {
return zap.Skip()
}
return zap.Object(key, timingStatsLog{s})
}

type renderSettingsLog struct{ s *proto.RenderSettings }

func (l renderSettingsLog) MarshalLogObject(e zapcore.ObjectEncoder) error {
e.AddBool("threaded_rendering", l.s.ThreadedRendering)
e.AddBool("vsync", l.s.Vsync)
e.AddInt32("renderer", l.s.Renderer)
return nil
}

func renderSettingsField(key string, s *proto.RenderSettings) zap.Field {
if s == nil {
return zap.Skip()
}
return zap.Object(key, renderSettingsLog{s})
}

type remotePeerReports []*proto.RemotePeerReport

func (rs remotePeerReports) MarshalLogArray(e zapcore.ArrayEncoder) error {
for _, r := range rs {
err := e.AppendObject(zapcore.ObjectMarshalerFunc(func(o zapcore.ObjectEncoder) error {
o.AddInt32("peer_id", r.PeerId)
o.AddInt32("recv_loss", r.RecvLoss)
o.AddInt32("send_loss", r.SendLoss)
o.AddInt32("ping_min_ms", r.PingMinMs)
o.AddInt32("ping_median_ms", r.PingMedianMs)
o.AddInt32("ping_max_ms", r.PingMaxMs)
o.AddString("route", r.Route)
return nil
}))
if err != nil {
return err
}
}
return nil
}
40 changes: 40 additions & 0 deletions gdxsv/lbs_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

pb "gdxsv/gdxsv/proto"

"go.uber.org/zap"
"go.uber.org/zap/zaptest/observer"
"google.golang.org/protobuf/proto"
)

Expand Down Expand Up @@ -239,3 +241,41 @@ func TestLbs_P2PMatchingReport(t *testing.T) {
assertEq(t, 1, replays[0].RenpoWin)
assertEq(t, 0, replays[0].ZeonWin)
}

func Test_p2pMatchingReportFields(t *testing.T) {
report := &pb.P2PMatchingReport{
BattleCode: "testreporttiming",
CloseReason: "game_end",
PlayerCount: 2,
InputDelay: 2,
Render: &pb.RenderSettings{Vsync: true, Renderer: 2},
RollbackDepthHist: []int32{0, 120, 30, 4},
LateFrames_1_5: 7,
RemotePeers: []*pb.RemotePeerReport{{PeerId: 1, RecvLoss: 4, PingMedianMs: 52, Route: "peer:2"}},
TimesyncFrames: []int32{300, 1800},
PresentInterval: &pb.TimingStats{Count: 5400, MeanUs: 16683, P99Us: 17100, OffPeriod: 3},
}
// Through the wire format, as the handler gets it.
bin, err := proto.Marshal(report)
must(t, err)
var got pb.P2PMatchingReport
must(t, proto.Unmarshal(bin, &got))

core, logs := observer.New(zap.InfoLevel)
zap.New(core).Info("P2PMatchingReport", p2pMatchingReportFields(&got)...)
f := logs.All()[0].ContextMap()
assertEq(t, int32(2), f["input_delay"])
assertEq(t, map[string]interface{}{"threaded_rendering": false, "vsync": true, "renderer": int32(2)}, f["render"])
assertEq(t, []interface{}{int32(0), int32(120), int32(30), int32(4)}, f["rollback_depth_hist"])
assertEq(t, int32(7), f["late_frames_1_5"])
assertEq(t, []interface{}{int32(300), int32(1800)}, f["timesync_frames"])
assertEq(t, []interface{}{map[string]interface{}{"peer_id": int32(1), "recv_loss": int32(4), "send_loss": int32(0),
"ping_min_ms": int32(0), "ping_median_ms": int32(52), "ping_max_ms": int32(0), "route": "peer:2"}}, f["remote_peers"])
present := f["present_interval"].(map[string]interface{})
assertEq(t, int32(16683), present["mean_us"])
assertEq(t, int32(17100), present["p99_us"])
assertEq(t, int32(3), present["off_period"])
// Not sent (an older client): not logged.
_, ok := f["rollback_budget"]
assertEq(t, false, ok)
}
Loading
Loading
0