pts-core: Add some old logging code
This commit is contained in:
@@ -474,7 +474,7 @@ class phoromatic extends pts_module_interface
|
||||
|
||||
if(pts_client::$pts_logger == false)
|
||||
{
|
||||
pts_client::$pts_logger = new pts_logger();
|
||||
pts_client::$pts_logger = new pts_logger(null, null, true, true);
|
||||
}
|
||||
pts_client::$pts_logger->log(pts_core::program_title() . ' [' . PTS_CORE_VERSION . '] starting Phoromatic client');
|
||||
|
||||
|
||||
@@ -809,6 +809,7 @@ class pts_client
|
||||
self::$display = new pts_concise_display_mode();
|
||||
break;
|
||||
}
|
||||
pts_logger::update_log_cli_output_state();
|
||||
}
|
||||
public static function program_requirement_checks($only_show_required = false, $always_report = false)
|
||||
{
|
||||
|
||||
@@ -25,7 +25,7 @@ class pts_logger
|
||||
{
|
||||
private $log_file = null;
|
||||
|
||||
public function __construct($log_file = null, $file_name = null, $flush_log_if_present = true)
|
||||
public function __construct($log_file = null, $file_name = null, $flush_log_if_present = true, $allow_including_std_output = false)
|
||||
{
|
||||
if($log_file == null)
|
||||
{
|
||||
@@ -45,9 +45,6 @@ class pts_logger
|
||||
}
|
||||
}
|
||||
|
||||
// if(file_exists($log_file))
|
||||
// unlink($log_file);
|
||||
|
||||
if($flush_log_if_present || !file_exists($log_file))
|
||||
{
|
||||
// Flush log
|
||||
@@ -59,6 +56,32 @@ class pts_logger
|
||||
|
||||
if(is_writable($log_file))
|
||||
$this->log_file = $log_file;
|
||||
|
||||
if($allow_including_std_output && pts_client::$display)
|
||||
{
|
||||
// Add to list of loggers indicating interest/relevance for possibly including std/cli output
|
||||
pts_logger_intercept_display::$loggers_interested_in_std_output[$this->log_file] = &$this;
|
||||
self::update_log_cli_output_state();
|
||||
}
|
||||
}
|
||||
public static function update_log_cli_output_state()
|
||||
{
|
||||
if(pts_env::read('LOG_CLI_OUTPUT'))
|
||||
{
|
||||
// enable
|
||||
if(pts_client::$display instanceof pts_display_mode_interface && !empty(pts_logger_intercept_display::$loggers_interested_in_std_output))
|
||||
{
|
||||
pts_client::$display = new pts_logger_intercept_display(pts_client::$display);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// disable/restore to original
|
||||
if(pts_client::$display instanceof pts_logger_intercept_display && pts_client::$display->underlying_display instanceof pts_display_mode_interface)
|
||||
{
|
||||
pts_client::$display = pts_client::$display->underlying_display;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static function default_log_file_path()
|
||||
{
|
||||
@@ -158,4 +181,66 @@ class pts_logger
|
||||
}
|
||||
}
|
||||
|
||||
class pts_logger_intercept_display
|
||||
{
|
||||
public $underlying_display;
|
||||
public static $loggers_interested_in_std_output = array();
|
||||
|
||||
public function __construct($display)
|
||||
{
|
||||
$this->underlying_display = $display;
|
||||
}
|
||||
public function __call($method, $args)
|
||||
{
|
||||
$intercepted_text = '';
|
||||
static $line_queued = '';
|
||||
|
||||
if($this->underlying_display instanceof pts_display_mode_interface)
|
||||
{
|
||||
foreach($args as &$arg)
|
||||
{
|
||||
// Workaround PHP warning for pts_display_mode_interface args that expect refs passed
|
||||
$arg = &$arg;
|
||||
}
|
||||
ob_start();
|
||||
call_user_func_array(array($this->underlying_display, $method), $args);
|
||||
$intercepted_text = ob_get_contents();
|
||||
ob_end_clean();
|
||||
echo $intercepted_text;
|
||||
}
|
||||
if(!empty($intercepted_text) && !empty(pts_logger_intercept_display::$loggers_interested_in_std_output))
|
||||
{
|
||||
$line_queued .= pts_user_io::strip_ansi_escape_sequences($intercepted_text);
|
||||
|
||||
// Wait until a line is printed in full before flushing to log due to how the display mode interface can build up strings
|
||||
if(substr($line_queued, -1) == "\n")
|
||||
{
|
||||
$lq_rebuild = '';
|
||||
foreach(explode(PHP_EOL, $line_queued) as $line)
|
||||
{
|
||||
if(function_exists('preg_replace'))
|
||||
{
|
||||
$line = preg_replace('/\s+/', ' ', $line);
|
||||
}
|
||||
// Trim excess gunk not useful for log
|
||||
$line = trim(rtrim(trim($line), '.'), '=');
|
||||
|
||||
if(!empty($line))
|
||||
{
|
||||
$lq_rebuild .= $line . PHP_EOL . str_repeat(' ', 27);
|
||||
}
|
||||
}
|
||||
foreach(pts_logger_intercept_display::$loggers_interested_in_std_output as &$logger)
|
||||
{
|
||||
if($logger)
|
||||
{
|
||||
$logger->log(trim($lq_rebuild));
|
||||
}
|
||||
}
|
||||
$line_queued = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
@@ -165,7 +165,7 @@ class pts_stress_run_manager extends pts_test_run_manager
|
||||
$this->sensor_data_archived = array();
|
||||
$this->sensor_data_archived_units = array();
|
||||
$this->sensor_data_archived_identifiers = array();
|
||||
$this->stress_logger = new pts_logger(null, 'phoronix-test-suite-stress-' . date('ymdHi') . '.log');
|
||||
$this->stress_logger = new pts_logger(null, 'phoronix-test-suite-stress-' . date('ymdHi') . '.log', true, true);
|
||||
$this->stress_logger->log('Log Initialized');
|
||||
pts_env::set('FORCE_TIMES_TO_RUN', 1);
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ class pts_test_run_manager
|
||||
|
||||
// 1/true is normal auto mode, 2 = auto + default benchmark mode
|
||||
$this->auto_mode = $auto_mode;
|
||||
$this->benchmark_log = new pts_logger(null, 'phoronix-test-suite-benchmark.log');
|
||||
$this->benchmark_log = new pts_logger(null, 'phoronix-test-suite-benchmark.log', true, true);
|
||||
$this->test_run_success_counter = 0;
|
||||
$this->remove_tests_on_completion = pts_config::read_bool_config('PhoronixTestSuite/Options/Testing/RemoveTestInstallOnCompletion', 'FALSE') || pts_env::read('REMOVE_TESTS_ON_COMPLETION');
|
||||
|
||||
|
||||
@@ -383,6 +383,14 @@ class pts_env
|
||||
'value_type' => 'bool',
|
||||
'advertise_in_phoromatic' => true,
|
||||
),
|
||||
'LOG_CLI_OUTPUT' => array(
|
||||
'description' => '[EXPERIMENTAL] When this option is enabled, the Phoronix Test Suite standard output from the terminal will be logged to any relevant Phoronix Test Suite / Phoromatic log file. This is mainly useful for debugging purposes and if wishing to always archive the standard output as part of Phoronix Test Suite logs.',
|
||||
'default' => false,
|
||||
'usage' => array('all'),
|
||||
'value_type' => 'bool',
|
||||
'advertise_in_phoromatic' => true,
|
||||
'onchange' => 'pts_logger::update_log_cli_output_state',
|
||||
),
|
||||
);
|
||||
|
||||
public static function read($name, &$overrides = null, $fallback_value = false)
|
||||
|
||||
@@ -389,7 +389,7 @@ class pts_result_viewer_embed
|
||||
$desc = str_replace(array(' Monitor', $res_desc_shortened ,'()' ,')', ' - '), '', $c_ro->get_arguments_description_shortened(false));
|
||||
$dindex = $desc == $res_desc_shortened || empty($desc) ? $c_ro->test_profile->get_result_scale() : $desc;
|
||||
$graph = pts_render::render_graph_process($c_ro, $result_file, false, $extra_attributes);
|
||||
if($c_ro->test_profile->get_result_scale() == 'Watts')
|
||||
if($c_ro->test_profile->get_result_scale() == 'Watts' && $graph)
|
||||
{
|
||||
$run_counts_for_identifier = array();
|
||||
foreach($result_object->test_result_buffer->buffer_items as $bi)
|
||||
|
||||
@@ -86,7 +86,7 @@ setlocale(LC_ALL, 'C');
|
||||
// Needed for shutdown functions
|
||||
// declare(ticks = 1);
|
||||
|
||||
$sent_command = strtolower(str_replace('-', '_', (isset($argv[1]) ? $argv[1] : null)));
|
||||
$sent_command = isset($argv[1]) && !empty($argv[1]) ? strtolower(str_replace('-', '_', $argv[1])) : '';
|
||||
$quick_start_options = array('dump_possible_options');
|
||||
pts_define('QUICK_START', in_array($sent_command, $quick_start_options));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user