function out = isBlockProfiled(block)
% Return if a block is profiled. The method checks recursively through
% the block hierarchy until either the root block is reached or the
% subsystem is filderd in/out

% Copyright 2018-2019 The MathWorks, Inc.

out = true;
while ~isempty(block) && ~strcmpi(get_param(block, 'type'), 'block_diagram')
cfg = get_param(block, 'CodeProfilingOverride');
if ~strcmpi(cfg, 'inherit')
out = strcmpi(cfg, 'on');
break;
end
block = get_param(block, 'parent');
end
end