Profile all the things

By Fabien Potencier, on Dec 17, 2014

Since day one, our main goal with Blackfire has been to ease profiling web applications as much as possible. Developers should profile their applications more than they are doing; and when they do, it pays off big-time:

But nowadays, web applications are not just about web pages in a browser anymore; most web applications also expose APIs or web services and they come with CLI scripts. And today, I’m very excited to announce a new utility to ease profiling this non-browsable code.

Before trying the following examples, upgrade the Blackfire packages to the latest versions we’ve released earlier today.

Profiling CLI Scripts

Profiling a CLI script is now as easy as it can get:

That’s right, just prefix your command with blackfire run and you’re good to go! By default, it asks for the slot you want the profile to be stored in and displays the URL where you can view the profile at the end of the execution. You can also make the command non-interactive and quiet:

Read the Profile CLI scripts documentation for more information.

Profiling APIs and Web Services

One of the most frequently asked features so far for Blackfire is the ability to profile web services and API calls. If you are already using cURL to test your calls, profiling them is again very easy:

Prefix your cURL command with blackfire and profiling will be automatically activated. You can also make everything quiet and non-interactive:

If you want to use wget, the excellent HTTPie utility, or your own script, read the Profile API /Web Services calls documentation as it explains how everything works behind the scenes.

Profiling Web Pages from the CLI

As you might have guessed already, you can use the blackfire curl command to profile your regular web pages as well… and that’s the first step towards automation, but that’s for another day!

Let me finish with a great tip: modern browsers have a “copy as cURL” feature that comes in very handy for more “complex” web pages like POST request on a form:

Happy profiling!

Fabien Potencier

Fabien Potencier is the CEO and founder of Blackfire.io. He founded the Symfony project in 2004 as he constantly looked for better ways to build websites. Fabien is also the creator of several other Open-Source projects, a writer, a blogger, a speaker at international conferences, and the happy father of two wonderful kids.