From 99b2f045256ea0b31f7afa2b84efb15692c4c124 Mon Sep 17 00:00:00 2001 From: Jon Edvald Date: Mon, 30 Mar 2020 17:44:55 +0200 Subject: [PATCH] feat(cli): print basic profiling data when GARDEN_ENABLE_PROFILING=1 --- garden-service/src/cli/cli.ts | 6 ++++++ garden-service/src/util/profiling.ts | 12 +++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/garden-service/src/cli/cli.ts b/garden-service/src/cli/cli.ts index f0a5cb8f97..c4b8d54784 100644 --- a/garden-service/src/cli/cli.ts +++ b/garden-service/src/cli/cli.ts @@ -55,6 +55,7 @@ import { generateBasicDebugInfoReport } from "../commands/get/get-debug-info" import { AnalyticsHandler } from "../analytics/analytics" import { defaultDotIgnoreFiles } from "../util/fs" import { renderError } from "../logger/renderers" +import { getDefaultProfiler } from "../util/profiling" const OUTPUT_RENDERERS = { json: (data: DeepPrimitiveMap) => { @@ -503,6 +504,11 @@ export async function run(): Promise { console.log(err) code = 1 } finally { + if (process.env.GARDEN_ENABLE_PROFILING === "1") { + // tslint:disable-next-line: no-console + console.log(getDefaultProfiler().report()) + } + shutdown(code) } } diff --git a/garden-service/src/util/profiling.ts b/garden-service/src/util/profiling.ts index facf1d8d44..dac92355f5 100644 --- a/garden-service/src/util/profiling.ts +++ b/garden-service/src/util/profiling.ts @@ -11,6 +11,8 @@ import { sum, sortBy } from "lodash" import { renderTable, tablePresets } from "./string" import chalk from "chalk" +const maxReportRows = 50 + // Just storing the invocation duration for now type Invocation = number @@ -64,7 +66,15 @@ export class Profiler { }), // Sort by total duration (row) => -row[2] - ).map((row) => [row[0], row[1], formatDuration(row[2]), formatDuration(row[3])]) + ) + .map((row) => [row[0], row[1], formatDuration(row[2]), formatDuration(row[3])]) + .slice(0, maxReportRows) + + const totalRows = keys.length + + if (totalRows > maxReportRows) { + tableData.push([chalk.gray("...")]) + } const table = renderTable([heading, [], ...tableData], tablePresets["no-borders"])