Skip to content

Linux & shell: Performance & tracing

10 Linux & shell commands: Performance & tracing. Click a command to see what each part does.

Index
10 items
Click a command to see what each part does.

Performance & tracing10

  • vmstat 1 5CPU, memory, swap and I/O wait every second

    What each part does

    1. vmstatr (run queue), free memory, si/so (swapping), wa (I/O wait), us/sy/id CPU
    2. 1 5every 1 second, 5 times (the first line is the average since boot)
  • iostat -xz 1Disk I/O per device

    What each part does

    1. iostatdisk statistics (sysstat package)
    2. -xextended: %util, await (latency), r/s, w/s
    3. -zhide idle devices
    4. 1refresh every second
  • mpstat -P ALL 1CPU usage per core

    What each part does

    1. mpstatCPU statistics (sysstat)
    2. -P ALLevery core, to spot one core at 100%
    3. 1every second
  • pidstat -u -r -d 1CPU, memory and I/O per process over time

    What each part does

    1. pidstatper-process statistics (sysstat)
    2. -u -r -dCPU, memory (faults, RSS) and disk I/O
    3. 1every second
  • sudo iotop -oPaWhich processes do the most disk I/O?

    What each part does

    1. iotoptop for disk I/O
    2. -oonly processes actually doing I/O
    3. -Pper process, not per thread
    4. -aaccumulated totals
  • ps -eo pid,user,%mem,rss,cmd --sort=-rss | head -15Top memory users

    What each part does

    1. ps -eo ...pick columns: PID, user, % of RAM, resident memory in KB, command
    2. --sort=-rssbiggest memory first
    3. | head -15top 14 plus the header
  • sudo strace -f -tt -p <pid> -e trace=network,fileTrace what a process is doing (system calls)

    What each part does

    1. strace -p <pid>attach to a running process
    2. -ffollow its threads and children
    3. -tttimestamps with microseconds
    4. -e trace=network,fileonly network and file calls (drop it to see everything)

    Tip Slows the process down a lot; use briefly in production.

  • sudo perf topLive CPU profile of the whole system

    What each part does

    1. perf topfunctions using the most CPU right now, across kernel and user space
  • sar -n DEV 1Network traffic per interface

    What each part does

    1. sar -n DEVpackets and KB per second per interface (sysstat)
    2. 1every second; sar without a count reads history if sysstat collection is enabled
  • watch -n 2 -d '<command>'Re-run a command every few seconds

    What each part does

    1. watchrun the command repeatedly, full-screen
    2. -n 2every 2 seconds
    3. -dhighlight what changed

My DevOps Playbook by Angelo John Calleja

New runbook

GitHub not connected

Saving is handled by the site: the GitHub token is stored in Cloudflare, not in your browser. Enter the editor password (the EDITOR_PASSWORD secret) to unlock saving in this browser.

Saving commits to gelogrammer/My_DevOps_Playbook. Create a fine-grained token with access to only this repo andContents: Read and write, then paste it here. It is stored only in this browser.

src/content/docs/…