Add Performance telemetry for deployment to device (#47)
PBI: 30429 Task: 30436 * Implement the telemetry for performance of New Project command and Open Simulator command * Refactor runDevice() and add performance for deployment to device * Address PR suggestions
This commit is contained in:
Родитель
d03a2b21c4
Коммит
14d9a5f22c
|
@ -99,7 +99,12 @@ export enum TelemetryEventName {
|
|||
ERROR_COMMAND_NEW_PROJECT = "ERROR.COMMAND.NEW.PROJECT",
|
||||
ERROR_DEPLOY_WITHOUT_DEVICE = "ERROR.DEPLOY.WITHOUT.DEVICE",
|
||||
|
||||
SUCCESS_COMMAND_DEPLOY_DEVICE = "SUCCESS.COMMAND.DEPLOY.DEVICE"
|
||||
SUCCESS_COMMAND_DEPLOY_DEVICE = "SUCCESS.COMMAND.DEPLOY.DEVICE",
|
||||
|
||||
// Performance
|
||||
PERFORMANCE_DEPLOY_DEVICE = "PERFORMANCE.DEPLOY.DEVICE",
|
||||
PERFORMANCE_NEW_PROJECT = "PERFORMANCE.NEW.PROJECT",
|
||||
PERFORMANCE_OPEN_SIMULATOR = "PERFORMANCE.OPEN.SIMULATOR"
|
||||
}
|
||||
|
||||
export enum WebviewMessages {
|
||||
|
|
|
@ -118,56 +118,57 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
"pacifica.openSimulator",
|
||||
() => {
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_OPEN_SIMULATOR);
|
||||
openWebview();
|
||||
TelemetryAI.runWithLatencyMeasure(openWebview, TelemetryEventName.PERFORMANCE_OPEN_SIMULATOR);
|
||||
}
|
||||
);
|
||||
|
||||
const openTemplateFile = () => {
|
||||
const fileName = "template.py";
|
||||
const filePath = __dirname + path.sep + fileName;
|
||||
const file = fs.readFileSync(filePath, "utf8");
|
||||
|
||||
if (shouldShowNewProject) {
|
||||
vscode.window
|
||||
.showInformationMessage(
|
||||
CONSTANTS.INFO.NEW_PROJECT,
|
||||
...[
|
||||
DialogResponses.DONT_SHOW,
|
||||
DialogResponses.EXAMPLE_CODE,
|
||||
DialogResponses.TUTORIALS
|
||||
]
|
||||
)
|
||||
.then((selection: vscode.MessageItem | undefined) => {
|
||||
if (selection === DialogResponses.DONT_SHOW) {
|
||||
shouldShowNewProject = false;
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_DONT_SHOW);
|
||||
} else if (selection === DialogResponses.EXAMPLE_CODE) {
|
||||
open(CONSTANTS.LINKS.EXAMPLE_CODE);
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_EXAMPLE_CODE);
|
||||
} else if (selection === DialogResponses.TUTORIALS) {
|
||||
open(CONSTANTS.LINKS.TUTORIALS);
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_TUTORIALS);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openWebview();
|
||||
|
||||
vscode.workspace
|
||||
.openTextDocument({ content: file, language: "python" })
|
||||
.then((template: vscode.TextDocument) => {
|
||||
vscode.window.showTextDocument(template, 1, false);
|
||||
}),
|
||||
(error: any) => {
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_COMMAND_NEW_PROJECT);
|
||||
console.error(`Failed to open a new text document: ${error}`);
|
||||
};
|
||||
}
|
||||
|
||||
const newProject: vscode.Disposable = vscode.commands.registerCommand(
|
||||
"pacifica.newProject",
|
||||
() => {
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_NEW_PROJECT);
|
||||
|
||||
const fileName = "template.py";
|
||||
const filePath = __dirname + path.sep + fileName;
|
||||
const file = fs.readFileSync(filePath, "utf8");
|
||||
|
||||
|
||||
if (shouldShowNewProject) {
|
||||
vscode.window
|
||||
.showInformationMessage(
|
||||
CONSTANTS.INFO.NEW_PROJECT,
|
||||
...[
|
||||
DialogResponses.DONT_SHOW,
|
||||
DialogResponses.EXAMPLE_CODE,
|
||||
DialogResponses.TUTORIALS
|
||||
]
|
||||
)
|
||||
.then((selection: vscode.MessageItem | undefined) => {
|
||||
if (selection === DialogResponses.DONT_SHOW) {
|
||||
shouldShowNewProject = false;
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_DONT_SHOW);
|
||||
} else if (selection === DialogResponses.EXAMPLE_CODE) {
|
||||
open(CONSTANTS.LINKS.EXAMPLE_CODE);
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_EXAMPLE_CODE);
|
||||
} else if (selection === DialogResponses.TUTORIALS) {
|
||||
open(CONSTANTS.LINKS.TUTORIALS);
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.CLICK_DIALOG_TUTORIALS);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
openWebview();
|
||||
|
||||
|
||||
vscode.workspace
|
||||
.openTextDocument({ content: file, language: "python" })
|
||||
.then((template: vscode.TextDocument) => {
|
||||
vscode.window.showTextDocument(template, 1, false);
|
||||
}),
|
||||
(error: any) => {
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.ERROR_COMMAND_NEW_PROJECT);
|
||||
console.error(`Failed to open a new text document: ${error}`);
|
||||
};
|
||||
TelemetryAI.runWithLatencyMeasure(openTemplateFile, TelemetryEventName.PERFORMANCE_NEW_PROJECT);
|
||||
}
|
||||
);
|
||||
|
||||
|
@ -197,7 +198,6 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_RUN_SIMULATOR);
|
||||
|
||||
|
||||
if (currentFileAbsPath === "") { logToOutputChannel(outChannel, CONSTANTS.ERROR.NO_FILE_TO_RUN, true); }
|
||||
|
||||
// Get the Python script path (And the special URI to use with the webview)
|
||||
|
@ -278,10 +278,8 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
"pacifica.runSimulator", () => { runSimulatorCommand(); }
|
||||
);
|
||||
|
||||
// Send message to the webview
|
||||
const runDevice: vscode.Disposable = vscode.commands.registerCommand("pacifica.runDevice", () => {
|
||||
const deployCodeToDevice = () => {
|
||||
console.info("Sending code to device");
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_DEPLOY_DEVICE);
|
||||
|
||||
logToOutputChannel(outChannel, CONSTANTS.INFO.DEPLOY_DEVICE);
|
||||
|
||||
|
@ -360,6 +358,13 @@ export function activate(context: vscode.ExtensionContext) {
|
|||
deviceProcess.on("end", (code: number) => {
|
||||
console.info(`Command execution exited with code: ${code}`);
|
||||
});
|
||||
}
|
||||
|
||||
const runDevice: vscode.Disposable = vscode.commands.registerCommand(
|
||||
"pacifica.runDevice",
|
||||
() => {
|
||||
TelemetryAI.trackFeatureUsage(TelemetryEventName.COMMAND_DEPLOY_DEVICE);
|
||||
TelemetryAI.runWithLatencyMeasure(deployCodeToDevice, TelemetryEventName.PERFORMANCE_DEPLOY_DEVICE);
|
||||
});
|
||||
|
||||
context.subscriptions.push(
|
||||
|
|
|
@ -4,10 +4,21 @@ import getPackageInfo from "./getPackageInfo";
|
|||
|
||||
// tslint:disable-next-line:export-name
|
||||
export default class TelemetryAI {
|
||||
static trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) {
|
||||
public static trackFeatureUsage(eventName: string, eventProperties?: { [key: string]: string }) {
|
||||
TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, eventProperties);
|
||||
}
|
||||
|
||||
public static runWithLatencyMeasure(functionToRun: () => void, eventName: string): void {
|
||||
const numberOfNanosecondsInSecond: number = 1000000000;
|
||||
const startTime: number = Number(process.hrtime.bigint());
|
||||
functionToRun();
|
||||
const latency: number = Number(process.hrtime.bigint()) - startTime;
|
||||
const measurement = {
|
||||
duration: latency / numberOfNanosecondsInSecond
|
||||
}
|
||||
TelemetryAI.telemetryReporter.sendTelemetryEvent(eventName, {}, measurement);
|
||||
}
|
||||
|
||||
private static telemetryReporter: TelemetryReporter;
|
||||
|
||||
constructor(vscodeContext: vscode.ExtensionContext) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче