mirror of
https://github.com/Mezeporta/Erupe.git
synced 2025-12-14 07:55:33 +01:00
add packet time profiling
This commit is contained in:
@@ -64,6 +64,7 @@ type Session struct {
|
|||||||
// For Debuging
|
// For Debuging
|
||||||
Name string
|
Name string
|
||||||
closed bool
|
closed bool
|
||||||
|
ackStart map[uint32]time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewSession creates a new Session type.
|
// NewSession creates a new Session type.
|
||||||
@@ -78,6 +79,7 @@ func NewSession(server *Server, conn net.Conn) *Session {
|
|||||||
lastPacket: time.Now(),
|
lastPacket: time.Now(),
|
||||||
sessionStart: TimeAdjusted().Unix(),
|
sessionStart: TimeAdjusted().Unix(),
|
||||||
stageMoveStack: stringstack.New(),
|
stageMoveStack: stringstack.New(),
|
||||||
|
ackStart: make(map[uint32]time.Time),
|
||||||
}
|
}
|
||||||
s.SetObjectID()
|
s.SetObjectID()
|
||||||
return s
|
return s
|
||||||
@@ -192,6 +194,10 @@ func (s *Session) handlePacketGroup(pktGroup []byte) {
|
|||||||
s.lastPacket = time.Now()
|
s.lastPacket = time.Now()
|
||||||
bf := byteframe.NewByteFrameFromBytes(pktGroup)
|
bf := byteframe.NewByteFrameFromBytes(pktGroup)
|
||||||
opcodeUint16 := bf.ReadUint16()
|
opcodeUint16 := bf.ReadUint16()
|
||||||
|
if len(bf.Data()) >= 6 {
|
||||||
|
s.ackStart[bf.ReadUint32()] = time.Now()
|
||||||
|
bf.Seek(2, io.SeekStart)
|
||||||
|
}
|
||||||
opcode := network.PacketID(opcodeUint16)
|
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.
|
// This shouldn't be needed, but it's better to recover and let the connection die than to panic the server.
|
||||||
@@ -262,7 +268,15 @@ func (s *Session) logMessage(opcode uint16, data []byte, sender string, recipien
|
|||||||
if ignored(opcodePID) {
|
if ignored(opcodePID) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
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("[%s] -> [%s]\n", sender, recipient)
|
||||||
|
}
|
||||||
fmt.Printf("Opcode: %s\n", opcodePID)
|
fmt.Printf("Opcode: %s\n", opcodePID)
|
||||||
if len(data) <= s.server.erupeConfig.DevModeOptions.MaxHexdumpLength {
|
if len(data) <= s.server.erupeConfig.DevModeOptions.MaxHexdumpLength {
|
||||||
fmt.Printf("Data [%d bytes]:\n%s\n", len(data), hex.Dump(data))
|
fmt.Printf("Data [%d bytes]:\n%s\n", len(data), hex.Dump(data))
|
||||||
|
|||||||
Reference in New Issue
Block a user