psrecord

博客介绍了psrecord工具,它基于psutil库,可统计某个进程的CPU和内存使用情况并图形化展示。生成图片需用到matplotlib。还说明了如何记录进程CPU和内存使用情况并写入日志,以及如何生成统计图片。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

关于psrecord

psrecord可以统计某个进行的CPU和内存的使用情况,并生成图形化展示
其基于psutil库实现。

prerequests

sudo pip install matplotlib

当要生成图片时,需要使用matplotlib

install

sudo install psrecord

记录某进程CPU和内存使用情况,并写入日志

psrecord $(pgrep -nf "wslconnect") --interval 1 --log wsl.txt
  • pgrep -nf "wslconnect"解释
    pgrep用于根据进程名查找进程pid,-n 表示如果有多个就选择最新的一个,-f表示进程名要全匹配。
  • psrecord将会attach到最新的一个wslconnect进程,然后每隔1秒统计一次该进程CPU和内存的使用情况,并写入wsl.txt
  • wsl.txt的内容如下
# Elapsed time   CPU (%)     Real (MB)   Virtual (MB)
       0.000        0.000        1.965        2.855
       1.002        0.000        1.965        2.855
       2.004        0.000        1.965        2.855
       3.006        0.000        1.965        2.855
       4.008        0.000        1.965        2.855
       5.010        0.000        1.965        2.855
       6.012        0.000        1.965        2.855
       7.014        0.000        1.965        2.855
       8.016        0.000        1.965        2.855
       9.018        0.000        1.965        2.855

记录某进程CPU和内存使用情况,并生成统计图片

psrecord $(pgrep -nf "wslconnect") --interval 1 --plot wsl.png

使用图片软件打开wsl.png即可看到统计信息。

### 处理 CMake 构建文件已写入指定目录的方法 当遇到 `ns-3.36.1` 的 CMake 构建文件已经写入到 `/home/zp/tarballs/ns-...common htop vim nano jq net-tools iputils-ping traceroute dnsutils tcpdump wireshark tshark bmon iftop iotop glances atop sysstat lm-sensors cifs-utils nfs-common sshfs fuse zstd p7zip-full unrar-free unzip pigz pv gawk sed grep findutils coreutils util-linux procps bash-completion man-db info texinfo docbook-xsl xsltproc xmlto asciidoc graphviz doxygen clang-format cppcheck valgrind gcovr lcov gengetopt autoconf automake autopoint gettext intltool libtool m4 flex bison wget rsync subversion bzr mercurial git-lfs cargo rustc protobuf-compiler libprotobuf-dev libprotoc-dev google-mock googletest libgtest-dev libgmock-dev ninja-build meson cmake-gui ccache distcc bear scan-build oclint cpplint cppcheck flawfinder splint tidy html-tidy xmllint jsonlint yamllint shellcheck markdown pandoc rst2pdf pdfgrep chktex latexmk texlive-latex-base texlive-fonts-recommended texlive-extra-utils texlive-lang-chinese texlive-lang-japanese texlive-lang-korean texlive-publishers texlive-science texlive-bibtex-extra biblatex biber perl-doc perldoc pod2man podchecker podlators makeinfo texi2html help2man info-install texinfo-doc-nonfree wdiff colordiff diffutils patchutils meld kdiff3 kompare bc dc calc units speedcrunch qalculate-gtk apcalc apcalc-common apcalc-dev bc boinc-client boinc-manager calcoo extcalc galculator gnome-calculator kalc kalgebra kmplot octave r-cran-runit r-cran-testthat sagemath jupyter-notebook spyder eric idle-python3.8 pylint pyflakes flake8 black yapf isort autoflake autopep8 mypy prospector bandit safety semmlecode sonar-scanner spotbugs checkstyle pmd cpd dependency-check gradle ant ivy sbt bazel buck pants npm yarn pnpm bun composer phpcs phpstan hhvm hhvm-debugger hhvm-nightly hhvm-phpdbg hhvm-sourcekit-lsp vscode code-insiders sublime-text atom brackets lighttable vscodium codium onivim neovide kakoune helix micro minicom screen tmux byobu fish zsh oh-my-zsh prezto powerlevel10k starship exa fd fzf bat ripgrep the_silver_searcher ag ack-grep pt rg sd sift ugrep delta hexyl broot bottom bpytop gotop heimdall procs psrecord smem slurm...
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值