DebugUtils.class.php

Go to the documentation of this file.
00001 <?php
00002 /***************************************************************************
00003  *   Copyright (C) 2006-2007 by Anton E. Lebedevich                        *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU Lesser General Public License as        *
00007  *   published by the Free Software Foundation; either version 3 of the    *
00008  *   License, or (at your option) any later version.                       *
00009  *                                                                         *
00010  ***************************************************************************/
00011 /* $Id: DebugUtils.class.php 4687 2007-12-09 18:57:18Z voxus $ */
00012 
00016     final class DebugUtils extends StaticFactory
00017     {
00018         private static $memoryAccumulator = 0;
00019         private static $currentMemory = null;
00020         
00021         public static function el($vr, $prefix = null)
00022         {
00023             if ($prefix === null) {
00024                 $trace = debug_backtrace();
00025                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00026             }
00027             
00028             error_log($prefix.': '.var_export($vr, true));
00029         }
00030         
00031         public static function ev($vr, $prefix = null)
00032         {
00033             if ($prefix === null) {
00034                 $trace = debug_backtrace();
00035                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00036             }
00037             
00038             echo
00039                 '<pre>'
00040                 .$prefix.': '.htmlspecialchars(var_export($vr, true))
00041                 .'</pre>';
00042         }
00043 
00044         public static function ec($vr, $prefix = null)
00045         {
00046             if ($prefix === null) {
00047                 $trace = debug_backtrace();
00048                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00049             }
00050             
00051             echo "\n".$prefix.': '.var_export($vr, true)."\n";
00052         }
00053         
00054         public static function eq(Query $query, $prefix = null)
00055         {
00056             if ($prefix === null) {
00057                 $trace = debug_backtrace();
00058                 $prefix = basename($trace[0]['file']).':'.$trace[0]['line'];
00059             }
00060             
00061             error_log(
00062                 $prefix.": ".$query->toDialectString(
00063                     DBPool::me()->getLink()->getDialect()
00064                 )
00065             );
00066         }
00067         
00068         public static function microtime()
00069         {
00070             list($usec, $sec) = explode(' ', microtime(), 2);
00071             return ((float) $usec + (float) $sec);      
00072         }
00073         
00074         public static function setMemoryCounter()
00075         {
00076             self::$currentMemory = memory_get_usage();
00077         }
00078         
00079         public static function addMemoryCounter()
00080         {
00081             self::$memoryAccumulator += memory_get_usage() - self::$currentMemory;
00082         }
00083         
00084         public static function getMemoryCounter()
00085         {
00086             return self::$memoryAccumulator;
00087         }
00088     }
00089 ?>

Generated on Sun Dec 9 21:56:24 2007 for onPHP by  doxygen 1.5.4