Skip to content

Commit

Permalink
feat(cli): print basic profiling data when GARDEN_ENABLE_PROFILING=1
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed Mar 31, 2020
1 parent fbebc7d commit 99b2f04
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
6 changes: 6 additions & 0 deletions garden-service/src/cli/cli.ts
Expand Up @@ -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) => {
Expand Down Expand Up @@ -503,6 +504,11 @@ export async function run(): Promise<void> {
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)
}
}
12 changes: 11 additions & 1 deletion garden-service/src/util/profiling.ts
Expand Up @@ -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

Expand Down Expand Up @@ -64,7 +66,15 @@ export class Profiler {
}),
// Sort by total duration
(row) => -row[2]
).map((row) => [row[0], row[1], formatDuration(<number>row[2]), formatDuration(<number>row[3])])
)
.map((row) => [row[0], row[1], formatDuration(<number>row[2]), formatDuration(<number>row[3])])
.slice(0, maxReportRows)

const totalRows = keys.length

if (totalRows > maxReportRows) {
tableData.push([chalk.gray("...")])
}

const table = renderTable([heading, [], ...tableData], tablePresets["no-borders"])

Expand Down

0 comments on commit 99b2f04

Please sign in to comment.