1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
<?php
/*****************************************************************************
*
* debug.php - Some functions for debugging
*
* Copyright (c) 2004-2016 NagVis Project (Contact: info@nagvis.org)
*
* License:
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*****************************************************************************/
/**
* @author Lars Michelsen <lm@larsmichelsen.com>
*/
// Save the start time of NagVis
define('DEBUGSTART',microtime_float());
/**
* Writes the debug output to the debug file
*
* @param String Debug message
* @author Lars Michelsen <lm@larsmichelsen.com>
*/
function debug($msg) {
$fh = fopen(DEBUGFILE, 'a');
fwrite($fh, iso8859_1_to_utf8(microtime_float().' '.$msg."\n"));
fclose($fh);
}
/**
* Writes the render time and the called URI to the debug file
*
* @author Lars Michelsen <lm@larsmichelsen.com>
*/
function debugFinalize() {
debug('==> Render Time: '.round((microtime_float() - DEBUGSTART), 2).'sec'
.' Mem peak: '.round(memory_get_peak_usage()/1024/1024, 2).'Mb'
.' URI: '.$_SERVER['REQUEST_URI']);
}
function log_mem($txt = 'somewhere') {
if (DEBUG && DEBUGLEVEL & 2)
debug('mem ['.$txt.']: ' . round(memory_get_usage()/1024/1024, 2) . 'Mb');
}
/**
* Returns the current time in microtime as float
*
* @return Float Microtime
* @author Lars Michelsen <lm@larsmichelsen.com>
*/
function microtime_float() {
list($usec, $sec) = explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function profilingStart() {
//xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);
}
function profilingFinalize($pre) {
//include_once "/usr/share/php5-xhprof/xhprof_lib/utils/xhprof_lib.php";
//include_once "/usr/share/php5-xhprof/xhprof_lib/utils/xhprof_runs.php";
//$xhprof_runs = new XHProfRuns_Default();
//$xhprof_runs->save_run(xhprof_disable(), 'nagvis-'.$pre);
}
// Start profiling now when configured to do so
if (PROFILE) profilingStart();
?>
|