Replaced --timing command-line switch with --stats, which prints out more information.

This commit is contained in:
Eric Traut 2019-04-14 17:44:44 -07:00
parent 78ade9973b
commit 21320b0288
7 changed files with 64 additions and 11 deletions

2
.vscode/launch.json vendored
View File

@ -12,7 +12,7 @@
"args": [
"-p",
"${workspaceRoot}/../brain",
"--timing"
"--stats"
],
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [

View File

@ -6,7 +6,7 @@ Pyright can be run as either a VS Code extension or as a node-based command-line
| :--------------------------------- | :--------------------------------------------------- |
| -h, --help | Show help message |
| -p, --project FILE OR DIRECTORY | Use the configuration file at this location |
| --timing | Print detailed timing stats |
| --stats | Print detailed performance stats |
| -t, --typeshed-path DIRECTORY | Use typeshed type stubs at this location (1) |
| -v, --venv-path DIRECTORY | Directory that contains virtual environments (2) |
| -w, --watch | Continue to run and watch for changes (3) |

View File

@ -88,6 +88,34 @@ export class Program {
return this._sourceFileList.length;
}
getAverageAnalysisPassCount() {
let passCount = 0;
this._sourceFileList.forEach(sourceFileInfo => {
passCount += sourceFileInfo.sourceFile.getAnalysisPassCount();
});
if (this._sourceFileList.length === 0) {
return 0;
}
return passCount / this._sourceFileList.length;
}
getMaxAnalysisPassCount(): [number, SourceFile?] {
let maxPassCount = 0;
let sourceFile: SourceFile | undefined;
this._sourceFileList.forEach(sourceFileInfo => {
const passCount = sourceFileInfo.sourceFile.getAnalysisPassCount();
if (passCount > maxPassCount) {
maxPassCount = passCount;
sourceFile = sourceFileInfo.sourceFile;
}
});
return [maxPassCount, sourceFile];
}
getFilesToAnalyzeCount() {
let sourceFileCount = 0;

View File

@ -106,10 +106,30 @@ export class AnalyzerService {
return this._program.getHoverForPosition(filePath, position);
}
printStats() {
this._console.log('');
this._console.log('Analysis stats');
const fileCount = this._program.getFileCount();
this._console.log('Total files analyzed: ' + fileCount.toString());
let averagePassCount = this._program.getAverageAnalysisPassCount();
averagePassCount = Math.round(averagePassCount * 10) / 10;
this._console.log('Average pass count: ' + averagePassCount.toString());
const [maxPassCount, sourceFile] = this._program.getMaxAnalysisPassCount();
const path = sourceFile ? ` (${ sourceFile.getFilePath() })` : '';
this._console.log('Maximum pass count: ' + maxPassCount.toString() + path);
}
test_getConfigOptions(commandLineOptions: CommandLineOptions): ConfigOptions {
return this._getConfigOptions(commandLineOptions);
}
test_getFileNamesFromFileSpecs(): string[] {
return this._getFileNamesFromFileSpecs();
}
// Calculates the effective options based on the command-line options,
// an optional config file, and default values.
private _getConfigOptions(commandLineOptions: CommandLineOptions): ConfigOptions {
@ -311,10 +331,6 @@ export class AnalyzerService {
}
}
test_getFileNamesFromFileSpecs(): string[] {
return this._getFileNamesFromFileSpecs();
}
private _getFileNamesFromFileSpecs(): string[] {
// Use a map to generate a list of unique files.
const fileMap: { [key: string]: string } = {};

View File

@ -370,6 +370,10 @@ export class SourceFile {
this._analysisJob.parseResults, position);
}
getAnalysisPassCount() {
return this._analysisJob.typeAnalysisPassNumber;
}
setTypeAnalysisPassNeeded() {
this._analysisJob.isTypeAnalysisPassNeeded = true;
this._analysisJob.isTypeAnalysisFinalized = false;

View File

@ -41,7 +41,9 @@ export class TimingStat {
}
printTime(): string {
return (this.totalTime / 1000).toString() + 'sec';
let totalTimeInSec = this.totalTime / 1000;
let roundedTime = Math.round(totalTimeInSec * 100) / 100;
return roundedTime.toString() + 'sec';
}
}
@ -60,6 +62,8 @@ export class TimingStats {
}
printDetails(console: ConsoleInterface) {
console.log('');
console.log('Timing stats');
console.log('Find Source Files: ' + this.findFilesTime.printTime());
console.log('Read Source Files: ' + this.readFileTime.printTime());
console.log('Tokenize: ' + this.tokenizeFileTime.printTime());

View File

@ -34,7 +34,7 @@ function processArgs() {
{ name: 'files', type: String, multiple: true, defaultOption: true },
{ name: 'help', alias: 'h', type: Boolean },
{ name: 'project', alias: 'p', type: String },
{ name: 'timing' },
{ name: 'stats' },
{ name: 'typeshed-path', alias: 't', type: String },
{ name: 'venv-path', alias: 'v', type: String },
{ name: 'watch', alias: 'w' }
@ -94,8 +94,9 @@ function processArgs() {
timingStats.printSummary(console);
}
if (args.timing !== undefined) {
// Print the timing details.
if (args.stats !== undefined) {
// Print the stats details.
service.printStats();
timingStats.printDetails(console);
}
@ -123,7 +124,7 @@ function printUsage() {
' Options:\n' +
' -h,--help Show this help message\n' +
' -p,--project FILE OR DIRECTORY Use the configuration file at this location\n' +
' --timing Print detailed timing stats\n' +
' --stats Print detailed performance stats\n' +
' -t,--typeshed-path DIRECTORY Use typeshed type stubs at this location\n' +
' -v,--venv-path DIRECTORY Directory that contains virtual environments\n' +
' -w,--watch Continue to run and watch for changes\n'