Book Image

Symfony2 Essentials

Book Image

Symfony2 Essentials

Overview of this book

Table of Contents (17 chapters)
Symfony2 Essentials
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

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...