Skip to content

Commit

Permalink
Use microtime(true) instead of manual explode. Also fixes a few uses …
Browse files Browse the repository at this point in the history
…of deprecated split-method
  • Loading branch information
SjonHortensius committed Jan 26, 2016
1 parent 23c422d commit 6b59311
Show file tree
Hide file tree
Showing 20 changed files with 41 additions and 81 deletions.
3 changes: 1 addition & 2 deletions cli/poller_output_empty.php
Expand Up @@ -65,8 +65,7 @@
}

/* record the start time */
list($micro,$seconds) = explode(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* open a pipe to rrdtool for writing */
$rrdtool_pipe = rrd_init();
Expand Down
6 changes: 2 additions & 4 deletions cmd.php
Expand Up @@ -185,8 +185,7 @@ function debug($message) {
}

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* initialize the polling items */
$polling_items = array();
Expand Down Expand Up @@ -635,8 +634,7 @@ function debug($message) {

if (($print_data_to_stdout) || (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM)) {
/* take time and log performance data */
list($micro,$seconds) = explode(' ', microtime());
$end = $seconds + $micro;
$end = microtime(true);

cacti_log(sprintf('Time: %01.4f s, ' .
'Theads: N/A, ' .
Expand Down
3 changes: 1 addition & 2 deletions cmd_realtime.php
Expand Up @@ -62,8 +62,7 @@
}

/* record the start time */
list($micro,$seconds) = split(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* initialize the polling items */
$polling_items = array();
Expand Down
3 changes: 1 addition & 2 deletions lib/boost.php
Expand Up @@ -485,8 +485,7 @@ function boost_timer($area, $type) {
global $boost_stats_log;

/* get the time */
list($micro,$seconds) = explode(' ', microtime());
$btime = $seconds + $micro;
$btime = microtime(true);

if ($type == BOOST_TIMER_START) {
$boost_stats_log[$area][BOOST_TIMER_START] = $btime;
Expand Down
6 changes: 2 additions & 4 deletions lib/cmd.php
Expand Up @@ -185,8 +185,7 @@ function debug($message) {
}

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* initialize the polling items */
$polling_items = array();
Expand Down Expand Up @@ -635,8 +634,7 @@ function debug($message) {

if (($print_data_to_stdout) || (read_config_option('log_verbosity') >= POLLER_VERBOSITY_MEDIUM)) {
/* take time and log performance data */
list($micro,$seconds) = explode(' ', microtime());
$end = $seconds + $micro;
$end = microtime(true);

cacti_log(sprintf('Time: %01.4f s, ' .
'Theads: N/A, ' .
Expand Down
9 changes: 3 additions & 6 deletions lib/data_query.php
Expand Up @@ -199,8 +199,7 @@ function query_debug_timer_start() {
global $query_debug_timer, $query_debug_start;

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$query_debug_timer = $seconds + $micro;
$query_debug_timer = microtime(true);
$query_debug_start = $query_debug_timer;
}

Expand All @@ -212,8 +211,7 @@ function query_debug_timer_offset($section, $message) {
}

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$cur_time = $seconds + $micro;
$cur_time = microtime(true);
$delta = $cur_time - $query_debug_timer;
$total = $cur_time - $query_debug_start;
$query_debug_timer = $cur_time;
Expand All @@ -227,8 +225,7 @@ function query_debug_timer_stop($sction, $message) {
global $query_debug_timer, $query_debug_start;

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$cur_time = $seconds + $micro;
$cur_time = microtime(true);
$delta = $cur_time - $query_debug_timer;
$total = $cur_time - $query_debug_start;
unset($query_debug_timer);
Expand Down
6 changes: 2 additions & 4 deletions lib/dsstats.php
Expand Up @@ -397,13 +397,11 @@ function log_dsstats_statistics($type) {
global $start;

/* take time and log performance data */
list($micro,$seconds) = split(" ", microtime());
$end = $seconds + $micro;
$end = microtime(true);

$cacti_stats = sprintf("Time:%01.4f ", round($end-$start,4));
/* take time and log performance data */
list($micro,$seconds) = split(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* log to the database */
db_execute("REPLACE INTO settings (name,value) VALUES ('stats_dsstats_$type', '" . $cacti_stats . "')");
Expand Down
6 changes: 2 additions & 4 deletions lib/functions.php
Expand Up @@ -424,16 +424,14 @@ function array_rekey($array, $key, $key_value) {
function timer_start() {
global $timer_start;

list($micro,$seconds) = explode(' ', microtime());
$timer_start = $seconds + $micro;
$timer_start = microtime(true);
}

/* timer end/step function */
function timer_end($message = 'default') {
global $timer_start;

list($micro,$seconds) = explode(' ', microtime());
$timer_end = $seconds + $micro;
$timer_end = microtime(true);

echo "TIMER: '$message' Time:'" . ($timer_end - $timer_start) . "' seconds\n";
$timer_start = $timer_end;
Expand Down
9 changes: 3 additions & 6 deletions lib/graph_export.php
Expand Up @@ -26,8 +26,7 @@ function graph_export($force = false) {
global $debug;

/* take time to log performance data */
list($micro,$seconds) = explode(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);

if ($debug) {
export_debug("This is a forced run");
Expand Down Expand Up @@ -152,8 +151,7 @@ function config_graph_export() {

function config_export_stats($start, $total_graphs_created) {
/* take time to log performance data */
list($micro,$seconds) = explode(" ", microtime());
$end = $seconds + $micro;
$end = microtime(true);

$export_stats = sprintf(
"ExportDate:%s ExportDuration:%01.4f TotalGraphsExported:%s",
Expand Down Expand Up @@ -1572,8 +1570,7 @@ function get_graph_tree_array_export($return_sql = false, $force_refresh = false

function create_dhtml_tree_export($tree_id) {
/* record start time */
list($micro,$seconds) = explode(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);
$search_key = "";

$dhtml_tree = array();
Expand Down
3 changes: 1 addition & 2 deletions lib/html_tree.php
Expand Up @@ -258,8 +258,7 @@ function draw_dhtml_tree_level($tree_id, $parent = 0, $graphing = false) {
global $config;

/* Record Start Time */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

$dhtml_tree = array();

Expand Down
8 changes: 3 additions & 5 deletions lib/ping.php
Expand Up @@ -49,16 +49,14 @@ function close_socket() {
}

function start_time() {
$this->timer_start_time = microtime();
$this->timer_start_time = microtime(true);
}

function get_time($acc=2) {
// format start time
$start_time = explode (" ", $this->timer_start_time);
$start_time = $start_time[1] + $start_time[0];
$start_time = $this->timer_start_time;
// get and format end time
$end_time = explode (" ", microtime());
$end_time = $end_time[1] + $end_time[0];
$end_time = microtime(true);
return number_format ($end_time - $start_time, $acc);
}

Expand Down
18 changes: 6 additions & 12 deletions poller.php
Expand Up @@ -115,8 +115,7 @@ function sig_handler($signo) {
api_plugin_hook('poller_top');

// record the start time
list($micro,$seconds) = explode(' ', microtime());
$poller_start = $seconds + $micro;
$poller_start = microtime(true);
$overhead_time = 0;

// get number of polling items from the database
Expand Down Expand Up @@ -227,8 +226,7 @@ function sig_handler($signo) {

while ($poller_runs_completed < $poller_runs) {
/* record the start time for this loop */
list($micro,$seconds) = explode(' ', microtime());
$loop_start = $seconds + $micro;
$loop_start = microtime(true);

/* calculate overhead time */
if ($overhead_time == 0) {
Expand Down Expand Up @@ -447,8 +445,7 @@ function sig_handler($signo) {
$poller_runs_completed++;

/* record the start time for this loop */
list($micro,$seconds) = explode(' ', microtime());
$loop_end = $seconds + $micro;
$loop_end = microtime(true);
$loop_time = $loop_end - $loop_start;

if ($loop_time < $poller_interval) {
Expand All @@ -468,8 +465,7 @@ function sig_handler($signo) {

/* sleep the appripriate amount of time */
if ($poller_runs_completed < $poller_runs) {
list($micro, $seconds) = split(' ', microtime());
$plugin_start = $seconds + $micro;
$plugin_start = microtime(true);

/* all plugins moved to core */
snmpagent_poller_bottom();
Expand All @@ -478,8 +474,7 @@ function sig_handler($signo) {

api_plugin_hook('poller_bottom');

list($micro, $seconds) = split(' ', microtime());
$plugin_end = $seconds + $micro;
$plugin_end = microtime(true);
if (($sleep_time - ($plugin_end - $plugin_start)) > 0) {
usleep(($sleep_time - ($plugin_end - $plugin_start)) * 1000000);
}
Expand All @@ -494,8 +489,7 @@ function log_cacti_stats($loop_start, $method, $concurrent_processes, $max_threa
$hosts_per_process, $num_polling_items, $rrds_processed) {

/* take time and log performance data */
list($micro,$seconds) = explode(' ', microtime());
$loop_end = $seconds + $micro;
$loop_end = microtime(true);

$perf_data = array(
round($loop_end-$loop_start,4),
Expand Down
6 changes: 2 additions & 4 deletions poller_automation.php
Expand Up @@ -86,8 +86,7 @@ function sig_handler($signo) {
}

/* take time and log performance data */
list($micro,$seconds) = explode(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);

// Unix Timestamp for Database
$startTime = time();
Expand Down Expand Up @@ -286,8 +285,7 @@ function sig_handler($signo) {
$totals = db_fetch_row_prepared('SELECT SUM(up_hosts) AS up, SUM(snmp_hosts) AS snmp FROM automation_processes WHERE network_id=?', array($network_id));

/* take time and log performance data */
list($micro,$seconds) = explode(" ", microtime());
$end = $seconds + $micro;
$end = microtime(true);

db_execute_prepared('UPDATE automation_networks
SET up_hosts = ?,
Expand Down
6 changes: 2 additions & 4 deletions poller_boost.php
Expand Up @@ -193,8 +193,7 @@ function log_boost_statistics($rrd_updates) {
global $start, $boost_stats_log, $verbose;

/* take time and log performance data */
list($micro,$seconds) = explode(' ', microtime());
$end = $seconds + $micro;
$end = microtime(true);

$cacti_stats = sprintf(
'Time:%01.4f ' .
Expand Down Expand Up @@ -302,8 +301,7 @@ function log_boost_statistics($rrd_updates) {
}

/* take time and log performance data */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* let's give this script lot of time to run for ever */
ini_set('max_execution_time', '0');
Expand Down
9 changes: 3 additions & 6 deletions poller_commands.php
Expand Up @@ -39,8 +39,7 @@
include_once($config['base_path'] . '/lib/rrd.php');

/* Record Start Time */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

$poller_commands = db_fetch_assoc('SELECT poller_command.action, poller_command.command FROM poller_command WHERE poller_command.poller_id = 0');

Expand Down Expand Up @@ -80,8 +79,7 @@
}

/* record current_time */
list($micro,$seconds) = explode(' ', microtime());
$current = $seconds + $micro;
$current = microtime(true);

/* end if runtime has been exceeded */
if (($current-$start) > MAX_RECACHE_RUNTIME) {
Expand All @@ -94,8 +92,7 @@
}

/* take time to log performance data */
list($micro,$seconds) = explode(' ', microtime());
$recache = $seconds + $micro;
$recache = microtime(true);

$recache_stats = sprintf('RecacheTime:%01.4f DevicesRecached:%s', round($recache - $start, 4), $recached_hosts);

Expand Down
3 changes: 1 addition & 2 deletions poller_dsstats.php
Expand Up @@ -113,8 +113,7 @@ function sig_handler($signo) {
}

/* take time and log performance data */
list($micro,$seconds) = split(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* let's give this script lot of time to run for ever */
ini_set('max_execution_time', '0');
Expand Down
6 changes: 2 additions & 4 deletions poller_maintenance.php
Expand Up @@ -34,8 +34,7 @@
chdir($dir);

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$poller_start = $seconds + $micro;
$poller_start = microtime(true);

include ('./include/global.php');

Expand Down Expand Up @@ -106,8 +105,7 @@
}

/* record the start time */
list($micro,$seconds) = explode(' ', microtime());
$poller_end = $seconds + $micro;
$poller_end = microtime(true);
$string = sprintf('RRDMAINT STATS: Time:%4.4f Purged:%s Archived:%s', ($poller_end - $poller_start), $purged, $archived);
cacti_log($string, true, 'SYSTEM');
}
Expand Down
3 changes: 1 addition & 2 deletions poller_realtime.php
Expand Up @@ -97,8 +97,7 @@
}

/* record the start time */
list($micro,$seconds) = split(" ", microtime());
$poller_start = $seconds + $micro;
$poller_start = microtime(true);

/* get number of polling items from the database */
$poller_interval = 1;
Expand Down
6 changes: 2 additions & 4 deletions poller_reports.php
Expand Up @@ -116,8 +116,7 @@ function sig_handler($signo) {
}

/* take time and log performance data */
list($micro,$seconds) = explode(" ", microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* let's give this script lot of time to run for ever */
ini_set("max_execution_time", "0");
Expand Down Expand Up @@ -145,8 +144,7 @@ function sig_handler($signo) {
}

/* record the end time */
list($micro,$seconds) = explode(" ", microtime());
$end = $seconds + $micro;
$end = microtime(true);

/* log statistics */
$reports_stats = sprintf("Time:%01.4f Reports:%s", $end - $start, $number_sent);
Expand Down
3 changes: 1 addition & 2 deletions script_server.php
Expand Up @@ -72,8 +72,7 @@ function sig_handler($signo) {
}

/* record the script start time */
list($micro,$seconds) = explode(' ', microtime());
$start = $seconds + $micro;
$start = microtime(true);

/* some debugging */
$pid = getmypid();
Expand Down

0 comments on commit 6b59311

Please sign in to comment.