
ProcDump-for-Linux v3.5.3
ProcDump Sysinternals 工具的 Linux 版本
ProcDump 
ProcDump 是经典 ProcDump 工具(来自 Windows 的 Sysinternals 套件)在 Linux 和 Mac 上的重新实现。ProcDump 为 Linux 和 Mac 开发者提供了一种便捷的方式,基于性能触发器为应用程序创建核心转储(core dump)。ProcDump for Linux and Mac 是 Sysinternals 的一部分。

安装与使用
系统要求
- 最低 Linux 操作系统版本:
- Red Hat Enterprise Linux / CentOS 7
- Fedora 29
- Ubuntu 16.04 LTS
gdb>= 7.6.1
- 最低 Mac 操作系统版本:Sierra
安装 ProcDump
请参阅安装说明此处。
构建
请参阅构建说明此处。
使用
重大变更 自 ProcDump 1.3 发布以来,命令行开关现已与 Windows 版 ProcDump 保持一致。 请注意,Mac 版本目前支持有限的触发器集。
Capture Usage:
procdump [-n Count]
[-s Seconds]
[-c|-cl CPU_Usage]
[-m|-ml Commit_Usage1[,Commit_Usage2...]]
[-gcm [<GCGeneration>: | LOH: | POH:]Memory_Usage1[,Memory_Usage2...]]
[-gcgen Generation]
[-restrack [nodump]]
[-sr Sample_Rate]
[-tc Thread_Threshold]
[-fc FileDescriptor_Threshold]
[-sig Signal_Number1[,Signal_Number2...]]
[-e]
[-f Include_Filter,...]
[-fx Exclude_Filter]
[-mc Custom_Dump_Mask]
[-pf Polling_Frequency]
[-o]
[-log syslog|stdout]
{
{{[-w] Process_Name | [-pgid] PID} [Dump_File | Dump_Folder]}
}
Options:
-n Number of dumps to write before exiting.
-s Consecutive seconds before dump is written (default is 10).
-c CPU threshold above which to create a dump of the process.
-cl CPU threshold below which to create a dump of the process.
-m Memory commit threshold(s) (MB) above which to create dumps.
-ml Memory commit threshold(s) (MB) below which to create dumps.
-gcm [.NET] GC memory threshold(s) (MB) above which to create dumps for the specified generation or heap (default is total .NET memory usage).
-gcgen [.NET] Create dump when the garbage collection of the specified generation starts and finishes.
-restrack Enable memory leak tracking (malloc family of APIs). If used without other triggers, use 't' to manually capture a restrack report. When used with other triggers, the 'nodump' option can be used to prevent dump generation and only produce restrack report(s).
-sr Sample rate when using -restrack.
-tc Thread count threshold above which to create a dump of the process.
-fc File descriptor count threshold above which to create a dump of the process.
-sig Comma separated list of signal number(s) during which any signal results in a dump of the process.
-e [.NET] Create dump when the process encounters an exception.
-f Filter (include) on the content of .NET exceptions (comma separated). Wildcards (*) are supported.
-fx Filter (exclude) on the content of -restrack call stacks. Wildcards (*) are supported.
-mc Custom core dump mask (in hex) indicating what memory should be included in the core dump. Please see 'man core' (/proc/[pid]/coredump_filter) for available options.
-pf Polling frequency.
-o Overwrite existing dump file.
-log Writes extended ProcDump tracing to the specified output stream (syslog or stdout).
-w Wait for the specified process to launch if it's not running.
-pgid Process ID specified refers to a process group ID.
资源跟踪
-restrack 开关激活资源跟踪功能,允许在生成核心转储时监测和报告所有尚未释放的资源分配。结果将保存到扩展名为 .restrack 的文件中。当前支持跟踪以下资源分配/释放函数:
分配:
- malloc
- calloc
- realloc
- reallocarray
- mmap
释放:
- free
- munmap
Mac 版本目前不支持资源跟踪。
示例
以下示例均针对进程 ID 为 1234 的进程
以下命令将立即创建核心转储。
sudo procdump 1234
以下命令将创建 3 个核心转储,每个间隔 10 秒。
sudo procdump -n 3 1234
以下命令将创建 3 个核心转储,每个间隔 5 秒。
sudo procdump -n 3 -s 5 1234
以下命令将在进程 CPU 使用率 >= 65% 时创建核心转储,最多 3 次,每次转储间隔至少 10 秒。
sudo procdump -c 65 -n 3 1234
以下命令将在进程 CPU 使用率 >= 65% 时创建核心转储,最多 3 次,每次转储间隔至少 5 秒。
sudo procdump -c 65 -n 3 -s 5 1234
以下命令将在 CPU 使用率超出 [10,65] 范围时创建核心转储。
sudo procdump -cl 10 -c 65 1234
以下命令将在 CPU 使用率 >= 65% 或内存使用率 >= 100 MB 时创建核心转储。
sudo procdump -c 65 -m 100 1234
以下命令将在内存使用率 >= 100 MB 时创建核心转储,之后在内存使用率 >= 200 MB 时再次创建转储。
sudo procdump -m 100,200 1234
以下命令将在用户每次按下 't' 时生成内存泄漏报告(无转储):
sudo procdump -restrack 1234
以下命令将创建 3 份内存泄漏报告(无转储),每份间隔 5 秒:
sudo procdump -n 3 -s 5 -restrack nodump 1234
以下命令将在内存使用率 >= 100 MB 时创建核心转储和内存泄漏报告。
sudo procdump -m 100 -restrack 1234
以下命令将在内存使用率 >= 100 MB 时创建内存泄漏报告(无转储)。
sudo procdump -m 100 -restrack nodump 1234
以下命令将在内存使用率 >= 100 MB 时创建核心转储和内存泄漏报告,采样率为每第 10 次内存分配采样一次。
sudo procdump -m 100 -restrack -sr 10 1234
以下命令将在内存使用率 >= 100 MB 时创建核心转储和内存泄漏报告,并排除任何调用栈中包含字符串 "cache" 的帧。
sudo procdump -m 100 -restrack -fx *cache* 1234
以下命令将在 .NET 总内存使用率 >= 100 MB 时创建核心转储,之后在内存使用率 >= 200 MB 时再次创建转储。
sudo procdump -gcm 100,200 1234
以下命令将在 .NET 第 1 代内存使用率 >= 1 MB 时创建核心转储,之后在内存使用率 >= 2 MB 时再次创建转储。
sudo procdump -gcm 1:1,2 1234
以下命令将在 .NET 大对象堆(LOH)内存使用率 >= 100 MB 时创建核心转储,之后在内存使用率 >= 200 MB 时再次创建转储。
sudo procdump -gcm LOH:100,200 1234
以下命令将在 .NET 第 1 代垃圾回收的开始和结束时各创建一个核心转储。
sudo procdump -gcgen 1
以下命令将立即在 /tmp 目录下创建核心转储。
sudo procdump 1234 /tmp
以下命令将在当前目录下创建名为 dump_0.1234 的核心转储。如果使用了 -n 选项,文件将依次命名为 dump_0.1234、dump_1.1234 等。
sudo procdump 1234 dump
以下命令将在发生 SIGSEGV 信号时创建核心转储。
sudo procdump -sig 11 1234
以下命令将在发生 SIGSEGV 信号时创建核心转储,且转储仅包含匿名私有映射。
sudo procdump -mc 1 -sig 11 1234
以下命令将在目标 .NET 应用程序抛出 System.InvalidOperationException 异常时创建核心转储。
sudo procdump -e -f System.InvalidOperationException 1234
包含筛选器支持部分匹配和通配符匹配,因此以下命令也会在出现 System.InvalidOperationException 时创建核心转储。
sudo procdump -e -f InvalidOperation 1234
或
sudo procdump -e -f "*Invali*Operation*" 1234
所有选项也可与
-w一起使用,以等待给定名称的进程启动。
以下命令等待名为 my_application 的进程,并在发现该进程时立即创建核心转储。
sudo procdump -w my_application
当前限制
- 目前只能在 Linux 内核 3.5+ 或 macOS Sierra+ 上运行。
- 不完全具备 Windows 版 ProcDump 的全部功能,特别是保持活动(stay alive)功能和自定义性能计数器。
反馈
- 在 StackOverflow 上提问(标签为 ProcDumpForLinux)
- 在 GitHub 上请求新功能
- 为热门功能请求投票
- 在 GitHub Issues 中提交错误
贡献
如果您有兴趣修复问题并直接为代码库做出贡献,请参阅贡献文档,其中包含以下内容:
- 如何从源码构建和运行
- 开发工作流程,包括调试和运行测试
- 编码指南
- 提交拉取请求
另请参阅我们的行为准则。
许可
版权所有 (c) Microsoft Corporation。保留所有权利。
根据 MIT 许可授权。
ProcDump for Linux:
- 克隆、编译并静态链接 libbpf (https://github.com/libbpf/libbpf)
- 复制来自 BCC (https://github.com/iovisor/bcc) 的符号解析源代码
- 使用 eBPF