public static formatTime ( $micros ) |
public static function formatTime($micros)
{
$seconds = $micros;
$minutes = $seconds / 60;
if ($minutes > 1) {
return sprintf("%1.0f minute%s %0.2f second%s", $minutes, $minutes === 1 ? " " : "s ", $seconds - floor($seconds / 60) * 60, $seconds % 60 === 1 ? "" : "s");
} else {
return sprintf("%0.4f second%s", $seconds, $seconds % 60 === 1 ? "" : "s");
}
}
/** * Fired when the build finishes, this adds the time taken and any * error stacktrace to the build element and writes the document to disk. * * @param BuildEvent $event An event with any relevant extra information. * Will not be <code>null</code>. * @throws BuildException */ public function buildFinished(BuildEvent $event) { $elapsedTime = Phing::currentTimeMillis() - $this->getBuildTimerStart(); $this->getBuildElement()->setAttribute(XmlLogger::TIME_ATTR, DefaultLogger::formatTime($elapsedTime)); if ($event->getException() != null) { $this->getBuildElement()->setAttribute(XmlLogger::ERROR_ATTR, $event->getException()->getMessage()); $errText = $this->getDoc()->createCDATASection($event->getException()->getTraceAsString()); $stacktrace = $this->getDoc()->createElement(XmlLogger::STACKTRACE_TAG); $stacktrace->appendChild($errText); $this->getBuildElement()->appendChild($stacktrace); } $this->getDoc()->appendChild($this->getBuildElement()); $outFilename = $event->getProject()->getProperty("JsonLogger.file"); if ($outFilename == null) { $outFilename = "log.json"; } try { $stream = $this->getOut(); if ($stream === null) { $stream = new FileOutputStream($outFilename); } $writer = new OutputStreamWriter($stream); $writer->write($this->xml2js(simplexml_import_dom($this->getDoc()))); $writer->close(); } catch (IOException $exc) { try { $stream->close(); // in case there is a stream open still ... } catch (Exception $x) { } throw new BuildException("Unable to write log file.", $exc); } // cleanup:remove the buildElement $this->setBuildElement(null); array_pop($this->getElementStack()); array_pop($this->getTimesStack()); }