Skip to content

Add telemetry for open JS files#23833

Merged
7 commits merged into
masterfrom
openFilesTelemetry
May 9, 2018
Merged

Add telemetry for open JS files#23833
7 commits merged into
masterfrom
openFilesTelemetry

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented May 2, 2018

Fixes #23178

@sheetalkamat mentioned that instead of saving to a file, we could send multiple events and have the editor use only the last event, which would simplify this PR a lot. Pushing this as-is for now but we should consider changing it.

@ghost ghost requested review from mhegazy and sheetalkamat May 2, 2018 20:52
@ghost ghost force-pushed the openFilesTelemetry branch from 82c5ce2 to ee4dfb8 Compare May 2, 2018 20:53
Copy link
Copy Markdown
Member

@sheetalkamat sheetalkamat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think sending openFileStats every file open is better than storing info on disk and sending in next session.

this.addFileOrFolderInFolder(baseFolder, folder);
}

createDirectoryRecursively(directoryName: string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont need this. you can use ensureFileOrFolder

@ghost
Copy link
Copy Markdown
Author

ghost commented May 7, 2018

I think we shouldn't send the telemetry for a project that has no .js files, or a project with "checkJs": true in its config?

@ghost ghost force-pushed the openFilesTelemetry branch from 6e7a7fc to f9fe7ea Compare May 7, 2018 19:02
@ghost ghost force-pushed the openFilesTelemetry branch from f9fe7ea to 2b3f4ab Compare May 7, 2018 19:03
Comment thread src/server/editorServices.ts Outdated
if (project && project.getCompilationSettings().checkJs) return;

const stats: Mutable<OpenFileStats> = { js: 0, checkJs: 0 };
this.filenameToScriptInfo.forEach(scriptInfo => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We arent sending stats from start of the session to this point in time here. I thought that was the indent of this event. Do we need this info only for open files or all files ?

Comment thread src/server/editorServices.ts Outdated

this.printProjects();

this.telemetryOnOpenFile(project, fileName, info);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

project here is could not be project for file being opened. Eg. configFile search results in creating configured project but that project doesnt include info. You would always want to do info.getDefaultProject() to correctly get the default project for the info.

Comment thread src/server/editorServices.ts Outdated
}

private telemetryOnOpenFile(project: ConfiguredProject | ExternalProject | undefined, fileName: NormalizedPath, info: ScriptInfo): void {
if (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would just want to assert that: info.containingProjects.length !== 0

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, that assertion fails at the test works when project root is used with case-sensitive system. It works with the case-insensitive version of that test -- is this a bug?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because you arent using info.path as key?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, thanks!

Comment thread src/server/editorServices.ts Outdated
// Won't be able to get sourceFile without containingProjects
info.containingProjects.length === 0 ||
// If we've already seen the file, no need to send a new evnt.
!addToSeen(this.allJsFilesForOpenFilesTelemetry, fileName)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not instead of just storing "seen" as true store value true or false as checkJsDirective. Then at all times the count of values === true and we dont need to store tsCheckCountForOpenFilesTelemetry separately.

Comment thread src/server/editorServices.ts Outdated
return;
}

if (info.getDefaultProject().getSourceFile(info.path).checkJsDirective) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we care if checkJsDirective changes? Project settings change to enable checkJS? and hence enabling checkJSDirective?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we'll still get good data in the aggregate, assuming these change rarely. We'll get the updated data the next time you use the editor.

@ghost ghost force-pushed the openFilesTelemetry branch from 8957b73 to 49dbd19 Compare May 7, 2018 20:41
Comment thread src/server/editorServices.ts Outdated
// We are only sending stats for JS files
!info.isJavaScript() ||
// If we've already seen the file, no need to send a new event.
this.allJsFilesForOpenFilesTelemetry.has(fileName)) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should use filePath as a key instead of fileName since the caseInsensitive system: "filename" === "fileName"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use info.path instead.

Comment thread src/server/editorServices.ts Outdated
if (
!this.eventHandler ||
// Don't send for a project with 'checkJs' enabled globally.
info.getDefaultProject().getCompilationSettings().checkJs ||
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldnt check this here since you want to add to allJsFilesForOpenFilesTelemetry if the info is js but project doesnt have checkJS

Comment thread src/server/editorServices.ts Outdated
}

export type ProjectServiceEvent = ProjectsUpdatedInBackgroundEvent | ConfigFileDiagEvent | ProjectLanguageServiceStateEvent | ProjectInfoTelemetryEvent;
export interface OpenFileStats {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought we will just send an event on every new file .js we see in openfile, and will have a flag whether it has checkjs or not. we can do the counting at the server side. no need for counting here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

}

const info: OpenFileInfo = { checkJs: !!scriptInfo.getDefaultProject().getSourceFile(scriptInfo.path).checkJsDirective };
this.eventHandler({ eventName: OpenFileInfoTelemetryEvent, data: { info } });
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dont you need to send the open file name so that at vscode side they can create a map of seen files and get correct count instead of count = 3 when opening same file 3 times?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we open the same file 3 times we should still only send one event, thanks to this.allJsFilesForOpenFileTelemetry.

@ghost ghost merged commit 7fb7eec into master May 9, 2018
@ghost ghost deleted the openFilesTelemetry branch May 9, 2018 14:51
@microsoft microsoft locked and limited conversation to collaborators Jul 31, 2018
This pull request was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants