@@ -26,6 +26,10 @@ export class Connection {
2626 resolve : ( response : proto . AnyResponse ) => void ;
2727 reject : ( error : Error ) => void ;
2828 } [ ] = [ ] ;
29+ private timestamps : Date [ ] = [ ] ;
30+
31+ private sendIndex : number = 0 ;
32+ private recvIndex : number = 0 ;
2933
3034 constructor ( private readonly link : link . ILink ) {
3135 this . link . onRecv = this . onLinkRecv . bind ( this ) ;
@@ -40,8 +44,31 @@ export class Connection {
4044 this . link . dispose ( ) ;
4145 }
4246
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+
4370 private async send ( packet : proto . ClientPacket ) : Promise < void > {
44- console . log ( '[RTL Debugger] C>S:' , packet ) ;
71+ this . traceSend ( packet ) ;
4572 if ( this . _state === ConnectionState . Disconnected ) {
4673 throw new Error ( 'unable to send packet after link is shutdown' ) ;
4774 } else {
@@ -50,7 +77,7 @@ export class Connection {
5077 }
5178
5279 private async onLinkRecv ( packet : proto . ServerPacket ) : Promise < void > {
53- console . log ( '[RTL Debugger] S>C:' , packet ) ;
80+ this . traceRecv ( packet ) ;
5481 if ( this . _state === ConnectionState . Initializing && packet . type === 'greeting' ) {
5582 if ( packet . version === 0 ) {
5683 this . _commands = packet . commands ;
0 commit comments