Skip to content

Commit

Permalink
Allow loading runtime reports through VSCode's File API (#233)
Browse files Browse the repository at this point in the history
  • Loading branch information
phschaad authored Aug 22, 2023
1 parent c3f8d75 commit 2f87a98
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 32 deletions.
2 changes: 0 additions & 2 deletions media/components/analysis/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
</span>
</div>
<div>
<input type="file" id="runtime-report-file-input"
style="display: none;">
<div class="input-group mb-2">
<input type="text" class="form-control"
id="runtime-report-filename-label"
Expand Down
2 changes: 1 addition & 1 deletion packages/sdfv
29 changes: 28 additions & 1 deletion src/components/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,36 @@ implements vscode.WebviewViewProvider {
}

@ICPCRequest(true)
public onReady(): Promise<void> {
public async onReady(): Promise<void> {
vscode.commands.executeCommand('sdfgAnalysis.sync');
return super.onReady();
}

@ICPCRequest(true)
public async selectReportFile(): Promise<{
path?: vscode.Uri,
data?: Record<string, unknown>,
}> {
return vscode.window.showOpenDialog({
canSelectFiles: true,
canSelectFolders: false,
canSelectMany: false,
filters: {
'Profile': ['json'],
},
openLabel: 'Load',
title: 'Load instrumentation report',
}).then(uri => {
if (uri) {
return vscode.workspace.fs.readFile(uri[0]).then(val => {
return {
path: uri[0],
data: JSON.parse(Buffer.from(val).toString('utf-8')),
};
});
}
return {};
});
}

}
43 changes: 15 additions & 28 deletions src/webclients/components/analysis/analysis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ class AnalysisPanel extends ICPCWebclientMessagingComponent {
private scalingMethodExpBaseContainer?: JQuery<HTMLElement>;
private scalingMethodExpBaseInput?: JQuery<HTMLInputElement>;

private runtimeReportFileInput?: JQuery<HTMLInputElement>;
private runtimeReportFilenameLabel?: JQuery<HTMLSpanElement>;
private runtimeTimeCriteriumSelect?: JQuery<HTMLSelectElement>;

Expand Down Expand Up @@ -212,31 +211,6 @@ class AnalysisPanel extends ICPCWebclientMessagingComponent {
this.onScalingUpdated();
});

this.runtimeReportFileInput = $('#runtime-report-file-input');
this.runtimeReportFileInput?.on('change', function () {
const fr = new FileReader();
const that = this as HTMLInputElement;
fr.onload = () => {
if (fr && that.files) {
const aPanel = AnalysisPanel.getInstance();
aPanel.rtReportLabel?.val(that.files[0].name);
aPanel.rtReportLabel?.prop(
'title', (that.files[0] as any).path
);
if (fr.result && typeof fr.result === 'string') {
const rtSelCrit = aPanel.rtTimeCriteriumSelect?.val();
if (!rtSelCrit || typeof rtSelCrit !== 'string')
return;
AnalysisPanel.onLoadInstrumentationReport(
JSON.parse(fr.result), rtSelCrit
);
}
}
};
if (that.files)
fr.readAsText(that.files[0]);
});

this.runtimeReportFilenameLabel = $('#runtime-report-filename-label');

this.runtimeTimeCriteriumSelect = $('#runtime-time-criterium-select');
Expand All @@ -255,7 +229,21 @@ class AnalysisPanel extends ICPCWebclientMessagingComponent {
this.clearRuntimeReport();
});
$('#runtime-report-browse-btn').on('click', () => {
this.runtimeReportFileInput?.trigger('click');
this.invoke('selectReportFile').then(retval => {
const aPanel = AnalysisPanel.getInstance();
if (retval.data && retval.path) {
const splits = retval.path.path.split('/');
const filename = splits[splits.length - 1];
aPanel.rtReportLabel?.val(filename);
aPanel.rtReportLabel?.prop('title', retval.path.fsPath);
const rtSelCrit = aPanel.rtTimeCriteriumSelect?.val();
if (!rtSelCrit || typeof rtSelCrit !== 'string')
return;
AnalysisPanel.onLoadInstrumentationReport(
retval.data, rtSelCrit
);
}
});
});
}

Expand Down Expand Up @@ -399,7 +387,6 @@ class AnalysisPanel extends ICPCWebclientMessagingComponent {
}

public clearRuntimeReport(): void {
this.runtimeReportFileInput?.val('');
this.runtimeReportFilenameLabel?.val('Load runtime report');
this.runtimeReportFilenameLabel?.prop('title', '');
const nodeType = this.nodeOverlaySelect?.val();
Expand Down

0 comments on commit 2f87a98

Please sign in to comment.