Skip to content

Commit 680994e

Browse files
committed
Better log for update graph and delay operations
1 parent 2a5d954 commit 680994e

File tree

5 files changed

+22
-10
lines changed

5 files changed

+22
-10
lines changed

src/compiler/utilities.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3592,7 +3592,10 @@ namespace ts {
35923592
const watcher = addWatch(host, file, (fileName, cbOptional1?) => {
35933593
const optionalInfo = cbOptional1 !== undefined ? ` ${cbOptional1}` : "";
35943594
log(`${watcherCaption}Trigger: ${fileName}${optionalInfo} ${info}`);
3595+
const start = timestamp();
35953596
cb(fileName, cbOptional1, optional);
3597+
const elapsed = timestamp() - start;
3598+
log(`${watcherCaption}Elapsed: ${elapsed}ms Trigger: ${fileName}${optionalInfo} ${info}`);
35963599
}, optional);
35973600
return {
35983601
close: () => {

src/server/editorServices.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ namespace ts.server {
401401

402402
this.currentDirectory = this.host.getCurrentDirectory();
403403
this.toCanonicalFileName = createGetCanonicalFileName(this.host.useCaseSensitiveFileNames);
404-
this.throttledOperations = new ThrottledOperations(this.host);
404+
this.throttledOperations = new ThrottledOperations(this.host, this.logger);
405405

406406
this.typingsInstaller.attach(this);
407407

src/server/project.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,8 @@ namespace ts.server {
789789
private updateGraphWorker() {
790790
const oldProgram = this.program;
791791

792-
this.writeLog(`Starting Update graph worker: Project: ${this.getProjectName()}`);
792+
this.writeLog(`Starting updateGraphWorker: Project: ${this.getProjectName()}`);
793+
const start = timestamp();
793794
this.resolutionCache.startCachingPerDirectoryResolution();
794795
this.program = this.languageService.getProgram();
795796
this.resolutionCache.finishCachingPerDirectoryResolution();
@@ -843,8 +844,8 @@ namespace ts.server {
843844
scriptInfoToDetach.detachFromProject(this);
844845
}
845846
});
846-
847-
this.writeLog(`Finishing Update graph worker: Project: ${this.getProjectName()}`);
847+
const elapsed = timestamp() - start;
848+
this.writeLog(`Finishing updateGraphWorker: Project: ${this.getProjectName()} structureChanged: ${hasChanges} Elapsed: ${elapsed}ms`);
848849
return hasChanges;
849850
}
850851

src/server/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ namespace ts.server {
252252
readonly typingSafeListLocation: string,
253253
private readonly npmLocation: string | undefined,
254254
private newLine: string) {
255-
this.throttledOperations = new ThrottledOperations(host);
255+
this.throttledOperations = new ThrottledOperations(host, this.logger);
256256
if (eventPort) {
257257
const s = net.connect({ port: eventPort }, () => {
258258
this.socket = s;

src/server/utilities.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,15 @@ namespace ts.server {
173173
export function createSortedArray<T>(): SortedArray<T> {
174174
return [] as SortedArray<T>;
175175
}
176+
}
176177

178+
/* @internal */
179+
namespace ts.server {
177180
export class ThrottledOperations {
178-
private pendingTimeouts: Map<any> = createMap<any>();
179-
constructor(private readonly host: ServerHost) {
181+
private readonly pendingTimeouts: Map<any> = createMap<any>();
182+
private readonly logger?: Logger | undefined;
183+
constructor(private readonly host: ServerHost, logger: Logger) {
184+
this.logger = logger.hasLevel(LogLevel.verbose) && logger;
180185
}
181186

182187
public schedule(operationId: string, delay: number, cb: () => void) {
@@ -187,10 +192,16 @@ namespace ts.server {
187192
}
188193
// schedule new operation, pass arguments
189194
this.pendingTimeouts.set(operationId, this.host.setTimeout(ThrottledOperations.run, delay, this, operationId, cb));
195+
if (this.logger) {
196+
this.logger.info(`Scheduled: ${operationId}${pendingTimeout ? ", Cancelled earlier one" : ""}`);
197+
}
190198
}
191199

192200
private static run(self: ThrottledOperations, operationId: string, cb: () => void) {
193201
self.pendingTimeouts.delete(operationId);
202+
if (self.logger) {
203+
self.logger.info(`Running: ${operationId}`);
204+
}
194205
cb();
195206
}
196207
}
@@ -221,10 +232,7 @@ namespace ts.server {
221232
}
222233
}
223234
}
224-
}
225235

226-
/* @internal */
227-
namespace ts.server {
228236
export function getBaseConfigFileName(configFilePath: NormalizedPath): "tsconfig.json" | "jsconfig.json" | undefined {
229237
const base = getBaseFileName(configFilePath);
230238
return base === "tsconfig.json" || base === "jsconfig.json" ? base : undefined;

0 commit comments

Comments
 (0)