Using the profiler in the application (definition of custom blocks and messages)

To use the profiler, you developers can use the Jet\Debug_Profiler facade. Thus, you don't need to create any instances and such. Just use a couple of static methods of this class - it's as simple, even primitive, as possible.

Starting and stopping a run block

For the sake of clarity, recall that Profiler allows you to "chunk" an application into blocks and observe its behavior along those blocks. Blocks are nested hierarchically, so there can be other blocks inside a block, with the parent block always including runtime information in all child blocks. You only need to tell it to start (open) the block and then close (close) it.

Suppose you suspect that your application is being held back by, for example, communication with a third-party system. You can put such a place in a block and then see if your theory is true. To do this:

Debug_Profiler::blockStart('My block - problem with something'); 

//... something ... 

Debug_Profiler::blockEnd('My block - problem with something');

And that's it ... You will then see information about the block in the profiler output.

Let's get some more information on this:

  • You can name the blocks whatever you want. On the other hand, it is desirable that the naming is somehow telling (which the above example is not :-D - sorry ... ).
  • It is absolutely necessary that the name is the same both at the beginning and at the end of the block.
  • Block labeling can be present in the application even when Profiler is inactive. Nothing will happen, it just won't do anything. Only a small overhead to call the method will remain.

Messages and debugging information

To evaluate a situation you sometimes need more information, to keep the state of some values and so on. This can be handled very easily as follows:

Debug_Profiler::message('It seems to be good...'); 
Debug_Profiler::message('Value of $var = '$var);

And you can see the information again at the given run block in the output.

And that's it ...

For normal profiler use, that's really it - there's nothing more complicated than that.

But you can see how the Profiler works in depth.

Previous chapter
Profiler output
Next chapter
How the profiler works (in depth)