Skip to content

Commit 8586948

Browse files
committed
inject PerfTracker for tracking in dataschemacompiler
1 parent f81a43d commit 8586948

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

packages/cubejs-schema-compiler/src/compiler/DataSchemaCompiler.ts

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import { CompilerInterface } from './PrepareCompiler';
2323
import { YamlCompiler } from './YamlCompiler';
2424
import { CubeDictionary } from './CubeDictionary';
2525
import { CompilerCache } from './CompilerCache';
26+
import { perfTracker } from './PerfTracker';
2627

2728
const ctxFileStorage = new AsyncLocalStorage<FileContent>();
2829

@@ -211,8 +212,12 @@ export class DataSchemaCompiler {
211212
}
212213

213214
protected async doCompile() {
215+
const compileTimer = perfTracker.start('doCompile', true);
216+
214217
const files = await this.repository.dataSchemaFiles();
215218

219+
console.log(`Compiling ${files.length} files...`);
220+
216221
this.pythonContext = await this.loadPythonContext(files, 'globals.py');
217222
this.yamlCompiler.initFromPythonContext(this.pythonContext);
218223

@@ -235,6 +240,8 @@ export class DataSchemaCompiler {
235240
}
236241

237242
const transpile = async (stage: CompileStage): Promise<FileContent[]> => {
243+
const transpileTimer = perfTracker.start(`transpilation-stage-${stage}`);
244+
238245
let cubeNames: string[] = [];
239246
let cubeSymbols: Record<string, Record<string, boolean>> = {};
240247
let transpilerNames: string[] = [];
@@ -301,6 +308,8 @@ export class DataSchemaCompiler {
301308
results = await Promise.all(toCompile.map(f => this.transpileFile(f, errorsReport, {})));
302309
}
303310

311+
transpileTimer.end();
312+
304313
return results.filter(f => !!f) as FileContent[];
305314
};
306315

@@ -398,6 +407,8 @@ export class DataSchemaCompiler {
398407
});
399408

400409
const compilePhase = async (compilers: CompileCubeFilesCompilers, stage: 0 | 1 | 2 | 3) => {
410+
const compilePhaseTimer = perfTracker.start(`compilation-phase-${stage}`);
411+
401412
// clear the objects for the next phase
402413
cubes = [];
403414
exports = {};
@@ -406,7 +417,9 @@ export class DataSchemaCompiler {
406417
asyncModules = [];
407418
transpiledFiles = await transpile(stage);
408419

409-
return this.compileCubeFiles(cubes, contexts, compiledFiles, asyncModules, compilers, transpiledFiles, errorsReport);
420+
const res = this.compileCubeFiles(cubes, contexts, compiledFiles, asyncModules, compilers, transpiledFiles, errorsReport);
421+
compilePhaseTimer.end();
422+
return res;
410423
};
411424

412425
return compilePhase({ cubeCompilers: this.cubeNameCompilers }, 0)
@@ -442,6 +455,12 @@ export class DataSchemaCompiler {
442455
} else if (transpilationWorkerThreads && this.workerPool) {
443456
this.workerPool.terminate();
444457
}
458+
459+
// End overall compilation timing and print performance report
460+
compileTimer.end();
461+
setImmediate(() => {
462+
perfTracker.printReport();
463+
});
445464
});
446465
}
447466

@@ -640,7 +659,9 @@ export class DataSchemaCompiler {
640659
asyncModules
641660
);
642661
});
662+
const asyncModulesTimer = perfTracker.start('asyncModules.reduce (jinja)');
643663
await asyncModules.reduce((a: Promise<void>, b: CallableFunction) => a.then(() => b()), Promise.resolve());
664+
asyncModulesTimer.end();
644665
return this.compileObjects(compilers.cubeCompilers || [], cubes, errorsReport)
645666
.then(() => this.compileObjects(compilers.contextCompilers || [], contexts, errorsReport));
646667
}
@@ -663,7 +684,9 @@ export class DataSchemaCompiler {
663684
compiledFiles[file.fileName] = true;
664685

665686
if (file.fileName.endsWith('.js')) {
687+
const compileJsFileTimer = perfTracker.start('compileJsFile');
666688
this.compileJsFile(file, errorsReport, { doSyntaxCheck });
689+
compileJsFileTimer.end();
667690
} else if (file.fileName.endsWith('.yml.jinja') || file.fileName.endsWith('.yaml.jinja') ||
668691
(
669692
file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')
@@ -677,7 +700,9 @@ export class DataSchemaCompiler {
677700
this.pythonContext!
678701
));
679702
} else if (file.fileName.endsWith('.yml') || file.fileName.endsWith('.yaml')) {
703+
const compileYamlFileTimer = perfTracker.start('compileYamlFile');
680704
this.yamlCompiler.compileYamlFile(file, errorsReport);
705+
compileYamlFileTimer.end();
681706
}
682707
}
683708

0 commit comments

Comments
 (0)