@ohos-perf/cli 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/index.js +166 -0
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -317,6 +317,57 @@ artifacts ${result.files.join(" ")}
317
317
  `, exitCode: 1 };
318
318
  }
319
319
  }
320
+ async function runTrend(deps2, req, opts) {
321
+ if (req.reports.length < 2) {
322
+ return {
323
+ stdout: "",
324
+ stderr: `trend needs at least two reports; got ${req.reports.length}. A trend of one is a report \u2014 use \`report\` for a single run.
325
+ `,
326
+ exitCode: 1
327
+ };
328
+ }
329
+ try {
330
+ const result = await deps2.trend({
331
+ ...req,
332
+ reports: req.reports.map((report) => ({
333
+ label: report.label ?? report.path,
334
+ path: report.path
335
+ }))
336
+ });
337
+ if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
338
+ const order = result.orderedBy === "startedAtNs" ? "ordered by capture start time" : "ordered by argument (a run has no capture start time)";
339
+ return {
340
+ stdout: `trend ${result.outDir}/trend.html
341
+ artifacts ${result.files.join(" ")}
342
+ runs ${result.runs.length} (${result.runs.map((run) => run.label).join(", ")}) \xB7 ${order}
343
+ series ${result.series} metrics \xB7 ${result.improved} improved, ${result.regressed} regressed, ${result.unchanged} unchanged, ${result.verdictless} without a known direction
344
+ `,
345
+ stderr: "",
346
+ exitCode: 0
347
+ };
348
+ } catch (err) {
349
+ return { stdout: "", stderr: `${failureLine(err)}
350
+ `, exitCode: 1 };
351
+ }
352
+ }
353
+ async function runRender(deps2, req, opts) {
354
+ try {
355
+ const result = await deps2.render(req);
356
+ if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
357
+ return {
358
+ stdout: `report ${result.outDir}/report.html
359
+ artifacts ${result.files.join(" ")}
360
+ sections ${result.sections} \xB7 ${result.metrics} metrics \xB7 ${result.evidence} evidence
361
+ source ${req.report} (re-rendered, not re-analyzed)
362
+ `,
363
+ stderr: "",
364
+ exitCode: 0
365
+ };
366
+ } catch (err) {
367
+ return { stdout: "", stderr: `${failureLine(err)}
368
+ `, exitCode: 1 };
369
+ }
370
+ }
320
371
  async function runHap(deps2, req, opts) {
321
372
  const pathError = packagePathError(req.packagePath);
322
373
  if (pathError !== void 0) return { stdout: "", stderr: `${pathError}
@@ -646,6 +697,7 @@ import {
646
697
  parseHilogText,
647
698
  analyzeHap,
648
699
  buildReport,
700
+ buildTrend,
649
701
  compareResults,
650
702
  compareSceneDirs,
651
703
  UI_DIFF_FILES,
@@ -655,6 +707,10 @@ import {
655
707
  renderReportJson,
656
708
  renderReportXlsx,
657
709
  renderSummaryJson,
710
+ renderBundle,
711
+ renderTrendHtml,
712
+ renderTrendJson,
713
+ trendRunFromReport,
658
714
  renderFlamegraphHtml,
659
715
  renderFlamegraphSvg,
660
716
  hapSection,
@@ -1118,6 +1174,89 @@ function realDeps(version = packageVersion(), overrides = {}) {
1118
1174
  ...model.comparison === void 0 ? {} : { comparison: { ...model.comparison.totals } }
1119
1175
  };
1120
1176
  },
1177
+ async render(req) {
1178
+ const file = req.report.endsWith(".json") ? req.report : join2(req.report, "report.json");
1179
+ let parsed;
1180
+ try {
1181
+ parsed = JSON.parse(readFileSync2(file, "utf8"));
1182
+ } catch (err) {
1183
+ throw new OhosPerfError3(
1184
+ `cannot read report ${file}: ${safeMessage(err)}`,
1185
+ { code: "RENDER_BAD_INPUT", cause: err }
1186
+ );
1187
+ }
1188
+ const model = parsed;
1189
+ if (!Array.isArray(model.sections) || model.scenario === void 0 || model.totals === void 0) {
1190
+ throw new OhosPerfError3(
1191
+ `${file} is not a report document (no sections, scenario or totals block)`,
1192
+ { code: "RENDER_BAD_INPUT" }
1193
+ );
1194
+ }
1195
+ const outDir = resolve(req.outDir);
1196
+ const artifacts = renderBundle({ model });
1197
+ await mkdir(outDir, { recursive: true });
1198
+ for (const [name, content] of artifacts) {
1199
+ await writeFile(join2(outDir, name), content);
1200
+ }
1201
+ return {
1202
+ outDir,
1203
+ files: artifacts.map(([name]) => name),
1204
+ sections: model.sections.length,
1205
+ metrics: model.totals.metrics,
1206
+ evidence: model.totals.evidence
1207
+ };
1208
+ },
1209
+ async trend(req) {
1210
+ const runs = req.reports.map((report) => {
1211
+ const file = report.path.endsWith(".json") ? report.path : join2(report.path, "report.json");
1212
+ let parsed;
1213
+ try {
1214
+ parsed = JSON.parse(readFileSync2(file, "utf8"));
1215
+ } catch (err) {
1216
+ throw new OhosPerfError3(
1217
+ `cannot read report ${file}: ${safeMessage(err)}`,
1218
+ { code: "TREND_BAD_INPUT", cause: err }
1219
+ );
1220
+ }
1221
+ const model = parsed;
1222
+ if (!Array.isArray(model.sections) || model.scenario === void 0) {
1223
+ throw new OhosPerfError3(
1224
+ `${file} is not a report document (no sections or scenario block)`,
1225
+ { code: "TREND_BAD_INPUT" }
1226
+ );
1227
+ }
1228
+ return trendRunFromReport(report.label ?? report.path, model);
1229
+ });
1230
+ const trend = buildTrend(runs);
1231
+ const outDir = resolve(req.outDir);
1232
+ const artifacts = [
1233
+ ["trend.html", renderTrendHtml(trend)],
1234
+ ["trend.json", renderTrendJson(trend)]
1235
+ ];
1236
+ await mkdir(outDir, { recursive: true });
1237
+ for (const [name, content] of artifacts) {
1238
+ await writeFile(join2(outDir, name), content);
1239
+ }
1240
+ const count = (status) => trend.series.filter((series) => series.status === status).length;
1241
+ const verdictless = trend.series.filter((series) => series.status === void 0).length;
1242
+ return {
1243
+ outDir,
1244
+ files: artifacts.map(([name]) => name),
1245
+ runs: trend.runs.map((run) => ({
1246
+ label: run.label,
1247
+ app: run.app,
1248
+ device: run.device,
1249
+ ...run.startedAtNs === void 0 ? {} : { startedAtNs: run.startedAtNs },
1250
+ metrics: run.metrics.length
1251
+ })),
1252
+ orderedBy: trend.orderedBy,
1253
+ series: trend.series.length,
1254
+ improved: count("improved"),
1255
+ regressed: count("regressed"),
1256
+ unchanged: count("unchanged"),
1257
+ verdictless
1258
+ };
1259
+ },
1121
1260
  async hap(req) {
1122
1261
  const analysis = analyzeHap(readFileSync2(req.packagePath), basename(req.packagePath));
1123
1262
  const capabilities = [{
@@ -1356,6 +1495,11 @@ function parseOnly(raw) {
1356
1495
  return ids;
1357
1496
  }
1358
1497
 
1498
+ // src/trend.ts
1499
+ function collectLabels(raw, previous) {
1500
+ return [...previous ?? [], raw];
1501
+ }
1502
+
1359
1503
  // src/program.ts
1360
1504
  function targetOptionsOf(opts) {
1361
1505
  return {
@@ -1492,6 +1636,28 @@ function buildProgram(deps2, io, opts = {}) {
1492
1636
  );
1493
1637
  }
1494
1638
  );
1639
+ program2.command("render").description("re-render a saved report bundle from its report.json, without re-analyzing").argument("<report>", "report.json file or the bundle directory that holds one").requiredOption("--out <dir>", "output directory for the re-rendered artifacts").option("--json", "print the artifact manifest as JSON").action(async (report, opts2) => {
1640
+ io.emit(await runRender(deps2, { report, outDir: opts2.out }, { json: opts2.json }));
1641
+ });
1642
+ program2.command("trend").description("aggregate two or more saved reports into one trend page").argument("<reports...>", "report.json files or report bundle directories (at least two)").requiredOption("--out <dir>", "output directory for trend.html and trend.json").option(
1643
+ "--label <label>",
1644
+ "a run label, repeated once per report in order (default: the report path)",
1645
+ collectLabels
1646
+ ).option("--json", "print the trend manifest as JSON").action(async (reports, opts2) => {
1647
+ io.emit(
1648
+ await runTrend(
1649
+ deps2,
1650
+ {
1651
+ reports: reports.map((path, index) => {
1652
+ const label = opts2.label?.[index];
1653
+ return { path, ...label === void 0 ? {} : { label } };
1654
+ }),
1655
+ outDir: opts2.out
1656
+ },
1657
+ { json: opts2.json }
1658
+ )
1659
+ );
1660
+ });
1495
1661
  program2.command("hap").description("inspect a .hap/.hsp package offline: files, sizes, technologies, duplicates").argument("<package>", "path to a .hap, .hsp or .zip file").option("--out <dir>", "write hap.json and hap.html to this directory").option("--json", "print the analysis as JSON").action(async (packagePath, opts2) => {
1496
1662
  io.emit(
1497
1663
  await runHap(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ohos-perf/cli",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools, compare, report, gesture, emulator and selector-driven scenarios",
5
5
  "keywords": [
6
6
  "harmonyos",
@@ -36,7 +36,7 @@
36
36
  "access": "public"
37
37
  },
38
38
  "dependencies": {
39
- "@ohos-perf/core": "0.15.0",
39
+ "@ohos-perf/core": "0.17.0",
40
40
  "commander": "^12.1.0"
41
41
  },
42
42
  "scripts": {