|
Revision 1, 1.5 kB
(checked in by heitor.barbieri, 4 years ago)
|
|
Criação do svn para Cisis.
|
| Line | |
|---|
| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | class Chronometer { |
|---|
| 4 | var $time; |
|---|
| 5 | var $handle; |
|---|
| 6 | |
|---|
| 7 | /* Constructor */ |
|---|
| 8 | function Chronometer($handle_name) { |
|---|
| 9 | $this->time = 0; |
|---|
| 10 | $this->handle = null; |
|---|
| 11 | |
|---|
| 12 | if ($handle_name != null) { |
|---|
| 13 | $this->handle = fopen($handle_name, "a+"); |
|---|
| 14 | if ($this->handle == false) { |
|---|
| 15 | echo("Chronometer/file open error\n"); |
|---|
| 16 | $this->handle = null; |
|---|
| 17 | } |
|---|
| 18 | } |
|---|
| 19 | } |
|---|
| 20 | |
|---|
| 21 | /* Destructor */ |
|---|
| 22 | function destroy() { |
|---|
| 23 | if ($this->handle) { |
|---|
| 24 | $this->time = 0; |
|---|
| 25 | if ($this->handle != null) { |
|---|
| 26 | fclose($this->handle); |
|---|
| 27 | $this->handle = null; |
|---|
| 28 | } |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | function start() { |
|---|
| 33 | list($usec, $sec) = explode(" ", microtime()); |
|---|
| 34 | $this->time = ((float)$usec + (float)$sec); |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | function stop($message) { |
|---|
| 38 | $before = $this->time; |
|---|
| 39 | list($usec, $sec) = explode(" ", microtime()); |
|---|
| 40 | $this->time = ((float)$usec + (float)$sec); |
|---|
| 41 | $dif = round($this->time - $before, 6); |
|---|
| 42 | |
|---|
| 43 | if (!$message) { |
|---|
| 44 | $message = ""; |
|---|
| 45 | } |
|---|
| 46 | if ($this->handle != null) { |
|---|
| 47 | if (!fwrite($this->handle, |
|---|
| 48 | $message."[".round($before, 6).", " |
|---|
| 49 | .round($this->time, 6).", ".$dif."]\n")) { |
|---|
| 50 | echo("stop/write file error\n"); |
|---|
| 51 | } |
|---|
| 52 | } else { |
|---|
| 53 | echo($message."[".round($before, 6).", " |
|---|
| 54 | .round($this->time, 6).", ".$dif."]\n"); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | return $dif; |
|---|
| 58 | } |
|---|
| 59 | } |
|---|
| 60 | ?> |
|---|