@ohos-perf/cli 0.11.0 → 0.12.1
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 +109 -12
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// src/commands.ts
|
|
4
|
-
import { readFileSync, statSync } from "fs";
|
|
4
|
+
import { existsSync, mkdirSync, readFileSync, statSync, writeFileSync } from "fs";
|
|
5
|
+
import { join } from "path";
|
|
5
6
|
import {
|
|
7
|
+
discoverCases,
|
|
8
|
+
loadCases,
|
|
6
9
|
OhosPerfError as OhosPerfError2,
|
|
7
10
|
parseScenario
|
|
8
11
|
} from "@ohos-perf/core";
|
|
@@ -367,6 +370,16 @@ function packagePathError(packagePath) {
|
|
|
367
370
|
return void 0;
|
|
368
371
|
}
|
|
369
372
|
async function runScenarioCommand(deps2, input, opts) {
|
|
373
|
+
if (input.casesDir !== void 0) {
|
|
374
|
+
if (input.scenarioPath !== "") {
|
|
375
|
+
return {
|
|
376
|
+
stdout: "",
|
|
377
|
+
stderr: "run: give either a scenario file or --cases <dir>, not both\n",
|
|
378
|
+
exitCode: 1
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
return runCases(deps2, input, opts);
|
|
382
|
+
}
|
|
370
383
|
let scenario;
|
|
371
384
|
try {
|
|
372
385
|
let text;
|
|
@@ -420,6 +433,88 @@ async function runScenarioCommand(deps2, input, opts) {
|
|
|
420
433
|
`, exitCode: 1 };
|
|
421
434
|
}
|
|
422
435
|
}
|
|
436
|
+
async function runCases(deps2, input, opts) {
|
|
437
|
+
let loads;
|
|
438
|
+
try {
|
|
439
|
+
loads = loadCases(discoverCases(input.casesDir, input.filter));
|
|
440
|
+
} catch (err) {
|
|
441
|
+
return { stdout: "", stderr: `${failureLine(err)}
|
|
442
|
+
`, exitCode: 1 };
|
|
443
|
+
}
|
|
444
|
+
const outcomes = [];
|
|
445
|
+
for (const load of loads) {
|
|
446
|
+
if (load.scenario === void 0) {
|
|
447
|
+
outcomes.push({
|
|
448
|
+
id: load.id,
|
|
449
|
+
status: "failed",
|
|
450
|
+
error: load.error ?? "the case could not be read"
|
|
451
|
+
});
|
|
452
|
+
continue;
|
|
453
|
+
}
|
|
454
|
+
const caseOut = join(input.outDir, load.id);
|
|
455
|
+
try {
|
|
456
|
+
const result = await deps2.run({
|
|
457
|
+
scenario: load.scenario,
|
|
458
|
+
scenarioPath: load.path,
|
|
459
|
+
outDir: caseOut,
|
|
460
|
+
...input.target === void 0 ? {} : { target: input.target },
|
|
461
|
+
...input.rounds === void 0 ? {} : { rounds: input.rounds },
|
|
462
|
+
...input.only === void 0 ? {} : { only: input.only },
|
|
463
|
+
...input.keepGoing === true ? { keepGoing: true } : {}
|
|
464
|
+
});
|
|
465
|
+
const ok = result.steps.filter((step) => step.status === "ok").length;
|
|
466
|
+
outcomes.push({
|
|
467
|
+
id: load.id,
|
|
468
|
+
status: result.status === "failed" ? "failed" : "ok",
|
|
469
|
+
outDir: load.id,
|
|
470
|
+
steps: { ok, total: result.steps.length },
|
|
471
|
+
...result.status === "failed" ? { error: firstFailure(result) ?? "the run reported failure" } : {}
|
|
472
|
+
});
|
|
473
|
+
} catch (err) {
|
|
474
|
+
outcomes.push({
|
|
475
|
+
id: load.id,
|
|
476
|
+
status: "failed",
|
|
477
|
+
...existsSync(caseOut) ? { outDir: load.id } : {},
|
|
478
|
+
error: safeMessage(err)
|
|
479
|
+
});
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
const index = { version: 1, cases: outcomes };
|
|
483
|
+
try {
|
|
484
|
+
mkdirSync(input.outDir, { recursive: true });
|
|
485
|
+
writeFileSync(join(input.outDir, "cases.json"), `${JSON.stringify(index, null, 2)}
|
|
486
|
+
`);
|
|
487
|
+
} catch (err) {
|
|
488
|
+
return {
|
|
489
|
+
stdout: "",
|
|
490
|
+
stderr: `cannot write cases.json: ${safeMessage(err)}
|
|
491
|
+
`,
|
|
492
|
+
exitCode: 1
|
|
493
|
+
};
|
|
494
|
+
}
|
|
495
|
+
const failed = outcomes.filter((entry) => entry.status === "failed").length;
|
|
496
|
+
const exitCode = failed === 0 ? 0 : 1;
|
|
497
|
+
if (opts.json) {
|
|
498
|
+
return { stdout: `${JSON.stringify(index, null, 2)}
|
|
499
|
+
`, stderr: "", exitCode };
|
|
500
|
+
}
|
|
501
|
+
const lines = outcomes.map((entry) => {
|
|
502
|
+
const steps = entry.steps === void 0 ? "" : ` steps ${entry.steps.ok}/${entry.steps.total} ok`;
|
|
503
|
+
const error = entry.status === "ok" ? "" : ` ${entry.error ?? "failed"}`;
|
|
504
|
+
return `${entry.status === "ok" ? "ok " : "failed"} ${entry.id}${steps}${error}`;
|
|
505
|
+
});
|
|
506
|
+
const summary = failed === 0 ? `cases ${outcomes.length}/${outcomes.length} ok` : `cases ${outcomes.length - failed}/${outcomes.length} ok, ${failed} failed`;
|
|
507
|
+
return {
|
|
508
|
+
stdout: `${lines.map((line) => `${line}
|
|
509
|
+
`).join("")}${summary}
|
|
510
|
+
`,
|
|
511
|
+
stderr: "",
|
|
512
|
+
exitCode
|
|
513
|
+
};
|
|
514
|
+
}
|
|
515
|
+
function firstFailure(result) {
|
|
516
|
+
return result.steps.find((step) => step.status === "failed")?.error;
|
|
517
|
+
}
|
|
423
518
|
function runTools(deps2, opts) {
|
|
424
519
|
try {
|
|
425
520
|
const tools = deps2.tools();
|
|
@@ -508,9 +603,9 @@ async function runEmulatorCreate(deps2, req, opts) {
|
|
|
508
603
|
}
|
|
509
604
|
|
|
510
605
|
// src/deps.ts
|
|
511
|
-
import { existsSync, readFileSync as readFileSync2 } from "fs";
|
|
606
|
+
import { existsSync as existsSync2, readFileSync as readFileSync2 } from "fs";
|
|
512
607
|
import { copyFile, mkdir, stat, writeFile } from "fs/promises";
|
|
513
|
-
import { basename, dirname, join, resolve } from "path";
|
|
608
|
+
import { basename, dirname, join as join2, resolve } from "path";
|
|
514
609
|
import { fileURLToPath } from "url";
|
|
515
610
|
import {
|
|
516
611
|
BinderQuery,
|
|
@@ -566,7 +661,7 @@ import {
|
|
|
566
661
|
unknownQueryError
|
|
567
662
|
} from "@ohos-perf/core";
|
|
568
663
|
var here = dirname(fileURLToPath(import.meta.url));
|
|
569
|
-
var manifestPath =
|
|
664
|
+
var manifestPath = join2(here, "../package.json");
|
|
570
665
|
function packageVersion(path = manifestPath) {
|
|
571
666
|
try {
|
|
572
667
|
const pkg = JSON.parse(readFileSync2(path, "utf8"));
|
|
@@ -801,7 +896,7 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
801
896
|
try {
|
|
802
897
|
const db = scene.traceDb;
|
|
803
898
|
const processes = new ProcessQuery(db);
|
|
804
|
-
const hasMetadataFile =
|
|
899
|
+
const hasMetadataFile = existsSync2(layout.metadataFile);
|
|
805
900
|
const metadata = hasMetadataFile ? readSceneMetadata(layout) : void 0;
|
|
806
901
|
const declared = (collector) => !hasMetadataFile || metadata !== void 0 && (metadata.capture?.collectors.includes(collector) ?? false);
|
|
807
902
|
const samples = declared("procfs") ? readProcfsSamples(layout.procfsFile) : [];
|
|
@@ -810,7 +905,7 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
810
905
|
const screenshotFile = declared("screenshot") ? layout.screenshotFile : void 0;
|
|
811
906
|
let screenshot;
|
|
812
907
|
let screenshotError;
|
|
813
|
-
if (screenshotFile !== void 0 &&
|
|
908
|
+
if (screenshotFile !== void 0 && existsSync2(screenshotFile)) {
|
|
814
909
|
try {
|
|
815
910
|
screenshot = decodePng(new Uint8Array(readFileSync2(screenshotFile)));
|
|
816
911
|
} catch (err) {
|
|
@@ -986,12 +1081,12 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
986
1081
|
const outDir = resolve(req.outDir);
|
|
987
1082
|
await mkdir(outDir, { recursive: true });
|
|
988
1083
|
for (const [name, content] of artifacts) {
|
|
989
|
-
await writeFile(
|
|
1084
|
+
await writeFile(join2(outDir, name), content);
|
|
990
1085
|
}
|
|
991
1086
|
const files = artifacts.map(([name]) => name);
|
|
992
1087
|
if (detailed.screenshotFile !== void 0 && detailed.screenshot !== void 0) {
|
|
993
|
-
await mkdir(
|
|
994
|
-
await copyFile(detailed.screenshotFile,
|
|
1088
|
+
await mkdir(join2(outDir, "assets"), { recursive: true });
|
|
1089
|
+
await copyFile(detailed.screenshotFile, join2(outDir, "assets", "screenshot.png"));
|
|
995
1090
|
files.push("assets/screenshot.png");
|
|
996
1091
|
}
|
|
997
1092
|
return {
|
|
@@ -1036,7 +1131,7 @@ function realDeps(version = packageVersion(), overrides = {}) {
|
|
|
1036
1131
|
const outDir = resolve(req.outDir);
|
|
1037
1132
|
await mkdir(outDir, { recursive: true });
|
|
1038
1133
|
for (const [name, content] of artifacts) {
|
|
1039
|
-
await writeFile(
|
|
1134
|
+
await writeFile(join2(outDir, name), content);
|
|
1040
1135
|
}
|
|
1041
1136
|
return { analysis, capabilities, outDir, artifacts: artifacts.map(([name]) => name) };
|
|
1042
1137
|
},
|
|
@@ -1392,7 +1487,7 @@ function buildProgram(deps2, io, opts = {}) {
|
|
|
1392
1487
|
)
|
|
1393
1488
|
);
|
|
1394
1489
|
});
|
|
1395
|
-
program2.command("run").description("run a declarative scenario, capturing one scene per step").argument("
|
|
1490
|
+
program2.command("run").description("run a declarative scenario, capturing one scene per step").argument("[scenario]", "scenario JSON file (omit when using --cases)").requiredOption("--out <dir>", "run output directory (one scene per step)").option("--cases <dir>", "run every *.scenario.json in this directory as one suite").option("--filter <regex>", "anchored regex over case ids; only with --cases").option("--target <id>", "run against this hdc target instead of the first connected one").option("--rounds <n>", "repeat every step this many times (overrides the scenario)").option("--only <ids>", "comma-separated step ids to run, in scenario order").option("--keep-going", "continue after a failed step instead of stopping").option("--json", "print the run result as JSON").action(async (scenarioPath, opts2) => {
|
|
1396
1491
|
let rounds;
|
|
1397
1492
|
let only;
|
|
1398
1493
|
try {
|
|
@@ -1411,8 +1506,10 @@ function buildProgram(deps2, io, opts = {}) {
|
|
|
1411
1506
|
return;
|
|
1412
1507
|
}
|
|
1413
1508
|
io.emit(await runScenarioCommand(deps2, {
|
|
1414
|
-
scenarioPath,
|
|
1509
|
+
scenarioPath: scenarioPath ?? "",
|
|
1415
1510
|
outDir: opts2.out,
|
|
1511
|
+
...opts2.cases === void 0 ? {} : { casesDir: opts2.cases },
|
|
1512
|
+
...opts2.filter === void 0 ? {} : { filter: opts2.filter },
|
|
1416
1513
|
...opts2.target === void 0 ? {} : { target: opts2.target },
|
|
1417
1514
|
...rounds === void 0 ? {} : { rounds },
|
|
1418
1515
|
...only === void 0 ? {} : { only },
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ohos-perf/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools, compare, report, gesture and
|
|
3
|
+
"version": "0.12.1",
|
|
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",
|
|
7
7
|
"openharmony",
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"access": "public"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@ohos-perf/core": "0.
|
|
39
|
+
"@ohos-perf/core": "0.12.1",
|
|
40
40
|
"commander": "^12.1.0"
|
|
41
41
|
},
|
|
42
42
|
"scripts": {
|