Ellis Michael

Understanding Traces

18 Feb 2019

For DSLabs, one of the pieces I built was a post-processing phase that runs on traces generated by the model checker. It takes a trace (i.e., a list of events) and produces a semantically equivalent trace which is, hopefully, more understandable to humans.

To motivate the problem, lets look at an example. Suppose we have a distributed system with four processes — , , , and , and consider the events represented by the following space-time diagram:

Because there are concurrent events (i.e., events not ordered by the happens-before relation) in the above execution, there is more than way to represent these events as a well-formed trace.1 Here, a well-formed trace is one in which the happens-before relation is respected by the ordering of events. However, not all traces are created equal. Without knowing the specifics of the protocol being run in this execution, I think most people, if asked to produce a trace, would write something like this:

  • sends to
  • receives , sends to
  • receives , sends to
  • receives
  • sends to
  • receives , sends to
  • receives , sends to
  • receives

They might, instead, pair up and , and , and and . But they certainly wouldn’t write down the following:

  • sends to
  • sends to
  • receives , sends to
  • receives , sends to
  • receives , sends to
  • receives
  • receives , sends to
  • receives

Not just that, but the latter trace is also harder to follow as a reader. It has several unnecessary “context switches.” The DSLabs model checker, however, does not distinguish between these two traces; they both have the same length. If an invariant was violated upon completion of the execution in question, the concurrent events in the trace produced by the model checker would be randomly ordered.

The post-processing phase I implemented is based on a simple idea, that events in traces should be followed by their immediate consequences. First, I took the trace produced by the model checker and built up the associated event graph. The event graph looks just like the space-time diagram above. Vertices are events; edges go between corresponding send and receive events and between subsequent events at the same process.

Then, I ran a depth-first topological sort of the event graph. By topologically sorting the graph, we get a well-formed trace. By doing it in a depth-first manner, we list events and their immediate consequences whenever possible.

To see what this looks like in practice, let’s look at an example from the primary-backup lab. First, we show an animated trace demonstrating an invariant-violation in a buggy solution.

Next, let’s see what the same invariant-violation looks with the post-processing phase for understandability.

Of course, you can’t necessarily follow what’s going on without knowing the details of the protocol. But, it should be much easier to follow the “flow” of the second video.

There are many possibilities for further improvement. You could bias the sorting of events towards message delivery or towards staying with the same process. You could even try to recognize group communication patterns (e.g., the “one→all→one” pattern) and order them in particular ways. For now, though, I think this solution works quite well.

  1. In fact, there are 20 such traces.