Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: collect perf results on failed command executions #431

Merged
merged 2 commits into from
Mar 7, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 31 additions & 25 deletions src/commandExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,35 @@ export class CommandExecution extends AsyncCreatable {

public toJson(): JsonMap {
const pluginInfo = this.getPluginInfo();

let oclifPerf: Record<string, number> = {};

try {
oclifPerf = {
'oclif.runMs': Performance.highlights.runTime,
// The amount of time (ms) required for oclif to get to the point where it can start running the command.
'oclif.initMs': Performance.highlights.initTime,
// The amount of time (ms) required for oclif to load the Config.
'oclif.configLoadMs': Performance.highlights.configLoadTime,
// The amount of time (ms) required for oclif to load the command.
'oclif.commandLoadMs': Performance.highlights.commandLoadTime,
// The amount of time (ms) required for oclif to load core (i.e. bundled) plugins.
'oclif.corePluginsLoadMs': Performance.highlights.corePluginsLoadTime,
// The amount of time (ms) required for oclif to load user plugins.
'oclif.userPluginsLoadMs': Performance.highlights.userPluginsLoadTime,
// The amount of time (ms) required for oclif to load linked plugins.
'oclif.linkedPluginsLoadMs': Performance.highlights.linkedPluginsLoadTime,
// The amount of time (ms) required for oclif to run all the init hooks
'oclif.initHookMs': Performance.highlights.hookRunTimes.init?.total,
// The amount of time (ms) required for oclif to run all the prerun hooks
'oclif.prerunHookMs': Performance.highlights.hookRunTimes.prerun?.total,
// The amount of time (ms) required for oclif to run all the postrun hooks
'oclif.postrunHookMs': Performance.highlights.hookRunTimes.postrun?.total,
};
} catch (err) {
debug('Unable to get oclif performance metrics', err);
}

return {
eventName: 'COMMAND_EXECUTION',
// System information
Expand Down Expand Up @@ -107,31 +136,8 @@ export class CommandExecution extends AsyncCreatable {
status: isNumber(this.status) ? this.status.toString() : undefined,
timestamp: String(Date.now()),

// The amount of time (ms) required for oclif to execute the main `run` function.
// This does not represent the entire execution time of the command. The `processUptime`
// metric is the most accurate measure of how long the command execution.
//
// Our CLIs instantiate the Config before running oclif's `run` method, meaning that
// this metric will be less than the actual time spent in oclif.
'oclif.runMs': Performance.highlights.runTime,
// The amount of time (ms) required for oclif to get to the point where it can start running the command.
'oclif.initMs': Performance.highlights.initTime,
// The amount of time (ms) required for oclif to load the Config.
'oclif.configLoadMs': Performance.highlights.configLoadTime,
// The amount of time (ms) required for oclif to load the command.
'oclif.commandLoadMs': Performance.highlights.commandLoadTime,
// The amount of time (ms) required for oclif to load core (i.e. bundled) plugins.
'oclif.corePluginsLoadMs': Performance.highlights.corePluginsLoadTime,
// The amount of time (ms) required for oclif to load user plugins.
'oclif.userPluginsLoadMs': Performance.highlights.userPluginsLoadTime,
// The amount of time (ms) required for oclif to load linked plugins.
'oclif.linkedPluginsLoadMs': Performance.highlights.linkedPluginsLoadTime,
// The amount of time (ms) required for oclif to run all the init hooks
'oclif.initHookMs': Performance.highlights.hookRunTimes.init?.total,
// The amount of time (ms) required for oclif to run all the prerun hooks
'oclif.prerunHookMs': Performance.highlights.hookRunTimes.prerun?.total,
// The amount of time (ms) required for oclif to run all the postrun hooks
'oclif.postrunHookMs': Performance.highlights.hookRunTimes.postrun?.total,
// Oclif Performance Metrics
...oclifPerf,

// Salesforce Information
// Set the usernames so the uploader can resolve it to orgIds.
Expand Down
3 changes: 2 additions & 1 deletion src/hooks/telemetryPrerun.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { join } from 'path';
import { Hook } from '@oclif/core';
import { Hook, Performance } from '@oclif/core';
import { Org, SfError, Lifecycle } from '@salesforce/core';
import { TelemetryReporter } from '@salesforce/telemetry';
import Telemetry from '../telemetry';
Expand Down Expand Up @@ -117,6 +117,7 @@ const hook: Hook.Prerun = async function (options): Promise<void> {
'cmdError',
// eslint-disable-next-line @typescript-eslint/no-misused-promises
async (cmdErr: SfError, _, org?: Org): Promise<void> => {
await Performance.collect();
const apiVersion = org ? org.getConnection().getApiVersion() : undefined;
let orgType: string | undefined;

Expand Down