Cover by Francesco Cesarini, Simon Thompson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

O'Reilly logo

Match Specifications: The fun Syntax

We introduced the powerful (but ugly) match specifications in Chapter 10. As you might recall, a match specification consists of an Erlang term describing a small program that expresses a condition to be matched over a set of arguments. Match specifications are limited in functionality, and in the case of the trace BIFs, they mainly deal with the filtering and manipulation of trace events. If they match successfully, a trace event is generated and some predefined actions can be executed. Match specifications are compiled to a format close to the one used by the emulator, making them more efficient than functions. But apart from being more efficient, the specifications are complex to write, and at first glance, they look incomprehensible.

Luckily, you can generate match specifications covering a majority of simple but useful cases using the dbg:fun2ms/1 call. It converts specifications that are described using fun syntax into match specifications. The results are as efficient as writing the match specifications by hand, but they are much easier to read, write, modify, and debug. We are using dbg:fun2ms/1 to turn an anonymous fun into a match specification, which is used when setting trace flags on local and global calls. We start by introducing this higher-level approach, but for those who need to harness the full power of the trace BIFs, we follow this by looking at the match specifications themselves.

Generating Specifications Using fun2ms

Remember ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required