ContentsThe library

Reading a Profile Honestly

The Function at Number Seven Received Nine Samples, Which Means You Know Almost Nothing About It

Last timeWatching Sometimes, or Counting Everything

Every share in a sampling profile is an estimate with an uncertainty, and the uncertainty depends on how many samples that line received. One square root tells you which lines to believe.

The share is an estimate

A sampling profile looks like a table of facts. It is a table of estimates, and

each one came from a finite number of observations.

The mechanism makes this obvious once stated. The profiler took three thousand

looks at the program. Each look either found a particular function on the stack

or did not. The share reported for that function is the number of times it was

found divided by three thousand. That is a proportion estimated from a sample,

which is the same object a survey produces, and it carries the same kind of

uncertainty for the same reason.

FIG 1The uncertainty on a share
standard error on the estimated share
the share the profile reports
total samples in the run
Two of these either side of the reported share covers the true value about nineteen times in twenty. For a function at 35 per cent of a three thousand sample run this is plus or minus 1.7 points, so the true share is somewhere between 33 and 37, which for most purposes is the same conclusion. The arithmetic only becomes interesting at the other end of the table.

Computing the uncertainty

The formula above is exact and slightly awkward to apply by eye. There is a

rearrangement that is easier to use and is the one worth carrying around.

For a small share, the relative error on a line is approximately one divided by

the square root of the number of samples that line received. Not the total

samples in the run: the samples on that line.

FIG 2One three thousand sample profile, line by line
samples receivedshare, per centplus or minus, pointsrelative error, per cent
the parser1050.0035.000.872.00
the hash lookup400.0013.300.625.00
the retry path60.002.000.2613.00
the logger9.000.300.1033.00
the configuration read2.000.070.0571.00
The absolute uncertainty falls as you go down the table, which is why the third column looks reassuring. The fourth column is the one that matters. The logger line is 0.3 per cent plus or minus a third of itself, and the configuration line could as easily be twice or half what it says. Nothing below the third row of this profile supports any statement at all.

The practical consequence is a reading habit. Before comparing two lines of a

profile, look at how many samples each received. Two entries at 1.1 and 0.9 per

cent in a three thousand sample run received about 33 and 27 samples, with a

relative error near twenty per cent each, so they are indistinguishable and the

order they appear in is an accident of this particular run.

The lesson stops here

2 more paragraphs to go

You have read the opening. The rest of the argument, the problems that check whether it landed, and the lines worth keeping at the end all come with a plan.

The first lesson of every course in the library reads the whole way through, free, so you can see exactly what the rest of them are.

See the planThe contents

This is the reading half

Starting the course gives you your own copy of it. Every idea on every page has problems standing under it, marked with a reason rather than a tick, and any sentence you do not believe can be opened and argued with. None of that can happen on a page nobody owns.

The contents

The rest of this course

  1. 01It Is Slow Is Not a Measurement, and Profiling Before You Have One Wastes the Week
  2. 02One Profiler Interrupts a Thousand Times a Second and Guesses, the Other Watches Every Call and Changes the Answeropening only
  3. 03The Function at Number Seven Received Nine Samples, Which Means You Know Almost Nothing About Ityou are here
  4. 04The Function Holding Ninety Per Cent of the Time Does Nothing, and the One Doing the Work Holds Four Per Centopening only
  5. 05The Same Function Is Cheap in Two Places and Ruinous in the Third, and the Flat List Shows One Numberopening only
  6. 06Three and a Half of the Four Seconds Are Invisible, Because the Profiler Only Looks When the Program Is Runningopening only
  7. 07The Sample Landed Three Instructions After the One That Was Slow, and the Function It Blames Does Not Exist Any Moreopening only
  8. 08The New Version Is Eight Per Cent Faster, and So Is the Old One If You Run It Enough Timesopening only

Read alongside