@ohos-perf/cli 0.15.0 → 0.16.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.
- package/dist/index.js +112 -0
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -317,6 +317,39 @@ 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
|
+
}
|
|
320
353
|
async function runHap(deps2, req, opts) {
|
|
321
354
|
const pathError = packagePathError(req.packagePath);
|
|
322
355
|
if (pathError !== void 0) return { stdout: "", stderr: `${pathError}
|
|
@@ -646,6 +679,7 @@ import {
|
|
|
646
679
|
parseHilogText,
|
|
647
680
|
analyzeHap,
|
|
648
681
|
buildReport,
|
|
682
|
+
buildTrend,
|
|
649
683
|
compareResults,
|
|
650
684
|
compareSceneDirs,
|
|
651
685
|
UI_DIFF_FILES,
|
|
@@ -655,6 +689,9 @@ import {
|
|
|
655
689
|
renderReportJson,
|
|
656
690
|
renderReportXlsx,
|
|
657
691
|
renderSummaryJson,
|
|
692
|
+
renderTrendHtml,
|
|
693
|
+
renderTrendJson,
|
|
694
|
+
trendRunFromReport,
|
|
658
695
|
renderFlamegraphHtml,
|
|
659
696
|
renderFlamegraphSvg,
|
|
660
697
|
hapSection,
|
|
@@ -1118,6 +1155,57 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
1118
1155
|
...model.comparison === void 0 ? {} : { comparison: { ...model.comparison.totals } }
|
|
1119
1156
|
};
|
|
1120
1157
|
},
|
|
1158
|
+
async trend(req) {
|
|
1159
|
+
const runs = req.reports.map((report) => {
|
|
1160
|
+
const file = report.path.endsWith(".json") ? report.path : join2(report.path, "report.json");
|
|
1161
|
+
let parsed;
|
|
1162
|
+
try {
|
|
1163
|
+
parsed = JSON.parse(readFileSync2(file, "utf8"));
|
|
1164
|
+
} catch (err) {
|
|
1165
|
+
throw new OhosPerfError3(
|
|
1166
|
+
`cannot read report ${file}: ${safeMessage(err)}`,
|
|
1167
|
+
{ code: "TREND_BAD_INPUT", cause: err }
|
|
1168
|
+
);
|
|
1169
|
+
}
|
|
1170
|
+
const model = parsed;
|
|
1171
|
+
if (!Array.isArray(model.sections) || model.scenario === void 0) {
|
|
1172
|
+
throw new OhosPerfError3(
|
|
1173
|
+
`${file} is not a report document (no sections or scenario block)`,
|
|
1174
|
+
{ code: "TREND_BAD_INPUT" }
|
|
1175
|
+
);
|
|
1176
|
+
}
|
|
1177
|
+
return trendRunFromReport(report.label ?? report.path, model);
|
|
1178
|
+
});
|
|
1179
|
+
const trend = buildTrend(runs);
|
|
1180
|
+
const outDir = resolve(req.outDir);
|
|
1181
|
+
const artifacts = [
|
|
1182
|
+
["trend.html", renderTrendHtml(trend)],
|
|
1183
|
+
["trend.json", renderTrendJson(trend)]
|
|
1184
|
+
];
|
|
1185
|
+
await mkdir(outDir, { recursive: true });
|
|
1186
|
+
for (const [name, content] of artifacts) {
|
|
1187
|
+
await writeFile(join2(outDir, name), content);
|
|
1188
|
+
}
|
|
1189
|
+
const count = (status) => trend.series.filter((series) => series.status === status).length;
|
|
1190
|
+
const verdictless = trend.series.filter((series) => series.status === void 0).length;
|
|
1191
|
+
return {
|
|
1192
|
+
outDir,
|
|
1193
|
+
files: artifacts.map(([name]) => name),
|
|
1194
|
+
runs: trend.runs.map((run) => ({
|
|
1195
|
+
label: run.label,
|
|
1196
|
+
app: run.app,
|
|
1197
|
+
device: run.device,
|
|
1198
|
+
...run.startedAtNs === void 0 ? {} : { startedAtNs: run.startedAtNs },
|
|
1199
|
+
metrics: run.metrics.length
|
|
1200
|
+
})),
|
|
1201
|
+
orderedBy: trend.orderedBy,
|
|
1202
|
+
series: trend.series.length,
|
|
1203
|
+
improved: count("improved"),
|
|
1204
|
+
regressed: count("regressed"),
|
|
1205
|
+
unchanged: count("unchanged"),
|
|
1206
|
+
verdictless
|
|
1207
|
+
};
|
|
1208
|
+
},
|
|
1121
1209
|
async hap(req) {
|
|
1122
1210
|
const analysis = analyzeHap(readFileSync2(req.packagePath), basename(req.packagePath));
|
|
1123
1211
|
const capabilities = [{
|
|
@@ -1356,6 +1444,11 @@ function parseOnly(raw) {
|
|
|
1356
1444
|
return ids;
|
|
1357
1445
|
}
|
|
1358
1446
|
|
|
1447
|
+
// src/trend.ts
|
|
1448
|
+
function collectLabels(raw, previous) {
|
|
1449
|
+
return [...previous ?? [], raw];
|
|
1450
|
+
}
|
|
1451
|
+
|
|
1359
1452
|
// src/program.ts
|
|
1360
1453
|
function targetOptionsOf(opts) {
|
|
1361
1454
|
return {
|
|
@@ -1492,6 +1585,25 @@ function buildProgram(deps2, io, opts = {}) {
|
|
|
1492
1585
|
);
|
|
1493
1586
|
}
|
|
1494
1587
|
);
|
|
1588
|
+
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(
|
|
1589
|
+
"--label <label>",
|
|
1590
|
+
"a run label, repeated once per report in order (default: the report path)",
|
|
1591
|
+
collectLabels
|
|
1592
|
+
).option("--json", "print the trend manifest as JSON").action(async (reports, opts2) => {
|
|
1593
|
+
io.emit(
|
|
1594
|
+
await runTrend(
|
|
1595
|
+
deps2,
|
|
1596
|
+
{
|
|
1597
|
+
reports: reports.map((path, index) => {
|
|
1598
|
+
const label = opts2.label?.[index];
|
|
1599
|
+
return { path, ...label === void 0 ? {} : { label } };
|
|
1600
|
+
}),
|
|
1601
|
+
outDir: opts2.out
|
|
1602
|
+
},
|
|
1603
|
+
{ json: opts2.json }
|
|
1604
|
+
)
|
|
1605
|
+
);
|
|
1606
|
+
});
|
|
1495
1607
|
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
1608
|
io.emit(
|
|
1497
1609
|
await runHap(
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-perf/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.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.
|
|
39
|
+
"@ohos-perf/core": "0.16.0",
|
|
40
40
|
"commander": "^12.1.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|