Skip to content

Commit

Permalink
provide a way to write out profile data to custom path (microsoft#99)
Browse files Browse the repository at this point in the history
* provide a way to write out profile data to custom path

* Change files
  • Loading branch information
kenotron authored Oct 19, 2020
1 parent 879398b commit 6694976
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 15 deletions.
8 changes: 8 additions & 0 deletions change/lage-2020-10-19-14-19-03-profile-path.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "minor",
"comment": "provide a way to write out profile data to custom path",
"packageName": "lage",
"email": "[email protected]",
"dependentChangeType": "patch",
"date": "2020-10-19T21:19:03.137Z"
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"fast-glob": "^3.2.2",
"git-url-parse": "^11.1.2",
"npmlog": "^4.1.2",
"p-profiler": "^0.1.2",
"p-profiler": "^0.2.1",
"workspace-tools": "^0.10.1",
"yargs-parser": "^18.1.3"
},
Expand Down
34 changes: 25 additions & 9 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,43 @@
import { Config } from "./types/Config";
import { RunContext } from "./types/RunContext";
import Profiler from "p-profiler";
import { join } from "path";
import { join, dirname } from "path";
import { tmpdir } from "os";
import { mkdirSync } from "fs";

export function createContext(config: Pick<Config, "concurrency">): RunContext {
const { concurrency } = config;
export function createContext(
config: Pick<Config, "concurrency" | "profile">
): RunContext {
const { concurrency, profile } = config;

const useCustomProfilePath = typeof profile === "string";

const profilerOutputDir = useCustomProfilePath
? dirname(profile as string)
: join(tmpdir(), "lage", "profiles");

const profilerOutputDir = join(tmpdir(), "lage", "profiles");
mkdirSync(profilerOutputDir, { recursive: true });

const profiler = new Profiler(
useCustomProfilePath
? {
concurrency,
customOutputPath: profile as string,
}
: {
concurrency,
prefix: "lage",
outDir: profilerOutputDir,
}
);

return {
measures: {
start: [0, 0],
duration: [0, 0],
failedTask: undefined,
},
tasks: new Map(),
profiler: new Profiler({
concurrency,
prefix: "lage",
outDir: profilerOutputDir,
}),
profiler,
};
}
2 changes: 1 addition & 1 deletion src/types/CliOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export interface CliOptions {
*
* Pay attention to the output summary to find the location of the JSON file.
*/
profile: boolean;
profile: boolean | string;

/**
* Ignores certain files when calculating the scope with `--since`
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8276,10 +8276,10 @@ p-map@^2.0.0:
resolved "https://registry.yarnpkg.com/p-map/-/p-map-2.1.0.tgz#310928feef9c9ecc65b68b17693018a665cea175"
integrity sha512-y3b8Kpd8OAN444hxfBbFfj1FY/RjtTd8tzYwhUqNYXx0fXx2iX4maP4Qr6qhIKbQXI02wTLAda4fYUbDagTUFw==

p-profiler@^0.1.2:
version "0.1.2"
resolved "https://registry.yarnpkg.com/p-profiler/-/p-profiler-0.1.2.tgz#ff737d74eaf429a986da5375fdbacfac4d05b07a"
integrity sha512-9aeI5KeYwt7eaxnGR7t+d/8f22cId2yPtPnWWQ2mVrhaFFFedwAuW4A1JbQGaopWaYtRNpv8oQX3HzNalOIixw==
p-profiler@^0.2.1:
version "0.2.1"
resolved "https://registry.yarnpkg.com/p-profiler/-/p-profiler-0.2.1.tgz#853b5e6b482c5d376e5e2bb1e94bd09c0e715983"
integrity sha512-/XDER5u19OrAJ283ofIgw9hsLSoyQnjzki+tmn42vdppHOfo8PgivSSZfwaiyRAzLC2h02+Q+MKiIuuSve+7nw==

p-queue@*:
version "6.3.0"
Expand Down

0 comments on commit 6694976

Please sign in to comment.