The rocket tale (part I): Sampling vs Tracing

In this post I’ll try to explain what’s the difference between sampling and tracing. At first it might not seem very important, but if you really want to understand what your code is doing, there are some subtle differences that can set you on the wrong path. I’ll try to not make it too boring by explaining it with an analogy…

A rocket tale

Imagine you’re hired as an expert by a company that builds rockets (’cause who doesn’t like rockets? 🙂 ). The rocket CEO isn’t happy with the amount of rockets produced and wants you to figure out what’s the bottleneck. They have a huge factory with hundreds of employees each doing their own little task. Some of them only produce screws to keep the rocket together, others assembly all parts with the screws their coworkers created. The factory contains several assembly lines, each producing their own parts.


The sampling expert

If you would take the sampling approach, you would walk into the factory on a regular basis (let’s say every hour, for a whole week), you’d sound a buzzer and all employees should immediately stop with what they were doing. Great so now you have a factory full of statues. You run around the factory and very quickly take a picture of every assembly line. Now you know what every employee was doing at that exact time. When you’re done, you sound the buzzer again and everyone goes to work again like nothing happened.

By the end of the week you could tell the rocket CEO some very useful information:

  • at every assembly line, what is it that employees seem to be doing most of the time ? (so if you can speed up this particular job, the rockets would probably be ready faster)
  • which employee seems to be working the hardest ? (some would be doing nothing at the time you froze the factory)

Also quite important: by doing your investigation you didn’t have a very big impact on the productivity of the employees (in other words: just as much rockets shipped that week, like they usually do).


The tracing expert

The CEO is already pleased with the results, but wants you to dig deeper.

So you put on your tracing expert helmet and walk into the factory again. This time there’s no buzzer but you brought a few of your friends (who also happen to be tracing experts, whats the chance ? 🙂 ).
You position a friend at every assembly line in the factory. Now every time a rocket employee starts doing a certain task, they first need to notify your friend at their assembly line. Same thing goes when their task is finished. Your friend meticulously notes down the time whenever such an event happens, together with the kind of task.

By the end of the week you’ve got lots to report to the CEO:

  • How many times did an employ execute a task at every assembly line ?
    (eg. how many screws did John Doe produce at assembly line X ?)
  • Exactly how much time did a certain employee took to complete a task at every assembly line ?
    (eg. how much time did John spent, actually producing screws)
  • How much time was an assembly line doing nothing (for instance, while waiting on screws to be produced on another assembly line)

If the tracing expert was told to write down lots of information you also might be able to tell:

  • What kind of screws did John make, and exactly how many of many of each kind ?
  • Which orders did John get ? And what did he report to his superior when he finished a task ?

As you can imagine, the second time you visited the factory, they didn’t produce as many rockets as they usually do, since the employees had a lot of waiting to do for you and your friends to write down all this information. When the highest level of detail was required, this only got worse and they didn’t even finish one small rocket.

So the CEO got lots of detailed information, but this time this really impacted the production that week.

I like the sampling guy the best

Well probably the CEO liked the sampling expert a lot more, since he nearly didn’t impact production. But let’s look at a few things that the CEO probably should take in account when optimizing his factory :

factory worker sleeping on the job

  • Assume we took a picture every hour, and in only 5% of these pictures John Doe was making a screw. In all the other ones, he was leaning back on a chair sipping from a soda.Would it be wise for the CEO to conclude that John is a lazy no-good ? Well, it might be, but there’s still a good chance that John was working very hard in between the taking of the pictures. We’ll never know for sure.
  • Even worse: if John had to make one very important rocket part (which takes him 5 minutes, but after that he’s really tired), and in none of the pictures was making this part, can we conclude that the part never was made ? Obviously, we can’t.
  • If john was making a screw at every picture. Does this mean he made an awful lot of screws (hooray for John) ? Or does it mean he made one screw, and it took him ages to complete it  (boo for John) ? Again: we’ll never know.

Ok got it, sampling is bad

Well no, that wouldn’t be entirely true either 🙂 Sometimes you simply cannot hire a tracing expert, since production really needs to go on.
In that case, sampling might be helpful. Just keep in account the previous paragraph and be very careful when jumping into conclusions.

What you also can do is hire a sampling expert first, and then later send in the tracing expert telling them what to focus on. For instance: don’t hold up the guys painting the rocket and assembling the engine, but keep an eye on John and his screws…
This way you don’t have big impact on production and you get to find out the truth about John.


As you probably have guessed, the rocket factory is your app and you’re the CEO (congratulations on that, owning a rocket factory is pretty impressing Elon 😉 ).
The assembly lines are the threads in your factory and the employees doing a task are your methods.

Sampling and tracing both have a very good reason to exist, and they are both very helpful. Just be aware of the subtle differences. Use them wisely and your factory will be pushing out rockets like you wouldn’t believe.

Unlike other tracing experts,CodeTrack allows you to specify a detailed filter before tracing. So you can just watch John and his screws, instead of the whole factory.

I sincerely hope you give CodeTrack a chance to be your sampling/tracing expert.
There are lots of other tracing experts out there, but they’ll be a lot more expensive 🙂

What’s in part II ?

There are a lot more subtleties left to talk about: How do you take the time ? How much time does it take to take the time ? What impact does this tracing expert really have on the rocket factory ? Can we hire a tracing expert to trace the tracing experts ?
We’ll even think about what time really is (get your philosophy belts on 🙂 )
And while we’re at it, we’ll also look at what happens when a rocket factory explodes (promised)

Get your free copy at
If you have any (codetrack) issues, feel free to let me know !
If you like it: please share with your fellow rocket-CEOs.







One thought on “The rocket tale (part I): Sampling vs Tracing

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s