4.5.24 · D1Software Engineering

Foundations — Performance profiling — CPU, memory, I - O profiling

2,423 words11 min readBack to topic

Before you can read the parent note, you need to genuinely understand a small pile of words and squiggles it throws at you: fractions like , a speedup , the difference between a stopwatch on the wall and a stopwatch on the brain, a square root that measures uncertainty, and pictures called flame graphs. We build each one from nothing.


0. The most basic picture: a program is a timeline

Everything starts here. Imagine time flowing left to right. A program runs along this line. At each instant it is doing one of: computing, or waiting for something.

Figure — Performance profiling — CPU, memory, I - O profiling

1. Time itself — two different clocks

The parent note's "most important distinction" is between two ways of measuring time. You must feel the difference before any formula.

The picture: look back at figure s01. The full width is . Add up only the black chunks and you get . The red waiting chunk is — exactly the gap between the two.

Recall

If wall time is 10 s but CPU time is 1 s, what was the program doing for 9 s? ::: Waiting — that 9 s is (I/O, a lock, or sleeping); it is I/O-bound.


2. Fractions and percentages — the language of "how much"

Profiling constantly says things like "this function is 75% of the time". A fraction is just a part-of-a-whole written as a number between and .

The picture: cut the timeline bar into slices. is the width of one slice as a fraction of the full bar.

Figure — Performance profiling — CPU, memory, I - O profiling

3. Speedup and factor — measuring "how much faster"

Two closely-named symbols. Keep them straight:

The picture: if the old bar was 100 ms wide and the new bar is 50 ms wide, the new bar is half as long, so .


4. The -free sum you already know: decomposing the whole

Amdahl's derivation writes . This is not scary — it is just "the whole = the part you touch + the part you don't."

The bracket-with-word-underneath notation is just an arrow saying "this chunk means this." Nothing more.


5. The hat and the square root — measuring uncertainty

Sampling profilers do not know the true ; they estimate it by taking random snapshots. Statisticians put a hat on a symbol to mean "our estimate of, not the true value".

Now — why the square root? Because a guess from random samples has wobble, and the amount of wobble is what the square-root formula measures.

Figure — Performance profiling — CPU, memory, I - O profiling
Recall

To halve your sampling error, how many more samples do you need? ::: Four times as many (error falls as ).


6. Self time vs cumulative time — the tree of calls

A program's functions call other functions, forming a tree. Two ways to add up a function's cost:

The picture: a boss (parent function) who delegates. Cumulative = the whole department's hours. Self = only the boss's own hours. A boss who only forwards emails has huge cumulative time but tiny self time.

Figure — Performance profiling — CPU, memory, I - O profiling

7. The flame graph — a picture where width = time

Once self/cumulative time and the call tree click, a flame graph is obvious: stack the call tree as boxes, and make each box's width proportional to time. Wide box = hotspot.

This is the parent note's main visual. Everything you need to read it, you now have: a call tree (§6), and time-as-width (which is just fraction turned into pixels, §2). Deep dive lives in Flame Graphs.


The three resources, named once

The topic splits "slow" into three buckets. You met all three in figure s01 conceptually; here are their names.


How the foundations feed the topic

Timeline of a program

Wall time vs CPU time vs wait time

Fraction p of a chosen whole

Speedup S and factor s

CPU vs Memory vs IO bound

Amdahl decides what to optimize

Hat p and square root error

Sampling profilers

Call tree

Self vs cumulative time

Flame graphs

Performance profiling topic

This map is a preview of the parent topic. If any box confuses you, re-read its section above.


Equipment checklist

Say the answer out loud before revealing. If you miss one, revisit its section.

I can explain wall-clock time in one sentence
The time a clock on the wall measures start-to-finish, including all waiting.
I can explain CPU time and how it differs from wall time
Time the processor was actively working; it excludes waiting, so it can be far less than wall time.
I know what is
The time the program was stuck doing nothing on the CPU — waiting for I/O, a lock, or a sleep; it is the gap .
I can split CPU time into user and sys
— my code vs the OS working for me.
I know what the symbol means, and against what whole
The fraction (0 to 1) of a chosen total a part occupies — wall-clock time for Amdahl, CPU time for a CPU profiler.
I can tell from
= how much faster one part got; = how much faster the whole program got.
I can read notation
A bracket labelling a chunk — here, the fraction of time you did not optimize.
I know what the hat in means
An estimate of built from samples, not the true value.
I know what actually goes into the SE formula in practice
The plug-in estimate — you substitute because the true is unknown.
I know why has a square root of
Random averaging error shrinks like , so 4× the samples halves the error.
I can distinguish self time from cumulative time
Self = a function's own work only; cumulative = self plus all its callees.
I know why flame-graph width means time
Each box's width is drawn proportional to how long that call took.
I can name the three resource buckets
CPU (busy), Memory (holding too much), I/O (waiting).