/spark tickmonitor
基本信息
| 属性 | 值 |
|---|---|
| 命令名 | tickmonitor |
| 别名 | tickmonitoring |
| 来源 | TickMonitoringModule(TickMonitoringModule.java:55) |
| 参数 | --threshold、--threshold-tick、--without-gc |
| Tab 补全 | TabCompleter.completeForOpts(arguments, "--threshold", "--threshold-tick", "--without-gc") |
| 类型 | 开关式(toggle) |
tick 耗时监控器:符合触发条件时自动把当时的完整主线程调用栈广播到聊天框。1.7.10 上这是排查「偶发卡顿 / 某个 mod 拖慢主线程」最直接的工具。
功能
执行时先取 platform.getTickHook(),为 null 则回复「Not supported!」并返回(红色)。
随后判断开关状态:
- 已在运行 →
close()关闭,回复「Tick monitor disabled.」 - 未运行 → 按参数构造
ReportPredicate并启动ReportingTickMonitor
触发条件是三选一,优先级从上到下(TickMonitoringModule.java:64-74):
| 条件 | 构造 |
|---|---|
传了 --threshold |
ReportPredicate.PercentageChangeGt(threshold) —— 相比滑窗平均上升百分比超过阈值 |
传了 --threshold-tick |
ReportPredicate.DurationGt(threshold) —— tick 时长绝对值(毫秒)超过阈值 |
| 都没传 | ReportPredicate.PercentageChangeGt(100) —— 默认即「涨幅超过 100%」,即 tick 耗时翻倍 |
--without-gc 传入后被取反(!arguments.boolFlag("without-gc"))作为构造参数,作用是默认会过滤掉 GC 引起的 tick 变慢;加该 flag 才把 GC 导致的尖峰也算作报告对象。
数值
| 数值名 | 值 | 来源 |
|---|---|---|
| 默认触发阈值 | 百分比涨幅 > 100% | TickMonitoringModule.java:73 |
--threshold 单位 |
百分比 | .argumentUsage("threshold", "percentage increase") |
--threshold-tick 单位 |
tick 时长毫秒 | .argumentUsage("threshold-tick", "tick duration") |
1.7.10 的数据来源
监控依赖 TickHook。1.7.10 适配层 Forge1710TickHook extends AbstractTickHook,在 @SubscribeEvent onTick(TickEvent e) 中过滤 e.phase == TickEvent.Phase.START 且 e.type 与构造时一致(服务端 TickEvent.Type.SERVER,客户端 TickEvent.Type.CLIENT)后调用 onTick()(Forge1710TickHook.java:28-44)。
注册与注销通过 FMLCommonHandler.instance().bus().register(this) / unregister(this) 完成(Forge1710TickHook.start() / close())。
注意 1.7.10 的 tick hook 依赖 FML 的通用事件总线,与 Forge1710TickReporter(Forge1710TickReporter)是两个独立对象:前者只在 tick 起始打点用于监控,后者同时监听 START/END 用于 MSPT 统计(Forge1710TickReporter.onTick 对 default 分支抛 AssertionError)。
交互
| 触发 | 行为 |
|---|---|
| 首次执行 | 按参数启动监控 |
| 再次执行 | 关闭监控,回复「Tick monitor disabled.」 |
| 平台不支持 tick hook | 回复「Not supported!」(红色) |
| tick 耗时越过阈值 | 广播该 tick 的主线程调用栈 |
相关条目
- /spark gcmonitor - 同为开关式监控器,监听 GC 事件
- /spark tps - 事后统计视角;tickmonitor 是实时报警视角