223 lines
7.0 KiB
HTML
223 lines
7.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; style-src 'self'; font-src 'self' data:; img-src 'self' data:; connect-src 'self'; base-uri 'self'; form-action 'self' https://defcon.social https://bsky.app;">
|
|
<meta http-equiv="X-Content-Type-Options" content="nosniff">
|
|
<link rel="stylesheet" href="../assets/css/style.css">
|
|
<link rel="icon" type="image/x-icon" href="../favicon.ico">
|
|
<script>
|
|
// Apply theme immediately to prevent flash
|
|
(function() {
|
|
const theme = localStorage.getItem('theme') ||
|
|
(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
|
|
document.documentElement.setAttribute('data-theme', theme);
|
|
})();
|
|
</script>
|
|
<title>perf Cheatsheet - Cheatsheets - Launch Pad</title>
|
|
</head>
|
|
<body>
|
|
<button class="theme-toggle" id="themeToggle" aria-label="Toggle dark mode">
|
|
<svg class="theme-icon theme-icon-moon" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"></path></svg>
|
|
<svg class="theme-icon theme-icon-sun" xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="display: none;"><circle cx="12" cy="12" r="5"></circle><line x1="12" y1="1" x2="12" y2="3"></line><line x1="12" y1="21" x2="12" y2="23"></line><line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line><line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line><line x1="1" y1="12" x2="3" y2="12"></line><line x1="21" y1="12" x2="23" y2="12"></line><line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line><line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line></svg>
|
|
</button>
|
|
<br/><br/>
|
|
<div class="name">
|
|
__ _______________________ _________._________________________
|
|
\_ _____/ \______ \ / _ \ / _____/ / _____/ | | \_ _____/
|
|
| __) | _/ / /_\ \ / \ ___ / \ ___ | | | __)_
|
|
| \ | | \ / | \ \ \_\ \ \ \_\ \ | |___ | \
|
|
\___ / |____|_ / \____|__ / \______ / \______ / |_______ \ /_______ /
|
|
\/ \/ \/ \/ \/ \/ \/
|
|
</div>
|
|
<div class="blog-page-header">
|
|
<div class="blog-header-content">
|
|
<a href="/cheatsheets" class="back-link" title="Back to Cheatsheets">
|
|
<svg xmlns="http://www.w3.org/2000/svg" width="42" height="42" viewBox="0 0 24 24" class="home-icon"><path fill="currentColor" d="M10 20v-6h4v6h5v-8h3L12 3 2 12h3v8z"/></svg>
|
|
</a>
|
|
<h1 class="blog-page-title">perf Cheatsheet</h1>
|
|
</div>
|
|
</div>
|
|
<div class="blog-post-container">
|
|
<div class="blog-posts-container" style="max-width: 900px; margin: 0 auto;">
|
|
<div class="blog-post">
|
|
<div class="blog-post-content">
|
|
<p><a href="index.html">← Back to cheatsheets</a></p>
|
|
<p><a href="../index.html">← Home</a></p>
|
|
<hr>
|
|
<p>perf is a performance analysis tool for Linux. Provides profiling, tracing, and performance monitoring capabilities using hardware performance counters and kernel tracing.</p>
|
|
<hr>
|
|
<h2>Basic Usage</h2>
|
|
<ul>
|
|
<li>perf stat command - Count events</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record command - Record performance data</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report - Analyze recorded data</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top - Real-time profiling</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf list - List available events</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>perf stat</h2>
|
|
<ul>
|
|
<li>perf stat command - Count events for command</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf stat -a - System-wide statistics</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf stat -e event - Count specific event</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf stat -p PID - Attach to process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf stat -r N - Run N times and average</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf stat -d - Detailed statistics</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf stat -I interval - Interval output</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>perf record</h2>
|
|
<ul>
|
|
<li>perf record command - Record command execution</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -a - System-wide recording</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -p PID - Record process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -g - Record call graphs</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -e event - Record specific event</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -F freq - Sampling frequency</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -o file - Output file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf record -s - Per-thread statistics</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>perf report</h2>
|
|
<ul>
|
|
<li>perf report - Analyze perf.data</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report -i file - Input file</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report -g - Show call graph</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report -s symbol - Sort by symbol</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report -n - Show overhead</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report --stdio - Text output</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf report --tui - TUI interface</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>perf top</h2>
|
|
<ul>
|
|
<li>perf top - Real-time profiling</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top -a - System-wide</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top -p PID - Specific process</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top -e event - Specific event</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top -g - Show call graph</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top -K - Hide kernel symbols</li>
|
|
</ul>
|
|
<ul>
|
|
<li>perf top -U - Hide user symbols</li>
|
|
</ul>
|
|
<hr>
|
|
<h2>Common Examples</h2>
|
|
<h3>Count Events</h3>
|
|
<pre><code>perf stat ls</code></pre>
|
|
<p>Count performance events for command.</p>
|
|
<h3>System-Wide Stats</h3>
|
|
<pre><code>perf stat -a sleep 5</code></pre>
|
|
<p>System-wide statistics.</p>
|
|
<h3>Record Performance</h3>
|
|
<pre><code>perf record -g ./program</code></pre>
|
|
<p>Record with call graph.</p>
|
|
<h3>Real-Time Profiling</h3>
|
|
<pre><code>perf top</code></pre>
|
|
<p>Interactive performance monitor.</p>
|
|
<h3>List Events</h3>
|
|
<pre><code>perf list</code></pre>
|
|
<p>Show available events.</p>
|
|
<h3>Analyze Recorded Data</h3>
|
|
<pre><code>perf report</code></pre>
|
|
<p>View performance report.</p>
|
|
<h3>Record Process</h3>
|
|
<pre><code>perf record -p 1234</code></pre>
|
|
<p>Record specific process.</p>
|
|
<h3>Specific Event</h3>
|
|
<pre><code>perf stat -e cache-misses command</code></pre>
|
|
<p>Count cache misses.</p>
|
|
<hr>
|
|
<h2>Tips</h2>
|
|
<ul>
|
|
<li>Use perf stat for quick measurements</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use perf record for detailed analysis</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use -g for call graph analysis</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Use perf top for real-time monitoring</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Check perf list for available events</li>
|
|
</ul>
|
|
<ul>
|
|
<li>May require root for system-wide profiling</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Essential for performance optimization</li>
|
|
</ul>
|
|
<ul>
|
|
<li>Powerful tool for kernel and application profiling</li>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<script async type="text/javascript" src="../blog/analytics.js"></script>
|
|
<script src="../theme.js"></script>
|
|
</body>
|
|
</html>
|
|
|