scenario 5: fix perf annotate command

This commit is contained in:
illustris 2026-01-11 07:37:09 +05:30
parent 51ab2ed553
commit 4f680b6a2d
Signed by: illustris
GPG Key ID: 56C8FC0B899FEFA3

View File

@ -72,22 +72,35 @@ With debug symbols, you can see exactly which lines are hot:
```bash ```bash
perf record ./withdebug 500 5000 perf record ./withdebug 500 5000
perf annotate compute_inner perf annotate --stdio -l compute_inner
``` ```
This shows the source code with cycle counts per line! The `-l` flag shows a summary of hot source lines at the top:
``` ```
│ double compute_inner(double x, int iterations) { Sorted summary for file .../withdebug
│ double result = x; ----------------------------------------------
1.23 │ for (int i = 0; i < iterations; i++) { 72.75 program.c:29
45.67 │ result = sin(result) * cos(result) + sqrt(fabs(result)); 27.25 program.c:28
23.45 │ result = result * 1.0001 + 0.0001;
│ }
│ return result;
│ }
``` ```
This tells you line 29 (`result = result * 1.0001 + 0.0001`) consumed ~73% of cycles!
Below the summary, you see interleaved source and assembly:
```
Percent | Source code & Disassembly of withdebug
--------------------------------------------------
: 9 double compute_inner(double x, int iterations) {
: 10 double result = x;
27.25 : 130f: addsd %xmm0,%xmm1 // program.c:28
27.67 : 1313: mulsd ... // program.c:29
```
**Note on line numbers**: The left margin (9, 10, etc.) shows objdump output
line numbers, NOT source file lines. The actual source lines are shown in the
summary and in `// program.c:XX` comments on assembly lines.
## Exercise 5: Understanding Symbol Tables ## Exercise 5: Understanding Symbol Tables
```bash ```bash