1<?php
2/**
3 * Measures the execution time of a block in a template and reports the result
4 * to the log.
5 *
6 * Copyright 2007-2008 Maintainable Software, LLC
7 * Copyright 2006-2016 Horde LLC (http://www.horde.org/)
8 *
9 * @author     Mike Naberezny <mike@maintainable.com>
10 * @author     Derek DeVries <derek@maintainable.com>
11 * @author     Chuck Hagenbuch <chuck@horde.org>
12 * @license    http://www.horde.org/licenses/bsd
13 * @category   Horde
14 * @package    View
15 * @subpackage Helper
16 */
17
18/**
19 * Measures the execution time of a block in a template and reports the result
20 * to the log.
21 *
22 * Example:
23 *
24 * <code>
25 * <?php $bench = $this->benchmark('Notes section') ?>
26 * <?php echo $this->expensiveNotesOperation() ?>
27 * <?php $bench->end() ?>
28 * </code>
29 *
30 * Will add something like "Notes section (0.34523)" to the log.
31 *
32 * You may give an optional logger level as the second argument ('debug',
33 * 'info', 'warn', 'error').  The default is 'info'.  The level may also be
34 * given as a Horde_Log::* constant.
35 *
36 * @author     Mike Naberezny <mike@maintainable.com>
37 * @author     Derek DeVries <derek@maintainable.com>
38 * @author     Chuck Hagenbuch <chuck@horde.org>
39 * @license    http://www.horde.org/licenses/bsd
40 * @category   Horde
41 * @package    View
42 * @subpackage Helper
43 */
44class Horde_View_Helper_Benchmark extends Horde_View_Helper_Base
45{
46    /**
47     * Starts a new benchmark.
48     *
49     * @param string $message        Message to log after the benchmark has
50     *                               ended.
51     * @param string|integer $level  Log level to log after the benchmark has
52     *                               ended.
53     *
54     * @return Horde_View_Helper_Benchmark_Timer  A benchmark timer object.
55     */
56    public function benchmark($message = 'Benchmarking', $level = 'info')
57    {
58        return new Horde_View_Helper_Benchmark_Timer($message, $level,
59                                                     $this->_view->logger);
60    }
61}
62