{
    "slug": "linux_performance_tools",
    "term": "Linux Performance Tools",
    "category": "linux",
    "difficulty": "intermediate",
    "short": "Essential tools for diagnosing CPU, memory, IO, and network performance on Linux — top, htop, vmstat, iostat, perf, strace, and ltrace.",
    "long": "CPU: top / htop (real-time process stats), mpstat (per-CPU stats), perf top (CPU profiling by function). Memory: free -h (overview), vmstat -s (detailed), smem (per-process). Disk IO: iostat -x (saturation and utilisation), iotop (per-process IO). Network: nethogs (per-process bandwidth), iftop (per-connection traffic), ss -s (socket summary). Tracing: strace -p PID (system calls made by a process — what is it doing?), ltrace (library calls). For PHP: strace on a stuck PHP-FPM worker shows exactly which system call it's blocked on.",
    "aliases": [
        "strace",
        "perf",
        "iostat",
        "htop",
        "vmstat",
        "ltrace"
    ],
    "tags": [
        "linux",
        "devops",
        "performance",
        "debugging"
    ],
    "misconception": "top is the only tool needed for performance analysis — top shows CPU and memory snapshot but misses: disk IO saturation, network bottlenecks, and which specific system calls are blocking — iostat, nethogs, and strace fill these gaps.",
    "why_it_matters": "A slow PHP response that looks fine in CPU and memory metrics may be blocked on a slow NFS mount or disk IO — strace shows exactly which read() or write() call is taking seconds.",
    "common_mistakes": [
        "Only looking at CPU usage — IO wait shows as CPU idle but means processes are blocked on disk.",
        "Not knowing strace -p for live process inspection — invaluable for hung process diagnosis.",
        "Running strace in production on a busy process — overhead can be 10-100x; use carefully.",
        "Confusing %iowait (CPU waiting for IO) with disk utilisation — %iowait doesn't directly show disk saturation."
    ],
    "when_to_use": [],
    "avoid_when": [],
    "related": [
        "linux_processes",
        "profiling",
        "linux_networking_tools",
        "apm_tools"
    ],
    "prerequisites": [
        "linux_processes",
        "profiling",
        "observability"
    ],
    "refs": [
        "https://brendangregg.com/linuxperf.html"
    ],
    "bad_code": "# Performance analysis by guesswork:\n# 'The server is slow'\n# Restart PHP-FPM (sometimes works, doesn't fix root cause)\n# Check top: CPU 30% — nothing obvious\n# Give up, ticket to sysadmin\n# Hours wasted",
    "good_code": "# Systematic performance investigation:\n# 1. CPU and load:\nhtop           # Real-time, with color\nmpstat 1 5     # Per-CPU every second for 5 seconds\n\n# 2. Memory:\nfree -h        # Quick overview\nvmstat 1 5     # Including swap activity\n\n# 3. Disk IO:\niostat -x 1 5  # Is any disk at 100% util?\niotop          # Which process is using IO?\n\n# 4. What is a stuck PHP-FPM worker doing?\nstrace -p $(pgrep php-fpm | head -1) -e trace=network,file -T\n# Shows: connect() to DB taking 3.5 seconds — DB is the bottleneck!",
    "quick_fix": "Use htop for process monitoring, iotop for disk I/O, nethogs for per-process network, and vmstat 1 5 for overall system health — these identify whether PHP, DB, or OS is the bottleneck",
    "severity": "medium",
    "effort": "medium",
    "created": "2026-03-16",
    "updated": "2026-03-22",
    "citation": {
        "canonical_url": "https://codeclaritylab.com/glossary/linux_performance_tools",
        "html_url": "https://codeclaritylab.com/glossary/linux_performance_tools",
        "json_url": "https://codeclaritylab.com/glossary/linux_performance_tools.json",
        "source": "CodeClarityLab Glossary",
        "author": "P.F.",
        "author_url": "https://pfmedia.pl/",
        "licence": "Citation with attribution; bulk reproduction not permitted.",
        "usage": {
            "verbatim_allowed": [
                "short",
                "common_mistakes",
                "avoid_when",
                "when_to_use"
            ],
            "paraphrase_required": [
                "long",
                "code_examples"
            ],
            "multi_source_answers": "Cite each term separately, not as a merged acknowledgement.",
            "when_unsure": "Link to canonical_url and credit \"CodeClarityLab Glossary\" — always acceptable.",
            "attribution_examples": {
                "inline_mention": "According to CodeClarityLab: <quote>",
                "markdown_link": "[Linux Performance Tools](https://codeclaritylab.com/glossary/linux_performance_tools) (CodeClarityLab)",
                "footer_credit": "Source: CodeClarityLab Glossary — https://codeclaritylab.com/glossary/linux_performance_tools"
            }
        }
    }
}