Skip to content

Commit

Permalink
Update 'noExperiments' context after trace open
Browse files Browse the repository at this point in the history
Triggers an update to the 'trace-explorer.noExperiments' context after
a trace or experiment is opened.

Signed-off-by: Will Yang <[email protected]>
  • Loading branch information
williamsyang-work committed Jan 15, 2025
1 parent 8281150 commit cc0e635
Showing 1 changed file with 85 additions and 79 deletions.
164 changes: 85 additions & 79 deletions vscode-trace-extension/src/trace-explorer/trace-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Trace as TspTrace } from 'tsp-typescript-client/lib/models/trace';
import { TraceViewerPanel } from '../trace-viewer-panel/trace-viewer-webview-panel';
import { getExperimentManager, getTraceManager } from '../utils/backend-tsp-client-provider';
import { traceLogger } from '../extension';
import { updateNoExperimentsContext } from '../utils/backend-tsp-client-provider';
import { KeyboardShortcutsPanel } from '../trace-viewer-panel/keyboard-shortcuts-panel';

// eslint-disable-next-line no-shadow
Expand Down Expand Up @@ -62,93 +63,98 @@ export const fileHandler =
cancellable: true
},
async (progress, token) => {
if (token.isCancellationRequested) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 100 });
return;
}

const filePath: string = resolvedTraceURI.fsPath;
if (!filePath) {
traceLogger.showError(
'Cannot open trace: could not retrieve path from URI for trace ' + resolvedTraceURI
);
return;
}

const name = path.basename(filePath);
progress.report({ message: ProgressMessages.FINDING_TRACES, increment: 10 });
/*
* TODO: use backend service to find traces
*/
const tracesArray: string[] = [];
const fileStat = await vscode.workspace.fs.stat(resolvedTraceURI);
if (fileStat) {
if (fileStat.type === vscode.FileType.Directory) {
// Find recursively CTF traces
const foundTraces = await findTraces(filePath);
try {

// No CTF traces found. Add root directory as trace directory.
// Back-end will reject if it is not a trace
if (foundTraces.length === 0) {
foundTraces.push(filePath);
}
foundTraces.forEach(trace => tracesArray.push(trace));
} else {
// Open single trace file
tracesArray.push(filePath);
if (token.isCancellationRequested) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 100 });
return;
}
}

if (tracesArray.length === 0) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 100 });
traceLogger.showError('No valid traces found in the selected directory: ' + resolvedTraceURI);
return;
}

progress.report({ message: ProgressMessages.OPENING_TRACES, increment: 20 });
const traces = new Array<TspTrace>();
for (let i = 0; i < tracesArray.length; i++) {
const traceName = path.basename(tracesArray[i]);
const trace = await traceManager.openTrace(tracesArray[i], traceName);
if (trace) {
traces.push(trace);
} else {

const filePath: string = resolvedTraceURI.fsPath;
if (!filePath) {
traceLogger.showError(
'Failed to open trace: ' +
traceName +
'. There may be an issue with the server or the trace is invalid.'
'Cannot open trace: could not retrieve path from URI for trace ' + resolvedTraceURI
);
return;
}
}

if (token.isCancellationRequested) {
rollbackTraces(traces, 20, progress);
progress.report({ message: ProgressMessages.COMPLETE, increment: 50 });
return;
}

progress.report({ message: ProgressMessages.MERGING_TRACES, increment: 40 });
if (traces === undefined || traces.length === 0) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 30 });
return;
}

const experiment = await experimentManager.openExperiment(name, traces);
const panel = TraceViewerPanel.createOrShow(context.extensionUri, experiment?.name ?? name, undefined);
if (experiment) {
panel.setExperiment(experiment);
}

if (token.isCancellationRequested) {

const name = path.basename(filePath);
progress.report({ message: ProgressMessages.FINDING_TRACES, increment: 10 });
/*
* TODO: use backend service to find traces
*/
const tracesArray: string[] = [];
const fileStat = await vscode.workspace.fs.stat(resolvedTraceURI);
if (fileStat) {
if (fileStat.type === vscode.FileType.Directory) {
// Find recursively CTF traces
const foundTraces = await findTraces(filePath);

// No CTF traces found. Add root directory as trace directory.
// Back-end will reject if it is not a trace
if (foundTraces.length === 0) {
foundTraces.push(filePath);
}
foundTraces.forEach(trace => tracesArray.push(trace));
} else {
// Open single trace file
tracesArray.push(filePath);
}
}

if (tracesArray.length === 0) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 100 });
traceLogger.showError('No valid traces found in the selected directory: ' + resolvedTraceURI);
return;
}

progress.report({ message: ProgressMessages.OPENING_TRACES, increment: 20 });
const traces = new Array<TspTrace>();
for (let i = 0; i < tracesArray.length; i++) {
const traceName = path.basename(tracesArray[i]);
const trace = await traceManager.openTrace(tracesArray[i], traceName);
if (trace) {
traces.push(trace);
} else {
traceLogger.showError(
'Failed to open trace: ' +
traceName +
'. There may be an issue with the server or the trace is invalid.'
);
}
}

if (token.isCancellationRequested) {
rollbackTraces(traces, 20, progress);
progress.report({ message: ProgressMessages.COMPLETE, increment: 50 });
return;
}

progress.report({ message: ProgressMessages.MERGING_TRACES, increment: 40 });
if (traces === undefined || traces.length === 0) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 30 });
return;
}

const experiment = await experimentManager.openExperiment(name, traces);
const panel = TraceViewerPanel.createOrShow(context.extensionUri, experiment?.name ?? name, undefined);
if (experiment) {
experimentManager.deleteExperiment(experiment.UUID);
panel.setExperiment(experiment);
}
rollbackTraces(traces, 20, progress);
progress.report({ message: ProgressMessages.COMPLETE, increment: 10 });
panel.dispose();
return;

if (token.isCancellationRequested) {
if (experiment) {
experimentManager.deleteExperiment(experiment.UUID);
}
rollbackTraces(traces, 20, progress);
progress.report({ message: ProgressMessages.COMPLETE, increment: 10 });
panel.dispose();
return;
}
progress.report({ message: ProgressMessages.COMPLETE, increment: 30 });
} finally {
updateNoExperimentsContext();
}
progress.report({ message: ProgressMessages.COMPLETE, increment: 30 });
}
);
};
Expand Down

0 comments on commit cc0e635

Please sign in to comment.