Author: Raymond Bosman
Date: 2006-01-13 10:07:29 +0100 (Fri, 13 Jan 2006)
New Revision: 1810
Log:
#- Updated doc
#- Moved parts to its own structure.
Added:
packages/Debug/trunk/src/structs/switch_timer.php
packages/Debug/trunk/src/structs/timer.php
Modified:
packages/Debug/trunk/ChangeLog
packages/Debug/trunk/review.txt
packages/Debug/trunk/src/debug.php
packages/Debug/trunk/src/debug_autoload.php
packages/Debug/trunk/src/debug_timer.php
packages/Debug/trunk/tests/debug_test.php
packages/Debug/trunk/tests/debug_timer_test.php
packages/Debug/trunk/tests/formatters/html_formatter_test.php
Modified: packages/Debug/trunk/ChangeLog
===================================================================
--- packages/Debug/trunk/ChangeLog 2006-01-13 09:04:47 UTC (rev 1809)
+++ packages/Debug/trunk/ChangeLog 2006-01-13 09:07:29 UTC (rev 1810)
@@ -1,3 +1,11 @@
+1.0rc1 - [RELEASEDATE]
+
+ezcDebug
+========
+
+- Removed the source parameter from the startTimer() method.
+
+
1.0beta2 - Thursday 22 December 2005
- Renamed the class ezcDebugReporter to ezcDebugOutputFormatter.
Modified: packages/Debug/trunk/review.txt
===================================================================
--- packages/Debug/trunk/review.txt 2006-01-13 09:04:47 UTC (rev 1809)
+++ packages/Debug/trunk/review.txt 2006-01-13 09:07:29 UTC (rev 1810)
@@ -8,11 +8,11 @@
ezcDebug::startTimer - what are you supposed to use source and group for?
-ezcDebug::switchTimer - Needs an example. How is this supposed to be used.
+[done] ezcDebug::switchTimer - Needs an example. How is this supposed to be
used.
ezcDebug::stopTimer - what happens if you call this with a null paramter and
several timers are running?
ezcDebugTimer::switchTimer - same as above, I think we should use exceptions
here....
-ezcDebugTimer::getStructure - renama to e.g getTimeData.
+[done] ezcDebugTimer::getStructure - rename to e.g getTimeData.
[done] ezcDebugReporter - I'd rename this class as I expect a reporter to
retrieve information as well. What about ezcDebugOutputFormatter. I'd also
rename getOutput to generateOutput.
ezcDebugReporter - Format of $writerData?
Modified: packages/Debug/trunk/src/debug.php
===================================================================
--- packages/Debug/trunk/src/debug.php 2006-01-13 09:04:47 UTC (rev 1809)
+++ packages/Debug/trunk/src/debug.php 2006-01-13 09:07:29 UTC (rev 1810)
@@ -30,22 +30,40 @@
* </code>
*
* The second parameter of the log method is the verbosity. This is a number
that
- * specifies the importance of the log message. This makes it easier to sort
out less important
- * messages. In this example, we assumed the more important the message, the
lower the
+ * specifies the importance of the log message. That makes it easier to sort
out messages of less importance.
+ * In this example, we assumed the more important the message, the lower the
* verbosity number.
*
- * An example of using timers:
+ * The ezcDebug timer is designed to allow the next two timing methods:
+ * - Timers, the time between two points in the program.
+ * - Accumulators, gets the relative time after the script started.
+ *
+ * The "Timers" are simply set with the methods [EMAIL PROTECTED]
startTimer()} and [EMAIL PROTECTED] stopTimer()}. The next example
+ * demonstrates the timing of a simple calculation:
* <code>
* $debug = ezcDebug::getInstance();
- * $debug->startTimer( "Loading template headers", "Paynet", "template_timers"
);
+ * $debug->startTimer( "Simple calculation" );
+ *
+ * //Simple calculation
+ * $result = 4 + 6;
+ *
+ * $debug->stopTimer( "Simple calculation" ); // Parameter can be omitted.
+ * </code>
+ *
+ * To get timing points, accumulators, use the [EMAIL PROTECTED]
switchTimer()} method. This is shown in the next example:
+ * <code>
+ * $debug = ezcDebug::getInstance();
+ * $debug->startTimer( "My script" );
* // ...
- * $debug->stopTimer( "Loading template headers" );
+ * $debug->switchTimer( "Reading ini file" );
+ * // ...
+ * $debug->switchTimer( "Initializing template parser" );
+ * // ...
+ * $debug->switchTimer( "Parsing" );
+ * // ...
+ * $debug->stopTimer();
* </code>
*
- * The timer will be stored in the group: "template_timers" gets the name
"Loading template headers".
- *
- * TODO More documentation needed.
- *
* @package Debug
* @version //autogentag//
*/
@@ -117,12 +135,38 @@
$filter = new ezcLogFilter();
$filter->severity = ezcLog::DEBUG;
- $this->log->map( $filter, $this->writer );
+ $this->log->getMapper()->appendRule( new ezcLogFilterRule( $filter,
$this->writer, true ) );
$this->reset();
}
/**
+ * Throws always an [EMAIL PROTECTED] ezcBasePropertyNotFoundException}.
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * @param string $name
+ * @return mixed
+ */
+ public function __get( $name )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+ /**
+ * Throws always an [EMAIL PROTECTED] ezcBasePropertyNotFoundException}.
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * @param string $name
+ * @param string $value
+ * @return mixed
+ */
+ public function __set( $name, $value )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+
+ /**
* Resets the log messages and timer information.
*
* @return void
@@ -154,7 +198,7 @@
/**
* Sets the formatter $reporter for the output.
*
- * If no formatter is set ezcDebugHtmlReporter will be used by default.
+ * If no formatter is set [EMAIL PROTECTED] ezcDebugHtmlReporter} will be
used by default.
*
* @param ezcDebugReporter $reporter
* @return void
@@ -174,7 +218,7 @@
if ( is_null( $this->formatter ) )
$this->formatter = new ezcDebugHtmlFormatter();
- return $this->formatter->generateOutput(
$this->writer->getStructure(), $this->timer->getStructure() );
+ return $this->formatter->generateOutput(
$this->writer->getStructure(), $this->timer->getTimeData() );
}
@@ -188,9 +232,9 @@
* @param string group
* @return void
*/
- public function startTimer( $name, $source, $group )
+ public function startTimer( $name, $group = null )
{
- $this->timer->startTimer( $name, $source, $group );
+ $this->timer->startTimer( $name, $group );
}
/**
@@ -209,7 +253,7 @@
/**
* Stops the timer identified by $name.
*
- * $name can be ommited if only one timer is running.
+ * $name can be omitted if only one timer is running.
*
* @param $name
* @return void
Modified: packages/Debug/trunk/src/debug_autoload.php
===================================================================
--- packages/Debug/trunk/src/debug_autoload.php 2006-01-13 09:04:47 UTC (rev
1809)
+++ packages/Debug/trunk/src/debug_autoload.php 2006-01-13 09:07:29 UTC (rev
1810)
@@ -17,6 +17,9 @@
'ezcDebugOutputFormatter' => 'Debug/interfaces/formatter.php',
'ezcDebugHtmlFormatter' => 'Debug/formatters/html_formatter.php',
+ 'ezcDebugTimerStruct' => 'Debug/structs/timer.php',
+ 'ezcDebugSwitchTimerStruct' => 'Debug/structs/switch_timer.php',
+
'ezcDebugMessage' => 'Debug/debug_message.php'
);
Modified: packages/Debug/trunk/src/debug_timer.php
===================================================================
--- packages/Debug/trunk/src/debug_timer.php 2006-01-13 09:04:47 UTC (rev
1809)
+++ packages/Debug/trunk/src/debug_timer.php 2006-01-13 09:07:29 UTC (rev
1810)
@@ -30,7 +30,7 @@
private $timers;
/**
- * Similar to $timers but stores timers that are currently running.
+ * Similar to [EMAIL PROTECTED] $timers} but stores those that are
currently running.
*
* @var array(string=>ezcDebugStructure)
*/
@@ -44,6 +44,13 @@
private $totalRunningTimers;
/**
+ * The submitted timer number.
+ *
+ * @var int
+ */
+ private $number = 0;
+
+ /**
* Constructs a timer object with no timers.
*/
public function __construct()
@@ -52,6 +59,32 @@
}
/**
+ * Throws always an [EMAIL PROTECTED] ezcBasePropertyNotFoundException}.
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * @param string $name
+ * @return mixed
+ */
+ public function __get( $name )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+ /**
+ * Throws always an [EMAIL PROTECTED] ezcBasePropertyNotFoundException}.
+ *
+ * @throws ezcBasePropertyNotFoundException
+ * @param string $name
+ * @param string $value
+ * @return mixed
+ */
+ public function __set( $name, $value )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+
+ /**
* Resets the timer object to its initial state with no timers.
*
* @return void
@@ -64,24 +97,22 @@
}
/**
- * Starts the timer identified by $name with the source $source and group
$group and returns true on success.
+ * Starts the timer identified by $name with the group $group and returns
true on success.
*
* If the timer was already started false is returned.
*
* @param string $name
- * @param string $source
* @param string $group
* @return bool
*/
- public function startTimer( $name, $source, $group )
+ public function startTimer( $name, $group )
{
if ( !isset( $this->runningTimers[ $name ] ) )
{
$this->totalRunningTimers++;
- $this->runningTimers[$name] = new ezcDebugStructure();
+ $this->runningTimers[$name] = new ezcDebugTimerStruct();
$this->runningTimers[$name]->name = $name;
- $this->runningTimers[$name]->source = $source;
$this->runningTimers[$name]->group = $group;
$this->runningTimers[$name]->switchTime = array();
$this->runningTimers[$name]->startTime = microtime( true );
@@ -96,7 +127,7 @@
/**
* Stops the timer $oldName and starts the timer $newName and return true
on success.
*
- * If the timer $oldName does not exist or if it was ommited with several
timers running
+ * If the timer $oldName does not exist or if it was omitted with several
timers running
* false is returned.
*
* @param string $newName
@@ -123,7 +154,7 @@
$this->runningTimers[$newName] = $this->runningTimers[$oldName];
unset( $this->runningTimers[$oldName] );
- $switchStruct = new ezcDebugStructure();
+ $switchStruct = new ezcDebugSwitchTimerStruct();
$switchStruct->name = $newName;
$switchStruct->time = microtime( true );
@@ -134,7 +165,7 @@
/**
* Stop the timer identified by $name and return true on success.
*
- * If the timer $oldName does not exist or if it was ommited with several
timers running
+ * If the timer $oldName does not exist or if it was omitted with several
timers running
* false is returned.
*
* @param $name
@@ -168,7 +199,7 @@
*
* @return array(ezcDebugStructure)
*/
- public function getStructure()
+ public function getTimeData()
{
/*
$result = new ezcDebugStructure();
@@ -181,7 +212,7 @@
}
/**
- * Returns time used per group.
+ * Returns the time used per group.
*
* The time is returned as an array in the format
* array( 'groupName' => array( number of ms ) )
Added: packages/Debug/trunk/src/structs/switch_timer.php
===================================================================
--- packages/Debug/trunk/src/structs/switch_timer.php 2006-01-13 09:04:47 UTC
(rev 1809)
+++ packages/Debug/trunk/src/structs/switch_timer.php 2006-01-13 09:07:29 UTC
(rev 1810)
@@ -0,0 +1,60 @@
+<?php
+
+/**
+ * File containing the ezcDebugSwitchTimerStruct.
+ *
+ * @package Debug
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @access private
+ */
+
+/**
+ *
+ *
+ * @package Debug
+ * @version //autogentag//
+ * @access private
+ */
+class ezcDebugSwitchTimerStruct
+{
+ /**
+ * The name of the timer took over the old timer.
+ *
+ * @var string
+ */
+ public $name;
+
+ /**
+ * The current time.
+ *
+ * @var float
+ */
+ public $time;
+
+ /**
+ * Empty constructor
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Throws a BasePropertyNotFound exception.
+ */
+ public function __set( $name, $value )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+ /**
+ * Throws a BasePropertyNotFound exception.
+ */
+ public function __get( $name )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+}
+
+?>
Property changes on: packages/Debug/trunk/src/structs/switch_timer.php
___________________________________________________________________
Name: svn:eol-style
+ native
Added: packages/Debug/trunk/src/structs/timer.php
===================================================================
--- packages/Debug/trunk/src/structs/timer.php 2006-01-13 09:04:47 UTC (rev
1809)
+++ packages/Debug/trunk/src/structs/timer.php 2006-01-13 09:07:29 UTC (rev
1810)
@@ -0,0 +1,115 @@
+<?php
+
+/**
+ * File containing the ezcDebugTimerStruct.
+ *
+ * @package Debug
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @access private
+ */
+
+/**
+ *
+ * The ezcDebugTimerStruct structure keeps track of the timing data.
+ *
+ * @package Debug
+ * @version //autogentag//
+ * @access private
+ */
+class ezcDebugTimerStruct
+{
+ /**
+ * The name of the timer.
+ *
+ * The name has two purposes:
+ * - The (unique) identifier of the running timer.
+ * - The description of the timer in the timer summary.
+ *
+ * @var string
+ */
+ public $name;
+
+ /**
+ * The source of the timer.
+ *
+ * @var string
+ */
+ public $source;
+
+ /**
+ * The group of the timer.
+ *
+ * @var string
+ */
+ public $group;
+
+ /**
+ * An array that contains the switchTimer structures.
+ *
+ * @var array(ezcDebugSwitchTimerStruct)
+ */
+ public $switchTime;
+
+ /**
+ * The start time in miliseconds.
+ *
+ * @var float
+ */
+ public $startTime;
+
+ /**
+ * The stop time in miliseconds.
+ *
+ * @var float
+ */
+ public $stopTime;
+
+ /**
+ * The time that elapsed between the startTimer and the stopTimer.
+ *
+ * @var float
+ */
+ public $elapsedTime;
+
+ /**
+ * The number of the timer that started.
+ *
+ * @var int
+ */
+ public $startNumber;
+
+ /**
+ * The number of the timer that stopped.
+ *
+ * @var int
+ */
+ public $stopNumber;
+
+
+ /**
+ * Empty constructor
+ */
+ public function __construct()
+ {
+ }
+
+ /**
+ * Throws a BasePropertyNotFound exception.
+ */
+ public function __set( $name, $value )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+
+ /**
+ * Throws a BasePropertyNotFound exception.
+ */
+ public function __get( $name )
+ {
+ throw new ezcBasePropertyNotFoundException( $name );
+ }
+}
+
+?>
Property changes on: packages/Debug/trunk/src/structs/timer.php
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: packages/Debug/trunk/tests/debug_test.php
===================================================================
--- packages/Debug/trunk/tests/debug_test.php 2006-01-13 09:04:47 UTC (rev
1809)
+++ packages/Debug/trunk/tests/debug_test.php 2006-01-13 09:07:29 UTC (rev
1810)
@@ -61,16 +61,32 @@
public function testTimers()
{
$dbg = $this->dbg;
- $dbg->startTimer("a", "b", "c");
+ $dbg->startTimer("a", "c");
$dbg->stopTimer("a");
$struct = $dbg->generateOutput();
$this->assertEquals(1, count( $struct[1] ) );
$this->assertEquals("a", $struct[1][0]->name );
- $this->assertEquals("b", $struct[1][0]->source );
$this->assertEquals("c", $struct[1][0]->group );
}
+ public function testDefaultTimers()
+ {
+ $dbg = $this->dbg;
+ $dbg->startTimer("a");
+ $dbg->stopTimer("a");
+
+ $struct = $dbg->generateOutput();
+
+/*
+ $this->assertEquals(1, count( $struct[1] ) );
+ $this->assertEquals("a", $struct[1][0]->name );
+ $this->assertEquals("c", $struct[1][0]->group );
+ */
+ }
+
+
+
public function testDefaultSourceAndCategory()
{
$dbg = $this->dbg;
@@ -79,7 +95,6 @@
$struct = $dbg->generateOutput();
$this->assertEquals(1, count( $struct[0] ) );
$this->assertEquals("default", $struct[0][0]->category );
- $this->assertEquals("default", $struct[0][0]->source );
// Changing the default source from the log.
ezcLog::getInstance()->source ="bla";
Modified: packages/Debug/trunk/tests/debug_timer_test.php
===================================================================
--- packages/Debug/trunk/tests/debug_timer_test.php 2006-01-13 09:04:47 UTC
(rev 1809)
+++ packages/Debug/trunk/tests/debug_timer_test.php 2006-01-13 09:07:29 UTC
(rev 1810)
@@ -9,15 +9,14 @@
$timer = new ezcDebugTimer();
$point1 = microtime(true);
- $timer->startTimer("Ray", "Local", "host");
+ $timer->startTimer("Ray", "host");
$point2 = microtime(true);
$timer->stopTimer("Ray");
$point3 = microtime(true);
- $structure = $timer->getStructure();
+ $structure = $timer->getTimeData();
$this->assertEquals(1, count($structure));
$this->assertEquals("Ray", $structure[0]->name);
- $this->assertEquals("Local", $structure[0]->source);
$this->assertEquals("host", $structure[0]->group);
$this->assertTrue( $structure[0]->startTime >= $point1 &&
$structure[0]->startTime <= $point2 );
@@ -32,7 +31,7 @@
$timer->startTimer("Ray", "Local", "host");
$timer->stopTimer();
- $structure = $timer->getStructure();
+ $structure = $timer->getTimeData();
$this->assertEquals(1, count($structure));
}
@@ -41,17 +40,16 @@
$timer = new ezcDebugTimer();
$point1 = microtime(true);
- $timer->startTimer("Ray", "Local", "host");
+ $timer->startTimer("Ray", "host");
$point2 = microtime(true);
$timer->switchTimer("Blaap", "Ray");
$point3 = microtime(true);
$timer->stopTimer("Blaap");
$point4 = microtime(true);
- $structure = $timer->getStructure();
+ $structure = $timer->getTimeData();
$this->assertEquals(1, count($structure));
$this->assertEquals("Ray", $structure[0]->name);
- $this->assertEquals("Local", $structure[0]->source);
$this->assertEquals("host", $structure[0]->group);
$this->assertEquals(1, count( $structure[0]->switchTime));
@@ -70,7 +68,7 @@
$timer->switchTimer("hehe", "Blaap");
$timer->stopTimer("hehe");
- $structure = $timer->getStructure();
+ $structure = $timer->getTimeData();
$this->assertEquals(2, count( $structure[0]->switchTime));
}
@@ -87,7 +85,7 @@
$timer->stopTimer("Ray3");
$timer->stopTimer("Ray");
- $structure = $timer->getStructure();
+ $structure = $timer->getTimeData();
$this->assertEquals(3, count( $structure));
// Expected order?
@@ -98,11 +96,10 @@
public function testComfortableStructure()
{
- $struct = $this->getStructure();
-
+ $struct = $this->getTimeData();
}
- protected function getStructure()
+ protected function getTimeData()
{
$time = new ezcDebugTimer();
$time->startTimer("Script", "html_reporter_test", "script");
@@ -122,7 +119,7 @@
$time->stopTimer("Script");
- return $time->getStructure();
+ return $time->getTimeData();
}
protected function mySQLFunction(&$time)
Modified: packages/Debug/trunk/tests/formatters/html_formatter_test.php
===================================================================
--- packages/Debug/trunk/tests/formatters/html_formatter_test.php
2006-01-13 09:04:47 UTC (rev 1809)
+++ packages/Debug/trunk/tests/formatters/html_formatter_test.php
2006-01-13 09:07:29 UTC (rev 1810)
@@ -76,7 +76,7 @@
$time->stopTimer("Script");
- return $time->getStructure();
+ return $time->getTimeData();
}
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components