Skip to content

Commit 3e133e0

Browse files
authored
Refactored socket connection (#73)
* initial commit * added recommendations page | error handling | redux store * updated unit testing * added constant for GPU limit * added new slice * redux store handling relevant states * changed comment * change connection lifecycle * merged with main * deleted console log messages * reset error text on restart
1 parent d0eee47 commit 3e133e0

File tree

3 files changed

+54
-32
lines changed

3 files changed

+54
-32
lines changed

deepview-explore/react-ui/src/App.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ function App() {
4040

4141
function restartProfiling() {
4242
console.log("restartProfiling");
43+
setTextChanged(false);
44+
setErrorText("");
4345
vscodeApi.postMessage({
4446
command: "restart_profiling_clicked",
4547
});
@@ -95,6 +97,13 @@ function App() {
9597
}, 1000);
9698
}
9799

100+
// Connection request when UI renders for the 1rst time
101+
if (vscodeApi) {
102+
vscodeApi.postMessage({
103+
command: "connect",
104+
});
105+
}
106+
98107
return () => {
99108
window.removeEventListener("message", () => {}); //remove event listener before re-render to avoid memory leaks
100109
};
@@ -179,16 +188,14 @@ function App() {
179188
/>
180189
</div>
181190
<div className="innpv-contents-subrows">
182-
<MemThroughputContainer
183-
SENDMOCK={sendMock}
184-
/>
191+
<MemThroughputContainer SENDMOCK={sendMock} />
185192
<Habitat />
186193
<EnergyConsumption />
187194
</div>
188195
</div>
189196
</Tab>
190197
<Tab eventKey="deploy" title="Deployment">
191-
<DeploymentTab/>
198+
<DeploymentTab />
192199
</Tab>
193200
</Tabs>
194201
</Container>

deepview-explore/react-ui/src/sections/ProviderPanel.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,20 @@ const ProviderPanel = () => {
185185
fetchData();
186186
// eslint-disable-next-line react-hooks/exhaustive-deps
187187
}, []);
188+
if (analysisState["habitat"].error) {
189+
return (
190+
<div className="innpv-memory innpv-subpanel">
191+
<Subheader icon="database">Providers</Subheader>
192+
<Container fluid>
193+
<Row className="mt-2">
194+
<Alert variant="danger">
195+
There was an error obtaining accurate DeepView Predictions
196+
</Alert>
197+
</Row>
198+
</Container>
199+
</div>
200+
);
201+
}
188202
return (
189203
<>
190204
{providerPanelSettings.plotData &&

deepview-explore/src/skyline_session.ts

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ export class SkylineSession {
9191
this.webviewPanel.webview.onDidReceiveMessage(this.webview_handle_message.bind(this));
9292
this.webviewPanel.onDidDispose(this.disconnect.bind(this));
9393
this.webviewPanel.webview.html = this._getHtmlForWebview();
94-
this.connect();
95-
94+
9695
vscode.workspace.onDidChangeTextDocument(this.on_text_change.bind(this));
9796
this.restart_profiling = this.restart_profiling.bind(this);
9897
}
@@ -121,6 +120,7 @@ export class SkylineSession {
121120
"status": true
122121
};
123122
this.webviewPanel.webview.postMessage(connectionMessage);
123+
this.on_open();
124124
}
125125

126126
on_open() {
@@ -142,17 +142,18 @@ export class SkylineSession {
142142
}
143143

144144
connect() {
145-
this.connection.connect(this.port, this.addr, this.on_open.bind(this));
145+
this.connection.connect(this.port, this.addr);
146146
}
147147

148148
disconnect() {
149-
this.connection.destroy()
149+
this.connection.destroy();
150150
}
151151

152-
restart_profiling() {
153-
console.log("restart_profiling", this.startSkyline);
154-
this.resetBackendConnection = true;
155-
this.disconnect();
152+
async restart_profiling() {
153+
this.reset_payload();
154+
let json_msg = await this.generateStateJson();
155+
json_msg['message_type'] = 'analysis';
156+
this.webviewPanel.webview.postMessage(json_msg);
156157
}
157158

158159
on_text_change() {
@@ -172,6 +173,26 @@ export class SkylineSession {
172173
this.webviewPanel.webview.postMessage(errorEvent);
173174
}
174175

176+
on_close_connection() {
177+
this.msg_initialize = undefined;
178+
this.reset_payload();
179+
let connectionMessage = {
180+
"message_type": "connection",
181+
"status": false
182+
};
183+
184+
if (this.webviewPanel.active) {
185+
this.webviewPanel.webview.postMessage(connectionMessage);
186+
}
187+
}
188+
189+
reset_payload(){
190+
this.msg_throughput = undefined;
191+
this.msg_breakdown = undefined;
192+
this.msg_habitat = undefined;
193+
this.msg_energy = undefined;
194+
}
195+
175196
webview_handle_message(msg: any) {
176197
console.log("webview_handle_message");
177198
console.log(msg);
@@ -337,25 +358,6 @@ export class SkylineSession {
337358
editor.setDecorations(simpleDecoration, Array.from(decorations.values()));
338359
}
339360

340-
on_close_connection() {
341-
if (this.resetBackendConnection)
342-
{
343-
this.startSkyline?.();
344-
}
345-
let connectionMessage = {
346-
"message_type": "connection",
347-
"status": false
348-
};
349-
this.msg_initialize = undefined;
350-
this.msg_throughput = undefined;
351-
this.msg_breakdown = undefined;
352-
this.msg_habitat = undefined;
353-
this.msg_energy = undefined;
354-
if (this.webviewPanel.active) {
355-
this.webviewPanel.webview.postMessage(connectionMessage);
356-
}
357-
}
358-
359361
private _getHtmlForWebview() {
360362
const buildPath = resolve(this.reactProjectRoot);
361363
console.log("resolved buildPath", buildPath);
@@ -466,7 +468,6 @@ export class SkylineSession {
466468
for (let prediction of this.msg_habitat.getPredictionsList()) {
467469
predictions.push([ prediction.getDeviceName(), prediction.getRuntimeMs() ]);
468470
}
469-
console.log(this.msg_habitat.getAnalysisError()?.getErrorMessage());
470471
fields['habitat'] = {
471472
predictions,
472473
error: this.msg_habitat.getAnalysisError()?.getErrorMessage()

0 commit comments

Comments
 (0)