# 运行时监控

运行时监控观察正在运行的程序执行是否满足形式化指定的性质，并在程序运行期间产生判定、警报或恢复动作。监控器读取程序生成的事件流，判断已观察到的前缀是否仍满足该性质，并从判定域报告一个真值，通常为真、假或不确定。<sup>[1](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/lectures/RV.pdf)</sup> 除被动检查外，监控器还可以发出警报、调用用户定义的处理器，或引导运行中的系统进入安全状态。<sup>[2](https://swtv.kaist.ac.kr/files/publications/international_conference/RV19-invited-MAC.pdf)</sup> 当重点是根据规约检查一次运行时，该领域通常称为运行时验证（RV）；当监控器进行干预以阻止违反时，则称为运行时强制；运行时强制的起点是安全自动机，它可以强制整类安全性质。<sup>[3](https://www.irisa.fr/vertecs/Publis/Ps/STTT-2011.pdf)</sup>

| 关键事实 | 数值 |
|---|---|
| 判定语义 | 三值 LTL₃：对无限迹的有限前缀，取 ⊤、⊥、?<sup>[4](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/papers/RV.pdf)</sup> |
| 可监控性质 | 严格大于安全性质与余安全性质的并集<sup>[4](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/papers/RV.pdf)</sup> |
| JavaMOP 开销 | 经过多年优化后，在 DaCapo 基准上平均为 15%<sup>[5](https://fsl.cs.illinois.edu/publications/jin-meredith-lee-rosu-2012-icse.pdf)</sup> |
| 多规约开销 | 同时监控 179 个 Java API 规约时，平均为 143%（RV-Monitor）对 163%（JavaMOP）<sup>[6](https://fsl.cs.illinois.edu/publications/luo-zhang-lee-jin-meredith-serbanuta-rosu-2014-rv.pdf)</sup> |
| 测试规模开销 | 在 1,544 个项目中平均为 23.6 倍；RV 时间的 60.5% 花在插桩上<sup>[7](https://www.cs.cornell.edu/~legunsen/pubs/GuanAndLegunsenRVOverheadStudyISSTA24.pdf)</sup> |
| 日志规模监控 | MonPoly 处理了诺基亚（Nokia）两年日志中的超过 260 亿个事件（0.4 TB）<sup>[8](https://people.inf.ethz.ch/basin/pubs/rvcubes17.pdf)</sup> |
| 内核内部署 | Linux 内置一个 RV 子系统，带有每 CPU 和每任务监控器与反应器<sup>[9](https://docs.kernel.org/6.19-rc7/trace/rv/runtime-verification.html)</sup> |

## 工作原理

形式上说，监控器是一种读取有限迹并给出判定的装置，可建模为一个元组，包含判定域、事件集、状态、确定性转移函数和判定函数。<sup>[10](https://www.cs.man.ac.uk/~regerg/papers/rv-tutorial-ios-2012.pdf)</sup> 判定合成遵循两条准则：公正性，即只要还存在可能产生另一判定的延续，就绝不判定为真或假；以及预判性，即一旦所有延续都一致就立即判定。<sup>[11](https://christian.schallhart.net/publications/2008--atva--impartial-anticiapation-in-runtime-verification.pdf)</sup> 对于 LTL，LTL₃ 语义将前缀 \(u\) 求值为：若每个无限延续都满足 \(\varphi\)，则为 ⊤；若每个延续都违反它，则为 ⊥；否则为 ?。<sup>[1](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/lectures/RV.pdf)</sup>

可监控性限制了能够判定什么。安全性质的失败总能在有限时间内被检测到，但对于 \(\Box p\)，没有任何有限前缀能给出肯定判定；而对于 \(\Box\Diamond p\)，在有限时间内永远不可能给出判定。<sup>[12](https://havelund.com/Publications/rv-2023-tutorial.pdf)</sup> 可监控类严格包含安全性质与余安全性质的并集。<sup>[4](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/papers/RV.pdf)</sup> 针对 LTL₃ 的监控器构造会得到一个大小为 \(\lvert M \rvert \in 2^{2^{O(\lvert \varphi \rvert)}}\) 的自动机，可通过 Myhill-Nerode 最小化；实现风格包括重写、交替自动机和确定性自动机。<sup>[1](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/lectures/RV.pdf)</sup>

## 如何实施

RV 流程有三个阶段：从性质合成监控器、对系统插桩以生成事件，以及与运行系统同步进行或事后从日志进行的执行分析。<sup>[10](https://www.cs.man.ac.uk/~regerg/papers/rv-tutorial-ios-2012.pdf)</sup> 插桩技术构成一个谱系，从完全异步监控到完全同步监控。<sup>[13](https://ar5iv.labs.arxiv.org/html/1708.07229)</sup> 早期的 MaC 架构使用过滤器、事件识别器和运行时检查器，并将依赖实现的事件（PEDL）与高层需求（MEDL）分离。<sup>[14](https://vmahesh.cs.illinois.edu/papers/ecrts99.pdf)</sup>

开销有两个组成部分：信息提取（探针）和性质求值；它取决于哪些程序点被插桩以及监控器的数据结构；表达力更强的形式化方法代价更高。<sup>[15](https://swtv.kaist.ac.kr/files/publications/international_conference/rv02a.pdf)</sup><sup> • </sup><sup>[10](https://www.cs.man.ac.uk/~regerg/papers/rv-tutorial-ios-2012.pdf)</sup> 对于一阶规约，事件速率无关和迹长度无关的算法都无法实现：在最坏情况下，监控 \(p(x)\) 需要与整个迹前缀成正比的内存。<sup>[16](https://people.inf.ethz.ch/basin/pubs/atva23.pdf)</sup> 响应范围从警报一直到恢复代码：MaC 的引导动作会改变运行系统的状态或调用恢复例程，<sup>[2](https://swtv.kaist.ac.kr/files/publications/international_conference/RV19-invited-MAC.pdf)</sup> 而 JavaMOP 生成的监控器在违反或验证通过时运行用户定义的处理器，从而允许程序内强制。<sup>[5](https://fsl.cs.illinois.edu/publications/jin-meredith-lee-rosu-2012-icse.pdf)</sup>

## 起源

MaC 项目始于 1997 至 2002 年间由美国海军研究办公室（ONR）多学科大学研究计划（MURI）资助的项目，Java-MaC 工具在 2001 年第一届运行时验证研讨会上展示。<sup>[2](https://swtv.kaist.ac.kr/files/publications/international_conference/RV19-invited-MAC.pdf)</sup> RV 会议本身最初是巴黎（Paris）的一个研讨会，后于 2010 年成为会议；2001 年的论文《用 Java PathExplorer 监控 Java 程序》在 RV 2018 上获得时间检验奖（Test of Time Award）。<sup>[17](https://www.havelund.com/Publications/rv-2018-test-of-time.pdf)</sup>

受 JPaX 局限推动的后续系统包括 Eagle 和 Mop（面向监控的编程）；Mop 使用 Perl 进行插桩，其他版本使用 AspectJ。<sup>[17](https://www.havelund.com/Publications/rv-2018-test-of-time.pdf)</sup> MOP 由陈峰（Feng Chen）和格里戈雷·罗舒（Grigore Roşu）于 2007 年在伊利诺伊大学厄巴纳-香槟分校（University of Illinois at Urbana-Champaign）的伊利诺伊学习与奖学金数字环境（Illinois Digital Environment for Access to Learning and Scholarship）中报告；他们提出从形式化规约自动合成监控器并将其集成到程序中。<sup>[18](https://dl.acm.org/doi/10.1145/1297027.1297069)</sup> 首届国际运行时验证竞赛（CRV 2014）由埃齐奥·巴尔托奇（Ezio Bartocci）、伊列斯·法尔科内（Yliès Falcone）、博尔祖·博纳克达普尔（Borzoo Bonakdarpour）及其同事于 2017 年在《软件工具与技术转移国际期刊》（International Journal on Software Tools for Technology Transfer）上记录。<sup>[19](https://doi.org/10.1007/s10009-017-0454-5)</sup> TraceMOP 和 LazyMOP 由凯文·关（Kevin Guan）、马塞洛·达莫林（Marcelo d'Amorim）和奥沃拉比·莱贡森（Owolabi Legunsen）于 2025 年在《ACM 编程语言论文集》（Proceedings of the ACM on Programming Languages）上报告。<sup>[20](https://doi.org/10.1145/3763183)</sup>

## 变体

**Java 工具。** Java PathExplorer 通过 Maude 重写引擎按 LTL 规约检查 Java 程序，同时使用取自 Eraser 和 Visual Threads 的数据竞争与死锁检测算法。<sup>[17](https://www.havelund.com/Publications/rv-2018-test-of-time.pdf)</sup> Java-MaC 在静态阶段从 PEDL/MEDL 规约生成其过滤器、事件识别器和检查器。<sup>[21](https://vmahesh.cs.illinois.edu/papers/fmsd04.pdf)</sup> JavaMOP 按参数实例切分迹，并用专用监控器检查每个切片；它不依赖特定的形式化体系，带有面向 FSM、ERE、CFG、PTLTL、同时包含未来和过去算子的 LTL，以及 PTCaRet 的插件。<sup>[5](https://fsl.cs.illinois.edu/publications/jin-meredith-lee-rosu-2012-icse.pdf)</sup> RV-Monitor 使用持有弱引用的索引树来避免内存泄漏，从而改进对许多性质的同时监控。<sup>[6](https://fsl.cs.illinois.edu/publications/luo-zhang-lee-jin-meredith-serbanuta-rosu-2014-rv.pdf)</sup>

**一阶与策略监控。** MonPoly 按度量一阶时序逻辑（MFOTL）检查日志和事件流，该逻辑限制为带有有界未来算子的安全片段；其家族后来增加了聚合、递归和分布式监控。<sup>[16](https://people.inf.ethz.ch/basin/pubs/atva23.pdf)</sup>

**其他语言。** Larva 使用 DATE 自动机语言（带定时器与事件的动态自动机）；Lola 提供离线和完全同步的在线监控，并具有有界资源保证；detectEr 以多种插桩模式监控 Erlang。<sup>[13](https://ar5iv.labs.arxiv.org/html/1708.07229)</sup> CCMOP 通过 Clang 编译器将 MOP 方法扩展到 C/C++。<sup>[22](https://zbchen.github.io/files/rv2023.pdf)</sup> PyMOP 是 MOP 的第一个 Python 实例，带有五个逻辑插件、参数化迹切片以及在线和离线监控。<sup>[23](https://arxiv.org/html/2509.06324)</sup> Linux 内核的 rvgen 工具将监控器合成为 C 头文件，用于确定性自动机、LTL 和混合自动机。<sup>[24](https://docs.kernel.org/7.1/trace/rv/monitor_synthesis.html)</sup> 时间性质工具包括 MonPoly、Uppaal SMC、R2U2、Reelay、Montre、AERIAL、AMT 和 RTAMT；2026 年《系统设计中的形式化方法》（Formal Methods in System Design）的一篇文章使用定时 Büchi 自动机和基于区域的表示，将 LTL₃ 风格的三值判定扩展到无限定时字。<sup>[25](https://link.springer.com/article/10.1007/s10703-026-00498-5)</sup> 一项综述称，20 个 RV 工具中有 13 个支持输入规约中的某些数据。<sup>[26](https://drops.dagstuhl.de/storage/00lipics/lipics-vol348-concur2025/LIPIcs.CONCUR.2025.4/LIPIcs.CONCUR.2025.4.pdf)</sup>

## 应用

LogScope 为支持喷气推进实验室（JPL）的火星车“好奇号”（Curiosity）飞行软件测试而构建，好奇号于 2012 年 8 月 6 日登陆火星。<sup>[17](https://www.havelund.com/Publications/rv-2018-test-of-time.pdf)</sup> 在诺基亚案例研究中，MonPoly 检查了两年期内超过 260 亿个事件、0.4 TB 协议缓冲区格式的日志文件的合规性，并使用 map-reduce 切分日志。<sup>[8](https://people.inf.ethz.ch/basin/pubs/rvcubes17.pdf)</sup> 互联网计算机（Internet Computer）是一个跨越 1,200 多个节点的分布式 Web3 平台，使用带量词、聚合以及过去和未来算子的 MFOTL 策略以 MonPoly 进行监控；该流水线在持续开发工作流中就违反策略的情况向工程师发出警报。<sup>[27](https://internetcomputer.org/whitepapers/Monitoring%20the%20Internet%20Computer.pdf)</sup> 对数千个 Java 项目中通过的测试按 JDK API 规约进行监控，发现了数百个缺陷。<sup>[23](https://arxiv.org/html/2509.06324)</sup> Linux 内核提供 RV 监控器以及 nop、printk 和 panic 等反应器，暴露于 /sys/kernel/tracing/rv/。<sup>[9](https://docs.kernel.org/6.19-rc7/trace/rv/runtime-verification.html)</sup>

## 局限与替代方案

不完整或不精确的迹可能使监控器无法给出可靠判定；缺失或歧义事件正出现在事件迹收集以及系统与监控器之间的通信中。<sup>[28](https://dl.acm.org/doi/10.1016/j.cosrev.2023.100594)</sup> 当使用采样，或观察顺序与执行顺序不一致时，可靠性与完备性无法得到保证。<sup>[29](https://www21.in.tum.de/~traytel/papers/sttt21-tax_long/tax_long.pdf)</sup> 一种缓解方法是增加“放弃”判定，使监控器放弃它永远无法得出结论的执行；这适用于计算和内存有限的自主系统。<sup>[30](https://iris.unimore.it/retrieve/4e63a873-ad18-429e-aac5-d6f17e0f725b/1-s2.0-S0167642324001436-main.pdf)</sup> 像 JavaMOP 这样的隐式迹监控器只报告违反迹的最后一个事件，使调试复杂化。<sup>[31](https://par.nsf.gov/servlets/purl/10628155)</sup>

RV 不是像模型检验那样的全面验证方法；它一次应用于一个执行，以覆盖范围换取摆脱状态空间复杂性限制。<sup>[12](https://havelund.com/Publications/rv-2023-tutorial.pdf)</sup> 它适合没有模型的黑盒环境，并在迹长度上具有多项式时间行为。<sup>[30](https://iris.unimore.it/retrieve/4e63a873-ad18-429e-aac5-d6f17e0f725b/1-s2.0-S0167642324001436-main.pdf)</sup> 运行时强制通过规避违反而不只是检测违反，扩展了验证。<sup>[3](https://www.irisa.fr/vertecs/Publis/Ps/STTT-2011.pdf)</sup>

## References

1. [Teaching Runtime Verification (lecture notes, Bonakdarpour, U. Waterloo CS745)](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/lectures/RV.pdf)
2. [A Retrospective Look at the Monitoring and Checking (MaC) Framework](https://swtv.kaist.ac.kr/files/publications/international_conference/RV19-invited-MAC.pdf)
3. [What can you verify and enforce at runtime?](https://www.irisa.fr/vertecs/Publis/Ps/STTT-2011.pdf)
4. [Runtime Verification for LTL and TLTL (Bauer, Leucker, Schallhart)](https://cs.uwaterloo.ca/~bbonakda/teaching/CS745/papers/RV.pdf)
5. [JavaMOP: Efficient Parametric Runtime Monitoring Framework (ICSE 2012)](https://fsl.cs.illinois.edu/publications/jin-meredith-lee-rosu-2012-icse.pdf)
6. [RV-Monitor: Efficient Parametric Runtime Verification with Simultaneous Properties](https://fsl.cs.illinois.edu/publications/luo-zhang-lee-jin-meredith-serbanuta-rosu-2014-rv.pdf)
7. [An In-Depth Study of Runtime Verification Overheads during Software Testing (ISSTA 2024)](https://www.cs.cornell.edu/~legunsen/pubs/GuanAndLegunsenRVOverheadStudyISSTA24.pdf)
8. [The MonPoly Monitoring Tool](https://people.inf.ethz.ch/basin/pubs/rvcubes17.pdf)
9. [Runtime Verification, The Linux Kernel documentation](https://docs.kernel.org/6.19-rc7/trace/rv/runtime-verification.html)
10. [A Tutorial on Runtime Verification (Falcone, Havelund, Reger)](https://www.cs.man.ac.uk/~regerg/papers/rv-tutorial-ios-2012.pdf)
11. [Impartial Anticipation in Runtime-Verification (Schallhart et al., ATVA 2008)](https://christian.schallhart.net/publications/2008--atva--impartial-anticiapation-in-runtime-verification.pdf)
12. [Monitorability for Runtime Verification](https://havelund.com/Publications/rv-2023-tutorial.pdf)
13. [A Survey of Runtime Monitoring Instrumentation Techniques (Francalanza et al.)](https://ar5iv.labs.arxiv.org/html/1708.07229)
14. [Formally Specified Monitoring of Temporal Properties (ECRTS 1999)](https://vmahesh.cs.illinois.edu/papers/ecrts99.pdf)
15. [Monitoring overhead / value abstraction paper (RV'02, Elsevier ENTCS)](https://swtv.kaist.ac.kr/files/publications/international_conference/rv02a.pdf)
16. [Correct and Efficient Policy Monitoring, a Retrospective (MonPoly project, ATVA 2023)](https://people.inf.ethz.ch/basin/pubs/atva23.pdf)
17. [Runtime Verification - 17 Years Later](https://www.havelund.com/Publications/rv-2018-test-of-time.pdf)
18. [Mop: an efficient and generic runtime verification framework (OOPSLA 2007)](https://dl.acm.org/doi/10.1145/1297027.1297069)
19. [Ezio Bartocci and colleagues (2017). First international Competition on Runtime Verification: rules, benchmarks, tools, and final results of CRV 2014. International Journal on Software Tools for Technology Transfer.](https://doi.org/10.1007/s10009-017-0454-5)
20. [Kevin Guan, Marcelo d'Amorim, Owolabi Legunsen (2025). Faster Explicit-Trace Monitoring-Oriented Programming for Runtime Verification of Software Tests. Proceedings of the ACM on Programming Languages.](https://doi.org/10.1145/3763183)
21. [Java-MaC: A Run-Time Assurance Approach for Java Programs](https://vmahesh.cs.illinois.edu/papers/fmsd04.pdf)
22. [CCMOP: runtime verification for C/C++ programs (RV 2023)](https://zbchen.github.io/files/rv2023.pdf)
23. [PyMOP: A Generic and Efficient Python Runtime Verification System and its Large-scale Evaluation](https://arxiv.org/html/2509.06324)
24. [Runtime Verification Monitor Synthesis, The Linux Kernel documentation](https://docs.kernel.org/7.1/trace/rv/monitor_synthesis.html)
25. [Efficient monitoring of timed properties (Formal Methods in System Design, 2026)](https://link.springer.com/article/10.1007/s10703-026-00498-5)
26. [Monitorability for the Modal Mu-Calculus over Systems with Data (CONCUR 2025)](https://drops.dagstuhl.de/storage/00lipics/lipics-vol348-concur2025/LIPIcs.CONCUR.2025.4/LIPIcs.CONCUR.2025.4.pdf)
27. [Monitoring the Internet Computer (FM 2023)](https://internetcomputer.org/whitepapers/Monitoring%20the%20Internet%20Computer.pdf)
28. [Uncertainty in runtime verification: A survey (Computer Science Review, Vol 50)](https://dl.acm.org/doi/10.1016/j.cosrev.2023.100594)
29. [Classifying Runtime Verification Tools (STTT)](https://www21.in.tum.de/~traytel/papers/sttt21-tax_long/tax_long.pdf)
30. [Towards partial monitoring: Never too early to give in (Science of Computer Programming, 2024)](https://iris.unimore.it/retrieve/4e63a873-ad18-429e-aac5-d6f17e0f725b/1-s2.0-S0167642324001436-main.pdf)
31. [TraceMOP / LazyMOP: Explicit-Trace Runtime Verification for Java (OOPSLA 2025)](https://par.nsf.gov/servlets/purl/10628155)

---
*Initially written Sep 29, 2026 · Edited: Oct 15, 2026*

Topic: 技术与人造世界 › 计算技术与数字系统 › 软件与编程 › Software engineering and development process › Software testing and quality

Copyright 2026 Edgepedia

License: Edgepedia Community License 1.0, https://www.edgepedia.org/edgepedia/license

Source: https://www.edgepedia.org/zh/runtime-monitoring

English original: https://www.edgepedia.org/runtime-monitoring
