function diff_page($ctl) { $file = $_REQUEST['file']; $from_rev = $_REQUEST['from_rev']; $to_rev = $_REQUEST['to_rev']; if (preg_match('@^/|(^|/)\\.\\.?($|/)|[\\"\'\\`\\(\\)\\[\\]\\&\\|\\>\\<]@', $file, $m) || preg_match('/[^\\d\\.]+/', $from_rev, $m) || !preg_match('/^([\\d\\.]+|local)$/', $to_rev, $m)) { return trigger_error("Please don't hack...", E_USER_ERROR); } ### Get the partial diff $to_rev_clause = $to_rev == 'local' ? "" : "-r {$to_rev}"; if (PROJECT_PROJECT_TIMERS) { START_TIMER('REPO_CMD'); } $revision_arg = $to_rev == 'local' ? "-r{$from_rev}" : "-r{$from_rev}:{$to_rev}"; $cmd_prefix = $ctl->stage->config('repo_cmd_prefix'); $cmd_name = $ctl->stage->repo()->command_name; $cdiff = `{$cmd_prefix}{$cmd_name} diff {$revision_arg} "{$file}" 2>&1 | cat`; if (PROJECT_PROJECT_TIMERS) { END_TIMER('REPO_CMD'); } return array('cdiff' => $cdiff, 'from_rev' => $from_rev, 'to_rev' => $to_rev, 'file' => $file, 'command_name' => $ctl->stage->repo()->command_name); }
/** * dbh_do_bind() - Execute a (possibly write access) SQL query with bound parameters * * @param string $sql The SQL query to run * @param mixed $params this can either be called passing an array of bind params, or just by passing the bind params as args after the SQL arg * @return PDOStatement */ function dbh_do_bind($sql) { $use_dbh = $this->dbh(); if (ORM_SQL_PROFILE) { START_TIMER('dbh_do_bind'); } $bind_params = array_slice(func_get_args(), 1); ### Allow params passed in an array or as args if (is_a($bind_params[count($bind_params) - 1], 'PDO') || is_a($bind_params[count($bind_params) - 1], 'PhoneyPDO')) { $use_dbh = array_pop($bind_params); } if (count($bind_params) == 1 && is_array(array_shift(array_values($bind_params)))) { $bind_params = array_shift(array_values($bind_params)); } $this->reverse_t_bools($bind_params); if (ORM_SQL_DEBUG || ORM_SQL_WRITE_DEBUG) { bug($sql, $bind_params); } $GLOBALS['ORM_SQL_LOG'][] = array(microtime(true), $sql, $bind_params); try { $sth = $use_dbh->prepare($sql); $rv = $sth->execute($bind_params); } catch (PDOException $e) { trace_dump(); $err_msg = 'There was an error running a SQL statement, [' . $sql . '] with (' . join(',', $bind_params) . '): ' . $e->getMessage() . ' in ' . trace_blame_line(); if (strlen($err_msg) > 1024) { bug($err_msg, $sql, $bind_params, $e->getMessage()); $sql = substr($sql, 0, 1020 + strlen($sql) - strlen($err_msg)) . '...'; } trigger_error('There was an error running a SQL statement, [' . $sql . '] with (' . join(',', $bind_params) . '): ' . $e->getMessage() . ' in ' . trace_blame_line(), E_USER_ERROR); return false; } if (ORM_SQL_PROFILE) { END_TIMER('dbh_do_bind'); } return $rv; }
public function handler() { // Load Main Libraries if (!empty($this->STARK_PROFILING)) { START_TIMER('STARK-controller-lib_load'); } require_once $this->lib_path . '/Stark/View.class.php'; require_once $this->lib_path . '/Stark/Controller/Base.class.php'; if (isset($this->CONTROLLER_PRELOAD_LIBS)) { foreach ($this->CONTROLLER_PRELOAD_LIBS as $lib) { require_once $lib; } } if (!empty($this->STARK_PROFILING)) { END_TIMER('STARK-controller-lib_load'); } // Main Controller Sequence if (!empty($this->STARK_PROFILING)) { START_TIMER('STARK-controller-handlers'); } $this->view = new Stark__View($_SERVER['SCRIPT_NAME']); $this->view->controller = $this; /// Reguster AJAX mode if (!empty($_SERVER['__STARK_AJAX_MODE__'])) { $this->ajax_mode = true; } /// Catch the Previous Step # TODO /// Page Handler list($page_ctl, $page_page) = $this->load_controller_by_path($this->path); $this->run_directory_handlers($this->path, $page_ctl); if (!empty($page_ctl)) { // If the controller is defined... $method = $page_page . (!empty($_SERVER['__STARK_AJAX_MODE__']) ? '_ajax' : '_page'); /// Call the handler if it is defined $exists = method_exists($page_ctl, 'real_method_exists') ? $page_ctl->real_method_exists($method) : method_exists($page_ctl, $method); if ($exists) { $scope = $page_ctl->{$method}($this); /// AJAX returnin if (!empty($_SERVER['__STARK_AJAX_MODE__'])) { header('Content-type: application/json'); print !empty($_REQUEST['callback']) ? 'function ' . $_REQUEST['callback'] . '(){return ' . json_encode($scope) . '}' : "{}&&\n" . json_encode($scope); exit; # if we let it proceed it might print report_timers(), which isn't waht we want! } else { if (!empty($scope) && is_array($scope)) { foreach (array_keys($scope) as $var) { if (isset($scope[$var])) { $this->view->{$var} = $scope[$var]; } } } } } } if (!empty($this->STARK_PROFILING)) { END_TIMER('STARK-controller-handlers'); } }
<?php if (STARK_EXTEND_PROFILE) { END_TIMER('Stark__Extend->include overhead'); } if (STARK_EXTEND_PROFILE) { RESUME_TIMER('Stark__Extend->run_hook'); } foreach ($GLOBALS['__Stark__Extend__object__']->extract_vars_keys(get_defined_vars()) as $__Stark__Extend__var__) { $GLOBALS['__Stark__Extend__object__']->scope()->set_var($__Stark__Extend__var__, ${$__Stark__Extend__var__}); } $GLOBALS['__Stark__Extend__object__']->scope()->run_hook($v);
public function run_hook() { /// Stark__Extend->run_hook has a RESUME_TIMER at the beginning of the include (or the rhni func) $this->lock(); $hooks = $this->__hooks; foreach ($hooks as $callback) { ////// Supported Formats: /// Static non-class functions (without parameters) if (is_string($callback) || is_array($callback) && isset($callback[0]) && !is_array($callback[0]) && isset($callback[1]) && !is_array($callback[1])) { list($func, $params) = array($callback, array()); } else { if (is_array($callback) && isset($callback[0]) && !is_object($callback[0]) && isset($callback[1]) && is_array($callback[1])) { list($func, $params) = $callback; } else { continue; } } // Should never happen, because of validation in hook() /// Always add the Extend object as the first parameter array_unshift($params, $this); if (STARK_EXTEND_PROFILE) { PAUSE_TIMER('Stark__Extend->run_hook'); } $ret_val = call_user_func_array($func, $params); if (STARK_EXTEND_PROFILE) { RESUME_TIMER('Stark__Extend->run_hook'); } /// If they had a non-null return value, then record it if (!is_null($ret_val)) { $this->set_return_value($ret_val); /// But don't break, because the other hooks need to run... } $this->extend->leave_finished_scopes(); } $this->finish(); // This will later trigger the closing of this scope and cleanup of the vars if (STARK_EXTEND_PROFILE) { END_TIMER('Stark__Extend->run_hook'); } }
<? END_TIMER('INC') ?> foo
function dax_scrub_tag($tagname, $tag, $scrub_config) { START_TIMER('DAX_SCRUB_tag'); global $dax_neverNested, $dax_freeElementAttrs; if (isset($scrub_config['allowed_tags'][$tagname])) { if (!is_array($scrub_config['allowed_tags'][$tagname])) { $scrub_config['allowed_tags'][$tagname] = isset($dax_freeElementAttrs[$tagname]) ? $dax_freeElementAttrs[$tagname] : array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'])) { $scrub_config['allowed_tags'][$tagname]['allowed_attrs'] = array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'])) { $scrub_config['allowed_tags'][$tagname]['allowed_styles'] = array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['disallowed_attrs'])) { $scrub_config['allowed_tags'][$tagname]['disallowed_attrs'] = array(); } if (!isset($scrub_config['allowed_tags'][$tagname]['disallowed_styles'])) { $scrub_config['allowed_tags'][$tagname]['disallowed_styles'] = array(); } ### Implied Style attr allowed unless globally disabled if (!isset($scrub_config['options']['disable_style_attr']) && empty($scrub_config['allowed_tags'][$tagname]['allowed_attrs']['style'])) { $scrub_config['allowed_tags'][$tagname]['allowed_attrs']['style'] = true; } ### Scrub the tag's attributes... $keepAttrs = array(); $close_tag = substr($tag, strlen($tag) - 2, 1) == '/' || isset($dax_neverNested[$tagname]) ? '/>' : '>'; $open_tag = (substr($tag, 1, 1) == '/' ? '</' : '<') . $tagname; if (preg_match_all('/(\\w+)\\=(\\"[^\\"]*\\"|\'[^\']*\'|[^\\"\\s]+)/', substr($tag, strlen($open_tag), strlen($tag) - strlen($open_tag) - strlen($close_tag)), $m) == 0) { END_TIMER('DAX_SCRUB_tag'); return array(true, $open_tag . $close_tag, true); } $attrs = $m[0]; $styleAttrRules = array(); ### Loop thru the attributes for ($i = 0; $i < count($attrs); $i++) { $n_v = null; # Keep the line count the same if (!preg_match('/^([\\w-]+)=\\"?([^\\"]+)\\"?$/', $attrs[$i], $n_v) && !preg_match('/^([\\w-]+)=\'?([^\']+)\'?$/', $attrs[$i], $mm)) { continue; } $attr = strtolower($n_v[1]); ### Attribute Rules : Simple Allow / Disallow if (!isset($scrub_config['allowed_attrs'][$attr]) && !isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]) || isset($scrub_config['allowed_tags'][$tagname]['disallowed_attrs'][$attr])) { continue; } ### Attribute Rules : Tag Inspecific Attr Value regexp if (isset($scrub_config['allowed_attrs'][$attr]) && is_array($scrub_config['allowed_attrs'][$attr]) && (isset($scrub_config['allowed_attrs'][$attr]['regexp']) && !preg_match($scrub_config['allowed_attrs'][$attr]['regexp'], $n_v[2], $m) || isset($scrub_config['allowed_attrs'][$attr]['neg_regexp']) && preg_match($scrub_config['allowed_attrs'][$attr]['neg_regexp'], $n_v[2], $m))) { continue; } ### Attribute Rules : Tag Specific Attr Value regexp if (isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]) && is_array($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]) && (isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['regexp']) && !preg_match($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['regexp'], $n_v[2], $m) || isset($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['neg_regexp']) && preg_match($scrub_config['allowed_tags'][$tagname]['allowed_attrs'][$attr]['neg_regexp'], $n_v[2], $m))) { continue; } ### Parse CSS Styles for Style Rules if ($attr == 'style') { $rules = preg_split('/\\s*;\\s*/', $n_v[2]); ### Loop thru STYLE rules for ($ii = 0; $ii < count($rules); $ii++) { $style_n_v = null; # Keep the line count the same; if (!preg_match('/^([\\w-]+)\\s*:\\s*(.+)?$/s', $rules[$ii], $style_n_v)) { continue; } $style = strtolower($style_n_v[1]); ### Style Rules : Simple Allow / Disallow if (!isset($scrub_config['allowed_styles'][$style]) && !isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]) || $scrub_config['allowed_tags'][$tagname]['disallowed_styles'][$style]) { continue; } ### Style Rules : Tag Inspecific Style Value regexp if (isset($scrub_config['allowed_styles'][$style]) && is_array($scrub_config['allowed_styles'][$style]) && (isset($scrub_config['allowed_styles'][$style]['regexp']) && !preg_match($scrub_config['allowed_styles'][$style]['regexp'], $style_n_v[2], $m) || isset($scrub_config['allowed_styles'][$style]['neg_regexp']) && preg_match($scrub_config['allowed_styles'][$style]['neg_regexp'], $style_n_v[2], $m))) { continue; } ### Style Rules : Tag Specific Style Value regexp if (isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]) && is_array($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]) && (isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['regexp']) && !preg_match($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['regexp'], $style_n_v[2], $m) || isset($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['neg_regexp']) && preg_match($scrub_config['allowed_tags'][$tagname]['allowed_styles'][$style]['neg_regexp'], $style_n_v[2], $m))) { continue; } array_push($styleAttrRules, $rules[$ii]); } } else { array_push($keepAttrs, $attrs[$i]); } } if (count($styleAttrRules) > 0) { array_push($keepAttrs, 'style="' . join($styleAttrRules, '; ') . '"'); } if (count($keepAttrs) > 0) { END_TIMER('DAX_SCRUB_tag'); return array(true, $open_tag . ' ' . join($keepAttrs, ' ') . $close_tag, false); } END_TIMER('DAX_SCRUB_tag'); return array(true, $open_tag . $close_tag, true); } else { END_TIMER('DAX_SCRUB_tag'); return array(false, '', true); } }
public function updateEntireRepoAction($tag, $user) { set_time_limit(0); $cmd = ''; $command_output = ''; ### Prepare for a MASS HEAD update if updating to HEAD $doing_indiv_dir_update = array(); if ($tag == 'HEAD') { $head_update_cmd = "svn update"; START_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $this->log_repo_action($head_update_cmd, 'entire_repo', $user); $command_output .= shell_exec($this->stage->config('repo_cmd_prefix') . "{$head_update_cmd} 2>&1 | cat -"); END_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $cmd .= "\n" . (strlen($cmd) ? ' ; ' : '') . $head_update_cmd; } else { ############################# ### Step 1 : First find any files that we have tags for but don't exist ### Start out by updating all rows in the tag table as mass_edit=1 ### as we delete and update, the ones that have tags will be set back to 0 $rv = dbh_do_bind("UPDATE file_tag SET mass_edit=1 AND tag=?", $tag); $command_output = ''; $status = $this->get_dir_status(); foreach (preg_split('/\\n/', $status) as $line) { if (preg_match('/^\\s*[A-Z]?\\s*\\d+\\s+(\\d+)\\s+\\S+\\s+(\\S.*)$/', $line, $m)) { $cur_rev = $m[1]; $file = rtrim($m[2], "\n\r"); /// Override this with the SLOW, but accurate alternate. This turns a 2 min update into a 2+ hour update list($cur_rev) = $this->get_current_rev($file); ### Skip dirs in SVN (for now)... if (is_dir($this->stage->env()->repo_base . '/' . $file)) { continue; } ### We could be cache-ing the tags here, but in some repos with long file paths and hundreds of thousands of files, we would run out of memory # ### See what the tag is... # $sth = dbh_query_bind("SELECT revision FROM file_tag WHERE file = ? AND tag = ?", $file, $tag); # $old_rev = $sth->fetch(PDO::FETCH_NUM); # $sth->closeCursor(); ### ALL we are doing for the files that exist for this loop is marking mass_edit as off $rv = dbh_do_bind("UPDATE file_tag SET mass_edit=0 WHERE file = ? AND tag = ?", $file, $tag); } } ############################# ### Step 2 : Update the files that didn't exist... ### The rows the mass_edit still need to be Un-tagged... ### See what the tag was before... $sth = dbh_query_bind("SELECT file,revision FROM file_tag WHERE mass_edit=1 AND tag=?", $tag); while (list($file, $rev) = $sth->fetch(PDO::FETCH_NUM)) { /// Each loop, do a $individual_file_rev_updates instead of globally $individual_file_rev_updates = array(); $dir_test = $file; ### Before we do Inidividual Tag updates on files the containing dirs must exist $dirs_to_update = array(); while (!empty($dir_test) && !is_dir(dirname($this->stage->env()->repo_base . "/{$dir_test}")) && $this->stage->env()->repo_base != dirname($this->stage->env()->repo_base . "/{$dir_test}") && !array_key_exists(dirname($dir_test), $doing_indiv_dir_update)) { $dir = dirname($dir_test); $dirs_to_update[] = $dir; $doing_indiv_dir_update[$dir] = true; $dir_test = $dir; // iterate backwards } /// Need to add in parent-first order /// NOTE: we only need to do the parent one, because the in-between ones will be included if (count($dirs_to_update)) { $individual_file_rev_updates[] = array(array_pop($dirs_to_update), $rev); } $individual_file_rev_updates[] = array($file, $rev); foreach ($individual_file_rev_updates as $update) { list($up_file, $up_rev) = $update; $indiv_update_cmd = "svn update -r{$up_rev} " . escapeshellcmd($up_file); START_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $this->log_repo_action($indiv_update_cmd, 'entire_repo', $user); $command_output .= shell_exec($this->stage->config('repo_cmd_prefix') . "{$indiv_update_cmd} 2>&1 | cat -"); END_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $cmd .= "\n" . (strlen($cmd) ? ' ; ' : '') . $indiv_update_cmd; } } $sth->closeCursor(); $rv = dbh_do_bind("UPDATE file_tag SET mass_edit=0 WHERE tag=?", $tag); ############################# ### Step 3 : NOW, get a new Status output, and go through again, now that all files are present and set everything to the right tags ### Reset Cache on dir status unset($this->repo_cache['dir_status']['*ROOTDIR*']); $status = $this->get_dir_status(); foreach (preg_split('/\\n/', $status) as $line) { if (preg_match('/^\\s*[A-Z]?\\s*\\d+\\s+(\\d+)\\s+\\S+\\s+(\\S.*)$/', $line, $m)) { $cur_rev = $m[1]; $file = rtrim($m[2], "\n\r"); if (is_dir($this->stage->env()->repo_base . "/{$file}")) { continue; } /// Each loop, do a $individual_file_rev_updates instead of globally $individual_file_rev_updates = array(); ### Get the tag rev for this file... $sth = dbh_query_bind("SELECT revision FROM file_tag WHERE file = ? AND tag = ?", $file, $tag); $rev = $sth->fetch(PDO::FETCH_NUM); $sth->closeCursor(); if (!empty($rev)) { $dir_test = $file; ### Before we do Inidividual Tag updates on files the containing dirs must exist $dirs_to_update = array(); while (!empty($dir_test) && !is_dir(dirname($this->stage->env()->repo_base . "/{$dir_test}")) && $this->stage->env()->repo_base != dirname($this->stage->env()->repo_base . "/{$dir_test}") && !array_key_exists(dirname($dir_test), $doing_indiv_dir_update)) { $dir = dirname($dir_test); $dirs_to_update[] = $dir; $doing_indiv_dir_update[$dir] = true; $dir_test = $dir; // iterate backwards } /// Need to add in parent-first order /// NOTE: we only need to do the parent one, because the in-between ones will be included if (count($dirs_to_update)) { # bug("Parent Dir update", $file); $individual_file_rev_updates[] = array(array_pop($dirs_to_update), $rev[0]); } else { if ($cur_rev != $rev[0]) { # bug("Regular update", $file); $individual_file_rev_updates[] = array($file, $rev[0]); } } } else { list($first_rev, $error) = $this->get_first_rev($file); # bug("NO TAG, intent-to-rm update", $file, $first_rev); if (empty($error)) { $rev_before_first = $first_rev - 1; $individual_file_rev_updates[] = array($file, $rev_before_first); } } /// Do updates... foreach ($individual_file_rev_updates as $update) { list($up_file, $up_rev) = $update; $indiv_update_cmd = "svn update -r{$up_rev} " . escapeshellcmd($up_file); START_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $this->log_repo_action($indiv_update_cmd, 'entire_repo', $user); $command_output .= shell_exec($this->stage->config('repo_cmd_prefix') . "{$indiv_update_cmd} 2>&1 | cat -"); END_TIMER('REPO_CMD', PROJECT_PROJECT_TIMERS); $cmd .= "\n" . (strlen($cmd) ? ' ; ' : '') . $indiv_update_cmd; } } } } if (empty($command_output)) { $command_output = '</xmp><i>No output</i>'; } return array($cmd, $command_output); }
<?php defined('LOAD_SAFE') or die('Server Error'); $included_files = get_included_files(); if ($gzip) { $output2 = gzcompress(ob_get_contents()); $page_size = "Gzip: " . mb_strlen($output2) / 1024; } else { $page_size = "None: " . ob_get_length() / 1024; } $t_ = array('TEMPLATE_PATH' => $configuration->config_values['template']['template_dir'] . "/" . $configuration->config_values['template']['default_template'], 'PAGE_SIZE' => substr($page_size, 0, 10) . "kb", 'COPYRIGHT' => $configuration->config_values['website']['copy'], 'LOAD_TIME' => END_TIMER($start_time) . "sec", 'FILES_LOADED' => count($included_files) . " Files Loaded"); $TEMPLATE->load("footer.tpl"); $TEMPLATE->assign($t_); $TEMPLATE->publish();
public function cache_statuses($files) { global $REPO_CMD_PREFIX, $MAX_BATCH_SIZE, $MAX_BATCH_STRING_SIZE; $cache_key = 'status'; ### Batch and run the command while (count($files) > 0) { $round = array(); $round_str = ''; while ($files && $round < $MAX_BATCH_SIZE && strlen($round_str) < $MAX_BATCH_STRING_SIZE) { $file = array_shift($files); ### Skip ones whos parent dir ! exists $parent_dir = dirname($file); if (!is_dir($_SERVER['PROJECT_REPO_BASE'] . "/{$parent_dir}")) { continue; } array_push($round, $file); $round_str .= " \"{$file}\""; } $round_checkoff = array_flip($round); if (PROJECT_PROJECT_TIMERS) { START_TIMER('REPO_CMD'); } $all_entries = `{$REPO_CMD_PREFIX}cvs status {$round_str} 2>&1 | cat`; # bug substr($all_entries, -200); if (PROJECT_PROJECT_TIMERS) { END_TIMER('REPO_CMD'); } foreach (preg_split('@===================================================================+\\n@', $all_entries) as $entry) { if (preg_match('/^\\s*$/s', $entry, $m)) { continue; } ### Get the filename if (preg_match('@Repository revision:\\s*[\\d\\.]+\\s*/sandbox/cvsroot/(?:project/)?(.+?),v\\n@', $entry, $m)) { $file = $m[1]; array_shift($round); } else { if (preg_match('@^File: (?:no file )?(.+?)\\s+Status@', $entry, $m)) { $file = $m[1]; if (preg_match('@/\\Q$file\\E$@', $round[0], $m)) { $file = array_shift($round); } else { # bug [$entry, $file]; } } else { # bug [$entry]; # silently skip continue; } } ### Cache if (!array_key_exists($round_checkoff[$file])) { continue; # BUG [$entry, $round, $file,$round_checkoff]; # return trigger_error("file not in round", E_USER_ERROR); } unset($round_checkoff[$file]); $this->repo_cache[$cache_key][$file] = $entry; } } }
<?php if (STARK_EXTEND_PROFILE) { END_TIMER('Stark__Extend->include overhead'); } if (STARK_EXTEND_PROFILE) { RESUME_TIMER('Stark__Extend->import_scope'); } foreach ($GLOBALS['__Stark__Extend__object__']->scope()->vars_keys() as $__Stark__Extend__import_var__) { ${$__Stark__Extend__import_var__} =& $GLOBALS['__Stark__Extend__object__']->scope()->get_var($__Stark__Extend__import_var__); } unset($__Stark__Extend__import_var__); if (STARK_EXTEND_PROFILE) { END_TIMER('Stark__Extend->import_scope'); }
/** * report_timers() - Print a report of all timers * * See the {@link debug.inc.php file-level docs} for an example if this output. */ function report_timers() { global $BUG_ON, $BUG_TIME_I, $BUG_TIMERS, $BUG_TIMESEQ, $BUG_TIMEX, $TIMER_LOG; if (!$BUG_ON && count($TIMER_LOG) == 0) { return true; } if (!empty($BUG_TIMERS) && (count($BUG_TIMERS) != 1 || !isset($BUG_TIMERS['all_global']))) { END_TIMER('all_global'); ### Print out logs if requested if (count($TIMER_LOG)) { foreach ($TIMER_LOG as $key => $ary) { if (is_array($ary)) { list($log, $format) = $ary; } else { $log = $ary; $format = 'default'; } $the_time = is_array($BUG_TIMERS[$key]) ? $BUG_TIMERS[$key][0] : $BUG_TIMERS[$key]; ### Formats (we ignore errors writing, too bad if they didn't do their homework) if ($format == 'csv_w_uri') { file_put_contents($log, '"' . date("Y-m-d H:i:s", time()) . '",' . sprintf("%.6f", $the_time) . "," . $BUG_TIMEX[$key][0] . ',"' . $_SERVER['REQUEST_URI'] . '"' . "\n", FILE_APPEND); } else { file_put_contents($log, time() . "," . sprintf("%.6f", $the_time) . "," . $BUG_TIMEX[$key][0] . "\n", FILE_APPEND); } } } ### Print a Table report of the timers if ($BUG_ON) { $nl = isset($_SERVER['REQUEST_METHOD']) ? "</td></tr><tr><td>\n" : "\n"; $sp = isset($_SERVER['REQUEST_METHOD']) ? " " : " "; $tmp_ary = array_keys($BUG_TIMERS); usort($tmp_ary, create_function('$a,$b', 'global $BUG_TIMESEQ; return( ($BUG_TIMESEQ[$a] == $BUG_TIMESEQ[$b]) ? 0 : ($BUG_TIMESEQ[$a] < $BUG_TIMESEQ[$b]) ? -1 : 1);')); $report_ary = array(); foreach ($tmp_ary as $_) { $the_time = is_array($BUG_TIMERS[$_]) ? $BUG_TIMERS[$_][0] : $BUG_TIMERS[$_]; $report_ary[] = array($_, sprintf("%.6f", $the_time) . "s", "x{$sp}" . $BUG_TIMEX[$_][0] . ($BUG_TIMEX[$_][1] != $BUG_TIMEX[$_][0] ? "{$sp}/{$sp}" . $BUG_TIMEX[$_][1] : '') . "{$sp}{$sp}", "averaging{$sp}" . sprintf("%.6f", $the_time / $BUG_TIMEX[$_][0]) . "s", "which" . $sp . "is{$sp}" . sprintf("%.6d", 1 / ($the_time / $BUG_TIMEX[$_][0])) . "/s", "totalling{$sp}" . ($BUG_TIMERS['all_global'] ? sprintf("%.2f", $the_time / $BUG_TIMERS['all_global'] * 100) : '') . "%{$sp}" . "of{$sp}" . "all_global"); } ### HTML table output if ($_SERVER['REQUEST_METHOD']) { print '<br/><div style="display: block; color: red; margin: 0; padding: 0; text-align: left"><table width="60%"><tr><td>'; print "TIMERS:{$nl}"; foreach ($report_ary as $line) { print join("</td><td>\n", $line) . $nl; } print "</td></tr></table></div>"; } else { $f_widths = array(23, 11, 10, 20, 17, false); foreach ($report_ary as $line) { $join_ary = array(); foreach ($line as $i => $str) { $join_ary[] = bug_fill_width($f_widths[$i]); } print join(" ", $join_ary); } } } } }