public static function set($title = NULL, $data = NULL) { static $last = NULL; // If no title is set, use the code location which executed the set() method if ($title === NULL) { $title = Amslib_Debug::getCodeLocation(3); } $time = microtime(true); // If is first benchmark point, set the start time to this time if (self::$start === NULL) { self::$start = $time; } // Always set the finish time to the last benchmark point self::$finish = $time; // Set the total to the subtraction of the last and first benchmark points self::$total = self::$finish - self::$start; // calculate the diff only when there was a previous benchmark point set $diff = $last === NULL ? 0 : $time - $last["time"]; // Set the basic data $e = array("title" => $title, "time" => $time, "diff" => $diff); // Save the data, store the last entry, add it to the list and return it to the calling method if ($data !== NULL) { $e["data"] = $data; } // Retain a copy of the previous execution so you can do the differential easier $last = $e; switch (self::$mode) { case "record": self::$entries[] = $e; break; case "log": // FIXME: refactor against log() Amslib_Debug::log("title[{$title}], time[{$time}], diff[{$diff}]"); break; } return $e; }
/** * method: setError * * todo: write documentation */ public function setError($data) { // Overload some default values just in case something failed $args = func_get_args() + array("__MISSING_QUERY__", $this->connection->errorInfo(), $this->connection->errorCode(), -1); $this->error = array("db_failure" => true, "db_query" => preg_replace('/\\s+/', ' ', $args[0]), "db_error" => $args[1], "db_error_num" => $args[2], "db_last_insert" => $this->lastInsertId, "db_insert_id" => $args[3], "db_location" => Amslib_Debug::getCodeLocation($this->errorStackDepth)); $this->debug("ERROR", $this->error); $this->setErrorStackDepth(); }