perf
Linux-এর standard profiler — PMU hardware counter পড়ে (`perf stat`) বা sampling করে (`perf record`+`perf report`) একটা প্রোগ্রাম আসলে কোথায় সময় ব্যয় করছে তা measure করে, অনুমান না করে।
also: flamegraph, PMU counters, performance monitoring unit
তিনটা মূল subcommand, তিনটা ভিন্ন প্রশ্নের উত্তর:
| Command | প্রশ্ন | Mode |
|---|---|---|
perf stat | সার্বিক IPC, cache-miss %, branch-miss %? | counting — hardware বাড়তে থাকে |
perf record | কোন function-এ সময় যাচ্ছে? | sampling — periodic interrupt |
perf report/flamegraph | সেই hotspot-এর call chain? | সংগৃহীত sample visualize |
PMU (Performance Monitoring Unit) — CPU-র ভেতরে বসানো আসল
সিলিকন, pipeline-এর frontend/backend/retirement স্তরে counter
রাখা। মাত্র 4-8টা general-purpose counter register থাকে প্রতি
core-এ — বেশি event চাইলে kernel সেগুলো multiplex (সময় ভাগ) করে,
সংখ্যা তখন extrapolated estimate হয়ে যায়।
Flamegraph পড়ার নিয়ম: width = sample-এর অনুপাত (সময়), বাম-ডান ক্রম সময়ক্রম বহন করে না (সাধারণত alphabetical), stack depth = call depth, root নিচে।
সবচেয়ে সাধারণ ব্যর্থতা: -O2-এ compile করা binary-তে frame
pointer omit হয়ে যায় বলে call-graph ভেঙে flat দেখায় — সমাধান
gcc -fno-omit-frame-pointer অথবা --call-graph dwarf/lbr।
Symbol resolution /proc/<pid>/maps থেকে আসে; unprivileged access
/proc/sys/kernel/perf_event_paranoid দিয়ে নিয়ন্ত্রিত।
Sampling profiler-এর overhead সাধারণত 1-5% — তাই production-এ
নিরাপদে চালানো যায়, instrumentation profiler (gprof)-এর মতো
২-১০× বিকৃতিকারী না।