hiperf_txt_parser 1.0.10 → 1.0.11
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/traceFormat.js +20 -3
- package/package.json +1 -1
package/dist/traceFormat.js
CHANGED
|
@@ -292,8 +292,7 @@ function formatArgBySpecifier(value, spec) {
|
|
|
292
292
|
}
|
|
293
293
|
function renderPrintFmt(printFmt, printArgs, fieldMap) {
|
|
294
294
|
const values = [];
|
|
295
|
-
function
|
|
296
|
-
// 允许表达式带括号与空格
|
|
295
|
+
function normalizeExpr(exprRaw) {
|
|
297
296
|
let expr = exprRaw.trim();
|
|
298
297
|
// 去掉外层括号(可能不止一层,也可能只有一侧被 match 捕获到)
|
|
299
298
|
while (expr.startsWith("("))
|
|
@@ -301,6 +300,11 @@ function renderPrintFmt(printFmt, printArgs, fieldMap) {
|
|
|
301
300
|
while (expr.endsWith(")"))
|
|
302
301
|
expr = expr.slice(0, -1).trim();
|
|
303
302
|
expr = expr.replace(/\s+/g, "");
|
|
303
|
+
return expr;
|
|
304
|
+
}
|
|
305
|
+
function evalExpr(exprRaw) {
|
|
306
|
+
// 允许表达式带括号与空格
|
|
307
|
+
const expr = normalizeExpr(exprRaw);
|
|
304
308
|
// (REC->__data_loc_reason&0xffff) / (REC->__data_loc_reason>>16)
|
|
305
309
|
let m = expr.match(/^REC->(\w+)&0xffff$/);
|
|
306
310
|
if (m) {
|
|
@@ -332,12 +336,25 @@ function renderPrintFmt(printFmt, printArgs, fieldMap) {
|
|
|
332
336
|
return v[0] ?? 0;
|
|
333
337
|
return v ?? 0;
|
|
334
338
|
}
|
|
339
|
+
const normalizedArgs = (printArgs ?? []).map(normalizeExpr);
|
|
335
340
|
for (const expr of printArgs ?? []) {
|
|
336
341
|
values.push(evalExpr(expr));
|
|
337
342
|
}
|
|
338
343
|
let valueIdx = 0;
|
|
339
344
|
return printFmt.replace(/%[0-9]*[lh]*([duxXsS])/g, (_all, spec) => {
|
|
340
|
-
const
|
|
345
|
+
const idx = valueIdx++;
|
|
346
|
+
const v = values[idx] ?? 0;
|
|
347
|
+
const argExpr = normalizedArgs[idx] ?? "";
|
|
348
|
+
// %s + REC->__data_loc_xxx 时,优先打印已解析出来的 xxx 字符串
|
|
349
|
+
if (spec.toLowerCase() === "s") {
|
|
350
|
+
const m = argExpr.match(/^REC->__data_loc_(\w+)$/);
|
|
351
|
+
if (m) {
|
|
352
|
+
const s = fieldMap[m[1]];
|
|
353
|
+
if (typeof s === "string") {
|
|
354
|
+
return s;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
341
358
|
return formatArgBySpecifier(v, spec);
|
|
342
359
|
});
|
|
343
360
|
}
|