@ohos-perf/core 0.22.4 → 0.23.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.d.ts +256 -2
- package/dist/index.js +541 -123
- package/package.json +48 -48
package/dist/index.js
CHANGED
|
@@ -562,8 +562,8 @@ function combined(result) {
|
|
|
562
562
|
${result.stderr}`;
|
|
563
563
|
}
|
|
564
564
|
var DETAIL_MAX_LINES = 5;
|
|
565
|
-
function detail(
|
|
566
|
-
const lines =
|
|
565
|
+
function detail(text2) {
|
|
566
|
+
const lines = text2.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.length > 0);
|
|
567
567
|
if (lines.length === 0) return "(no output)";
|
|
568
568
|
const shown = lines.slice(0, DETAIL_MAX_LINES).join(" | ");
|
|
569
569
|
return lines.length > DETAIL_MAX_LINES ? `${shown} | ... (${lines.length - DETAIL_MAX_LINES} more lines)` : shown;
|
|
@@ -749,8 +749,8 @@ var DONE_MARKER = "DONE";
|
|
|
749
749
|
var SKELETON_MAX_BYTES = 2048;
|
|
750
750
|
var MAX_DURATION_MS = 2147483647;
|
|
751
751
|
var DETAIL_MAX_LINES2 = 5;
|
|
752
|
-
function detail2(
|
|
753
|
-
const lines =
|
|
752
|
+
function detail2(text2) {
|
|
753
|
+
const lines = text2.split(/\r?\n/).map((l) => l.trim()).filter((l) => l.length > 0);
|
|
754
754
|
if (lines.length === 0) return "(no output)";
|
|
755
755
|
const shown = lines.slice(0, DETAIL_MAX_LINES2).join(" | ");
|
|
756
756
|
return lines.length > DETAIL_MAX_LINES2 ? `${shown} | ... (${lines.length - DETAIL_MAX_LINES2} more lines)` : shown;
|
|
@@ -1003,21 +1003,21 @@ var HITCH_WINDOW = /^\s*window \[\] Id\[(\d+)\]:\s*$/gm;
|
|
|
1003
1003
|
var HITCH_16_67 = /^\s*more than 16\.67 ms\s+(\d+)\s*$/m;
|
|
1004
1004
|
var HITCH_33 = /^\s*more than 33 ms\s+(\d+)\s*$/m;
|
|
1005
1005
|
var HITCH_66 = /^\s*more than 66 ms\s+(\d+)\s*$/m;
|
|
1006
|
-
function parseFpsCounts(
|
|
1007
|
-
const header =
|
|
1006
|
+
function parseFpsCounts(text2) {
|
|
1007
|
+
const header = text2.indexOf(FPS_HEADER);
|
|
1008
1008
|
if (header < 0) return [];
|
|
1009
|
-
const block =
|
|
1009
|
+
const block = text2.slice(header + FPS_HEADER.length);
|
|
1010
1010
|
return [...block.matchAll(FPS_LINE)].map((match) => ({
|
|
1011
1011
|
refreshRate: Number(match[1]),
|
|
1012
1012
|
count: Number(match[2])
|
|
1013
1013
|
}));
|
|
1014
1014
|
}
|
|
1015
|
-
function parseHitches(
|
|
1016
|
-
const headers = [...
|
|
1015
|
+
function parseHitches(text2) {
|
|
1016
|
+
const headers = [...text2.matchAll(HITCH_WINDOW)];
|
|
1017
1017
|
return headers.map((match, index) => {
|
|
1018
1018
|
const start = (match.index ?? 0) + match[0].length;
|
|
1019
1019
|
const next = headers[index + 1];
|
|
1020
|
-
const block =
|
|
1020
|
+
const block = text2.slice(start, next?.index ?? text2.length);
|
|
1021
1021
|
const count = (pattern, label2) => {
|
|
1022
1022
|
const found = block.match(pattern);
|
|
1023
1023
|
if (found === null) {
|
|
@@ -1215,9 +1215,9 @@ function parseHilogLine(line, year, captureNs) {
|
|
|
1215
1215
|
parsed: true
|
|
1216
1216
|
};
|
|
1217
1217
|
}
|
|
1218
|
-
function parseHilogText(
|
|
1219
|
-
if (
|
|
1220
|
-
const parts =
|
|
1218
|
+
function parseHilogText(text2, opts) {
|
|
1219
|
+
if (text2 === "") return [];
|
|
1220
|
+
const parts = text2.split(/\r?\n/);
|
|
1221
1221
|
if (parts.length > 0 && parts[parts.length - 1] === "") parts.pop();
|
|
1222
1222
|
const year = opts.year;
|
|
1223
1223
|
return parts.map((line, index) => {
|
|
@@ -1257,22 +1257,22 @@ var HilogCollector = class {
|
|
|
1257
1257
|
assertDuration4(opts.durationMs);
|
|
1258
1258
|
removeStaleArtifacts(layout);
|
|
1259
1259
|
const result = await hdc.shellFor(target, HILOG_COMMAND, opts.durationMs);
|
|
1260
|
-
const
|
|
1261
|
-
if (
|
|
1260
|
+
const text2 = result.stdout;
|
|
1261
|
+
if (text2.trim() === "") {
|
|
1262
1262
|
throw new OhosPerfError(
|
|
1263
1263
|
`hilog produced no output in ${opts.durationMs} ms` + (result.stderr.trim() === "" ? "" : `; device stderr: ${result.stderr.trim().slice(0, 200)}`),
|
|
1264
1264
|
{ code: "HILOG_NO_OUTPUT" }
|
|
1265
1265
|
);
|
|
1266
1266
|
}
|
|
1267
1267
|
mkdirSync3(layout.root, { recursive: true });
|
|
1268
|
-
writeFileSync3(layout.hilogFile,
|
|
1269
|
-
const rows = parseHilogText(
|
|
1268
|
+
writeFileSync3(layout.hilogFile, text2);
|
|
1269
|
+
const rows = parseHilogText(text2, { captureNs: 0 });
|
|
1270
1270
|
writeFileSync3(
|
|
1271
1271
|
layout.hilogJsonlFile,
|
|
1272
1272
|
rows.map((row2) => `${JSON.stringify(row2)}
|
|
1273
1273
|
`).join("")
|
|
1274
1274
|
);
|
|
1275
|
-
const lines =
|
|
1275
|
+
const lines = text2.split(/\r?\n/).filter((line) => line.trim() !== "").length;
|
|
1276
1276
|
return { lines };
|
|
1277
1277
|
}
|
|
1278
1278
|
};
|
|
@@ -1291,10 +1291,10 @@ var EVENT_PATTERN = /^[a-z0-9-]+$/;
|
|
|
1291
1291
|
var SAMPLES_MARKER = /\[ Sample records: (\d+), Non sample records: (\d+) \]/;
|
|
1292
1292
|
var LOST_MARKER = /\[ Sample lost: (\d+), Non sample lost: (\d+) \]/;
|
|
1293
1293
|
var NOT_DEBUGGABLE = /only support debug(?: or profileable)? application/;
|
|
1294
|
-
function parseHiperfSummary(
|
|
1295
|
-
const samples = SAMPLES_MARKER.exec(
|
|
1294
|
+
function parseHiperfSummary(text2) {
|
|
1295
|
+
const samples = SAMPLES_MARKER.exec(text2);
|
|
1296
1296
|
if (samples === null) return void 0;
|
|
1297
|
-
const lost = LOST_MARKER.exec(
|
|
1297
|
+
const lost = LOST_MARKER.exec(text2);
|
|
1298
1298
|
return {
|
|
1299
1299
|
samples: Number(samples[1]),
|
|
1300
1300
|
nonSamples: Number(samples[2]),
|
|
@@ -1390,8 +1390,8 @@ function combined3(result) {
|
|
|
1390
1390
|
return `${result.stdout}
|
|
1391
1391
|
${result.stderr}`;
|
|
1392
1392
|
}
|
|
1393
|
-
function detail4(
|
|
1394
|
-
const lines =
|
|
1393
|
+
function detail4(text2) {
|
|
1394
|
+
const lines = text2.split(/\r?\n/).map((line) => line.trim()).filter((line) => line.length > 0);
|
|
1395
1395
|
if (lines.length === 0) return "(no output)";
|
|
1396
1396
|
const shown = lines.slice(0, DETAIL_MAX_LINES3).join(" | ");
|
|
1397
1397
|
return lines.length > DETAIL_MAX_LINES3 ? `${shown} | ... (${lines.length - DETAIL_MAX_LINES3} more lines)` : shown;
|
|
@@ -1458,15 +1458,15 @@ var MIN_INTERVAL_MS2 = 100;
|
|
|
1458
1458
|
var APP_PATTERN2 = /^[A-Za-z0-9_.]+$/;
|
|
1459
1459
|
var STATUS_FIELDS = /^(VmRSS|VmHWM|Threads):\s+(\d+)(?:\s+kB)?$/gm;
|
|
1460
1460
|
var SMAPS_FIELDS = /^(Pss|Private_Dirty|SwapPss):\s+(\d+)(?:\s+kB)?$/gm;
|
|
1461
|
-
function parseFields(
|
|
1461
|
+
function parseFields(text2, pattern) {
|
|
1462
1462
|
const values = /* @__PURE__ */ new Map();
|
|
1463
|
-
for (const match of
|
|
1463
|
+
for (const match of text2.matchAll(pattern)) {
|
|
1464
1464
|
values.set(match[1], Number(match[2]));
|
|
1465
1465
|
}
|
|
1466
1466
|
return values;
|
|
1467
1467
|
}
|
|
1468
|
-
function parseProcfsStatus(
|
|
1469
|
-
const values = parseFields(
|
|
1468
|
+
function parseProcfsStatus(text2) {
|
|
1469
|
+
const values = parseFields(text2, STATUS_FIELDS);
|
|
1470
1470
|
const vmRssKb = values.get("VmRSS");
|
|
1471
1471
|
const vmHwmKb = values.get("VmHWM");
|
|
1472
1472
|
const threads = values.get("Threads");
|
|
@@ -1479,8 +1479,8 @@ function parseProcfsStatus(text) {
|
|
|
1479
1479
|
threads
|
|
1480
1480
|
};
|
|
1481
1481
|
}
|
|
1482
|
-
function parseSmapsRollup(
|
|
1483
|
-
const values = parseFields(
|
|
1482
|
+
function parseSmapsRollup(text2) {
|
|
1483
|
+
const values = parseFields(text2, SMAPS_FIELDS);
|
|
1484
1484
|
const pssKb = values.get("Pss");
|
|
1485
1485
|
const privateDirtyKb = values.get("Private_Dirty");
|
|
1486
1486
|
const swapPssKb = values.get("SwapPss");
|
|
@@ -2600,14 +2600,14 @@ function assertKey(key) {
|
|
|
2600
2600
|
`gesture key must be Back, Home, Power or a positive key code (got ${JSON.stringify(key)})`
|
|
2601
2601
|
);
|
|
2602
2602
|
}
|
|
2603
|
-
function assertText(
|
|
2604
|
-
if (
|
|
2605
|
-
if (CONTROL_CHARS.test(
|
|
2603
|
+
function assertText(text2) {
|
|
2604
|
+
if (text2 === "") throw badGesture("gesture text must not be empty");
|
|
2605
|
+
if (CONTROL_CHARS.test(text2)) {
|
|
2606
2606
|
throw badGesture("gesture text must not contain control characters");
|
|
2607
2607
|
}
|
|
2608
2608
|
}
|
|
2609
|
-
function quote(
|
|
2610
|
-
return `'${
|
|
2609
|
+
function quote(text2) {
|
|
2610
|
+
return `'${text2.replace(/'/g, "'\\''")}'`;
|
|
2611
2611
|
}
|
|
2612
2612
|
function detail9(result) {
|
|
2613
2613
|
const lines = `${result.stdout}
|
|
@@ -3149,8 +3149,8 @@ var UNSUPPORTED_PREFIX = "event not support";
|
|
|
3149
3149
|
function parseBinaries(whichOutputs) {
|
|
3150
3150
|
const binaries = {};
|
|
3151
3151
|
for (const [name, output] of Object.entries(whichOutputs)) {
|
|
3152
|
-
const
|
|
3153
|
-
binaries[name] =
|
|
3152
|
+
const text2 = output.trim();
|
|
3153
|
+
binaries[name] = text2 !== "" && !text2.includes("MISSING") && !text2.includes("No such file");
|
|
3154
3154
|
}
|
|
3155
3155
|
return binaries;
|
|
3156
3156
|
}
|
|
@@ -3793,9 +3793,9 @@ function defaultCommonPaths3(env, platform) {
|
|
|
3793
3793
|
paths.push(join6("C:", "Program Files", "Huawei", "DevEco Studio", ...tail));
|
|
3794
3794
|
return paths;
|
|
3795
3795
|
}
|
|
3796
|
-
function parseEmuConfig(
|
|
3796
|
+
function parseEmuConfig(text2) {
|
|
3797
3797
|
const entries = {};
|
|
3798
|
-
for (const line of
|
|
3798
|
+
for (const line of text2.split(/\r?\n/)) {
|
|
3799
3799
|
const at = line.indexOf(":");
|
|
3800
3800
|
if (at <= 0) continue;
|
|
3801
3801
|
const key = line.slice(0, at).trim();
|
|
@@ -3817,13 +3817,13 @@ function readEmuConfigRoots(env, platform) {
|
|
|
3817
3817
|
}
|
|
3818
3818
|
const roots = {};
|
|
3819
3819
|
for (const dir of dirs) {
|
|
3820
|
-
let
|
|
3820
|
+
let text2;
|
|
3821
3821
|
try {
|
|
3822
|
-
|
|
3822
|
+
text2 = readFileSync9(join6(huawei, dir, ".emu_config"), "utf8");
|
|
3823
3823
|
} catch {
|
|
3824
3824
|
continue;
|
|
3825
3825
|
}
|
|
3826
|
-
const entries = parseEmuConfig(
|
|
3826
|
+
const entries = parseEmuConfig(text2);
|
|
3827
3827
|
if (roots.instancePath === void 0 && entries.emuPath) roots.instancePath = entries.emuPath;
|
|
3828
3828
|
if (roots.imageRoot === void 0 && entries.imagePath) roots.imageRoot = entries.imagePath;
|
|
3829
3829
|
if (roots.instancePath !== void 0 && roots.imageRoot !== void 0) break;
|
|
@@ -4733,9 +4733,9 @@ function compileRules(rules) {
|
|
|
4733
4733
|
return {
|
|
4734
4734
|
name: rule.name,
|
|
4735
4735
|
match(line) {
|
|
4736
|
-
const
|
|
4736
|
+
const text2 = rule.scope === "line" ? renderLine(line) : line.message;
|
|
4737
4737
|
regex.lastIndex = 0;
|
|
4738
|
-
const hit = regex.exec(
|
|
4738
|
+
const hit = regex.exec(text2);
|
|
4739
4739
|
if (hit === null) return void 0;
|
|
4740
4740
|
const extracted = groupIndexes.map((index) => {
|
|
4741
4741
|
if (index === 0) return hit[0];
|
|
@@ -5495,12 +5495,12 @@ function parseSelector(value, path) {
|
|
|
5495
5495
|
checkKeys(value, selectorKind, path);
|
|
5496
5496
|
switch (selectorKind) {
|
|
5497
5497
|
case "text": {
|
|
5498
|
-
const
|
|
5498
|
+
const text2 = requiredText(value.text, `${path}.text`);
|
|
5499
5499
|
const exact = value.exact;
|
|
5500
5500
|
if (exact !== void 0 && typeof exact !== "boolean") {
|
|
5501
5501
|
bad3(`${path}.exact`, "expected true or false");
|
|
5502
5502
|
}
|
|
5503
|
-
return exact === void 0 ? { kind: "text", text } : { kind: "text", text, exact };
|
|
5503
|
+
return exact === void 0 ? { kind: "text", text: text2 } : { kind: "text", text: text2, exact };
|
|
5504
5504
|
}
|
|
5505
5505
|
case "id":
|
|
5506
5506
|
return { kind: "id", id: requiredText(value.id, `${path}.id`) };
|
|
@@ -5728,11 +5728,11 @@ function requiredString(value, path, error) {
|
|
|
5728
5728
|
return value;
|
|
5729
5729
|
}
|
|
5730
5730
|
function bareName(value, path, error) {
|
|
5731
|
-
const
|
|
5732
|
-
if (!BARE_NAME2.test(
|
|
5733
|
-
throw error(path, `expected a bare name matching ${String(BARE_NAME2)}, got ${JSON.stringify(
|
|
5731
|
+
const text2 = requiredString(value, path, error);
|
|
5732
|
+
if (!BARE_NAME2.test(text2)) {
|
|
5733
|
+
throw error(path, `expected a bare name matching ${String(BARE_NAME2)}, got ${JSON.stringify(text2)}`);
|
|
5734
5734
|
}
|
|
5735
|
-
return
|
|
5735
|
+
return text2;
|
|
5736
5736
|
}
|
|
5737
5737
|
function positiveInt(value, path, error) {
|
|
5738
5738
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value <= 0) {
|
|
@@ -5747,11 +5747,11 @@ function nonNegativeInt(value, path, error) {
|
|
|
5747
5747
|
return value;
|
|
5748
5748
|
}
|
|
5749
5749
|
function gestureText(value, path, error) {
|
|
5750
|
-
const
|
|
5751
|
-
if (CONTROL_CHARS2.test(
|
|
5750
|
+
const text2 = requiredString(value, path, error);
|
|
5751
|
+
if (CONTROL_CHARS2.test(text2)) {
|
|
5752
5752
|
throw error(path, "expected no control characters");
|
|
5753
5753
|
}
|
|
5754
|
-
return
|
|
5754
|
+
return text2;
|
|
5755
5755
|
}
|
|
5756
5756
|
var ACTION_KEYS = {
|
|
5757
5757
|
launch: ["kind", "ability"],
|
|
@@ -5845,14 +5845,14 @@ function parseAction(value, path, error) {
|
|
|
5845
5845
|
};
|
|
5846
5846
|
}
|
|
5847
5847
|
case "tapText": {
|
|
5848
|
-
const
|
|
5849
|
-
if (
|
|
5848
|
+
const text2 = requiredString(action.text, at("text"), error);
|
|
5849
|
+
if (text2 === "") {
|
|
5850
5850
|
throw error(at("text"), "expected a non-empty label; an empty one matches every node");
|
|
5851
5851
|
}
|
|
5852
5852
|
const scrollTo = action.scrollTo === void 0 ? void 0 : parseSelector(action.scrollTo, at("scrollTo"));
|
|
5853
5853
|
return {
|
|
5854
5854
|
kind: "tapText",
|
|
5855
|
-
text,
|
|
5855
|
+
text: text2,
|
|
5856
5856
|
...scrollTo === void 0 ? {} : { scrollTo }
|
|
5857
5857
|
};
|
|
5858
5858
|
}
|
|
@@ -6043,10 +6043,10 @@ function parseExpectation(value, path) {
|
|
|
6043
6043
|
...foreground === void 0 ? {} : { foreground }
|
|
6044
6044
|
};
|
|
6045
6045
|
}
|
|
6046
|
-
function parseScenario(
|
|
6046
|
+
function parseScenario(text2) {
|
|
6047
6047
|
let parsed;
|
|
6048
6048
|
try {
|
|
6049
|
-
parsed = JSON.parse(
|
|
6049
|
+
parsed = JSON.parse(text2);
|
|
6050
6050
|
} catch (err) {
|
|
6051
6051
|
throw new OhosPerfError(
|
|
6052
6052
|
`invalid scenario: not valid JSON (${err instanceof Error ? err.message : String(err)})`,
|
|
@@ -6137,9 +6137,9 @@ function discoverCases(dir, filter) {
|
|
|
6137
6137
|
}
|
|
6138
6138
|
function loadCases(cases) {
|
|
6139
6139
|
return cases.map((entry) => {
|
|
6140
|
-
let
|
|
6140
|
+
let text2;
|
|
6141
6141
|
try {
|
|
6142
|
-
|
|
6142
|
+
text2 = readFileSync11(entry.path, "utf8");
|
|
6143
6143
|
} catch (err) {
|
|
6144
6144
|
return {
|
|
6145
6145
|
id: entry.id,
|
|
@@ -6148,7 +6148,7 @@ function loadCases(cases) {
|
|
|
6148
6148
|
};
|
|
6149
6149
|
}
|
|
6150
6150
|
try {
|
|
6151
|
-
return { id: entry.id, path: entry.path, scenario: parseScenario(
|
|
6151
|
+
return { id: entry.id, path: entry.path, scenario: parseScenario(text2) };
|
|
6152
6152
|
} catch (err) {
|
|
6153
6153
|
return { id: entry.id, path: entry.path, error: `${basename(entry.path)}: ${message(err)}` };
|
|
6154
6154
|
}
|
|
@@ -6375,6 +6375,34 @@ var PARITY_ROWS = [
|
|
|
6375
6375
|
name: "Report comparison",
|
|
6376
6376
|
status: "ported",
|
|
6377
6377
|
reason: ""
|
|
6378
|
+
},
|
|
6379
|
+
/*
|
|
6380
|
+
* Rows 36–39 were added after the pinned revision. They keep counting from
|
|
6381
|
+
* 35 so a reader can tell the original inventory from what followed it.
|
|
6382
|
+
*/
|
|
6383
|
+
{
|
|
6384
|
+
row: 36,
|
|
6385
|
+
name: "Root-cause narrative (`root-cause`)",
|
|
6386
|
+
status: "ported",
|
|
6387
|
+
reason: ""
|
|
6388
|
+
},
|
|
6389
|
+
{
|
|
6390
|
+
row: 37,
|
|
6391
|
+
name: "Debug HAP build (`build`, wraps deveco-cli)",
|
|
6392
|
+
status: "out",
|
|
6393
|
+
reason: "this is a build tool, not a measurement: it invokes deveco-cli to produce a debug package. A package analyzer cannot own the toolchain that compiles the package it reads, and a half-ported wrapper would make every measurement depend on a compiler version this package does not control. `hap` and `opt` read what the build produced instead."
|
|
6394
|
+
},
|
|
6395
|
+
{
|
|
6396
|
+
row: 38,
|
|
6397
|
+
name: "LLM exploration strategy and state comparator (`haptest`)",
|
|
6398
|
+
status: "missing",
|
|
6399
|
+
reason: "HapRay hands the whole step to a model: `llm_strategy.py` asks it which node to tap, and `llm_state_comparator.py` asks whether the screen changed. Neither answer is checked, so a model that taps a dead button reports progress. Not ported yet; P29 covers it, and the design requires the model's answer to be verified against the screen it was given before the step counts."
|
|
6400
|
+
},
|
|
6401
|
+
{
|
|
6402
|
+
row: 39,
|
|
6403
|
+
name: "Thermal analysis (`hidumper -s ThermalService`)",
|
|
6404
|
+
status: "missing",
|
|
6405
|
+
reason: "a collector plus an analyzer, so it is a capability of its own rather than part of the root-cause narrative: HapRay samples each sensor through hidumper and reports start/end/peak/mean and the rise. Not ported yet; the collector is the part that has to be measured on a device first, because a sensor list that is assumed rather than read would produce a thermal curve for a sensor the device lacks."
|
|
6378
6406
|
}
|
|
6379
6407
|
];
|
|
6380
6408
|
function paritySummary() {
|
|
@@ -6392,10 +6420,10 @@ function paritySummary() {
|
|
|
6392
6420
|
}
|
|
6393
6421
|
|
|
6394
6422
|
// src/analyze/redundant-file.ts
|
|
6395
|
-
function parseRedundantFile(
|
|
6423
|
+
function parseRedundantFile(text2) {
|
|
6396
6424
|
const byPath2 = /* @__PURE__ */ new Map();
|
|
6397
6425
|
let reads = 0;
|
|
6398
|
-
const lines =
|
|
6426
|
+
const lines = text2.split(/\r?\n/);
|
|
6399
6427
|
for (let index = 0; index < lines.length; index += 1) {
|
|
6400
6428
|
const line = lines[index].trim();
|
|
6401
6429
|
if (line === "" || line.startsWith("#")) continue;
|
|
@@ -6430,8 +6458,8 @@ var RedundantFileAnalyzer = class {
|
|
|
6430
6458
|
id = "redundant-file";
|
|
6431
6459
|
requires = [];
|
|
6432
6460
|
async run(ctx) {
|
|
6433
|
-
const
|
|
6434
|
-
if (
|
|
6461
|
+
const text2 = ctx.redundantFile;
|
|
6462
|
+
if (text2 === void 0) {
|
|
6435
6463
|
return {
|
|
6436
6464
|
metrics: [],
|
|
6437
6465
|
evidence: [
|
|
@@ -6448,7 +6476,7 @@ var RedundantFileAnalyzer = class {
|
|
|
6448
6476
|
]
|
|
6449
6477
|
};
|
|
6450
6478
|
}
|
|
6451
|
-
const report = parseRedundantFile(
|
|
6479
|
+
const report = parseRedundantFile(text2);
|
|
6452
6480
|
const make = (id, value) => metric({
|
|
6453
6481
|
id,
|
|
6454
6482
|
value,
|
|
@@ -7303,9 +7331,9 @@ function renderReportHtml(model) {
|
|
|
7303
7331
|
// src/report/csv.ts
|
|
7304
7332
|
function cell(value) {
|
|
7305
7333
|
if (value === void 0) return "";
|
|
7306
|
-
const
|
|
7307
|
-
if (!/[,",\n\r]/.test(
|
|
7308
|
-
return `"${
|
|
7334
|
+
const text2 = String(value);
|
|
7335
|
+
if (!/[,",\n\r]/.test(text2)) return text2;
|
|
7336
|
+
return `"${text2.replace(/"/g, '""')}"`;
|
|
7309
7337
|
}
|
|
7310
7338
|
function row(fields2) {
|
|
7311
7339
|
return fields2.map(cell).join(",") + "\n";
|
|
@@ -7704,10 +7732,10 @@ function readSummary(value, section) {
|
|
|
7704
7732
|
};
|
|
7705
7733
|
return { lines: ratio("lines"), functions: ratio("functions"), branches: ratio("branches") };
|
|
7706
7734
|
}
|
|
7707
|
-
function parseCoverageReport(
|
|
7735
|
+
function parseCoverageReport(text2) {
|
|
7708
7736
|
let document;
|
|
7709
7737
|
try {
|
|
7710
|
-
document = JSON.parse(
|
|
7738
|
+
document = JSON.parse(text2);
|
|
7711
7739
|
} catch (err) {
|
|
7712
7740
|
throw new OhosPerfError(
|
|
7713
7741
|
`coverageReport.json is not valid JSON: ${err.message}`,
|
|
@@ -7753,8 +7781,8 @@ var CoverageAnalyzer = class {
|
|
|
7753
7781
|
id = "coverage";
|
|
7754
7782
|
requires = [];
|
|
7755
7783
|
async run(ctx) {
|
|
7756
|
-
const
|
|
7757
|
-
if (
|
|
7784
|
+
const text2 = ctx.coverage;
|
|
7785
|
+
if (text2 === void 0) {
|
|
7758
7786
|
return {
|
|
7759
7787
|
metrics: [],
|
|
7760
7788
|
evidence: [
|
|
@@ -7771,7 +7799,7 @@ var CoverageAnalyzer = class {
|
|
|
7771
7799
|
]
|
|
7772
7800
|
};
|
|
7773
7801
|
}
|
|
7774
|
-
const report = parseCoverageReport(
|
|
7802
|
+
const report = parseCoverageReport(text2);
|
|
7775
7803
|
const make = (id, value, unit) => metric({
|
|
7776
7804
|
id,
|
|
7777
7805
|
value,
|
|
@@ -8634,8 +8662,8 @@ function describeDecision(decision) {
|
|
|
8634
8662
|
return `type ${JSON.stringify(action.text)}`;
|
|
8635
8663
|
}
|
|
8636
8664
|
}
|
|
8637
|
-
function oneLine(
|
|
8638
|
-
return
|
|
8665
|
+
function oneLine(text2) {
|
|
8666
|
+
return text2.replace(/\r?\n/g, "\\n").replace(/\t/g, "\\t");
|
|
8639
8667
|
}
|
|
8640
8668
|
function renderTree(tree) {
|
|
8641
8669
|
if (tree.length === 0) {
|
|
@@ -8722,17 +8750,17 @@ function parseGesture(value) {
|
|
|
8722
8750
|
}
|
|
8723
8751
|
return value;
|
|
8724
8752
|
}
|
|
8725
|
-
function unfence(
|
|
8726
|
-
const match = /^\s*```(?:json)?\s*\n([\s\S]*?)\n\s*```\s*$/.exec(
|
|
8727
|
-
return match === null ?
|
|
8753
|
+
function unfence(text2) {
|
|
8754
|
+
const match = /^\s*```(?:json)?\s*\n([\s\S]*?)\n\s*```\s*$/.exec(text2);
|
|
8755
|
+
return match === null ? text2 : match[1];
|
|
8728
8756
|
}
|
|
8729
|
-
function parseDecision(
|
|
8757
|
+
function parseDecision(text2) {
|
|
8730
8758
|
let parsed;
|
|
8731
8759
|
try {
|
|
8732
|
-
parsed = JSON.parse(unfence(
|
|
8760
|
+
parsed = JSON.parse(unfence(text2));
|
|
8733
8761
|
} catch {
|
|
8734
8762
|
throw badInput(
|
|
8735
|
-
`the model's answer is not JSON: ${JSON.stringify(
|
|
8763
|
+
`the model's answer is not JSON: ${JSON.stringify(text2.slice(0, 120))}`
|
|
8736
8764
|
);
|
|
8737
8765
|
}
|
|
8738
8766
|
const decision = assertDecision(parsed, 0);
|
|
@@ -8973,7 +9001,7 @@ function typeOf(info) {
|
|
|
8973
9001
|
function symbolTableOf(dv, sections, links, bytes, index) {
|
|
8974
9002
|
const section = sections[index];
|
|
8975
9003
|
const link = links[index];
|
|
8976
|
-
const
|
|
9004
|
+
const strings2 = link >= 0 && link < sections.length ? bytes.subarray(sections[link].offset, sections[link].offset + sections[link].size) : new Uint8Array(0);
|
|
8977
9005
|
const entrySize = section.entrySize === 0 ? 24 : section.entrySize;
|
|
8978
9006
|
const count = Math.floor(section.size / entrySize);
|
|
8979
9007
|
const symbols = [];
|
|
@@ -8985,7 +9013,7 @@ function symbolTableOf(dv, sections, links, bytes, index) {
|
|
|
8985
9013
|
const sectionIndex = field(dv, base + 6, 2, "st_shndx");
|
|
8986
9014
|
const value = field(dv, base + 8, 8, "st_value");
|
|
8987
9015
|
const size = field(dv, base + 16, 8, "st_size");
|
|
8988
|
-
const name = readString(
|
|
9016
|
+
const name = readString(strings2, nameOffset);
|
|
8989
9017
|
symbols.push({ name, bind: bindOf(info), type: typeOf(info), size, value, sectionIndex });
|
|
8990
9018
|
}
|
|
8991
9019
|
return symbols;
|
|
@@ -9069,9 +9097,9 @@ function readElf(bytes) {
|
|
|
9069
9097
|
}
|
|
9070
9098
|
}
|
|
9071
9099
|
const nameTable = raw[shstrndx];
|
|
9072
|
-
const
|
|
9100
|
+
const strings2 = bytes.subarray(nameTable.offset, nameTable.offset + nameTable.size);
|
|
9073
9101
|
const sections = raw.map((section) => ({
|
|
9074
|
-
name: readString(
|
|
9102
|
+
name: readString(strings2, section.nameOffset),
|
|
9075
9103
|
type: section.type,
|
|
9076
9104
|
flags: section.flags,
|
|
9077
9105
|
offset: section.offset,
|
|
@@ -9209,13 +9237,13 @@ function recoverSymbols(bytes, unresolved) {
|
|
|
9209
9237
|
}
|
|
9210
9238
|
var PLACEHOLDER = /^(?:fcn|sym|sub|loc|unk|fun)[._][0-9a-f]+$/i;
|
|
9211
9239
|
function normaliseName(name) {
|
|
9212
|
-
let
|
|
9213
|
-
|
|
9214
|
-
|
|
9215
|
-
|
|
9216
|
-
|
|
9217
|
-
|
|
9218
|
-
return
|
|
9240
|
+
let text2 = name.trim();
|
|
9241
|
+
text2 = text2.replace(/^(?:sym\.(?:imp\.)?|fcn\.)/i, "");
|
|
9242
|
+
text2 = text2.replace(/\(.*\)$/, "");
|
|
9243
|
+
text2 = text2.replace(/\s*->.*$/, "");
|
|
9244
|
+
text2 = text2.replace(/^_Z\d+/, "");
|
|
9245
|
+
text2 = text2.replace(/^_+/, "");
|
|
9246
|
+
return text2.toLowerCase();
|
|
9219
9247
|
}
|
|
9220
9248
|
function isNameable(symbol) {
|
|
9221
9249
|
if (symbol.type !== "func" || symbol.size === 0) return false;
|
|
@@ -9231,12 +9259,12 @@ async function measureNaming(bytes, answer) {
|
|
|
9231
9259
|
size: symbol.size,
|
|
9232
9260
|
bind: symbol.bind
|
|
9233
9261
|
})).sort((a, b) => a.start - b.start || (a.truth < b.truth ? -1 : a.truth > b.truth ? 1 : 0));
|
|
9234
|
-
const
|
|
9262
|
+
const text2 = elf.bytesOf(".text");
|
|
9235
9263
|
const textStart = elf.section(".text")?.offset ?? 0;
|
|
9236
9264
|
const bodyOf = (start, size) => {
|
|
9237
9265
|
const from = start - textStart;
|
|
9238
|
-
if (from < 0 || from + size >
|
|
9239
|
-
return
|
|
9266
|
+
if (from < 0 || from + size > text2.length) return new Uint8Array(0);
|
|
9267
|
+
return text2.subarray(from, from + size);
|
|
9240
9268
|
};
|
|
9241
9269
|
const cases = [];
|
|
9242
9270
|
for (const held_out of held) {
|
|
@@ -9273,6 +9301,7 @@ async function measureNaming(bytes, answer) {
|
|
|
9273
9301
|
}
|
|
9274
9302
|
|
|
9275
9303
|
// src/scenario/agent-client.ts
|
|
9304
|
+
var GUI_TURN = { prompt: agentPrompt, parse: parseDecision };
|
|
9276
9305
|
var OWN_BASE_URL = "OHOS_PERF_AGENT_BASE_URL";
|
|
9277
9306
|
var OWN_API_KEY = "OHOS_PERF_AGENT_API_KEY";
|
|
9278
9307
|
var OWN_MODEL = "OHOS_PERF_AGENT_MODEL";
|
|
@@ -9331,11 +9360,12 @@ function httpAgentModel(options) {
|
|
|
9331
9360
|
if (model === "") throw badClient("the agent model name must not be empty");
|
|
9332
9361
|
const url = `${baseUrl}/chat/completions`;
|
|
9333
9362
|
const timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS4;
|
|
9363
|
+
const shape = options.shape ?? GUI_TURN;
|
|
9334
9364
|
return {
|
|
9335
9365
|
async decide(turn) {
|
|
9336
9366
|
const body = {
|
|
9337
9367
|
model,
|
|
9338
|
-
messages: [{ role: "user", content:
|
|
9368
|
+
messages: [{ role: "user", content: shape.prompt(turn) }],
|
|
9339
9369
|
// The answer is JSON the loop parses, so the endpoint is asked for JSON
|
|
9340
9370
|
// rather than for prose that happens to contain some.
|
|
9341
9371
|
response_format: { type: "json_object" }
|
|
@@ -9357,29 +9387,29 @@ function httpAgentModel(options) {
|
|
|
9357
9387
|
{ code: "AGENT_UNREACHABLE", cause: err }
|
|
9358
9388
|
);
|
|
9359
9389
|
}
|
|
9360
|
-
const
|
|
9390
|
+
const text2 = await response.text();
|
|
9361
9391
|
if (!response.ok) {
|
|
9362
9392
|
throw new OhosPerfError(
|
|
9363
|
-
`the agent endpoint answered ${response.status}: ${
|
|
9393
|
+
`the agent endpoint answered ${response.status}: ${text2.slice(0, EXCERPT_CHARS)}`,
|
|
9364
9394
|
{ code: "AGENT_HTTP_ERROR" }
|
|
9365
9395
|
);
|
|
9366
9396
|
}
|
|
9367
|
-
const content = contentOf(safeJson(
|
|
9397
|
+
const content = contentOf(safeJson(text2));
|
|
9368
9398
|
if (content.trim() === "") {
|
|
9369
9399
|
throw new OhosPerfError("the model returned an empty answer", {
|
|
9370
9400
|
code: "AGENT_BAD_RESPONSE"
|
|
9371
9401
|
});
|
|
9372
9402
|
}
|
|
9373
|
-
return
|
|
9403
|
+
return shape.parse(content);
|
|
9374
9404
|
}
|
|
9375
9405
|
};
|
|
9376
9406
|
}
|
|
9377
|
-
function safeJson(
|
|
9407
|
+
function safeJson(text2) {
|
|
9378
9408
|
try {
|
|
9379
|
-
return JSON.parse(
|
|
9409
|
+
return JSON.parse(text2);
|
|
9380
9410
|
} catch {
|
|
9381
9411
|
throw new OhosPerfError(
|
|
9382
|
-
`the agent endpoint answered with something that is not JSON: ${
|
|
9412
|
+
`the agent endpoint answered with something that is not JSON: ${text2.slice(0, EXCERPT_CHARS)}`,
|
|
9383
9413
|
{ code: "AGENT_BAD_RESPONSE" }
|
|
9384
9414
|
);
|
|
9385
9415
|
}
|
|
@@ -10495,7 +10525,7 @@ ORDER BY id`,
|
|
|
10495
10525
|
const dict = /* @__PURE__ */ new Map();
|
|
10496
10526
|
if (!this.hasTable("data_dict")) return dict;
|
|
10497
10527
|
const ids = [...new Set(
|
|
10498
|
-
frames.map((frame) => frameName(frame.name)).filter((
|
|
10528
|
+
frames.map((frame) => frameName(frame.name)).filter((text2) => /^\d+$/.test(text2)).map((text2) => Number(text2))
|
|
10499
10529
|
)].filter((id) => id !== 0).sort((a, b) => a - b);
|
|
10500
10530
|
if (ids.length === 0) return dict;
|
|
10501
10531
|
const rows = this.db.query(
|
|
@@ -10505,8 +10535,8 @@ ORDER BY id`,
|
|
|
10505
10535
|
ids
|
|
10506
10536
|
);
|
|
10507
10537
|
for (const row2 of rows) {
|
|
10508
|
-
const
|
|
10509
|
-
if (
|
|
10538
|
+
const text2 = str(row2.data).trim();
|
|
10539
|
+
if (text2 !== "") dict.set(num(row2.id), text2);
|
|
10510
10540
|
}
|
|
10511
10541
|
return dict;
|
|
10512
10542
|
}
|
|
@@ -10710,8 +10740,8 @@ LEFT JOIN data_dict kd ON a.key = kd.id
|
|
|
10710
10740
|
LEFT JOIN data_dict vd ON a.value = vd.id AND a.datatype = 1
|
|
10711
10741
|
WHERE c.name LIKE '%binder%'`;
|
|
10712
10742
|
function parseCode(value) {
|
|
10713
|
-
const
|
|
10714
|
-
const first =
|
|
10743
|
+
const text2 = String(value).trim();
|
|
10744
|
+
const first = text2.split(/\s+/)[0] ?? "";
|
|
10715
10745
|
if (!first.startsWith("0x")) return value;
|
|
10716
10746
|
const parsed = Number.parseInt(first, 16);
|
|
10717
10747
|
return Number.isNaN(parsed) ? value : parsed;
|
|
@@ -13477,18 +13507,18 @@ function divideRoundHalfEven(numerator, denominator) {
|
|
|
13477
13507
|
return quotient;
|
|
13478
13508
|
}
|
|
13479
13509
|
function decimalText(quotient, digits) {
|
|
13480
|
-
let
|
|
13510
|
+
let text2 = quotient.toString();
|
|
13481
13511
|
if (digits > 0) {
|
|
13482
|
-
if (
|
|
13483
|
-
|
|
13512
|
+
if (text2.length <= digits) {
|
|
13513
|
+
text2 = `0.${"0".repeat(digits - text2.length)}${text2}`;
|
|
13484
13514
|
} else {
|
|
13485
|
-
const split =
|
|
13486
|
-
|
|
13515
|
+
const split = text2.length - digits;
|
|
13516
|
+
text2 = `${text2.slice(0, split)}.${text2.slice(split)}`;
|
|
13487
13517
|
}
|
|
13488
13518
|
} else if (digits < 0) {
|
|
13489
|
-
|
|
13519
|
+
text2 += "0".repeat(-digits);
|
|
13490
13520
|
}
|
|
13491
|
-
return
|
|
13521
|
+
return text2;
|
|
13492
13522
|
}
|
|
13493
13523
|
function roundedDecimalText(value, digits) {
|
|
13494
13524
|
const { negative, mantissa, exponent } = exactDouble(value);
|
|
@@ -16433,14 +16463,14 @@ function appProcessName9(ctx) {
|
|
|
16433
16463
|
}
|
|
16434
16464
|
function treeStats(nodes) {
|
|
16435
16465
|
let clickable = 0;
|
|
16436
|
-
let
|
|
16466
|
+
let text2 = 0;
|
|
16437
16467
|
let depth = 0;
|
|
16438
16468
|
for (const node of nodes) {
|
|
16439
16469
|
if (node.clickable) clickable += 1;
|
|
16440
|
-
if (node.text !== "")
|
|
16470
|
+
if (node.text !== "") text2 += 1;
|
|
16441
16471
|
if (node.depth > depth) depth = node.depth;
|
|
16442
16472
|
}
|
|
16443
|
-
return { nodes: nodes.length, clickable, text, depth };
|
|
16473
|
+
return { nodes: nodes.length, clickable, text: text2, depth };
|
|
16444
16474
|
}
|
|
16445
16475
|
function treeMetrics(ctx, nodes) {
|
|
16446
16476
|
if (nodes === void 0) {
|
|
@@ -18936,12 +18966,12 @@ var EntryReader = class {
|
|
|
18936
18966
|
};
|
|
18937
18967
|
function matchContent(ruleId, rule, data) {
|
|
18938
18968
|
if (data === void 0) return { matched: false };
|
|
18939
|
-
const
|
|
18969
|
+
const text2 = new TextDecoder("utf-8").decode(data);
|
|
18940
18970
|
let best;
|
|
18941
18971
|
for (const item of rule.patterns ?? []) {
|
|
18942
18972
|
const source = typeof item === "string" ? item : item.pattern;
|
|
18943
18973
|
const own = typeof item === "string" ? void 0 : item.confidence;
|
|
18944
|
-
if (!compile(ruleId, source).test(
|
|
18974
|
+
if (!compile(ruleId, source).test(text2)) continue;
|
|
18945
18975
|
const confidence = own ?? rule.confidence ?? 1;
|
|
18946
18976
|
best = best === void 0 ? confidence : Math.max(best, confidence);
|
|
18947
18977
|
}
|
|
@@ -19832,10 +19862,10 @@ function drawFrame(frame, x, width, total, out) {
|
|
|
19832
19862
|
out.push(
|
|
19833
19863
|
`<rect x="${round(x)}" y="${y}" width="${round(width)}" height="${FRAME_HEIGHT}" fill="${fill}"><title>${escapeHtml(frame.path)} (${frame.weight} samples, ${share3}%)</title></rect>`
|
|
19834
19864
|
);
|
|
19835
|
-
const
|
|
19836
|
-
if (
|
|
19865
|
+
const text2 = label(frame.name);
|
|
19866
|
+
if (text2 !== "" && width >= 24) {
|
|
19837
19867
|
out.push(
|
|
19838
|
-
`<text x="${round(x + 4)}" y="${y + 13}" fill="#1c1f24" font-size="11" font-family="system-ui, sans-serif">${escapeHtml(
|
|
19868
|
+
`<text x="${round(x + 4)}" y="${y + 13}" fill="#1c1f24" font-size="11" font-family="system-ui, sans-serif">${escapeHtml(text2)}</text>`
|
|
19839
19869
|
);
|
|
19840
19870
|
}
|
|
19841
19871
|
}
|
|
@@ -19936,6 +19966,382 @@ function renderFlamegraphHtml(input) {
|
|
|
19936
19966
|
""
|
|
19937
19967
|
].join("\n");
|
|
19938
19968
|
}
|
|
19969
|
+
|
|
19970
|
+
// src/report/root-cause.ts
|
|
19971
|
+
var ROOT_CAUSE_SCHEMA_VERSION = 1;
|
|
19972
|
+
var SEVERITY_RANK = {
|
|
19973
|
+
critical: 0,
|
|
19974
|
+
warn: 1,
|
|
19975
|
+
info: 2
|
|
19976
|
+
};
|
|
19977
|
+
function rankObservations(evidence2) {
|
|
19978
|
+
return [...evidence2].sort((a, b) => SEVERITY_RANK[a.severity] - SEVERITY_RANK[b.severity] || (a.id < b.id ? -1 : a.id > b.id ? 1 : 0)).map((item) => ({
|
|
19979
|
+
evidenceId: item.id,
|
|
19980
|
+
kind: item.kind,
|
|
19981
|
+
severity: item.severity,
|
|
19982
|
+
explain: item.explain,
|
|
19983
|
+
// Only the identity a reader needs; `pid` and `rule` are not part of the
|
|
19984
|
+
// narrative and would make the document's shape depend on the analyzer.
|
|
19985
|
+
subject: {
|
|
19986
|
+
process: item.subject.process,
|
|
19987
|
+
...item.subject.thread === void 0 ? {} : { thread: item.subject.thread },
|
|
19988
|
+
...item.subject.frameNo === void 0 ? {} : { frameNo: item.subject.frameNo }
|
|
19989
|
+
},
|
|
19990
|
+
signals: { ...item.signals }
|
|
19991
|
+
}));
|
|
19992
|
+
}
|
|
19993
|
+
function countSeverities(evidence2) {
|
|
19994
|
+
const totals = { info: 0, warn: 0, critical: 0, gaps: 0 };
|
|
19995
|
+
for (const item of evidence2) {
|
|
19996
|
+
totals[item.severity] += 1;
|
|
19997
|
+
if (isGap(item)) totals.gaps += 1;
|
|
19998
|
+
}
|
|
19999
|
+
return totals;
|
|
20000
|
+
}
|
|
20001
|
+
function isGap(item) {
|
|
20002
|
+
if (item.kind === "degraded_capability" || item.kind === "no_data") return true;
|
|
20003
|
+
return Object.keys(item.signals).length === 0;
|
|
20004
|
+
}
|
|
20005
|
+
function observationIsGap(item) {
|
|
20006
|
+
if (item.kind === "degraded_capability" || item.kind === "no_data") return true;
|
|
20007
|
+
return Object.keys(item.signals).length === 0;
|
|
20008
|
+
}
|
|
20009
|
+
function verdictFor(ranked, total, gaps) {
|
|
20010
|
+
if (total === 0) {
|
|
20011
|
+
return "no evidence was produced for this scene, so there is nothing to explain";
|
|
20012
|
+
}
|
|
20013
|
+
const finding = ranked.find((item) => !observationIsGap(item));
|
|
20014
|
+
if (finding === void 0) {
|
|
20015
|
+
return `nothing was measured: all ${total} observation${total === 1 ? "" : "s"} report a gap in the capture, not a finding about the app`;
|
|
20016
|
+
}
|
|
20017
|
+
const more = total === 1 ? "" : ` (and ${total - 1} other observation${total === 2 ? "" : "s"}${gaps === 0 ? "" : `, ${gaps} of them gaps in the capture`})`;
|
|
20018
|
+
return `${finding.severity}: ${finding.explain}${more}`;
|
|
20019
|
+
}
|
|
20020
|
+
function buildRootCauseDocument(input) {
|
|
20021
|
+
const ranked = rankObservations(input.evidence);
|
|
20022
|
+
const totals = countSeverities(input.evidence);
|
|
20023
|
+
return {
|
|
20024
|
+
schemaVersion: ROOT_CAUSE_SCHEMA_VERSION,
|
|
20025
|
+
generator: { ...input.generator },
|
|
20026
|
+
scene: {
|
|
20027
|
+
app: input.app,
|
|
20028
|
+
device: input.device,
|
|
20029
|
+
window: { startNs: input.window.startNs, endNs: input.window.endNs }
|
|
20030
|
+
},
|
|
20031
|
+
summary: {
|
|
20032
|
+
totals,
|
|
20033
|
+
verdict: verdictFor(ranked, input.evidence.length, totals.gaps)
|
|
20034
|
+
},
|
|
20035
|
+
observations: ranked
|
|
20036
|
+
};
|
|
20037
|
+
}
|
|
20038
|
+
|
|
20039
|
+
// src/report/root-cause-model.ts
|
|
20040
|
+
var PROMPT_EVIDENCE_LIMIT = 40;
|
|
20041
|
+
var BAD_RESPONSE = "ROOT_CAUSE_BAD_RESPONSE";
|
|
20042
|
+
function badResponse(message3) {
|
|
20043
|
+
return new OhosPerfError(message3, { code: BAD_RESPONSE });
|
|
20044
|
+
}
|
|
20045
|
+
var ANSWER_SHAPE = [
|
|
20046
|
+
"{",
|
|
20047
|
+
' "summary": "one sentence naming the dominant cause",',
|
|
20048
|
+
' "suspects": [',
|
|
20049
|
+
" {",
|
|
20050
|
+
' "evidenceIds": ["the ids you reasoned from"],',
|
|
20051
|
+
' "rootCause": "1-2 sentences",',
|
|
20052
|
+
' "fix": "what to change",',
|
|
20053
|
+
' "confidence": "high | medium | low",',
|
|
20054
|
+
' "triggerChain": "optional: A -> B -> C"',
|
|
20055
|
+
" }",
|
|
20056
|
+
" ],",
|
|
20057
|
+
' "caveats": ["what limits this conclusion"],',
|
|
20058
|
+
' "needsMoreData": ["what would raise confidence"]',
|
|
20059
|
+
"}"
|
|
20060
|
+
].join("\n");
|
|
20061
|
+
function rootCausePrompt(document) {
|
|
20062
|
+
const observations = document.observations.slice(0, PROMPT_EVIDENCE_LIMIT);
|
|
20063
|
+
const omitted = document.observations.length - observations.length;
|
|
20064
|
+
const lines = observations.map((item) => {
|
|
20065
|
+
const subject = item.subject.thread === void 0 ? item.subject.process : `${item.subject.process}/${item.subject.thread}`;
|
|
20066
|
+
const signals = Object.keys(item.signals).sort().map((key) => `${key}=${String(item.signals[key])}`).join(", ");
|
|
20067
|
+
return `- [${item.evidenceId}] ${item.severity} ${item.kind} ${subject}: ${item.explain}` + (signals === "" ? "" : ` {${signals}}`);
|
|
20068
|
+
});
|
|
20069
|
+
return [
|
|
20070
|
+
"You are explaining the measured performance evidence for one app run.",
|
|
20071
|
+
"Every observation below was produced by an analyzer in this package; the",
|
|
20072
|
+
"bracketed id is what you must cite.",
|
|
20073
|
+
"",
|
|
20074
|
+
`app ${document.scene.app === "unknown" ? "(not identified in this capture)" : document.scene.app} on ${document.scene.device === "offline" ? "an offline analysis" : document.scene.device}`,
|
|
20075
|
+
`verdict ${document.summary.verdict}`,
|
|
20076
|
+
"",
|
|
20077
|
+
"Observations:",
|
|
20078
|
+
...lines.length === 0 ? ["(none)"] : lines,
|
|
20079
|
+
...omitted <= 0 ? [] : [`(${omitted} lower-severity observations omitted)`],
|
|
20080
|
+
"",
|
|
20081
|
+
"Answer with one JSON object and nothing else:",
|
|
20082
|
+
ANSWER_SHAPE,
|
|
20083
|
+
"",
|
|
20084
|
+
"Rules:",
|
|
20085
|
+
"- Cite only ids that appear above; an id you invent is rejected and recorded.",
|
|
20086
|
+
"- Name a file, symbol, library or thread only if it appears above.",
|
|
20087
|
+
"- If the evidence does not support a cause, say so in caveats rather than guessing."
|
|
20088
|
+
].join("\n");
|
|
20089
|
+
}
|
|
20090
|
+
function turnFor(document) {
|
|
20091
|
+
return {
|
|
20092
|
+
task: "explain the root cause of the measured performance evidence",
|
|
20093
|
+
app: document.scene.app,
|
|
20094
|
+
step: 0,
|
|
20095
|
+
maxSteps: 1,
|
|
20096
|
+
screen: rootCausePrompt(document),
|
|
20097
|
+
history: []
|
|
20098
|
+
};
|
|
20099
|
+
}
|
|
20100
|
+
var ROOT_CAUSE_TURN = {
|
|
20101
|
+
prompt: (turn) => turn.screen,
|
|
20102
|
+
parse(content) {
|
|
20103
|
+
try {
|
|
20104
|
+
JSON.parse(unfence2(content));
|
|
20105
|
+
} catch {
|
|
20106
|
+
throw badResponse(
|
|
20107
|
+
`the model's answer is not JSON: ${JSON.stringify(content.slice(0, 200))}`
|
|
20108
|
+
);
|
|
20109
|
+
}
|
|
20110
|
+
return { done: true, reason: content };
|
|
20111
|
+
}
|
|
20112
|
+
};
|
|
20113
|
+
function unfence2(text2) {
|
|
20114
|
+
const match = /^\s*```(?:json)?\s*\n([\s\S]*?)\n\s*```\s*$/.exec(text2);
|
|
20115
|
+
return match === null ? text2 : match[1];
|
|
20116
|
+
}
|
|
20117
|
+
function asRecord(value, what) {
|
|
20118
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
20119
|
+
throw badResponse(`the model's ${what} must be a JSON object`);
|
|
20120
|
+
}
|
|
20121
|
+
return value;
|
|
20122
|
+
}
|
|
20123
|
+
function strings(value) {
|
|
20124
|
+
if (!Array.isArray(value)) return [];
|
|
20125
|
+
return value.filter((item) => typeof item === "string" && item.trim() !== "").map((item) => item.trim());
|
|
20126
|
+
}
|
|
20127
|
+
function text(value) {
|
|
20128
|
+
return typeof value === "string" ? value.trim() : "";
|
|
20129
|
+
}
|
|
20130
|
+
var CONFIDENCE = /* @__PURE__ */ new Set(["high", "medium", "low"]);
|
|
20131
|
+
function confidenceOf(value) {
|
|
20132
|
+
return typeof value === "string" && CONFIDENCE.has(value) ? value : "low";
|
|
20133
|
+
}
|
|
20134
|
+
function parseRootCauseAnswer(content, document, model) {
|
|
20135
|
+
let parsed;
|
|
20136
|
+
try {
|
|
20137
|
+
parsed = JSON.parse(unfence2(content));
|
|
20138
|
+
} catch {
|
|
20139
|
+
throw badResponse(
|
|
20140
|
+
`the model's answer is not JSON: ${JSON.stringify(content.slice(0, 200))}`
|
|
20141
|
+
);
|
|
20142
|
+
}
|
|
20143
|
+
const record = asRecord(parsed, "answer");
|
|
20144
|
+
const known = new Set(document.observations.map((item) => item.evidenceId));
|
|
20145
|
+
const rawSuspects = record["suspects"];
|
|
20146
|
+
const suspects = [];
|
|
20147
|
+
if (rawSuspects !== void 0 && !Array.isArray(rawSuspects)) {
|
|
20148
|
+
throw badResponse(`the model's "suspects" must be an array`);
|
|
20149
|
+
}
|
|
20150
|
+
for (const [index, entry] of (rawSuspects ?? []).entries()) {
|
|
20151
|
+
const suspect = asRecord(entry, `suspects[${index}]`);
|
|
20152
|
+
const cited = strings(suspect["evidenceIds"]);
|
|
20153
|
+
const evidenceIds = cited.filter((id) => known.has(id));
|
|
20154
|
+
const ungrounded = cited.filter((id) => !known.has(id));
|
|
20155
|
+
suspects.push({
|
|
20156
|
+
rank: suspects.length + 1,
|
|
20157
|
+
evidenceIds,
|
|
20158
|
+
rootCause: text(suspect["rootCause"]),
|
|
20159
|
+
fix: text(suspect["fix"]),
|
|
20160
|
+
confidence: confidenceOf(suspect["confidence"]),
|
|
20161
|
+
ungrounded,
|
|
20162
|
+
...text(suspect["triggerChain"]) === "" ? {} : { triggerChain: text(suspect["triggerChain"]) }
|
|
20163
|
+
});
|
|
20164
|
+
}
|
|
20165
|
+
return {
|
|
20166
|
+
model,
|
|
20167
|
+
summary: text(record["summary"]),
|
|
20168
|
+
suspects,
|
|
20169
|
+
caveats: strings(record["caveats"]),
|
|
20170
|
+
needsMoreData: strings(record["needsMoreData"])
|
|
20171
|
+
};
|
|
20172
|
+
}
|
|
20173
|
+
function groundingVocabulary(document) {
|
|
20174
|
+
const vocabulary = /* @__PURE__ */ new Set();
|
|
20175
|
+
for (const item of document.observations) {
|
|
20176
|
+
vocabulary.add(item.subject.process);
|
|
20177
|
+
if (item.subject.thread !== void 0) vocabulary.add(item.subject.thread);
|
|
20178
|
+
for (const value of Object.values(item.signals)) {
|
|
20179
|
+
if (typeof value === "string") vocabulary.add(value);
|
|
20180
|
+
else if (Array.isArray(value)) for (const entry of value) vocabulary.add(entry);
|
|
20181
|
+
}
|
|
20182
|
+
vocabulary.add(item.kind);
|
|
20183
|
+
for (const token of identifierTokens(item.explain)) vocabulary.add(token);
|
|
20184
|
+
}
|
|
20185
|
+
return vocabulary;
|
|
20186
|
+
}
|
|
20187
|
+
function identifierTokens(text2) {
|
|
20188
|
+
return (text2.match(/[A-Za-z_][A-Za-z0-9_.\-]{2,}/g) ?? []).map((token) => token.replace(/[.\-]+$/, "")).filter((token) => looksLikeIdentifier(token));
|
|
20189
|
+
}
|
|
20190
|
+
function ungroundedNames(suspect, vocabulary) {
|
|
20191
|
+
const text2 = [suspect.rootCause, suspect.fix, suspect.triggerChain ?? ""].join(" ");
|
|
20192
|
+
const candidates = text2.match(/[A-Za-z_][A-Za-z0-9_.\-]{2,}/g) ?? [];
|
|
20193
|
+
const found = /* @__PURE__ */ new Set();
|
|
20194
|
+
for (const token of candidates) {
|
|
20195
|
+
const trimmed = token.replace(/[.\-]+$/, "");
|
|
20196
|
+
if (trimmed === "" || vocabulary.has(trimmed)) continue;
|
|
20197
|
+
if (!looksLikeIdentifier(trimmed)) continue;
|
|
20198
|
+
found.add(trimmed);
|
|
20199
|
+
}
|
|
20200
|
+
return [...found].sort();
|
|
20201
|
+
}
|
|
20202
|
+
function looksLikeIdentifier(token) {
|
|
20203
|
+
if (/\.(?:so|ets|ts|js|json|hap|hsp|db|abc)$/i.test(token)) return true;
|
|
20204
|
+
if (token.includes("_")) return true;
|
|
20205
|
+
if (/[a-z][A-Z]/.test(token)) return true;
|
|
20206
|
+
return false;
|
|
20207
|
+
}
|
|
20208
|
+
async function askRootCause(model, document, options) {
|
|
20209
|
+
const decision = await model.decide(turnFor(document));
|
|
20210
|
+
const content = "done" in decision ? decision.reason : "";
|
|
20211
|
+
const analysis = parseRootCauseAnswer(content, document, options.model);
|
|
20212
|
+
const vocabulary = groundingVocabulary(document);
|
|
20213
|
+
return {
|
|
20214
|
+
...document,
|
|
20215
|
+
observations: document.observations.map((item) => ({ ...item, signals: { ...item.signals } })),
|
|
20216
|
+
summary: { ...document.summary, totals: { ...document.summary.totals } },
|
|
20217
|
+
scene: { ...document.scene, window: { ...document.scene.window } },
|
|
20218
|
+
generator: { ...document.generator },
|
|
20219
|
+
analysis: {
|
|
20220
|
+
...analysis,
|
|
20221
|
+
suspects: analysis.suspects.map((suspect) => {
|
|
20222
|
+
const names = ungroundedNames(suspect, vocabulary);
|
|
20223
|
+
return names.length === 0 ? suspect : { ...suspect, ungrounded: [...suspect.ungrounded, ...names] };
|
|
20224
|
+
})
|
|
20225
|
+
}
|
|
20226
|
+
};
|
|
20227
|
+
}
|
|
20228
|
+
|
|
20229
|
+
// src/report/root-cause-markdown.ts
|
|
20230
|
+
var PIPE = /\|/g;
|
|
20231
|
+
var NEWLINE = /\r?\n/g;
|
|
20232
|
+
function cell2(value) {
|
|
20233
|
+
return value.replace(PIPE, "\\|").replace(NEWLINE, " ");
|
|
20234
|
+
}
|
|
20235
|
+
function signalsCell(signals) {
|
|
20236
|
+
const keys = Object.keys(signals).sort();
|
|
20237
|
+
if (keys.length === 0) return "\u2014";
|
|
20238
|
+
return keys.map((key) => `${key}=${String(signals[key])}`).join(", ");
|
|
20239
|
+
}
|
|
20240
|
+
function subjectText2(subject) {
|
|
20241
|
+
const parts = [subject.process];
|
|
20242
|
+
if (subject.thread !== void 0) parts.push(subject.thread);
|
|
20243
|
+
if (subject.frameNo !== void 0) parts.push(`frame ${subject.frameNo}`);
|
|
20244
|
+
return parts.join(" / ");
|
|
20245
|
+
}
|
|
20246
|
+
function renderObservations(observations) {
|
|
20247
|
+
if (observations.length === 0) {
|
|
20248
|
+
return ["no evidence was produced for this scene."];
|
|
20249
|
+
}
|
|
20250
|
+
const lines = [
|
|
20251
|
+
"| # | severity | kind | subject | what was measured | signals |",
|
|
20252
|
+
"| --- | --- | --- | --- | --- | --- |"
|
|
20253
|
+
];
|
|
20254
|
+
for (const [index, item] of observations.entries()) {
|
|
20255
|
+
lines.push(
|
|
20256
|
+
`| ${index + 1} | ${item.severity} | ${cell2(item.kind)} | ${cell2(subjectText2(item.subject))} | ${cell2(item.explain)} | ${cell2(signalsCell(item.signals))} |`
|
|
20257
|
+
);
|
|
20258
|
+
}
|
|
20259
|
+
return lines;
|
|
20260
|
+
}
|
|
20261
|
+
function renderSuspect(suspect) {
|
|
20262
|
+
const lines = [];
|
|
20263
|
+
const mark = suspect.ungrounded.length === 0 ? "" : " \u2014 **ungrounded**";
|
|
20264
|
+
lines.push(`### ${suspect.rank}. ${suspect.confidence} confidence${mark}`);
|
|
20265
|
+
lines.push("");
|
|
20266
|
+
lines.push(suspect.rootCause === "" ? "(no cause stated)" : suspect.rootCause);
|
|
20267
|
+
lines.push("");
|
|
20268
|
+
lines.push(`**Fix:** ${suspect.fix === "" ? "(none stated)" : suspect.fix}`);
|
|
20269
|
+
if (suspect.triggerChain !== void 0) {
|
|
20270
|
+
lines.push("");
|
|
20271
|
+
lines.push(`**Trigger chain:** ${suspect.triggerChain}`);
|
|
20272
|
+
}
|
|
20273
|
+
if (suspect.evidenceIds.length > 0) {
|
|
20274
|
+
lines.push("");
|
|
20275
|
+
lines.push(`**Grounded in:** ${suspect.evidenceIds.join(", ")}`);
|
|
20276
|
+
}
|
|
20277
|
+
if (suspect.ungrounded.length > 0) {
|
|
20278
|
+
lines.push("");
|
|
20279
|
+
lines.push(
|
|
20280
|
+
`**Ungrounded:** ${suspect.ungrounded.join(", ")} \u2014 not measured in this run, so this suspect may describe something the capture never saw.`
|
|
20281
|
+
);
|
|
20282
|
+
}
|
|
20283
|
+
lines.push("");
|
|
20284
|
+
return lines;
|
|
20285
|
+
}
|
|
20286
|
+
function renderRootCauseMarkdown(document) {
|
|
20287
|
+
const { summary, scene } = document;
|
|
20288
|
+
const lines = [];
|
|
20289
|
+
lines.push("# Root cause");
|
|
20290
|
+
lines.push("");
|
|
20291
|
+
lines.push(`app ${scene.app}`);
|
|
20292
|
+
lines.push(`device ${scene.device}`);
|
|
20293
|
+
lines.push(
|
|
20294
|
+
isWholeCapture(scene.window) ? "window the whole capture" : `window ${scene.window.startNs}..${scene.window.endNs} ns (${((scene.window.endNs - scene.window.startNs) / 1e9).toFixed(2)} s)`
|
|
20295
|
+
);
|
|
20296
|
+
lines.push(`produced by ${document.generator.name} ${document.generator.version}`);
|
|
20297
|
+
lines.push("");
|
|
20298
|
+
lines.push("## Verdict");
|
|
20299
|
+
lines.push("");
|
|
20300
|
+
lines.push(summary.verdict);
|
|
20301
|
+
lines.push("");
|
|
20302
|
+
lines.push(
|
|
20303
|
+
`totals: ${summary.totals.critical} critical, ${summary.totals.warn} warn, ${summary.totals.info} info` + (summary.totals.gaps === 0 ? "" : ` (${summary.totals.gaps} report a gap in the capture rather than a finding)`)
|
|
20304
|
+
);
|
|
20305
|
+
lines.push("");
|
|
20306
|
+
lines.push("## Observations");
|
|
20307
|
+
lines.push("");
|
|
20308
|
+
lines.push(...renderObservations(document.observations));
|
|
20309
|
+
lines.push("");
|
|
20310
|
+
const analysis = document.analysis;
|
|
20311
|
+
if (analysis === void 0) {
|
|
20312
|
+
lines.push("## Offline report");
|
|
20313
|
+
lines.push("");
|
|
20314
|
+
lines.push(
|
|
20315
|
+
"no model was asked: this report was produced offline from the measured evidence alone. Configure a model endpoint and run without `--offline` to add an analysis section."
|
|
20316
|
+
);
|
|
20317
|
+
lines.push("");
|
|
20318
|
+
} else {
|
|
20319
|
+
lines.push(`## Model analysis (${analysis.model})`);
|
|
20320
|
+
lines.push("");
|
|
20321
|
+
lines.push(analysis.summary === "" ? "(no summary stated)" : analysis.summary);
|
|
20322
|
+
lines.push("");
|
|
20323
|
+
if (analysis.suspects.length === 0) {
|
|
20324
|
+
lines.push("the model proposed no suspects.");
|
|
20325
|
+
lines.push("");
|
|
20326
|
+
} else {
|
|
20327
|
+
for (const suspect of analysis.suspects) lines.push(...renderSuspect(suspect));
|
|
20328
|
+
}
|
|
20329
|
+
if (analysis.caveats.length > 0) {
|
|
20330
|
+
lines.push("### Caveats");
|
|
20331
|
+
lines.push("");
|
|
20332
|
+
for (const caveat of analysis.caveats) lines.push(`- ${caveat}`);
|
|
20333
|
+
lines.push("");
|
|
20334
|
+
}
|
|
20335
|
+
if (analysis.needsMoreData.length > 0) {
|
|
20336
|
+
lines.push("### What would raise confidence");
|
|
20337
|
+
lines.push("");
|
|
20338
|
+
for (const item of analysis.needsMoreData) lines.push(`- ${item}`);
|
|
20339
|
+
lines.push("");
|
|
20340
|
+
}
|
|
20341
|
+
}
|
|
20342
|
+
return `${lines.join("\n").replace(/\n+$/, "")}
|
|
20343
|
+
`;
|
|
20344
|
+
}
|
|
19939
20345
|
export {
|
|
19940
20346
|
ANIMATION_BANDS,
|
|
19941
20347
|
BUNDLE_RENDERED_FILES,
|
|
@@ -19973,6 +20379,7 @@ export {
|
|
|
19973
20379
|
FrameLoadIndex,
|
|
19974
20380
|
FrameQuery,
|
|
19975
20381
|
GEOMETRY_TOLERANCE_PX,
|
|
20382
|
+
GUI_TURN,
|
|
19976
20383
|
GcAnalyzer,
|
|
19977
20384
|
GestureDriver,
|
|
19978
20385
|
HILOG_COMMAND,
|
|
@@ -20004,10 +20411,13 @@ export {
|
|
|
20004
20411
|
OhosPerfError,
|
|
20005
20412
|
PARITY_ROWS,
|
|
20006
20413
|
PLANE_A_PLUGINS,
|
|
20414
|
+
PROMPT_EVIDENCE_LIMIT,
|
|
20007
20415
|
PerfQuery,
|
|
20008
20416
|
ProcessQuery,
|
|
20009
20417
|
ProcfsCollector,
|
|
20010
20418
|
REPORT_SCHEMA_VERSION,
|
|
20419
|
+
ROOT_CAUSE_SCHEMA_VERSION,
|
|
20420
|
+
ROOT_CAUSE_TURN,
|
|
20011
20421
|
RedundantFileAnalyzer,
|
|
20012
20422
|
RenderAnalyzer,
|
|
20013
20423
|
RsSkipAnalyzer,
|
|
@@ -20037,12 +20447,14 @@ export {
|
|
|
20037
20447
|
analyzeHap,
|
|
20038
20448
|
analyzeThreadWakeup,
|
|
20039
20449
|
animationSeverity,
|
|
20450
|
+
askRootCause,
|
|
20040
20451
|
buildDepGraph,
|
|
20041
20452
|
buildHiprofilerConfig,
|
|
20042
20453
|
buildInventory,
|
|
20043
20454
|
buildMatrix,
|
|
20044
20455
|
buildNativeTimeline,
|
|
20045
20456
|
buildReport,
|
|
20457
|
+
buildRootCauseDocument,
|
|
20046
20458
|
buildTrend,
|
|
20047
20459
|
categorize,
|
|
20048
20460
|
classifyInstruction,
|
|
@@ -20086,6 +20498,7 @@ export {
|
|
|
20086
20498
|
ftracePlugin,
|
|
20087
20499
|
functionAt,
|
|
20088
20500
|
gpuPlugin,
|
|
20501
|
+
groundingVocabulary,
|
|
20089
20502
|
hapSection,
|
|
20090
20503
|
hashTree,
|
|
20091
20504
|
hiperfRecordCommand,
|
|
@@ -20123,11 +20536,13 @@ export {
|
|
|
20123
20536
|
parseHitches,
|
|
20124
20537
|
parseProcfsStatus,
|
|
20125
20538
|
parseRedundantFile,
|
|
20539
|
+
parseRootCauseAnswer,
|
|
20126
20540
|
parseScenario,
|
|
20127
20541
|
parseSelector,
|
|
20128
20542
|
parseSmapsRollup,
|
|
20129
20543
|
planNextAction,
|
|
20130
20544
|
queryDefinitions,
|
|
20545
|
+
rankObservations,
|
|
20131
20546
|
readAgentConfig,
|
|
20132
20547
|
readElf,
|
|
20133
20548
|
readHidumperCapture,
|
|
@@ -20145,6 +20560,7 @@ export {
|
|
|
20145
20560
|
renderReportHtml,
|
|
20146
20561
|
renderReportJson,
|
|
20147
20562
|
renderReportXlsx,
|
|
20563
|
+
renderRootCauseMarkdown,
|
|
20148
20564
|
renderScenesComparison,
|
|
20149
20565
|
renderSummaryJson,
|
|
20150
20566
|
renderTree,
|
|
@@ -20156,6 +20572,7 @@ export {
|
|
|
20156
20572
|
resolveAppIpids,
|
|
20157
20573
|
resolveQueryLimit,
|
|
20158
20574
|
resolveSelector,
|
|
20575
|
+
rootCausePrompt,
|
|
20159
20576
|
round2HalfEven,
|
|
20160
20577
|
runAgent,
|
|
20161
20578
|
runAnalyzerSections,
|
|
@@ -20168,6 +20585,7 @@ export {
|
|
|
20168
20585
|
symbolIndex,
|
|
20169
20586
|
tableRowCounts,
|
|
20170
20587
|
trendRunFromReport,
|
|
20588
|
+
ungroundedNames,
|
|
20171
20589
|
unknownQueryError,
|
|
20172
20590
|
validateRules,
|
|
20173
20591
|
writeProcfsSamples,
|