hm-pt-core 1.0.2 → 1.0.3

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/README.md CHANGED
@@ -19,7 +19,7 @@ npm install hm-pt-core
19
19
 
20
20
  | hm-pt-core | hiperf_txt_parser | hmtrace-parser |
21
21
  |------------|-------------------|----------------|
22
- | 1.0.x | 2.0.x | 0.8.x |
22
+ | 1.0.x(当前 **1.0.3**) | **2.1.x** | **0.8.x** |
23
23
 
24
24
  ## 开发
25
25
 
package/dist/index.d.ts CHANGED
@@ -9,5 +9,5 @@ export type { Endian, BuildTraceParserRegistryOptions } from "./trace/parse.js";
9
9
  export { TraceFieldDecodeError } from "./trace/parse.js";
10
10
  export type { PrintfSpec } from "./trace/printf.js";
11
11
  export { parseTraceFormat, parseCommonFieldsFromRaw, parseAllFieldsFromRaw, rawHexLinesToBuffer, bufferToRawHexLines, buildTraceParserRegistry, } from "./trace/parse.js";
12
- export { formatPrintfValue, tokenizePrintfFormat } from "./trace/printf.js";
12
+ export { formatPrintfValue, tokenizePrintfFormat, renderPrintFmt, renderPrintFmtAsFieldDict } from "./trace/printf.js";
13
13
  export { decodeRawByRegistry } from "./trace/decode_raw.js";
package/dist/index.js CHANGED
@@ -4,5 +4,5 @@
4
4
  export { isPerfDataLike } from "./perf/is_perf_data_like.js";
5
5
  export { TraceFieldDecodeError } from "./trace/parse.js";
6
6
  export { parseTraceFormat, parseCommonFieldsFromRaw, parseAllFieldsFromRaw, rawHexLinesToBuffer, bufferToRawHexLines, buildTraceParserRegistry, } from "./trace/parse.js";
7
- export { formatPrintfValue, tokenizePrintfFormat } from "./trace/printf.js";
7
+ export { formatPrintfValue, tokenizePrintfFormat, renderPrintFmt, renderPrintFmtAsFieldDict } from "./trace/printf.js";
8
8
  export { decodeRawByRegistry } from "./trace/decode_raw.js";
@@ -138,6 +138,24 @@ function scanBalancedPrintArgs(argsPart) {
138
138
  }
139
139
  return args;
140
140
  }
141
+ /**
142
+ * 从 print fmt 逗号后参数段提取表达式。
143
+ * 内核 trace 常在首个 __data_loc 参数外套 ((char*)((void *)...)),括号平衡切分只得 1 段;
144
+ * 此时回退为按 `REC->` 切分(与 hiperf 1.x 行为一致)。
145
+ */
146
+ function parsePrintArgExpressions(argsPart) {
147
+ const balanced = scanBalancedPrintArgs(argsPart);
148
+ const recExprs = argsPart.match(/REC->[^,]+/g)?.map((s) => s.trim().replace(/\)+$/, "")) ?? [];
149
+ if (recExprs.length > balanced.length) {
150
+ return recExprs;
151
+ }
152
+ if (recExprs.length === 1 &&
153
+ balanced.length === 1 &&
154
+ balanced[0] !== recExprs[0]) {
155
+ return recExprs;
156
+ }
157
+ return balanced;
158
+ }
141
159
  function parsePrintFmtLine(line) {
142
160
  const prefix = line.match(/^print\s+fmt\s*:\s*/i);
143
161
  if (!prefix)
@@ -151,7 +169,7 @@ function parsePrintFmtLine(line) {
151
169
  const argsMatch = rest.match(/^,\s*(.*)$/);
152
170
  if (!argsMatch)
153
171
  return undefined;
154
- return { printFmt: lit.value, printArgs: scanBalancedPrintArgs(argsMatch[1]) };
172
+ return { printFmt: lit.value, printArgs: parsePrintArgExpressions(argsMatch[1]) };
155
173
  }
156
174
  function splitTypeAndName(rest) {
157
175
  const trimmed = rest.trim();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hm-pt-core",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "DFX perf trace shared types and trace format decode primitives",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",