@ohos-perf/cli 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +44 -2
- package/dist/index.js +769 -0
- package/package.json +39 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 growvv
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @ohos-perf/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The `ohos-perf` command line for HarmonyOS performance analysis: probe a
|
|
4
|
+
device's capabilities, capture a scene, analyze it offline, drill into
|
|
5
|
+
evidence, and compare against a baseline.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install -g @ohos-perf/cli
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
or run it without installing:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx @ohos-perf/cli doctor
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Requires Node `^22.13.0 || >=23.4.0`. Live capture needs `hdc` and
|
|
20
|
+
`trace_streamer` from a DevEco Studio installation.
|
|
21
|
+
|
|
22
|
+
## Commands
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
ohos-perf doctor # hdc / trace_streamer / attached device
|
|
26
|
+
ohos-perf caps --json # capability matrix with reasons
|
|
27
|
+
ohos-perf collect --app com.example.app --duration 10s --out ./scene --procfs
|
|
28
|
+
ohos-perf analyze ./scene --json # offline analysis
|
|
29
|
+
ohos-perf tools --json # named drill-down queries
|
|
30
|
+
ohos-perf query ./scene frames.get --args '{"id":42}' --json
|
|
31
|
+
ohos-perf compare ./before ./after --json
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
`--app` is required only by the modes that resolve a pid: `--procfs`,
|
|
35
|
+
`--cold-start`, `--hiperf` and the hiprofiler `nativehook` plugin. The
|
|
36
|
+
device-wide collectors — `--hidumper`, `--uitest` and `--hiprofiler --plugins
|
|
37
|
+
memory` — capture without it.
|
|
38
|
+
|
|
39
|
+
`--json` output is the same structure the `@ohos-perf/core` API returns and is
|
|
40
|
+
byte-identical across runs for the same input. Any failure produces empty
|
|
41
|
+
stdout, one stderr line and exit 1.
|
|
42
|
+
|
|
43
|
+
- Website: <https://growvv.github.io/ohos-perf/>
|
|
44
|
+
- Source and full documentation: <https://github.com/growvv/ohos-perf>
|
|
45
|
+
- License: MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// src/doctor.ts
|
|
4
|
+
function byId(a, b) {
|
|
5
|
+
if (a.id < b.id) return -1;
|
|
6
|
+
if (a.id > b.id) return 1;
|
|
7
|
+
return 0;
|
|
8
|
+
}
|
|
9
|
+
function safeMessage(err) {
|
|
10
|
+
if (err instanceof Error) return err.message;
|
|
11
|
+
try {
|
|
12
|
+
return String(err);
|
|
13
|
+
} catch {
|
|
14
|
+
return "<unprintable error>";
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
function message(err) {
|
|
18
|
+
return safeMessage(err);
|
|
19
|
+
}
|
|
20
|
+
async function doctorReport(deps2) {
|
|
21
|
+
const hdc = { ok: false };
|
|
22
|
+
try {
|
|
23
|
+
hdc.path = await deps2.resolveHdc();
|
|
24
|
+
hdc.ok = true;
|
|
25
|
+
} catch (err) {
|
|
26
|
+
hdc.error = message(err);
|
|
27
|
+
}
|
|
28
|
+
const streamer = { ok: false };
|
|
29
|
+
try {
|
|
30
|
+
const resolved = await deps2.resolveStreamer();
|
|
31
|
+
streamer.path = resolved.path;
|
|
32
|
+
streamer.version = resolved.version;
|
|
33
|
+
streamer.ok = true;
|
|
34
|
+
} catch (err) {
|
|
35
|
+
streamer.error = message(err);
|
|
36
|
+
}
|
|
37
|
+
let device;
|
|
38
|
+
let capabilities = [];
|
|
39
|
+
let probeError;
|
|
40
|
+
try {
|
|
41
|
+
const connected = await deps2.connectDevice();
|
|
42
|
+
const matrix = await connected.capabilities();
|
|
43
|
+
device = { id: connected.id, kind: connected.kind, abi: connected.abi };
|
|
44
|
+
capabilities = [...matrix.all()].sort(byId);
|
|
45
|
+
} catch (err) {
|
|
46
|
+
device = void 0;
|
|
47
|
+
capabilities = [];
|
|
48
|
+
probeError = safeMessage(err);
|
|
49
|
+
}
|
|
50
|
+
return { hdc, streamer, device, probeError, capabilities };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/commands.ts
|
|
54
|
+
function formatCapability(state, idWidth, collectorWidth) {
|
|
55
|
+
const mark = state.available ? "\u2713" : "\u2717";
|
|
56
|
+
const collector = state.collector ?? "\u2014";
|
|
57
|
+
const line = `${mark} ${state.id.padEnd(idWidth)} ${collector.padEnd(collectorWidth)} ${state.fidelity}`;
|
|
58
|
+
return state.reason === void 0 ? line : `${line} ${state.reason}`;
|
|
59
|
+
}
|
|
60
|
+
function formatCapabilities(states) {
|
|
61
|
+
if (states.length === 0) return "no capabilities (no device probed)\n";
|
|
62
|
+
const idWidth = Math.max(...states.map((s) => s.id.length));
|
|
63
|
+
const collectorWidth = Math.max(...states.map((s) => (s.collector ?? "\u2014").length));
|
|
64
|
+
return states.map((state) => formatCapability(state, idWidth, collectorWidth) + "\n").join("");
|
|
65
|
+
}
|
|
66
|
+
function firstLine(text) {
|
|
67
|
+
const [first] = text.split("\n");
|
|
68
|
+
const marker = " Searched paths:";
|
|
69
|
+
const at = first.indexOf(marker);
|
|
70
|
+
if (at !== -1) return { text: first.slice(0, at), truncated: true };
|
|
71
|
+
return { text: first, truncated: false };
|
|
72
|
+
}
|
|
73
|
+
function json(value) {
|
|
74
|
+
return JSON.stringify(value, null, 2) + "\n";
|
|
75
|
+
}
|
|
76
|
+
async function runDoctor(deps2, opts) {
|
|
77
|
+
const report = await doctorReport(deps2.doctor);
|
|
78
|
+
const exitCode = report.hdc.ok ? 0 : 1;
|
|
79
|
+
if (opts.json) return { stdout: json(report), stderr: "", exitCode };
|
|
80
|
+
let stdout = "";
|
|
81
|
+
if (report.hdc.ok) {
|
|
82
|
+
stdout += `hdc ok ${report.hdc.path}
|
|
83
|
+
`;
|
|
84
|
+
} else {
|
|
85
|
+
const hdc = firstLine(report.hdc.error ?? "unknown error");
|
|
86
|
+
const hint = hdc.truncated ? " (use --json for the full search path list)" : "";
|
|
87
|
+
stdout += `hdc FAIL ${hdc.text}${hint}
|
|
88
|
+
`;
|
|
89
|
+
}
|
|
90
|
+
if (report.streamer.ok) {
|
|
91
|
+
stdout += `streamer ok ${report.streamer.path} (${report.streamer.version})
|
|
92
|
+
`;
|
|
93
|
+
} else {
|
|
94
|
+
const streamer = firstLine(report.streamer.error ?? "unknown error");
|
|
95
|
+
const hint = streamer.truncated ? " (use --json for the full search path list)" : "";
|
|
96
|
+
stdout += `streamer FAIL ${streamer.text}${hint}
|
|
97
|
+
`;
|
|
98
|
+
}
|
|
99
|
+
if (report.probeError !== void 0) {
|
|
100
|
+
stdout += `device probe failed: ${report.probeError}
|
|
101
|
+
`;
|
|
102
|
+
} else if (report.device === void 0) {
|
|
103
|
+
stdout += "device none attached\n";
|
|
104
|
+
} else {
|
|
105
|
+
stdout += `device ${report.device.id} (${report.device.kind}, ${report.device.abi})
|
|
106
|
+
`;
|
|
107
|
+
}
|
|
108
|
+
stdout += report.probeError !== void 0 ? "" : formatCapabilities(report.capabilities);
|
|
109
|
+
return { stdout, stderr: "", exitCode };
|
|
110
|
+
}
|
|
111
|
+
async function runCaps(deps2, opts) {
|
|
112
|
+
const report = await deps2.capsReport();
|
|
113
|
+
if (!report.hdcOk) {
|
|
114
|
+
return { stdout: "", stderr: `hdc unavailable: ${report.hdcError}
|
|
115
|
+
`, exitCode: 1 };
|
|
116
|
+
}
|
|
117
|
+
let stdout;
|
|
118
|
+
if (opts.json) {
|
|
119
|
+
stdout = json(report.capabilities);
|
|
120
|
+
} else if (report.probeError !== void 0) {
|
|
121
|
+
stdout = `capabilities unavailable: ${report.probeError}
|
|
122
|
+
`;
|
|
123
|
+
} else {
|
|
124
|
+
stdout = formatCapabilities(report.capabilities);
|
|
125
|
+
}
|
|
126
|
+
return { stdout, stderr: "", exitCode: 0 };
|
|
127
|
+
}
|
|
128
|
+
async function runAnalyze(deps2, sceneDir, opts) {
|
|
129
|
+
try {
|
|
130
|
+
const result = await deps2.analyze(sceneDir, opts.app);
|
|
131
|
+
if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
|
|
132
|
+
const metrics = result.metrics.map((metric) => `${metric.id} ${metric.value} ${metric.unit} (${metric.fidelity})
|
|
133
|
+
`).join("");
|
|
134
|
+
const jank = result.evidence.filter((item) => item.kind === "jank").length;
|
|
135
|
+
const summary = `evidence ${result.evidence.length} items (jank: ${jank})
|
|
136
|
+
`;
|
|
137
|
+
return { stdout: metrics + summary, stderr: "", exitCode: 0 };
|
|
138
|
+
} catch (err) {
|
|
139
|
+
return { stdout: "", stderr: `${safeMessage(err)}
|
|
140
|
+
`, exitCode: 1 };
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
async function runCollect(deps2, req, opts) {
|
|
144
|
+
try {
|
|
145
|
+
const result = await deps2.collect(req);
|
|
146
|
+
if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
|
|
147
|
+
let stdout = `scene ${result.sceneDir}
|
|
148
|
+
`;
|
|
149
|
+
if (result.collectors.length > 0) {
|
|
150
|
+
stdout += `collectors ${result.collectors.join(", ")}
|
|
151
|
+
`;
|
|
152
|
+
}
|
|
153
|
+
const samples = [
|
|
154
|
+
...result.hiperf === void 0 ? [] : [`hiperf ${result.hiperf.samples}`],
|
|
155
|
+
...result.hidumper === void 0 ? [] : [`hidumper ${result.hidumper.frames}`],
|
|
156
|
+
...result.ui === void 0 ? [] : [`ui ${result.ui.nodes}`]
|
|
157
|
+
];
|
|
158
|
+
if (samples.length > 0) stdout += `samples ${samples.join(", ")}
|
|
159
|
+
`;
|
|
160
|
+
return { stdout, stderr: "", exitCode: 0 };
|
|
161
|
+
} catch (err) {
|
|
162
|
+
return { stdout: "", stderr: `${safeMessage(err)}
|
|
163
|
+
`, exitCode: 1 };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
async function runQuery(deps2, req, opts) {
|
|
167
|
+
try {
|
|
168
|
+
const result = await deps2.query(req);
|
|
169
|
+
if (opts.json) return { stdout: json(result), stderr: "", exitCode: 0 };
|
|
170
|
+
const summary = `${result.query} ${result.rows.length}/${result.total} rows${result.truncated ? " (truncated)" : ""}
|
|
171
|
+
`;
|
|
172
|
+
const rows = result.rows.map((row) => JSON.stringify(row) + "\n").join("");
|
|
173
|
+
return { stdout: summary + rows, stderr: "", exitCode: 0 };
|
|
174
|
+
} catch (err) {
|
|
175
|
+
return { stdout: "", stderr: `${safeMessage(err)}
|
|
176
|
+
`, exitCode: 1 };
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
var DELTA_ORDER = [
|
|
180
|
+
"improved",
|
|
181
|
+
"regressed",
|
|
182
|
+
"unchanged",
|
|
183
|
+
"added",
|
|
184
|
+
"removed",
|
|
185
|
+
"incomparable"
|
|
186
|
+
];
|
|
187
|
+
function compareValues(row) {
|
|
188
|
+
const show = (value) => value === null ? "-" : String(value);
|
|
189
|
+
return `${show(row.baseline)} -> ${show(row.current)}`;
|
|
190
|
+
}
|
|
191
|
+
async function runCompare(deps2, req, opts) {
|
|
192
|
+
try {
|
|
193
|
+
const comparison = await deps2.compare(req);
|
|
194
|
+
if (opts.json) return { stdout: json(comparison), stderr: "", exitCode: 0 };
|
|
195
|
+
const rows = comparison.rows.map((row) => {
|
|
196
|
+
const pct = row.deltaPct === void 0 ? "" : ` (${row.deltaPct}%)`;
|
|
197
|
+
return `${row.id} ${compareValues(row)}${pct} ${row.status}
|
|
198
|
+
`;
|
|
199
|
+
});
|
|
200
|
+
const totals = DELTA_ORDER.map((status) => `${status} ${comparison.totals[status]}`).join(", ");
|
|
201
|
+
return { stdout: rows.join("") + `totals ${totals}
|
|
202
|
+
`, stderr: "", exitCode: 0 };
|
|
203
|
+
} catch (err) {
|
|
204
|
+
return { stdout: "", stderr: `${safeMessage(err)}
|
|
205
|
+
`, exitCode: 1 };
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
function runTools(deps2, opts) {
|
|
209
|
+
try {
|
|
210
|
+
const tools = deps2.tools();
|
|
211
|
+
if (opts.json) return { stdout: json(tools), stderr: "", exitCode: 0 };
|
|
212
|
+
const lines = tools.map((tool) => {
|
|
213
|
+
const args = tool.args.map((arg) => arg.required ? arg.name : `${arg.name}?`).join(", ");
|
|
214
|
+
return `${tool.name}(${args}) -> ${tool.returns}
|
|
215
|
+
${tool.description}
|
|
216
|
+
`;
|
|
217
|
+
});
|
|
218
|
+
return { stdout: lines.join(""), stderr: "", exitCode: 0 };
|
|
219
|
+
} catch (err) {
|
|
220
|
+
return { stdout: "", stderr: `${safeMessage(err)}
|
|
221
|
+
`, exitCode: 1 };
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
// src/deps.ts
|
|
226
|
+
import { existsSync, readFileSync } from "fs";
|
|
227
|
+
import { stat } from "fs/promises";
|
|
228
|
+
import { dirname, join, resolve } from "path";
|
|
229
|
+
import { fileURLToPath } from "url";
|
|
230
|
+
import {
|
|
231
|
+
BinderQuery,
|
|
232
|
+
CallstackQuery,
|
|
233
|
+
CapabilityMatrix,
|
|
234
|
+
FrameQuery,
|
|
235
|
+
Hdc,
|
|
236
|
+
InstantQuery,
|
|
237
|
+
MemMeasureQuery,
|
|
238
|
+
OhosPerfError,
|
|
239
|
+
PerfQuery,
|
|
240
|
+
ProcessQuery,
|
|
241
|
+
SchedQuery,
|
|
242
|
+
StartupQuery,
|
|
243
|
+
Streamer,
|
|
244
|
+
ThreadQuery,
|
|
245
|
+
ThreadStateQuery,
|
|
246
|
+
connect,
|
|
247
|
+
createSceneLayout,
|
|
248
|
+
defaultAnalyzers,
|
|
249
|
+
ingestScene,
|
|
250
|
+
lookupQuery,
|
|
251
|
+
queryDefinitions,
|
|
252
|
+
readHidumperCapture,
|
|
253
|
+
readProcfsSamples,
|
|
254
|
+
compareResults,
|
|
255
|
+
readSceneMetadata,
|
|
256
|
+
readUiTree,
|
|
257
|
+
resolveAppIdentity,
|
|
258
|
+
resolveQueryLimit,
|
|
259
|
+
runAnalyzers,
|
|
260
|
+
runNamedQuery,
|
|
261
|
+
unknownQueryError
|
|
262
|
+
} from "@ohos-perf/core";
|
|
263
|
+
var here = dirname(fileURLToPath(import.meta.url));
|
|
264
|
+
var manifestPath = join(here, "../package.json");
|
|
265
|
+
function packageVersion(path = manifestPath) {
|
|
266
|
+
try {
|
|
267
|
+
const pkg = JSON.parse(readFileSync(path, "utf8"));
|
|
268
|
+
const version = typeof pkg.version === "string" ? pkg.version.trim() : "";
|
|
269
|
+
return version === "" ? "0.0.0" : version;
|
|
270
|
+
} catch {
|
|
271
|
+
return "0.0.0";
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
var OFFLINE_PROBE = () => ({ command: "", stdout: "", stderr: "", code: 0 });
|
|
275
|
+
function offlineState(id, collector) {
|
|
276
|
+
return {
|
|
277
|
+
id,
|
|
278
|
+
available: true,
|
|
279
|
+
collector,
|
|
280
|
+
fidelity: "exact",
|
|
281
|
+
probe: OFFLINE_PROBE()
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
var TABLE_RULES = [
|
|
285
|
+
{ id: "trace.frames", collector: "hitrace", tables: ["frame_slice", "process"] },
|
|
286
|
+
{ id: "trace.sched", collector: "hitrace", tables: ["sched_slice", "instant"] },
|
|
287
|
+
{ id: "trace.binder", collector: "hitrace", tables: ["callstack", "args", "data_dict", "process", "thread", "trace_range"] },
|
|
288
|
+
{ id: "trace.thread_state", collector: "hitrace", tables: ["thread_state", "thread", "process"] },
|
|
289
|
+
// Scene artifacts, not tables: `procfs.jsonl`, `hidumper.json` and `ui.json`
|
|
290
|
+
// are satisfied by the parsed artifact the caller passes in.
|
|
291
|
+
{ id: "mem.procfs", collector: "procfs", tables: ["procfs.jsonl"] },
|
|
292
|
+
{ id: "render.fps_live", collector: "hidumper", tables: ["hidumper.json"] },
|
|
293
|
+
{ id: "ui.tree", collector: "uitest", tables: ["ui.json"] },
|
|
294
|
+
{ id: "perf.samples", collector: "hiperf", tables: ["perf_sample"], perf: true },
|
|
295
|
+
// `mem.native_hook` is the design's hiprofiler-memory row. Offline it is
|
|
296
|
+
// satisfied by the memory-plugin tables, exactly as `trace.frames` is
|
|
297
|
+
// satisfied by `frame_slice` + `process` rather than by the hitrace binary.
|
|
298
|
+
// The analyzer joins both tables, so a trace missing the filter table would
|
|
299
|
+
// crash rather than degrade; requiring both keeps the matrix honest. An
|
|
300
|
+
// ftrace-only scene does not offer it, and the engine reports `mem-measure`
|
|
301
|
+
// as skipped.
|
|
302
|
+
{
|
|
303
|
+
id: "mem.native_hook",
|
|
304
|
+
collector: "hiprofiler",
|
|
305
|
+
tables: ["process_measure", "process_measure_filter"]
|
|
306
|
+
}
|
|
307
|
+
];
|
|
308
|
+
function artifactPresent(name, artifacts) {
|
|
309
|
+
switch (name) {
|
|
310
|
+
case "procfs.jsonl":
|
|
311
|
+
return (artifacts.procfsSamples?.length ?? 0) > 0;
|
|
312
|
+
case "hidumper.json":
|
|
313
|
+
return artifacts.hidumper !== void 0;
|
|
314
|
+
case "ui.json":
|
|
315
|
+
return (artifacts.uiTree?.length ?? 0) > 0;
|
|
316
|
+
default:
|
|
317
|
+
return false;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
var ARTIFACT_NAMES = /* @__PURE__ */ new Set(["procfs.jsonl", "hidumper.json", "ui.json"]);
|
|
321
|
+
function offlineCapabilities(db, artifacts, perfDb) {
|
|
322
|
+
const tablesOf = (target) => new Set(
|
|
323
|
+
target.query(
|
|
324
|
+
"SELECT name FROM sqlite_master WHERE type = 'table'"
|
|
325
|
+
).map((row) => row.name)
|
|
326
|
+
);
|
|
327
|
+
const tables = tablesOf(db);
|
|
328
|
+
const perfTables = perfDb === void 0 ? /* @__PURE__ */ new Set() : tablesOf(perfDb);
|
|
329
|
+
const states = [];
|
|
330
|
+
for (const rule of TABLE_RULES) {
|
|
331
|
+
const source = rule.perf === true ? perfTables : tables;
|
|
332
|
+
const present = rule.tables.every(
|
|
333
|
+
(name) => ARTIFACT_NAMES.has(name) ? artifactPresent(name, artifacts) : source.has(name)
|
|
334
|
+
);
|
|
335
|
+
if (!present) continue;
|
|
336
|
+
if (rule.perf === true && perfDb !== void 0) {
|
|
337
|
+
const first = rule.tables[0];
|
|
338
|
+
if (perfDb.query(`SELECT 1 FROM ${first} LIMIT 1`).length === 0) continue;
|
|
339
|
+
}
|
|
340
|
+
states.push(offlineState(rule.id, rule.collector));
|
|
341
|
+
}
|
|
342
|
+
return new CapabilityMatrix(states);
|
|
343
|
+
}
|
|
344
|
+
async function isDirectory(path) {
|
|
345
|
+
try {
|
|
346
|
+
return (await stat(path)).isDirectory();
|
|
347
|
+
} catch {
|
|
348
|
+
return false;
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
async function analyzeScene(open, sceneDir, app) {
|
|
352
|
+
const opened = await open(sceneDir, app);
|
|
353
|
+
try {
|
|
354
|
+
const db = opened.scene.traceDb;
|
|
355
|
+
const context = {
|
|
356
|
+
db,
|
|
357
|
+
frames: new FrameQuery(db),
|
|
358
|
+
processes: new ProcessQuery(db),
|
|
359
|
+
threads: new ThreadQuery(db),
|
|
360
|
+
sched: new SchedQuery(db),
|
|
361
|
+
instant: new InstantQuery(db),
|
|
362
|
+
threadStates: new ThreadStateQuery(db),
|
|
363
|
+
callstacks: new CallstackQuery(db),
|
|
364
|
+
// A hiperf capture lives in its own converted database; the trace
|
|
365
|
+
// database has no perf_* tables, so reading them from `db` would
|
|
366
|
+
// silently report no samples.
|
|
367
|
+
perf: new PerfQuery(opened.scene.perfDb ?? db),
|
|
368
|
+
binder: new BinderQuery(db),
|
|
369
|
+
startup: new StartupQuery(db),
|
|
370
|
+
// memory-plugin writes an .htrace that converts into trace.db, so the
|
|
371
|
+
// tables are in `db`, not in the separate perf database.
|
|
372
|
+
memMeasure: new MemMeasureQuery(db),
|
|
373
|
+
...opened.samples.length > 0 ? { procfs: opened.samples } : {},
|
|
374
|
+
...opened.hidumper === void 0 ? {} : { hidumper: opened.hidumper },
|
|
375
|
+
...opened.metadata !== void 0 ? { metadata: opened.metadata } : {},
|
|
376
|
+
app: opened.app,
|
|
377
|
+
// The whole database: a CLI run has no capture window to honour.
|
|
378
|
+
window: { startNs: 0, endNs: Number.MAX_SAFE_INTEGER },
|
|
379
|
+
caps: opened.caps,
|
|
380
|
+
deviceId: "offline"
|
|
381
|
+
};
|
|
382
|
+
return await runAnalyzers(defaultAnalyzers(), context);
|
|
383
|
+
} finally {
|
|
384
|
+
opened.scene.close();
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function readAnalysisFile(path) {
|
|
388
|
+
let parsed;
|
|
389
|
+
try {
|
|
390
|
+
parsed = JSON.parse(readFileSync(path, "utf8"));
|
|
391
|
+
} catch (err) {
|
|
392
|
+
throw new OhosPerfError(
|
|
393
|
+
`cannot read analysis ${path}: ${safeMessage(err)}`,
|
|
394
|
+
{ code: "COMPARE_BAD_INPUT", cause: err }
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
if (typeof parsed !== "object" || parsed === null || !Array.isArray(parsed.metrics) || !Array.isArray(parsed.evidence)) {
|
|
398
|
+
throw new OhosPerfError(
|
|
399
|
+
`analysis ${path} has no metrics/evidence arrays; pass a scene directory or the output of \`ohos-perf analyze --json\``,
|
|
400
|
+
{ code: "COMPARE_BAD_INPUT" }
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
return parsed;
|
|
404
|
+
}
|
|
405
|
+
function realDeps(version = packageVersion(), overrides = {}) {
|
|
406
|
+
const resolveHdc = () => (overrides.hdc ?? new Hdc()).resolvePath();
|
|
407
|
+
const connectDevice = overrides.connectDevice ?? (() => connect());
|
|
408
|
+
const ingest = overrides.ingest ?? ingestScene;
|
|
409
|
+
const collectDevice = overrides.collectDevice ?? (() => connect());
|
|
410
|
+
const doctor = {
|
|
411
|
+
resolveHdc,
|
|
412
|
+
async resolveStreamer() {
|
|
413
|
+
const streamer = new Streamer();
|
|
414
|
+
return { path: await streamer.resolvePath(), version: await streamer.version() };
|
|
415
|
+
},
|
|
416
|
+
connectDevice
|
|
417
|
+
};
|
|
418
|
+
const openOfflineScene = async (sceneDir, app) => {
|
|
419
|
+
const layout = createSceneLayout(resolve(sceneDir));
|
|
420
|
+
const scene = await ingest(new Streamer(), layout);
|
|
421
|
+
try {
|
|
422
|
+
const db = scene.traceDb;
|
|
423
|
+
const processes = new ProcessQuery(db);
|
|
424
|
+
const hasMetadataFile = existsSync(layout.metadataFile);
|
|
425
|
+
const metadata = hasMetadataFile ? readSceneMetadata(layout) : void 0;
|
|
426
|
+
const declared = (collector) => !hasMetadataFile || metadata !== void 0 && (metadata.capture?.collectors.includes(collector) ?? false);
|
|
427
|
+
const samples = declared("procfs") ? readProcfsSamples(layout.procfsFile) : [];
|
|
428
|
+
const hidumper = declared("hidumper") ? readHidumperCapture(layout.hidumperFile) : void 0;
|
|
429
|
+
const uiTree = declared("uitest") ? readUiTree(layout.uiFile) : void 0;
|
|
430
|
+
let appIdentity;
|
|
431
|
+
if (app !== void 0) {
|
|
432
|
+
appIdentity = resolveAppIdentity(processes, app);
|
|
433
|
+
} else if (metadata !== void 0) {
|
|
434
|
+
const resolved = resolveAppIdentity(processes, metadata.app.packageName);
|
|
435
|
+
appIdentity = resolved.pids.length === 0 && metadata.pids.length > 0 ? {
|
|
436
|
+
packageName: metadata.app.packageName,
|
|
437
|
+
pids: [...new Set(metadata.pids)].sort((a, b) => a - b),
|
|
438
|
+
processNames: metadata.app.processNames.length > 0 ? [...metadata.app.processNames] : [metadata.app.packageName]
|
|
439
|
+
} : resolved;
|
|
440
|
+
} else {
|
|
441
|
+
appIdentity = resolveAppIdentity(processes, "unknown");
|
|
442
|
+
}
|
|
443
|
+
return {
|
|
444
|
+
scene,
|
|
445
|
+
layout,
|
|
446
|
+
...metadata !== void 0 ? { metadata } : {},
|
|
447
|
+
samples,
|
|
448
|
+
app: appIdentity,
|
|
449
|
+
caps: offlineCapabilities(
|
|
450
|
+
db,
|
|
451
|
+
{
|
|
452
|
+
procfsSamples: samples,
|
|
453
|
+
...hidumper === void 0 ? {} : { hidumper },
|
|
454
|
+
...uiTree === void 0 ? {} : { uiTree }
|
|
455
|
+
},
|
|
456
|
+
scene.perfDb
|
|
457
|
+
),
|
|
458
|
+
...uiTree === void 0 ? {} : { uiTree },
|
|
459
|
+
...hidumper === void 0 ? {} : { hidumper }
|
|
460
|
+
};
|
|
461
|
+
} catch (err) {
|
|
462
|
+
scene.close();
|
|
463
|
+
throw err;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
return {
|
|
467
|
+
doctor,
|
|
468
|
+
version,
|
|
469
|
+
async capsReport() {
|
|
470
|
+
try {
|
|
471
|
+
await resolveHdc();
|
|
472
|
+
} catch (err) {
|
|
473
|
+
return { hdcOk: false, hdcError: safeMessage(err), capabilities: [] };
|
|
474
|
+
}
|
|
475
|
+
try {
|
|
476
|
+
const device = await connectDevice();
|
|
477
|
+
const matrix = await device.capabilities();
|
|
478
|
+
return { hdcOk: true, capabilities: matrix.all() };
|
|
479
|
+
} catch (err) {
|
|
480
|
+
return { hdcOk: true, probeError: safeMessage(err), capabilities: [] };
|
|
481
|
+
}
|
|
482
|
+
},
|
|
483
|
+
analyze: (sceneDir, app) => analyzeScene(openOfflineScene, sceneDir, app),
|
|
484
|
+
async query(req) {
|
|
485
|
+
const definition = lookupQuery(req.name);
|
|
486
|
+
if (definition === void 0) throw unknownQueryError(req.name);
|
|
487
|
+
const args = req.args ?? {};
|
|
488
|
+
definition.parseArgs(args);
|
|
489
|
+
const limit = resolveQueryLimit(req.limit);
|
|
490
|
+
const opened = await openOfflineScene(req.sceneDir, req.app);
|
|
491
|
+
try {
|
|
492
|
+
return runNamedQuery(
|
|
493
|
+
{
|
|
494
|
+
db: opened.scene.traceDb,
|
|
495
|
+
app: opened.app,
|
|
496
|
+
caps: opened.caps,
|
|
497
|
+
...opened.uiTree === void 0 ? {} : { uiTree: opened.uiTree }
|
|
498
|
+
},
|
|
499
|
+
req.name,
|
|
500
|
+
args,
|
|
501
|
+
{ limit }
|
|
502
|
+
);
|
|
503
|
+
} finally {
|
|
504
|
+
opened.scene.close();
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
async compare(req) {
|
|
508
|
+
const load = async (input) => await isDirectory(input) ? analyzeScene(openOfflineScene, input) : readAnalysisFile(input);
|
|
509
|
+
const [baseline, current] = await Promise.all([load(req.baseline), load(req.current)]);
|
|
510
|
+
return compareResults(baseline, current);
|
|
511
|
+
},
|
|
512
|
+
tools() {
|
|
513
|
+
return queryDefinitions().map((definition) => ({
|
|
514
|
+
name: definition.name,
|
|
515
|
+
description: definition.description,
|
|
516
|
+
args: definition.args,
|
|
517
|
+
returns: definition.returns
|
|
518
|
+
}));
|
|
519
|
+
},
|
|
520
|
+
async collect(req) {
|
|
521
|
+
const sceneDir = resolve(req.out);
|
|
522
|
+
const device = await collectDevice();
|
|
523
|
+
const session = await device.collect({
|
|
524
|
+
app: req.app,
|
|
525
|
+
durationMs: req.durationMs,
|
|
526
|
+
sceneRoot: sceneDir,
|
|
527
|
+
...req.procfs === true ? { procfs: true } : {},
|
|
528
|
+
...req.coldStart !== void 0 ? { coldStart: { ability: req.coldStart } } : {},
|
|
529
|
+
...req.hiprofiler === void 0 ? {} : {
|
|
530
|
+
hiprofiler: req.hiprofiler.plugins === void 0 ? {} : { plugins: req.hiprofiler.plugins }
|
|
531
|
+
},
|
|
532
|
+
...req.hiperf === void 0 ? {} : { hiperf: req.hiperf },
|
|
533
|
+
...req.hidumper === true ? { hidumper: true } : {},
|
|
534
|
+
...req.uitest === true ? { uitest: true } : {}
|
|
535
|
+
});
|
|
536
|
+
const scene = await session.ingest();
|
|
537
|
+
try {
|
|
538
|
+
const layout = createSceneLayout(sceneDir);
|
|
539
|
+
const meta = readSceneMetadata(layout);
|
|
540
|
+
return {
|
|
541
|
+
sceneDir,
|
|
542
|
+
device: { id: device.id, kind: device.kind },
|
|
543
|
+
collectors: meta?.capture?.collectors ?? [],
|
|
544
|
+
...meta?.capture?.hiperf === void 0 ? {} : { hiperf: { samples: meta.capture.hiperf.samples } },
|
|
545
|
+
...meta?.capture?.hidumper === void 0 ? {} : { hidumper: { frames: meta.capture.hidumper.frames } },
|
|
546
|
+
...meta?.capture?.uitest === void 0 ? {} : { ui: { nodes: meta.capture.uitest.nodes } }
|
|
547
|
+
};
|
|
548
|
+
} finally {
|
|
549
|
+
scene.close();
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/program.ts
|
|
556
|
+
import { Command } from "commander";
|
|
557
|
+
|
|
558
|
+
// src/collect.ts
|
|
559
|
+
import {
|
|
560
|
+
HIPROFILER_PLUGIN_NAMES,
|
|
561
|
+
OhosPerfError as OhosPerfError2
|
|
562
|
+
} from "@ohos-perf/core";
|
|
563
|
+
var MAX_TIMEOUT_MS = 2147483647;
|
|
564
|
+
function parseDurationSeconds(raw) {
|
|
565
|
+
const text = raw.trim();
|
|
566
|
+
const match = /^(\d+(?:\.\d+)?|\.\d+)s?$/.exec(text);
|
|
567
|
+
const seconds = match === null ? Number.NaN : Number(match[1]);
|
|
568
|
+
const bad = (why) => new OhosPerfError2(
|
|
569
|
+
`invalid --duration ${JSON.stringify(raw)}: ${why} (expected a positive whole number of milliseconds, e.g. 10 or 10s)`,
|
|
570
|
+
{ code: "COLLECT_BAD_DURATION" }
|
|
571
|
+
);
|
|
572
|
+
if (!Number.isFinite(seconds) || seconds <= 0) {
|
|
573
|
+
throw bad("expected a positive number of seconds");
|
|
574
|
+
}
|
|
575
|
+
const rawMs = seconds * 1e3;
|
|
576
|
+
if (!Number.isFinite(rawMs) || rawMs > MAX_TIMEOUT_MS) {
|
|
577
|
+
throw bad("duration exceeds the 32-bit setTimeout limit");
|
|
578
|
+
}
|
|
579
|
+
const durationMs = Math.round(rawMs);
|
|
580
|
+
if (Math.abs(rawMs - durationMs) >= 1e-6) {
|
|
581
|
+
throw bad("duration is not a whole number of milliseconds");
|
|
582
|
+
}
|
|
583
|
+
if (!Number.isSafeInteger(durationMs) || durationMs <= 0 || durationMs > MAX_TIMEOUT_MS) {
|
|
584
|
+
throw bad("duration is not a positive whole number of milliseconds within the 32-bit limit");
|
|
585
|
+
}
|
|
586
|
+
return durationMs;
|
|
587
|
+
}
|
|
588
|
+
function parsePluginList(raw) {
|
|
589
|
+
const names = raw.split(",").map((name) => name.trim());
|
|
590
|
+
if (names.length === 0 || names.some((name) => name === "")) {
|
|
591
|
+
throw new OhosPerfError2(
|
|
592
|
+
`invalid --plugins ${JSON.stringify(raw)}: expected a comma-separated list of ` + HIPROFILER_PLUGIN_NAMES.join(", "),
|
|
593
|
+
{ code: "COLLECT_BAD_PLUGIN" }
|
|
594
|
+
);
|
|
595
|
+
}
|
|
596
|
+
const plugins = [];
|
|
597
|
+
for (const name of names) {
|
|
598
|
+
if (!HIPROFILER_PLUGIN_NAMES.includes(name)) {
|
|
599
|
+
throw new OhosPerfError2(
|
|
600
|
+
`unknown hiprofiler plugin ${JSON.stringify(name)}; expected one of ${HIPROFILER_PLUGIN_NAMES.join(", ")}`,
|
|
601
|
+
{ code: "COLLECT_BAD_PLUGIN" }
|
|
602
|
+
);
|
|
603
|
+
}
|
|
604
|
+
if (!plugins.includes(name)) {
|
|
605
|
+
plugins.push(name);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
return plugins;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
// src/query.ts
|
|
612
|
+
import { MAX_QUERY_LIMIT, OhosPerfError as OhosPerfError3, resolveQueryLimit as resolveQueryLimit2 } from "@ohos-perf/core";
|
|
613
|
+
function parseQueryArgs(raw) {
|
|
614
|
+
let value;
|
|
615
|
+
try {
|
|
616
|
+
value = JSON.parse(raw);
|
|
617
|
+
} catch {
|
|
618
|
+
throw new OhosPerfError3("invalid --args: not valid JSON", { code: "QUERY_BAD_ARGS" });
|
|
619
|
+
}
|
|
620
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
621
|
+
throw new OhosPerfError3("invalid --args: expected a JSON object", { code: "QUERY_BAD_ARGS" });
|
|
622
|
+
}
|
|
623
|
+
return value;
|
|
624
|
+
}
|
|
625
|
+
function parseLimit(raw) {
|
|
626
|
+
const text = raw.trim();
|
|
627
|
+
const bad = () => new OhosPerfError3(
|
|
628
|
+
`limit must be an integer between 1 and ${MAX_QUERY_LIMIT}, got ${JSON.stringify(raw)}`,
|
|
629
|
+
{ code: "QUERY_BAD_LIMIT" }
|
|
630
|
+
);
|
|
631
|
+
if (!/^-?\d+$/.test(text)) throw bad();
|
|
632
|
+
try {
|
|
633
|
+
return resolveQueryLimit2(Number(text));
|
|
634
|
+
} catch {
|
|
635
|
+
throw bad();
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
// src/program.ts
|
|
640
|
+
function buildProgram(deps2, io, opts = {}) {
|
|
641
|
+
const program2 = new Command();
|
|
642
|
+
program2.configureOutput({
|
|
643
|
+
writeOut: io.writeOut,
|
|
644
|
+
writeErr: io.writeErr
|
|
645
|
+
});
|
|
646
|
+
if (opts.exitOverride) program2.exitOverride();
|
|
647
|
+
program2.name("ohos-perf").description("Performance analysis for OpenHarmony devices and captured traces").version(deps2.version);
|
|
648
|
+
program2.command("doctor").description("check the hdc/trace_streamer toolchain and the attached device").option("--json", "print the report as JSON").action(async (opts2) => {
|
|
649
|
+
io.emit(await runDoctor(deps2, opts2));
|
|
650
|
+
});
|
|
651
|
+
program2.command("caps").description("print the capability matrix of the attached device").option("--json", "print the capabilities as JSON").action(async (opts2) => {
|
|
652
|
+
io.emit(await runCaps(deps2, opts2));
|
|
653
|
+
});
|
|
654
|
+
program2.command("analyze").description("analyze a captured scene directory (trace.db or trace.htrace)").argument("<scene-dir>", "directory containing trace.db / trace.htrace").option("--app <packageName>", "app package name, for evidence wording").option("--json", "print the analysis result as JSON").action(async (sceneDir, opts2) => {
|
|
655
|
+
io.emit(await runAnalyze(deps2, sceneDir, opts2));
|
|
656
|
+
});
|
|
657
|
+
program2.command("collect").description("capture a scene from the attached device").option(
|
|
658
|
+
"--app <pkg>",
|
|
659
|
+
"application package name (required for --procfs, --cold-start, --hiperf and hiprofiler nativehook)"
|
|
660
|
+
).requiredOption("--duration <seconds>", "capture duration in seconds (10 or 10s)").requiredOption("--out <dir>", "scene output directory").option("--procfs", "also sample /proc memory state for the app").option("--cold-start <ability>", "launch this ability before capturing").option("--hiprofiler", "capture through hiprofiler instead of hitrace").option(
|
|
661
|
+
"--plugins <list>",
|
|
662
|
+
"hiprofiler plugins, comma-separated: ftrace, gpu, xpower, nativehook, memory"
|
|
663
|
+
).option("--hiperf", "also capture a hiperf perf.data (debuggable app only)").option("--hidumper", "also sample the RenderService fps and hitch counters").option("--uitest", "also dump the on-screen UI tree").option("--json", "print the result as JSON").action(async (opts2) => {
|
|
664
|
+
let durationMs;
|
|
665
|
+
try {
|
|
666
|
+
durationMs = parseDurationSeconds(opts2.duration);
|
|
667
|
+
} catch (err) {
|
|
668
|
+
io.emit({ stdout: "", stderr: `${safeMessage(err)}
|
|
669
|
+
`, exitCode: 1 });
|
|
670
|
+
return;
|
|
671
|
+
}
|
|
672
|
+
if (opts2.plugins !== void 0 && opts2.hiprofiler !== true) {
|
|
673
|
+
io.emit({
|
|
674
|
+
stdout: "",
|
|
675
|
+
stderr: "invalid --plugins: --hiprofiler is required\n",
|
|
676
|
+
exitCode: 1
|
|
677
|
+
});
|
|
678
|
+
return;
|
|
679
|
+
}
|
|
680
|
+
let hiprofilerRequest;
|
|
681
|
+
if (opts2.hiprofiler === true) {
|
|
682
|
+
try {
|
|
683
|
+
hiprofilerRequest = opts2.plugins === void 0 ? {} : { plugins: parsePluginList(opts2.plugins) };
|
|
684
|
+
} catch (err) {
|
|
685
|
+
io.emit({ stdout: "", stderr: `${safeMessage(err)}
|
|
686
|
+
`, exitCode: 1 });
|
|
687
|
+
return;
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
const needsApp = opts2.procfs === true || opts2.coldStart !== void 0 || opts2.hiperf === true || (hiprofilerRequest?.plugins?.includes("nativehook") ?? false);
|
|
691
|
+
if (needsApp && (opts2.app === void 0 || opts2.app === "")) {
|
|
692
|
+
io.emit({
|
|
693
|
+
stdout: "",
|
|
694
|
+
stderr: "missing --app: --procfs, --cold-start, --hiperf and the nativehook plugin require an application package name\n",
|
|
695
|
+
exitCode: 1
|
|
696
|
+
});
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
io.emit(await runCollect(deps2, {
|
|
700
|
+
...opts2.app === void 0 ? {} : { app: opts2.app },
|
|
701
|
+
durationMs,
|
|
702
|
+
out: opts2.out,
|
|
703
|
+
...opts2.procfs === true ? { procfs: true } : {},
|
|
704
|
+
...opts2.coldStart !== void 0 ? { coldStart: opts2.coldStart } : {},
|
|
705
|
+
...hiprofilerRequest === void 0 ? {} : { hiprofiler: hiprofilerRequest },
|
|
706
|
+
...opts2.hiperf === true ? { hiperf: {} } : {},
|
|
707
|
+
...opts2.hidumper === true ? { hidumper: true } : {},
|
|
708
|
+
...opts2.uitest === true ? { uitest: true } : {}
|
|
709
|
+
}, { json: opts2.json }));
|
|
710
|
+
});
|
|
711
|
+
program2.command("query").description("run one named drill-down query against a captured scene").argument("<scene-dir>", "directory containing trace.db / trace.htrace").argument("<name>", "named query; list them with `ohos-perf tools`").option("--app <packageName>", "app package name, overriding scene.json").option("--args <json>", "query arguments as a JSON object").option("--limit <n>", "maximum rows to return (default 100, max 1000)").option("--json", "print the result as JSON").action(async (sceneDir, name, opts2) => {
|
|
712
|
+
let args;
|
|
713
|
+
let limit;
|
|
714
|
+
try {
|
|
715
|
+
args = opts2.args === void 0 ? void 0 : parseQueryArgs(opts2.args);
|
|
716
|
+
limit = opts2.limit === void 0 ? void 0 : parseLimit(opts2.limit);
|
|
717
|
+
} catch (err) {
|
|
718
|
+
io.emit({ stdout: "", stderr: `${safeMessage(err)}
|
|
719
|
+
`, exitCode: 1 });
|
|
720
|
+
return;
|
|
721
|
+
}
|
|
722
|
+
io.emit(await runQuery(deps2, {
|
|
723
|
+
sceneDir,
|
|
724
|
+
name,
|
|
725
|
+
...opts2.app !== void 0 ? { app: opts2.app } : {},
|
|
726
|
+
...args !== void 0 ? { args } : {},
|
|
727
|
+
...limit !== void 0 ? { limit } : {}
|
|
728
|
+
}, { json: opts2.json }));
|
|
729
|
+
});
|
|
730
|
+
program2.command("compare").description("compare a current analysis against a baseline").argument("<baseline>", "scene directory or `analyze --json` file").argument("<current>", "scene directory or `analyze --json` file").option("--json", "print the comparison as JSON").action(async (baseline, current, opts2) => {
|
|
731
|
+
io.emit(await runCompare(deps2, { baseline, current }, { json: opts2.json }));
|
|
732
|
+
});
|
|
733
|
+
program2.command("tools").description("list the named drill-down queries an agent can call").option("--json", "print the query definitions as JSON").action((opts2) => {
|
|
734
|
+
io.emit(runTools(deps2, opts2));
|
|
735
|
+
});
|
|
736
|
+
return program2;
|
|
737
|
+
}
|
|
738
|
+
|
|
739
|
+
// src/index.ts
|
|
740
|
+
var deps = realDeps();
|
|
741
|
+
function emit(result) {
|
|
742
|
+
try {
|
|
743
|
+
if (result.stdout) process.stdout.write(result.stdout);
|
|
744
|
+
if (result.stderr) process.stderr.write(result.stderr);
|
|
745
|
+
} catch (err) {
|
|
746
|
+
if (err.code !== "EPIPE") throw err;
|
|
747
|
+
}
|
|
748
|
+
if (result.exitCode !== 0) process.exitCode = result.exitCode;
|
|
749
|
+
}
|
|
750
|
+
function ignoreEpipe(stream) {
|
|
751
|
+
stream.on("error", (err) => {
|
|
752
|
+
if (err.code === "EPIPE") return;
|
|
753
|
+
process.stderr.write(`${safeMessage(err)}
|
|
754
|
+
`);
|
|
755
|
+
process.exitCode = 1;
|
|
756
|
+
});
|
|
757
|
+
}
|
|
758
|
+
ignoreEpipe(process.stdout);
|
|
759
|
+
ignoreEpipe(process.stderr);
|
|
760
|
+
var program = buildProgram(deps, {
|
|
761
|
+
writeOut: (text) => process.stdout.write(text),
|
|
762
|
+
writeErr: (text) => process.stderr.write(text),
|
|
763
|
+
emit
|
|
764
|
+
});
|
|
765
|
+
program.parseAsync(process.argv).catch((err) => {
|
|
766
|
+
process.stderr.write(`${safeMessage(err)}
|
|
767
|
+
`);
|
|
768
|
+
process.exitCode = 1;
|
|
769
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@ohos-perf/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-perf/cli",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Command-line interface for HarmonyOS performance analysis: doctor, caps, collect, analyze, query, tools and compare",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"harmonyos",
|
|
7
|
+
"openharmony",
|
|
8
|
+
"ohos",
|
|
9
|
+
"performance",
|
|
10
|
+
"profiling",
|
|
11
|
+
"cli",
|
|
12
|
+
"hapray"
|
|
13
|
+
],
|
|
14
|
+
"type": "module",
|
|
15
|
+
"bin": { "ohos-perf": "./dist/index.js" },
|
|
16
|
+
"files": ["dist"],
|
|
17
|
+
"engines": { "node": "^22.13.0 || >=23.4.0" },
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"author": "growvv",
|
|
20
|
+
"homepage": "https://growvv.github.io/ohos-perf/",
|
|
21
|
+
"repository": {
|
|
22
|
+
"type": "git",
|
|
23
|
+
"url": "git+https://github.com/growvv/ohos-perf.git",
|
|
24
|
+
"directory": "packages/cli"
|
|
25
|
+
},
|
|
26
|
+
"bugs": { "url": "https://github.com/growvv/ohos-perf/issues" },
|
|
27
|
+
"publishConfig": { "access": "public" },
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@ohos-perf/core": "0.1.0",
|
|
30
|
+
"commander": "^12.1.0"
|
|
31
|
+
},
|
|
32
|
+
"scripts": {
|
|
33
|
+
"build": "tsup src/index.ts --format esm --target node22",
|
|
34
|
+
"typecheck": "tsc --noEmit -p tsconfig.test.json",
|
|
35
|
+
"pretest": "npm run build -w @ohos-perf/core",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"prepublishOnly": "npm run build"
|
|
38
|
+
}
|
|
39
|
+
}
|