Skip to content

Commit

Permalink
Replaced --timing command-line switch with --stats, which prints out …
Browse files Browse the repository at this point in the history
…more information.
  • Loading branch information
msfterictraut committed Apr 15, 2019
1 parent 78ade99 commit 21320b0
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"args": [
"-p",
"${workspaceRoot}/../brain",
"--timing"
"--stats"
],
"internalConsoleOptions": "openOnSessionStart",
"outFiles": [
Expand Down
2 changes: 1 addition & 1 deletion docs/command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -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) |
Expand Down
28 changes: 28 additions & 0 deletions server/src/analyzer/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
24 changes: 20 additions & 4 deletions server/src/analyzer/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 } = {};
Expand Down
4 changes: 4 additions & 0 deletions server/src/analyzer/sourceFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion server/src/common/timing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}

Expand All @@ -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());
Expand Down
9 changes: 5 additions & 4 deletions server/src/pyright.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' }
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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'
Expand Down

0 comments on commit 21320b0

Please sign in to comment.