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 <william.yang@ericsson.com>
  • Loading branch information
williamsyang-work authored and bhufmann committed Jan 17, 2025
1 parent 884666c commit 47e7087
Showing 1 changed file with 83 additions and 74 deletions.
157 changes: 83 additions & 74 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,101 @@ export const fileHandler =
cancellable: true
},
async (progress, token) => {
if (token.isCancellationRequested) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 100 });
return;
}
try {
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 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);

// 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);
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);
}
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 (tracesArray.length === 0) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 100 });
traceLogger.showError('No valid traces found in the selected directory: ' + resolvedTraceURI);
return;
}
}

if (token.isCancellationRequested) {
rollbackTraces(traces, 20, progress);
progress.report({ message: ProgressMessages.COMPLETE, increment: 50 });
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.'
);
}
}

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

const experiment = await experimentManager.openExperiment(name, traces);
const panel = TraceViewerPanel.createOrShow(context.extensionUri, experiment?.name ?? name, undefined);
if (experiment) {
panel.setExperiment(experiment);
}
progress.report({ message: ProgressMessages.MERGING_TRACES, increment: 40 });
if (traces === undefined || traces.length === 0) {
progress.report({ message: ProgressMessages.COMPLETE, increment: 30 });
return;
}

if (token.isCancellationRequested) {
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);
}

if (token.isCancellationRequested) {
if (experiment) {
experimentManager.deleteExperiment(experiment.UUID);
}
rollbackTraces(traces, 20, progress);
progress.report({ message: ProgressMessages.COMPLETE, increment: 10 });
panel.dispose();
return;
}
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 47e7087

Please sign in to comment.