[Solar-svn] Revision 3172
pmjones at solarphp.com
pmjones at solarphp.com
Thu May 22 09:28:13 CDT 2008
Solar_Sql_Adapter: [REF] Refactor "profile" element addition into its own method, and add a backtrace to the profile elements so you can see what generated the query.
Modified: trunk/Solar/Sql/Adapter.php
===================================================================
--- trunk/Solar/Sql/Adapter.php 2008-05-22 14:09:22 UTC (rev 3171)
+++ trunk/Solar/Sql/Adapter.php 2008-05-22 14:28:13 UTC (rev 3172)
@@ -367,7 +367,7 @@
}
// start profile time
- $before = microtime(true);
+ $time = microtime(true);
// attempt the connection
$this->_pdo = new PDO(
@@ -380,10 +380,7 @@
$this->_postConnect();
// retain the profile data?
- if ($this->_profiling) {
- $after = microtime(true);
- $this->_profile[] = array($after - $before, '__CONNECT');
- }
+ $this->_addProfile($time, '__CONNECT');
}
/**
@@ -523,7 +520,7 @@
$this->connect();
// begin the profile time
- $before = microtime(true);
+ $time = microtime(true);
// prepare the statment
try {
@@ -607,15 +604,41 @@
}
// retain the profile data?
- if ($this->_profiling) {
- $after = microtime(true);
- $this->_profile[] = array($after - $before, $obj->queryString, $data);
- }
+ $this->_addProfile($time, $obj->queryString, $data);
// done!
return $obj;
}
+ /**
+ *
+ * Adds an element to the profile array.
+ *
+ * @param int $time The microtime when the profile element started.
+ *
+ * @param string $stmt The SQL statement being profiled.
+ *
+ * @param array $data Any data bound into the statement.
+ *
+ * @return void
+ *
+ */
+ protected function _addProfile($time, $stmt, $data = null)
+ {
+ if (! $this->_profiling) {
+ return;
+ }
+
+ $timespan = microtime(true) - $time;
+ $e = new Exception();
+ $this->_profile[] = array(
+ $timespan,
+ $stmt,
+ $data,
+ $e->getTraceAsString(),
+ );
+ }
+
// -----------------------------------------------------------------
//
// Transactions
@@ -632,12 +655,9 @@
public function begin()
{
$this->connect();
- $before = microtime(true);
+ $time = microtime(true);
$result = $this->_pdo->beginTransaction();
- if ($this->_profiling) {
- $after = microtime(true);
- $this->_profile[] = array($after - $before, "__BEGIN");
- }
+ $this->_addProfile($time, '__BEGIN');
return $result;
}
@@ -651,12 +671,9 @@
public function commit()
{
$this->connect();
- $before = microtime(true);
+ $time = microtime(true);
$result = $this->_pdo->commit();
- if ($this->_profiling) {
- $after = microtime(true);
- $this->_profile[] = array($after - $before, "__COMMIT");
- }
+ $this->_addProfile($time, '__COMMIT');
return $result;
}
@@ -670,12 +687,9 @@
public function rollback()
{
$this->connect();
- $before = microtime(true);
+ $time = microtime(true);
$result = $this->_pdo->rollBack();
- if ($this->_profiling) {
- $after = microtime(true);
- $this->_profile[] = array($after - $before, "__ROLLBACK");
- }
+ $this->_addProfile($time, '__ROLLBACK');
return $result;
}
More information about the Solar-svn
mailing list