snapshot-checker 0.1.2 → 0.1.4
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/commands/context_demo.d.ts.map +1 -1
- package/dist/commands/context_demo.js +3 -3
- package/dist/commands/context_demo.js.map +1 -1
- package/dist/commands/forkall.d.ts +1 -11
- package/dist/commands/forkall.d.ts.map +1 -1
- package/dist/commands/forkall.js +133 -148
- package/dist/commands/forkall.js.map +1 -1
- package/dist/commands/report.d.ts +1 -1
- package/dist/commands/report.d.ts.map +1 -1
- package/dist/commands/report.js +115 -128
- package/dist/commands/report.js.map +1 -1
- package/dist/src/index.d.ts +2 -2
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +1 -1
- package/dist/src/index.js.map +1 -1
- package/dist/src/lib/common_groups.d.ts +58 -0
- package/dist/src/lib/common_groups.d.ts.map +1 -0
- package/dist/src/lib/common_groups.js +218 -0
- package/dist/src/lib/common_groups.js.map +1 -0
- package/dist/src/lib/trace_formatter.d.ts +9 -0
- package/dist/src/lib/trace_formatter.d.ts.map +1 -0
- package/dist/src/lib/trace_formatter.js +124 -0
- package/dist/src/lib/trace_formatter.js.map +1 -0
- package/dist/src/runCommand.d.ts.map +1 -1
- package/dist/src/runCommand.js +33 -11
- package/dist/src/runCommand.js.map +1 -1
- package/dist/src/runGroups.d.ts.map +1 -1
- package/dist/src/runGroups.js +2 -1
- package/dist/src/runGroups.js.map +1 -1
- package/dist/src/types.d.ts +21 -2
- package/dist/src/types.d.ts.map +1 -1
- package/dist/src/types.js +20 -0
- package/dist/src/types.js.map +1 -1
- package/package.json +2 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context_demo.d.ts","sourceRoot":"","sources":["../../commands/context_demo.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"context_demo.d.ts","sourceRoot":"","sources":["../../commands/context_demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4D,KAAK,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAMxG;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,MAAM,EAAE,MA8CpB,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAqD,CAAC"}
|
|
@@ -39,9 +39,9 @@ export const groups = {
|
|
|
39
39
|
kind: CommandKind.BuiltinFunction,
|
|
40
40
|
description: '调用 lib/foo 的工具函数写入变量',
|
|
41
41
|
func: (ctx) => {
|
|
42
|
-
const user = ctx.user ?? 'unknown';
|
|
43
|
-
ctx.builtinTag
|
|
44
|
-
ctx.fromFoo
|
|
42
|
+
const user = ctx.get('user') ?? 'unknown';
|
|
43
|
+
ctx.set('builtinTag', buildTag('context_demo'));
|
|
44
|
+
ctx.set('fromFoo', buildUserGreeting(user));
|
|
45
45
|
},
|
|
46
46
|
},
|
|
47
47
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context_demo.js","sourceRoot":"","sources":["../../commands/context_demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,sBAAsB,
|
|
1
|
+
{"version":3,"file":"context_demo.js","sourceRoot":"","sources":["../../commands/context_demo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,sBAAsB,EAAoC,MAAM,iBAAiB,CAAC;AACxG,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAEhE,oCAAoC;AACpC,MAAM,IAAI,GAAG,sBAAsB,EAAE,CAAC;AAEtC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,MAAM,GAAW;IAC5B,OAAO,EAAE;QACP;YACE,IAAI;YACJ,WAAW,EAAE,oBAAoB;YACjC,GAAG,EAAE,QAAQ;YACb,YAAY,EAAE;gBACZ,IAAI,EAAE,MAAM;aACb;SACF;KACF;IACD,KAAK,EAAE;QACL;YACE,IAAI;YACJ,WAAW,EAAE,eAAe;YAC5B,GAAG,EAAE,wBAAwB;SAC9B;KACF;IACD,SAAS,EAAE;QACT;YACE,IAAI,EAAE,WAAW,CAAC,eAAe;YACjC,WAAW,EAAE,sBAAsB;YACnC,IAAI,EAAE,CAAC,GAAmB,EAAE,EAAE;gBAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,GAAG,CAAS,MAAM,CAAC,IAAI,SAAS,CAAC;gBAClD,GAAG,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,CAAC,CAAC;gBAChD,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;YAC9C,CAAC;SACF;QACD;YACE,IAAI;YACJ,WAAW,EAAE,aAAa;YAC1B,GAAG,EAAE,qCAAqC;SAC3C;KACF;IACD,WAAW,EAAE;QACX;YACE,IAAI,EAAE,WAAW,CAAC,eAAe;YACjC,WAAW,EAAE,uCAAuC;YACpD,IAAI,EAAE,GAAG,EAAE,CAAC,KAAK;SAClB;QACD;YACE,IAAI;YACJ,WAAW,EAAE,6BAA6B;YAC1C,GAAG,EAAE,qDAAqD;SAC3D;KACF;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAa,CAAC,SAAS,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC"}
|
|
@@ -29,20 +29,10 @@ interface ForkallOptions {
|
|
|
29
29
|
bufferSize?: string;
|
|
30
30
|
mode?: string;
|
|
31
31
|
outputDir?: string;
|
|
32
|
+
traceFormatProfile?: string;
|
|
32
33
|
}
|
|
33
34
|
/**
|
|
34
35
|
* 将 CLI 解析出来的参数应用到 forkall 场景,动态生成各阶段命令。
|
|
35
|
-
*
|
|
36
|
-
* 关键映射关系:
|
|
37
|
-
* - eventPath -> dump_stack.bat 中的 event_path
|
|
38
|
-
* - app -> dump_stack.bat 中的 app
|
|
39
|
-
* - systemSymbolFilePath -> dump_stack.bat 中的 system_symbol_file_path
|
|
40
|
-
* - logKey -> dump_stack.bat 中的 log_key(默认 pid)
|
|
41
|
-
* - duration -> dump_stack.bat 中的 duration(默认 70)
|
|
42
|
-
* - defaultTimeout -> dump_stack.bat 中的 default_timeout(默认 90)
|
|
43
|
-
* - bufferSize -> dump_stack.bat 中的 buffer_size(默认 512000)
|
|
44
|
-
* - mode -> dump_stack.bat 中根据参数跳转到 REBOOT 或 MONITOR 的条件分支
|
|
45
|
-
* - outputDir -> 本地输出目录(默认 .\output)
|
|
46
36
|
*/
|
|
47
37
|
export declare function applyOptions(ctx: {
|
|
48
38
|
groups: Groups;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forkall.d.ts","sourceRoot":"","sources":["../../commands/forkall.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"forkall.d.ts","sourceRoot":"","sources":["../../commands/forkall.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK1E;;;;;;;;GAQG;AACH,eAAO,MAAM,MAAM,EAAE,MAAW,CAAC;AAEjC,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAiD,CAAC;AAExF,eAAO,MAAM,OAAO;;;;;;;;IA+BnB,CAAC;AAEF,UAAU,cAAc;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAmJD;;GAEG;AACH,wBAAgB,YAAY,CAAC,GAAG,EAAE;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,OAAO,EAAE,cAAc,CAAC;CACzB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAAE,CA2FlD"}
|
package/dist/commands/forkall.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { CommandKind } from '../src/types.js';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { existsSync, mkdirSync } from 'node:fs';
|
|
4
|
+
import { buildCommonAnalysisGroup, buildCommonCollectGroup, buildCommonInitEnvGroup } from '../src/lib/common_groups.js';
|
|
4
5
|
/**
|
|
5
6
|
* forkall 场景的基础占位配置。
|
|
6
7
|
* 实际要执行的命令会在 applyOptions 中,根据 CLI 传入的参数(eventPath/app 等)动态生成。
|
|
@@ -38,201 +39,185 @@ export const options = [
|
|
|
38
39
|
description: '本地输出目录(默认 .\\output)',
|
|
39
40
|
defaultValue: String.raw `.\output`,
|
|
40
41
|
},
|
|
42
|
+
{
|
|
43
|
+
flags: '--trace-format-profile <name>',
|
|
44
|
+
description: 'trace 事件格式版本(默认 default)',
|
|
45
|
+
defaultValue: 'default',
|
|
46
|
+
},
|
|
41
47
|
];
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
* - app -> dump_stack.bat 中的 app
|
|
48
|
-
* - systemSymbolFilePath -> dump_stack.bat 中的 system_symbol_file_path
|
|
49
|
-
* - logKey -> dump_stack.bat 中的 log_key(默认 pid)
|
|
50
|
-
* - duration -> dump_stack.bat 中的 duration(默认 70)
|
|
51
|
-
* - defaultTimeout -> dump_stack.bat 中的 default_timeout(默认 90)
|
|
52
|
-
* - bufferSize -> dump_stack.bat 中的 buffer_size(默认 512000)
|
|
53
|
-
* - mode -> dump_stack.bat 中根据参数跳转到 REBOOT 或 MONITOR 的条件分支
|
|
54
|
-
* - outputDir -> 本地输出目录(默认 .\output)
|
|
55
|
-
*/
|
|
56
|
-
export function applyOptions(ctx) {
|
|
57
|
-
const { eventPath = '', app = '', systemSymbolFilePath = '', logKey = 'pid', duration = '70', defaultTimeout = '90', bufferSize = '512000', mode = 'monitor', outputDir = String.raw `.\output`, } = ctx.options ?? {};
|
|
58
|
-
const eventName = eventPath ? eventPath.replace(/\//g, ':') : '';
|
|
59
|
-
const checkStateCommand = "hidumper -s 1901 -a '-p libforkall_plugin.z.so --list'";
|
|
60
|
-
const outputDirNormalized = path.normalize(outputDir);
|
|
61
|
-
const outputDirWithSep = outputDirNormalized.endsWith(path.sep)
|
|
62
|
-
? outputDirNormalized
|
|
63
|
-
: `${outputDirNormalized}${path.sep}`;
|
|
64
|
-
const snapshotLogFile = path.join(outputDirNormalized, 'snapshot_log.txt');
|
|
65
|
-
const snapshotPerfFile = path.join(outputDirNormalized, 'snapshot_perf.data.txt');
|
|
66
|
-
const dumpStackTxt = path.join(outputDirNormalized, 'dump_stack.txt');
|
|
67
|
-
const dumpStackXlsx = path.join(outputDirNormalized, 'dump_stack.xlsx');
|
|
68
|
-
const dumpStackJson = path.join(outputDirNormalized, 'dump_stack.json');
|
|
69
|
-
const hiperfTxtFilterScript = path.normalize(path.join('.', 'tools', 'host', 'checker', 'hiperf_txt_filter.py'));
|
|
70
|
-
const parserSystemStackScript = path.normalize(path.join('.', 'tools', 'host', 'checker', 'parse_system_stack.py'));
|
|
71
|
-
const start_app_command = `hidumper -s 1901 -a '-p libforkall_plugin.z.so --create 100 ${app}'`;
|
|
72
|
-
if (!existsSync(outputDirNormalized)) {
|
|
73
|
-
mkdirSync(outputDirNormalized, { recursive: true });
|
|
74
|
-
}
|
|
75
|
-
const rebootGroup = mode === 'reboot-monitor'
|
|
76
|
-
? [
|
|
77
|
-
{
|
|
78
|
-
kind: CommandKind.Windows,
|
|
79
|
-
run: 'hdc shell remount',
|
|
80
|
-
},
|
|
81
|
-
{
|
|
82
|
-
kind: CommandKind.Windows,
|
|
83
|
-
run: 'hdc shell "test ! -f /system/etc/hiview/hitrace_utils.json.bk && mv /system/etc/hiview/hitrace_utils.json /system/etc/hiview/hitrace_utils.json.bk"',
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
kind: CommandKind.Windows,
|
|
87
|
-
run: 'hdc shell "test ! -f /bin/hiperf.bk && mv /bin/hiperf /bin/hiperf.bk"',
|
|
88
|
-
},
|
|
89
|
-
{
|
|
90
|
-
kind: CommandKind.Windows,
|
|
91
|
-
description: '上传hitrace配置文件',
|
|
92
|
-
run: String.raw `hdc file send .\config\hitrace\hitrace_utils_snapshot.json /system/etc/hiview/hitrace_utils.json`,
|
|
93
|
-
},
|
|
94
|
-
{
|
|
95
|
-
kind: CommandKind.Windows,
|
|
96
|
-
description: '上传hiperf',
|
|
97
|
-
run: String.raw `hdc file send .\tools\host\hiperf\hiperf /bin/hiperf`,
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
kind: CommandKind.Windows,
|
|
101
|
-
description: '配置自定义trace事件',
|
|
102
|
-
run: String.raw `hdc shell "sed -i 's|<TARGET_EVENT>|${eventPath}|g' /system/etc/hiview/hitrace_utils.json"`,
|
|
103
|
-
},
|
|
104
|
-
{
|
|
105
|
-
kind: CommandKind.Windows,
|
|
106
|
-
description: '配置hiperf权限',
|
|
107
|
-
run: 'hdc shell "chmod 755 /bin/hiperf && chcon u:object_r:hiperf_exec:s0 /bin/hiperf"',
|
|
108
|
-
},
|
|
109
|
-
{
|
|
110
|
-
kind: CommandKind.Windows,
|
|
111
|
-
description: '重启设备',
|
|
112
|
-
run: 'hdc shell reboot',
|
|
113
|
-
},
|
|
114
|
-
{
|
|
115
|
-
kind: CommandKind.Embed,
|
|
116
|
-
description: '等待设备重启中,按任意键可跳过',
|
|
117
|
-
run: `timeout ${defaultTimeout}`,
|
|
118
|
-
},
|
|
119
|
-
]
|
|
120
|
-
: [];
|
|
121
|
-
const initEnvGroup = [
|
|
48
|
+
function buildRebootGroup(input) {
|
|
49
|
+
const { mode, eventPath, defaultTimeout } = input;
|
|
50
|
+
if (mode !== 'reboot-monitor')
|
|
51
|
+
return [];
|
|
52
|
+
return [
|
|
122
53
|
{
|
|
123
54
|
kind: CommandKind.Windows,
|
|
124
55
|
run: 'hdc shell remount',
|
|
125
56
|
},
|
|
126
57
|
{
|
|
127
58
|
kind: CommandKind.Windows,
|
|
128
|
-
|
|
129
|
-
run: 'hdc shell "rm -rf /data/local/tmp/snapshot_hitrace.txt /data/local/tmp/perf.data /data/local/tmp/snapshot_perf.data.txt"',
|
|
59
|
+
run: 'hdc shell "test ! -f /system/etc/hiview/hitrace_utils.json.bk && mv /system/etc/hiview/hitrace_utils.json /system/etc/hiview/hitrace_utils.json.bk"',
|
|
130
60
|
},
|
|
131
61
|
{
|
|
132
62
|
kind: CommandKind.Windows,
|
|
133
|
-
|
|
134
|
-
run: `del /q "${snapshotLogFile}" 2>nul || exit /b 0`,
|
|
63
|
+
run: 'hdc shell "test ! -f /bin/hiperf.bk && mv /bin/hiperf /bin/hiperf.bk"',
|
|
135
64
|
},
|
|
136
65
|
{
|
|
137
66
|
kind: CommandKind.Windows,
|
|
138
|
-
description: '
|
|
139
|
-
run: `hdc
|
|
67
|
+
description: '上传hitrace配置文件',
|
|
68
|
+
run: String.raw `hdc file send .\config\hitrace\hitrace_utils_snapshot.json /system/etc/hiview/hitrace_utils.json`,
|
|
140
69
|
},
|
|
141
70
|
{
|
|
142
71
|
kind: CommandKind.Windows,
|
|
143
|
-
description: '
|
|
144
|
-
run: `hdc
|
|
72
|
+
description: '上传hiperf',
|
|
73
|
+
run: String.raw `hdc file send .\tools\host\hiperf\hiperf /bin/hiperf`,
|
|
145
74
|
},
|
|
146
75
|
{
|
|
147
76
|
kind: CommandKind.Windows,
|
|
148
|
-
description: '
|
|
149
|
-
run: `hdc shell "
|
|
77
|
+
description: '配置自定义trace事件',
|
|
78
|
+
run: String.raw `hdc shell "sed -i 's|<TARGET_EVENT>|${eventPath}|g' /system/etc/hiview/hitrace_utils.json"`,
|
|
150
79
|
},
|
|
151
80
|
{
|
|
152
81
|
kind: CommandKind.Windows,
|
|
153
|
-
description: '
|
|
154
|
-
run:
|
|
82
|
+
description: '配置hiperf权限',
|
|
83
|
+
run: 'hdc shell "chmod 755 /bin/hiperf && chcon u:object_r:hiperf_exec:s0 /bin/hiperf"',
|
|
155
84
|
},
|
|
156
85
|
{
|
|
157
86
|
kind: CommandKind.Windows,
|
|
158
|
-
description: '
|
|
159
|
-
run:
|
|
160
|
-
}
|
|
87
|
+
description: '重启设备',
|
|
88
|
+
run: 'hdc shell reboot',
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
kind: CommandKind.Embed,
|
|
92
|
+
description: '等待设备重启中,按任意键可跳过',
|
|
93
|
+
run: `timeout ${defaultTimeout}`,
|
|
94
|
+
},
|
|
161
95
|
];
|
|
162
|
-
|
|
96
|
+
}
|
|
97
|
+
function buildMonitorGroup(input) {
|
|
98
|
+
const { eventName, app, logKey, bufferSize, duration, snapshotLogFile, startAppCommand, checkStateCommand, } = input;
|
|
99
|
+
return [
|
|
163
100
|
{
|
|
164
101
|
kind: CommandKind.Windows,
|
|
165
102
|
description: '收集日志到本地',
|
|
166
103
|
background: true,
|
|
167
104
|
run: `hdc shell "hilog -t kmsg | grep ${logKey}" >> ${snapshotLogFile}`,
|
|
168
105
|
},
|
|
106
|
+
{
|
|
107
|
+
kind: CommandKind.Windows,
|
|
108
|
+
run: 'hdc shell pidof apppool',
|
|
109
|
+
captureToVar: {
|
|
110
|
+
name: 'apppool_pids',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
kind: CommandKind.BuiltinFunction,
|
|
115
|
+
description: '提取检测目标信息',
|
|
116
|
+
func: (ctx) => {
|
|
117
|
+
const apppoolPids = ctx.get('apppool_pids');
|
|
118
|
+
if (!apppoolPids) {
|
|
119
|
+
console.warn('[提取检测目标信息] apppool_pids 缺失或不是字符串,跳过处理');
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
const monitorTarget = apppoolPids.split(/\s+/).join(',');
|
|
123
|
+
ctx.set('monitor_target', monitorTarget);
|
|
124
|
+
console.info('提取检测目标: ', monitorTarget);
|
|
125
|
+
},
|
|
126
|
+
},
|
|
169
127
|
{
|
|
170
128
|
kind: CommandKind.Windows,
|
|
171
129
|
description: '收集风险事件数据',
|
|
172
130
|
run: [
|
|
173
131
|
'hdc shell "',
|
|
174
|
-
`echo [SnapshotChecker]: Setting Target && `,
|
|
175
132
|
`hitrace custom_event --overwrite -b ${bufferSize} -t ${duration} -o /data/local/tmp/snapshot_hitrace.txt & `,
|
|
176
133
|
eventName
|
|
177
|
-
? `hiperf record -e ${eventName} --period 1 -s fp --clockid boottime --cpu-limit 100 -o /data/local/tmp/perf.data -
|
|
178
|
-
: '',
|
|
179
|
-
`echo [SnapshotChecker]: Monitor start, Target: app=${app} && `,
|
|
180
|
-
`sleep 5 && `,
|
|
181
|
-
app
|
|
182
|
-
? `${start_app_command} && `
|
|
134
|
+
? `hiperf record -e ${eventName} --period 1 -s fp --clockid boottime --callchain-useronly --cpu-limit 100 -o /data/local/tmp/perf.data -p {{monitor_target}} -d ${duration} & `
|
|
183
135
|
: '',
|
|
136
|
+
'sleep 1 && ',
|
|
137
|
+
app ? `${startAppCommand} && ` : '',
|
|
184
138
|
`${checkStateCommand} & `,
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
`hiperf dump -i /data/local/tmp/perf.data -o /data/local/tmp/snapshot_perf.data.txt"`,
|
|
139
|
+
'wait && ',
|
|
140
|
+
'hiperf dump -i /data/local/tmp/perf.data -o /data/local/tmp/snapshot_perf.data.txt"',
|
|
188
141
|
]
|
|
189
142
|
.filter(Boolean)
|
|
190
143
|
.join(''),
|
|
191
144
|
},
|
|
192
145
|
];
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
].join(''),
|
|
207
|
-
},
|
|
208
|
-
];
|
|
209
|
-
const analysisGroup = [
|
|
210
|
-
{
|
|
211
|
-
kind: CommandKind.Windows,
|
|
212
|
-
description: '获取目标tgid',
|
|
213
|
-
run: `hdc shell pgrep -f -o ${app}`,
|
|
214
|
-
captureToVar: {
|
|
215
|
-
name: 'target_tgid',
|
|
216
|
-
},
|
|
217
|
-
},
|
|
218
|
-
{
|
|
219
|
-
kind: CommandKind.Windows,
|
|
220
|
-
description: '过滤目标数据',
|
|
221
|
-
run: `python ${hiperfTxtFilterScript} --keep_raw_data --keep_duplicate_stacks --input_file ${snapshotPerfFile} --output_file ${snapshotPerfFile} --filter_by_tgid {{target_tgid}}`,
|
|
222
|
-
},
|
|
223
|
-
{
|
|
224
|
-
kind: CommandKind.Windows,
|
|
225
|
-
description: '系统栈解栈',
|
|
226
|
-
run: systemSymbolFilePath
|
|
227
|
-
? `python ${parserSystemStackScript} ${snapshotPerfFile} ${snapshotPerfFile} -S ${systemSymbolFilePath}`
|
|
228
|
-
: '',
|
|
229
|
-
},
|
|
230
|
-
{
|
|
231
|
-
kind: CommandKind.Windows,
|
|
232
|
-
description: '风险调用栈数据分析',
|
|
233
|
-
run: `python ${hiperfTxtFilterScript} --to_backtrace_stack --input_file ${snapshotPerfFile} --output_file ${dumpStackTxt} --output_csv ${dumpStackXlsx} --output_json ${dumpStackJson}`,
|
|
234
|
-
},
|
|
146
|
+
}
|
|
147
|
+
function buildAnalysisPreDecodeCommands(input) {
|
|
148
|
+
const { systemSymbolFilePath, snapshotPerfFile, parserSystemStackScript, } = input;
|
|
149
|
+
return [
|
|
150
|
+
...(systemSymbolFilePath
|
|
151
|
+
? [
|
|
152
|
+
{
|
|
153
|
+
kind: CommandKind.Windows,
|
|
154
|
+
description: '系统栈解栈',
|
|
155
|
+
run: `python ${parserSystemStackScript} ${snapshotPerfFile} ${snapshotPerfFile} -S ${systemSymbolFilePath}`,
|
|
156
|
+
},
|
|
157
|
+
]
|
|
158
|
+
: []),
|
|
235
159
|
];
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* 将 CLI 解析出来的参数应用到 forkall 场景,动态生成各阶段命令。
|
|
163
|
+
*/
|
|
164
|
+
export function applyOptions(ctx) {
|
|
165
|
+
const { eventPath = '', app = '', systemSymbolFilePath = '', logKey = 'pid', duration = '70', defaultTimeout = '90', bufferSize = '512000', mode = 'monitor', outputDir = String.raw `.\output`, traceFormatProfile = 'default', } = ctx.options ?? {};
|
|
166
|
+
const eventName = eventPath ? eventPath.replace(/\//g, ':') : '';
|
|
167
|
+
const checkStateCommand = "hidumper -s 1901 -a '-p libforkall_plugin.z.so --list'";
|
|
168
|
+
const outputDirNormalized = path.normalize(outputDir);
|
|
169
|
+
const outputDirWithSep = outputDirNormalized.endsWith(path.sep)
|
|
170
|
+
? outputDirNormalized
|
|
171
|
+
: `${outputDirNormalized}${path.sep}`;
|
|
172
|
+
const snapshotLogFile = path.join(outputDirNormalized, 'snapshot_log.txt');
|
|
173
|
+
const snapshotPerfFile = path.join(outputDirNormalized, 'snapshot_perf.data.txt');
|
|
174
|
+
const dumpStackTxt = path.join(outputDirNormalized, 'dump_stack.txt');
|
|
175
|
+
const dumpStackJson = path.join(outputDirNormalized, 'dump_stack.json');
|
|
176
|
+
const parserSystemStackScript = path.normalize(path.join('.', 'tools', 'host', 'checker', 'parse_system_stack.py'));
|
|
177
|
+
const startAppCommand = `hidumper -s 1901 -a '-p libforkall_plugin.z.so --create 100 ${app}'`;
|
|
178
|
+
if (!existsSync(outputDirNormalized)) {
|
|
179
|
+
mkdirSync(outputDirNormalized, { recursive: true });
|
|
180
|
+
}
|
|
181
|
+
const rebootGroup = buildRebootGroup({ mode, eventPath, defaultTimeout });
|
|
182
|
+
const initEnvGroup = buildCommonInitEnvGroup({
|
|
183
|
+
app,
|
|
184
|
+
snapshotLogFile,
|
|
185
|
+
checkStateCommand,
|
|
186
|
+
permissionCommands: [
|
|
187
|
+
`hdc shell "chmod 755 /sys/kernel/tracing/events/${eventPath} && chmod 666 /sys/kernel/tracing/events/${eventPath}/enable"`,
|
|
188
|
+
],
|
|
189
|
+
});
|
|
190
|
+
const monitorGroup = buildMonitorGroup({
|
|
191
|
+
eventName,
|
|
192
|
+
app,
|
|
193
|
+
logKey,
|
|
194
|
+
bufferSize,
|
|
195
|
+
duration,
|
|
196
|
+
snapshotLogFile,
|
|
197
|
+
startAppCommand,
|
|
198
|
+
checkStateCommand,
|
|
199
|
+
});
|
|
200
|
+
const collectGroup = buildCommonCollectGroup({
|
|
201
|
+
checkStateCommand,
|
|
202
|
+
snapshotPerfReceiveDirWithSep: outputDirWithSep,
|
|
203
|
+
outputDirWithSep,
|
|
204
|
+
});
|
|
205
|
+
const analysisGroup = buildCommonAnalysisGroup({
|
|
206
|
+
app,
|
|
207
|
+
snapshotPerfFile,
|
|
208
|
+
writeBacktraceStacks: false,
|
|
209
|
+
preDecodeCommands: buildAnalysisPreDecodeCommands({
|
|
210
|
+
systemSymbolFilePath,
|
|
211
|
+
snapshotPerfFile,
|
|
212
|
+
parserSystemStackScript,
|
|
213
|
+
}),
|
|
214
|
+
decodeInput: { inputFilePath: snapshotPerfFile },
|
|
215
|
+
dumpStackTxt,
|
|
216
|
+
dumpStackJson,
|
|
217
|
+
traceFormatProfile,
|
|
218
|
+
decodeStageName: '风险调用栈数据分析',
|
|
219
|
+
missingInputMessage: '[风险调用栈数据分析] 输入文件缺失,跳过处理',
|
|
220
|
+
});
|
|
236
221
|
const resultGroups = {
|
|
237
222
|
reboot: rebootGroup,
|
|
238
223
|
init: initEnvGroup,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"forkall.js","sourceRoot":"","sources":["../../commands/forkall.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EA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BAAiB;KAClB,CAAC,CAAC;IACH,MAAM,YAAY,GAAG,uBAAuB,CAAC;QAC3C,iBAAiB;QACjB,6BAA6B,EAAE,gBAAgB;QAC/C,gBAAgB;KACjB,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,wBAAwB,CAAC;QAC7C,GAAG;QACH,gBAAgB;QAChB,oBAAoB,EAAE,KAAK;QAC3B,iBAAiB,EAAE,8BAA8B,CAAC;YAChD,oBAAoB;YACpB,gBAAgB;YAChB,uBAAuB;SACxB,CAAC;QACF,WAAW,EAAE,EAAE,aAAa,EAAE,gBAAgB,EAAE;QAChD,YAAY;QACZ,aAAa;QACb,kBAAkB;QAClB,eAAe,EAAE,WAAW;QAC5B,mBAAmB,EAAE,yBAAyB;KAC/C,CAAC,CAAC;IAEH,MAAM,YAAY,GAAW;QAC3B,MAAM,EAAE,WAAW;QACnB,IAAI,EAAE,YAAY;QAClB,OAAO,EAAE,YAAY;QACrB,OAAO,EAAE,YAAY;QACrB,QAAQ,EAAE,aAAa;KACxB,CAAC;IAEF,MAAM,KAAK,GACT,IAAI,KAAK,gBAAgB;QACvB,CAAC,CAAE,CAAC,QAAQ,EAAE,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAc;QACpE,CAAC,CAAE,CAAC,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,CAAc,CAAC;IAE/D,OAAO;QACL,MAAM,EAAE,YAAY;QACpB,iBAAiB,EAAE,KAAK;KACzB,CAAC;AACJ,CAAC"}
|
|
@@ -11,7 +11,6 @@ export declare const options: ({
|
|
|
11
11
|
defaultValue: string;
|
|
12
12
|
})[];
|
|
13
13
|
interface ForkallOptions {
|
|
14
|
-
eventPath?: string;
|
|
15
14
|
app?: string;
|
|
16
15
|
hstackToolPath?: string;
|
|
17
16
|
sourcemapDir?: string;
|
|
@@ -19,6 +18,7 @@ interface ForkallOptions {
|
|
|
19
18
|
duration?: string;
|
|
20
19
|
bufferSize?: string;
|
|
21
20
|
outputDir?: string;
|
|
21
|
+
traceFormatProfile?: string;
|
|
22
22
|
}
|
|
23
23
|
export declare function applyOptions(ctx: {
|
|
24
24
|
groups: Groups;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../commands/report.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"report.d.ts","sourceRoot":"","sources":["../../commands/report.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAK1E,eAAO,MAAM,MAAM,EAAE,MAAW,CAAC;AAEjC,eAAO,MAAM,iBAAiB,EAAE,MAAM,EAAiD,CAAC;AAExF,eAAO,MAAM,OAAO;;;;;;;;IAqBnB,CAAC;AAEF,UAAU,cAAc;IACtB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B;AA4HD,wBAAgB,YAAY,CAAC,GAAG,EAAE;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,OAAO,EAAE,cAAc,CAAC;CACzB,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,iBAAiB,EAAE,MAAM,EAAE,CAAA;CAAE,CA6FlD"}
|