Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Symfony2 Essentials

You're reading from   Symfony2 Essentials

Arrow left icon
Product type Paperback
Published in Sep 2015
Publisher
ISBN-13 9781784398767
Length 158 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Toc

The stopwatch component


Since Symfony 2.2, the stopwatch component has been included in the standard Symfony. It allows you to measure time used in your various code fragments. You can add your own entries to the timeline section of the profile.

Amend the controller code as follows:

        // src/AppBundle/Controller/TaskController
        $watch = $this->get('debug.stopwatch');
        $watch->start('Fetching Tasks');

        $tasks = $em->getRepository('AppBundle:Task')
            ->createQueryBuilder('t')
            ->where('t.finished = :finished')
            ->andWhere('t.user = :user')
            ->orderBy('t.due_date', 'ASC')
            ->setParameter('finished', false)
            ->setParameter('user', $this->getUser())
            ->getQuery()
            ->getResult();

        $watch->stop('Fetching Tasks');

Now, when you refresh and go to your profiler timeline section, you will see the additional fragment with the description of how...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime
Banner background image