Skip to content

Commit

Permalink
fix: tweak CPU Nx audits
Browse files Browse the repository at this point in the history
  • Loading branch information
getlarge committed Oct 11, 2024
1 parent 4d01bba commit b461f89
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
8 changes: 2 additions & 6 deletions tooling/measures/nx-performance/audit/project-task.audit.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import { AuditOutput, Audit, Table, Issue } from '@code-pushup/models';
import {
executeProcess,
slugify,
formatDuration,
} from '@code-pushup/utils';
import { executeProcess, slugify, formatDuration } from '@code-pushup/utils';
import { logger, readJsonFile } from '@nx/devkit';
import { DEFAULT_PLUGIN_OUTPUT } from '../constant';
import { join } from 'node:path';
Expand Down Expand Up @@ -102,7 +98,7 @@ export async function projectTaskCacheSizeData<T extends string>(
};
});

const { project, target } = task.split(':');
const [project, target] = task.split(':');
results.push({
data: {
title: `Task time for ${task}`,
Expand Down
30 changes: 26 additions & 4 deletions tooling/measures/nx-performance/audit/task-graph.audit.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Audit, AuditOutputs } from '@code-pushup/models';
import { execFile } from 'node:child_process';
import { slugify } from '@code-pushup/utils';
import { promisify } from 'node:util';
import { join } from 'node:path';

export const DEFAULT_MAX_TASK_GRAPH_TIME = 300;
export const TASK_GRAPH_TIME_AUDIT_POSTFIX = 'graph-time-task';
Expand All @@ -25,8 +27,10 @@ export type TaskGraphAuditOptions = {
export async function taskGraphAudits(
options?: TaskGraphAuditOptions
): Promise<AuditOutputs> {
const { maxTaskGraphTime = DEFAULT_MAX_TASK_GRAPH_TIME, taskGraphTasks } =
options ?? {};
const {
maxTaskGraphTime = DEFAULT_MAX_TASK_GRAPH_TIME,
taskGraphTasks = [],
} = options ?? {};
const results = await taskGraphTiming(taskGraphTasks);

return results.map(({ duration, task }) => ({
Expand Down Expand Up @@ -54,10 +58,28 @@ export async function taskGraphTiming(
tasks: string[]
): Promise<{ duration: number; task: string }[]> {
const results: { duration: number; task: string }[] = [];
const isWindows = process.platform === 'win32';
for (const task of tasks) {
const start = performance.now();
execFile(
`NX_DAEMON=true NX_CACHE_PROJECT_GRAPH=false NX_ISOLATE_PLUGINS=true npx nx run-many -t ${task} --graph tmp/nx-performance/task-graph/${task}.graph.json`
await promisify(execFile)(
'npx',
[
'nx',
'run-many',
'-t',
task,
'--graph',
join('tmp', 'nx-performance', 'task-graph', `${task}.graph.json`),
],
{
shell: isWindows,
env: {
...process.env,
NX_CACHE_PROJECT_GRAPH: 'false',
NX_ISOLATE_PLUGINS: 'true',
NX_DAEMON: 'false',
},
}
);
const execFileDuration = Number((performance.now() - start).toFixed(3));
results.push({
Expand Down

0 comments on commit b461f89

Please sign in to comment.