diff --git a/src/sql/workbench/contrib/profiler/browser/profilerActions.contribution.ts b/src/sql/workbench/contrib/profiler/browser/profilerActions.contribution.ts index 1196101aa8..a2cb5bf482 100644 --- a/src/sql/workbench/contrib/profiler/browser/profilerActions.contribution.ts +++ b/src/sql/workbench/contrib/profiler/browser/profilerActions.contribution.ts @@ -19,6 +19,7 @@ import { IConnectionDialogService } from 'sql/workbench/services/connection/comm import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService'; import { KeyCode, KeyMod } from 'vs/base/common/keyCodes'; import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; +import { IFileService } from 'vs/platform/files/common/files'; CommandsRegistry.registerCommand({ id: 'profiler.newProfiler', @@ -107,9 +108,10 @@ CommandsRegistry.registerCommand({ const editorService: IEditorService = accessor.get(IEditorService); const fileDialogService: IFileDialogService = accessor.get(IFileDialogService); const profilerService: IProfilerService = accessor.get(IProfilerService); - const instantiationService: IInstantiationService = accessor.get(IInstantiationService) + const instantiationService: IInstantiationService = accessor.get(IInstantiationService); + const fileService: IFileService = accessor.get(IFileService); - const result = await profilerService.openFile(fileDialogService, editorService, instantiationService); + const result = await profilerService.openFile(fileDialogService, editorService, instantiationService, fileService); return result; } diff --git a/src/sql/workbench/services/profiler/browser/interfaces.ts b/src/sql/workbench/services/profiler/browser/interfaces.ts index e8d5f8db05..587ee4d57b 100644 --- a/src/sql/workbench/services/profiler/browser/interfaces.ts +++ b/src/sql/workbench/services/profiler/browser/interfaces.ts @@ -11,6 +11,7 @@ import * as azdata from 'azdata'; import { INewProfilerState } from 'sql/workbench/common/editor/profiler/profilerState'; import { IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; +import { IFileService } from 'vs/platform/files/common/files'; const PROFILER_SERVICE_ID = 'profilerService'; export const IProfilerService = createDecorator(PROFILER_SERVICE_ID); @@ -148,7 +149,7 @@ export interface IProfilerService { * @param editorService service to open profiler editor * @param instantiationService service to create profiler instance */ - openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService): Promise; + openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService, fileService: IFileService): Promise; } export enum ProfilingSessionType { diff --git a/src/sql/workbench/services/profiler/browser/profilerService.ts b/src/sql/workbench/services/profiler/browser/profilerService.ts index 2ff9566a17..093b738742 100644 --- a/src/sql/workbench/services/profiler/browser/profilerService.ts +++ b/src/sql/workbench/services/profiler/browser/profilerService.ts @@ -22,6 +22,7 @@ import { ProfilerFilterDialog } from 'sql/workbench/services/profiler/browser/pr import { mssqlProviderName } from 'sql/platform/connection/common/constants'; import { ACTIVE_GROUP, IEditorService } from 'vs/workbench/services/editor/common/editorService'; import { IFileDialogService } from 'vs/platform/dialogs/common/dialogs'; +import { ByteSize, IFileService } from 'vs/platform/files/common/files'; class TwoWayMap { private forwardMap: Map; @@ -303,7 +304,7 @@ export class ProfilerService implements IProfilerService { await this._configurationService.updateValue(PROFILER_FILTER_SETTINGS, config, ConfigurationTarget.USER); } - public async openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService): Promise { + public async openFile(fileDialogService: IFileDialogService, editorService: IEditorService, instantiationService: IInstantiationService, fileService: IFileService): Promise { const fileURIs = await fileDialogService.showOpenDialog({ filters: [ { @@ -317,6 +318,21 @@ export class ProfilerService implements IProfilerService { if (fileURIs?.length === 1) { const fileURI = fileURIs[0]; + try { + const fileSize = (await fileService.stat(fileURI)).size; + const fileLimitSize = 1 * ByteSize.GB; + const fileOpenWarningSize = 100 * ByteSize.MB; + + if (fileSize > fileLimitSize) { + this._notificationService.error(nls.localize('FileTooLarge', "The file is too large to open in profiler. The profiler can open files that are less than 1GB.")); + return false; + } else if (fileSize > fileOpenWarningSize) { + this._notificationService.info(nls.localize('LargeFileWait', "Loading the file might take a moment due to the file size.")); + } + } catch (err) { + this._notificationService.error(err.message); + } + let profilerInput: ProfilerInput = instantiationService.createInstance(ProfilerInput, undefined, fileURI); await editorService.openEditor(profilerInput, { pinned: true }, ACTIVE_GROUP); profilerInput.setConnectionState(false); // Reset connection to be not connected for File session, so that "Start" is not enabled.