linux - Mac 或 Linux 上的内存监控

标签 linux macos memory memory-profiling

<分区>

是否有任何工具可以随时间监控应用程序内存并将其显示为图表?

例如,在 Windows 中有一个 perfmon。我可以轻松配置我想要监控的进程和分辨率,并查看一段时间内的图表。

在 Mac 或 Linux 中有类似的东西吗?

谢谢。

最佳答案

一种方法是使用 gnuplotbash 自己编写脚本:

$ cat memory-plot.pg
#!/usr/bin/gnuplot
reset
set terminal dumb 120,40
set xdata time
set timefmt "%Y-%m-%dT%H:%M:%S"
set format x "%H:%M"
set xlabel "time"
set ylabel "RSS, KB"
set title "Process RSS over time."
set grid
set style data linespoints
plot "< tail -n 90 rss.txt" using 1:2 title "RSS"

$ pid=`pgrep Xorg`; clear; while sleep 1; do (printf "%(%Y-%m-%dT%H:%M:%S)T "; ps -ho rss,cmd -p $pid) >> rss.txt; printf "\033[0;0H"; gnuplot memory-plot.pg; done

在终端中输出实时图表:

                                                   Process RSS over time.

  105500 +-+--+-----+----+----+-----+----+----+-----+----+-----+----+----+-----+----+----+-----+----+----+-----+--+-+
         +          +         +          +          +          +         +          +          +         +          +
         |          :A        :          :          :          :         :          :          :        RSS +--A--+ |
         |          :|        :          :          :          :         :          :          :         :          |
         |          :|      A : -A     A :          :          :         :          :          :         :          |
  105000 +-+.........|......|..A.|....A|..........................................................................+-+
         |          :|      | :| |    || :          :          :         :          :          :         :          |
         |          :|      |||  |    || :   AA     :          :         :          :          :         :          |
         |          :|      |||  |    || :   ||     :          :         :          :          :         :          |
  104500 +-+.........|.....|.|...|....||....A..|..................................................................+-+
         |          :||    | A:  |    || :  |  |    :          :         :          :          :         :          |
         |          :||    |  :  |   | | :  |   |   :          :         :          :          :         :          |
         |          :||    |  :  |   | | :  |   A   :          :         :          :          :         :          |
         |          :||    A  :  |   | | :  |   |   :          :         :          :          :         :          |
  104000 +-+.........||.AAA.......|..|..|...|...|.................................................................+-+
         |          :||A      :   |  |  |: |    |   :          :         :          :          :         :          |
         |          :|||      :   | AA  |: |    |   :          :         :          :          :         :          |
         |          | |       :   |A    |: |     |  :          :         :          :          :         :          |
         |          | A       :   ||    |: |     |  :          :         :          :          :         :          |
  103500 +-+........|.............||....|..|.....|................................................................+-+
         |          |         :   ||    |: A     |AAAAAAAAAAAA-AAAAAAAAAAAA-AA-AAAAAAAAAAAAAA-AAAAAAAAAAAAA         |
         |          |         :   |     |: |     || :          :         :          :          :         :          |
         |          |         :   |     |:|      A  :          :         :          :          :         :          |
         |          |         :   A     AAA         :          :         :          :          :         :          |
  103000 +-+........|.............................................................................................+-+
         |          |         :          :          :          :         :          :          :         :          |
         |          |         :          :          :          :         :          :          :         :          |
         |          |         :          :          :          :         :          :          :         :          |
  102500 +-+........|.............................................................................................+-+
         |          |         :          :          :          :         :          :          :         :          |
         |          |         :          :          :          :         :          :          :         :          |
         AAAAAAAA-AAA         :          :          :          :         :          :          :         :          |
         +          +         +          +          +          +         +          +          +         +          +
  102000 +-+--+-----+----+----+-----+----+----+-----+----+-----+----+----+-----+----+----+-----+----+----+-----+--+-+
       11:49      11:49     11:49      11:49      11:49      11:49     11:50      11:50      11:50     11:50      11:50

关于linux - Mac 或 Linux 上的内存监控,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40908880/

相关文章:

c++ - G++ 无法找到对 raw() 或 cbreak() 的引用,即使在链接 curses 时也是如此

c - 十六进制字符到整数的转换

c - C 语言和 Mac OSX

macos - 在 Swift 中获取鼠标坐标

Android - 避免内存泄漏的良好实践

python - bool 值的大列表和小列表以及字节数组的相对性能

C++游戏训练器进程监控

linux - 在 Docker 中为 Linux 主机预留 CPU 和内存

c++ - 使用 CppUnit 链接测试库

ruby - 连接到后台 EventMachine 应用程序以进行单元测试