Four Seconds of Wall Clock, Half a Second of Work, and Where the Rest Went
Last timeBeing Interrupted
The system keeps an account of your process whether you ask or not. Here is how to read it, how to attribute a slowdown to the processor, a device or a lock, and what the numbers cannot tell you.
The account that always balances
Run anything under a timer that reports three numbers rather than one and the
shape of the problem is usually visible immediately.
- elapsed time, the wall clock
- time the processor spent executing your code
- time the processor spent in kernel code on your behalf
- time your process was not running at all, which nobody reports directly
Two refinements matter. On a machine with several processors, the first two
terms can exceed the elapsed time, because they are summed across threads: four
seconds elapsed with twelve seconds of charged time means three processors were
busy throughout. And the second term is charged to you for work the kernel did
because you asked, which includes the crossings from the second lesson, so an
unexpectedly large second term is very often a request-count problem.
What the system will tell you
Four instruments, each answering one question well.
The per-process counters give the split above, plus the page fault counts and,
crucially, two switch counts: voluntary, meaning the process gave up the
processor because it blocked, and involuntary, meaning it was preempted. That
pair is the most under-used diagnostic on the machine.
A call trace shows each request the process made, in order, with how long each
took. It answers which device, which file, which address, and it is the fastest
way to find a program making a hundred thousand tiny requests where it could
have made ten.
System-wide utilisation says whether the machine is short of anything, which is
a different question from whether your process is slow, and confusing the two
is the commonest mistake in this area.
And a sampling profiler says where in your own code the charged time went,
which matters only if the first term above was large. A profiler pointed at a
program that is blocked tells you nothing, beautifully.
The lesson stops here
3 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 contentsThis 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