Skip to content

Commit

Permalink
add packet time profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
sekaiwish committed Nov 19, 2023
1 parent 1e6675b commit e5fa050
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions server/channelserver/sys_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ type Session struct {
mailList []int

// For Debuging
Name string
closed bool
Name string
closed bool
ackStart map[uint32]time.Time
}

// NewSession creates a new Session type.
Expand All @@ -78,6 +79,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
lastPacket: time.Now(),
sessionStart: TimeAdjusted().Unix(),
stageMoveStack: stringstack.New(),
ackStart: make(map[uint32]time.Time),
}
s.SetObjectID()
return s
Expand Down Expand Up @@ -192,6 +194,10 @@ func (s *Session) handlePacketGroup(pktGroup []byte) {
s.lastPacket = time.Now()
bf := byteframe.NewByteFrameFromBytes(pktGroup)
opcodeUint16 := bf.ReadUint16()
if len(bf.Data()) >= 6 {
s.ackStart[bf.ReadUint32()] = time.Now()
bf.Seek(2, io.SeekStart)
}
opcode := network.PacketID(opcodeUint16)

// This shouldn't be needed, but it's better to recover and let the connection die than to panic the server.
Expand Down Expand Up @@ -262,7 +268,15 @@ func (s *Session) logMessage(opcode uint16, data []byte, sender string, recipien
if ignored(opcodePID) {
return
}
fmt.Printf("[%s] -> [%s]\n", sender, recipient)
var ackHandle uint32
if len(data) >= 6 {
ackHandle = binary.BigEndian.Uint32(data[2:6])
}
if t, ok := s.ackStart[ackHandle]; ok {
fmt.Printf("[%s] -> [%s] (%fs)\n", sender, recipient, float64(time.Now().UnixNano()-t.UnixNano())/1000000000)
} else {
fmt.Printf("[%s] -> [%s]\n", sender, recipient)
}
fmt.Printf("Opcode: %s\n", opcodePID)
if len(data) <= s.server.erupeConfig.DevModeOptions.MaxHexdumpLength {
fmt.Printf("Data [%d bytes]:\n%s\n", len(data), hex.Dump(data))
Expand Down

0 comments on commit e5fa050

Please sign in to comment.