Skip to content

Commit 906d33f

Browse files
committed
Log latency of CXXRTL server commands.
1 parent 39d7507 commit 906d33f

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

.vscode/tasks.json

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,19 @@
44
{
55
"type": "npm",
66
"script": "esbuild:watch",
7-
"problemMatcher": "$esbuild-watch",
7+
"problemMatcher": "$ts-esbuild-watch",
8+
"isBackground": true,
9+
"presentation": {
10+
"reveal": "never"
11+
},
12+
"group": {
13+
"kind": "build"
14+
}
15+
},
16+
{
17+
"type": "npm",
18+
"script": "tsc:watch",
19+
"problemMatcher": "$tsc-watch",
820
"isBackground": true,
921
"presentation": {
1022
"reveal": "never"

src/cxxrtl/client.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/cxxrtl/link.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as stream from 'node:stream';
2+
23
import * as proto from './proto';
34

45
export interface ILink {

src/cxxrtl/proto.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ export type CommandReferenceItems = {
171171

172172
export type ResponseReferenceItems = {
173173
type: 'response';
174-
response: 'reference_items';
174+
command: 'reference_items';
175175
};
176176

177177
// ## Command: Query Interval

0 commit comments

Comments
 (0)