-
Nicola Vigano authored
Signed-off-by:
Nicola Vigano <nicola.vigano@esrf.fr>
Nicola Vigano authoredSigned-off-by:
Nicola Vigano <nicola.vigano@esrf.fr>
logviewOar.m 5.28 KiB
function logviewOar(queryname, file_type)
% LOGVIEWOAR Read log file from OAR
% logviewOar(queryname, [file_type])
% -------------------------------------------------
%
% Version 002 17-11-2011 by LNervo
% Also the jobid can be use as input to look at .err .out files
%
% Version 001 27-10-2011 by LNervo
% Read .log file for given function or job array id
%
% INPUT:
% queryname = function name <string>
% arrayid <double> (if not known it will ask which one
% from the existing id(s))
% jobid <double>
%
% file_type = type of logfile
% <string> [{'log'} | 'err' | 'out' | 'oar' | 'params']
%
if (~exist('file_type', 'var') || isempty(file_type))
file_type = 'log';
end
if (~ismember(file_type, {'log', 'err', 'out', 'oar', 'params'}))
error('logviewOar:wrong_file_type', ...
['File type %s not allowed! It should be chosen among: ' ...
'[ ''err'' | ''out'' | ''log'' | ''params'' | ''oar'' ]'], ...
file_type);
end
if (~exist('oarparameters.mat', 'file'))
error('OAR:no_parameters_found', ...
'You must run this function from the directory in which there is the oarparameters.mat file.')
end
log_file_dir = fullfile('/tmp_14_days','oar','log');
% Load of parameters file (if exists)
oarparameters = [];
load('oarparameters.mat');
ask = false;
if (ischar(queryname))
func_name = queryname;
ask = true;
if (ismember(file_type, {'err', 'out'}))
error('logviewOar:wrong_file_type', ...
'Can''t use (''err'', ''out'') options when only using function name')
end
else
query_id = queryname;
oar_stats = gtOarGetStats(query_id, {'name','job_array_id','cpuset_name'});
func_name = oar_stats(1).('name');
selected_array_id = str2double(char(oar_stats(1).('job_array_id')));
% We match "_[numbers]" because some users have numbers in their usernames
% (experiments) at the ESRF
job_id = regexp(oar_stats(1).('cpuset_name'), '_\d+', 'match');
job_id = str2double(job_id{1}(2:end));
end
array_ids = get_arrays_from_function(oarparameters, func_name);
oar_stats = gtOarGetStats(array_ids, ...
{'job_array_id', 'cpuset_name', 'job_array_index', ...
'submissionTime', 'resubmit_job_id'});
if (ask) % idarray is not known
selected_array_id = select_id('array', func_name, array_ids);
end
ind = find(array_ids == selected_array_id);
if (~isempty(ind))
switch (lower(file_type))
case 'log'
file_name = get_log_file(log_file_dir, func_name, oar_stats(ind), file_type, selected_array_id);
case {'err', 'out'}
file_name = get_log_file(log_file_dir, func_name, oar_stats(ind), file_type, job_id);
case {'oar', 'params'}
file_name = get_submission_file(func_name, oar_stats(ind), file_type);
end
if (~exist(file_name, 'file'))
error('logviewOar:wrong_file_name', ...
'File not found: %s\n', file_name)
end
read_file(file_name, func_name, oar_stats(ind))
end
end % end of function
function read_file(file_name, func_name, oar_stats)
disp(' ')
disp('-----------------------------------------------------------------------------------------')
fprintf('Reading:\n - file: %s\n - array: %s\n - function: %s\n - submitted: %s\n', ...
file_name, oar_stats.('job_array_id'), func_name, oar_stats.('submissionTime'))
disp('-----------------------------------------------------------------------------------------')
type(file_name);
disp('-----------------------------------------------------------------------------------------')
disp(' ')
end
function base_user_file_name = get_base_filename(fname, oar_stats)
base_user_file_name = [fname '-' getenv('USER') '_' oar_stats.('resubmit_job_id')];
end
function filename = get_log_file(log_file_dir, func_name, oar_stats, file_type, id)
base_user_file_name = get_base_filename(func_name, oar_stats);
filename = fullfile(log_file_dir, sprintf('oar.%s.%d.%s', base_user_file_name, id, file_type));
end
function filename = get_submission_file(func_name, oar_stats, file_type)
base_user_file_name = get_base_filename(func_name, oar_stats);
filename = sprintf('%s.%s', base_user_file_name, file_type);
end
function array_ids = get_arrays_from_function(oar_parameters, func_name)
if (~isfield(oar_parameters, func_name))
error('logviewOar:wrong_function_name', 'Function %s was not found in OAR parameters', func_name);
end
subnames = fieldnames(oar_parameters.(func_name));
array_ids = cellfun(@(x)str2double(x(6:end)), subnames);
if (isempty(array_ids))
error('logviewOar:wrong_function', ...
'No array id(s) found for %s!', func_name)
end
end
function selected = select_id(id_type, func_name, list_of_ids)
fprintf('Found %d %s_id(s) for %s:\n', numel(list_of_ids), id_type, func_name)
fprintf(' - %d\n', list_of_ids)
selected = inputwdefaultnumeric( ...
sprintf('Which %s_id do you want to look at? ', id_type), ...
num2str(list_of_ids(end)));
end