@@ -26,6 +26,10 @@ export class Connection {
26
26
resolve : ( response : proto . AnyResponse ) => void ;
27
27
reject : ( error : Error ) => void ;
28
28
} [ ] = [ ] ;
29
+ private timestamps : Date [ ] = [ ] ;
30
+
31
+ private sendIndex : number = 0 ;
32
+ private recvIndex : number = 0 ;
29
33
30
34
constructor ( private readonly link : link . ILink ) {
31
35
this . link . onRecv = this . onLinkRecv . bind ( this ) ;
@@ -40,8 +44,31 @@ export class Connection {
40
44
this . link . dispose ( ) ;
41
45
}
42
46
47
+ private traceSend ( packet : proto . ClientPacket ) {
48
+ this . timestamps . push ( new Date ( ) ) ;
49
+ if ( packet . type === 'greeting' ) {
50
+ console . debug ( `C>S` , packet ) ;
51
+ } else if ( packet . type === 'command' ) {
52
+ console . debug ( `C>S#${ this . sendIndex ++ } ` , packet ) ;
53
+ }
54
+ }
55
+
56
+ private traceRecv ( packet : proto . ServerPacket ) {
57
+ if ( packet . type === 'greeting' ) {
58
+ console . debug ( `S>C` , packet ) ;
59
+ } else if ( packet . type === 'response' ) {
60
+ const elapsed = new Date ( ) . getTime ( ) - this . timestamps . shift ( ) ! . getTime ( ) ;
61
+ console . debug ( `S>C#${ this . recvIndex ++ } ` , packet , `(${ elapsed } ms)` ) ;
62
+ } else if ( packet . type === 'error' ) {
63
+ this . timestamps . shift ( ) ;
64
+ console . error ( `S>C#${ this . recvIndex ++ } ` , packet ) ;
65
+ } else if ( packet . type === 'event' ) {
66
+ console . debug ( `S>C` , packet ) ;
67
+ }
68
+ }
69
+
43
70
private async send ( packet : proto . ClientPacket ) : Promise < void > {
44
- console . log ( '[RTL Debugger] C>S:' , packet ) ;
71
+ this . traceSend ( packet ) ;
45
72
if ( this . _state === ConnectionState . Disconnected ) {
46
73
throw new Error ( 'unable to send packet after link is shutdown' ) ;
47
74
} else {
@@ -50,7 +77,7 @@ export class Connection {
50
77
}
51
78
52
79
private async onLinkRecv ( packet : proto . ServerPacket ) : Promise < void > {
53
- console . log ( '[RTL Debugger] S>C:' , packet ) ;
80
+ this . traceRecv ( packet ) ;
54
81
if ( this . _state === ConnectionState . Initializing && packet . type === 'greeting' ) {
55
82
if ( packet . version === 0 ) {
56
83
this . _commands = packet . commands ;
0 commit comments