image thumbnail

Estimating memory footprint of generated code

by

 

11 Jun 2009 (Updated )

This tool outputs the code size and data footprint for code generated with Embedded Coder(TM).

exp_target_make_rtw_hook(hookMethod,modelName,rtwroot,templateMakefile,buildOpts,buildArgs)
function exp_target_make_rtw_hook(hookMethod,modelName,rtwroot,templateMakefile,buildOpts,buildArgs)
% EXP_TARGET_MAKE_RTW_HOOK - 
%
% hookMethod:
%   Specifies the stage of the RTW build process.  Possible values are
%   entry, before_tlc, after_tlc, before_make, after_make and exit, etc.
%
% modelName:
%   Name of model.  Valid for all stages.
%
% rtwroot:
%   Reserved.
%
% templateMakefile:
%   Name of template makefile.  Valid for stages 'before_make' and 'exit'.
%
% buildOpts:
%   Valid for stages 'before_make' and 'exit', a MATLAB structure
%   containing fields
%
%   modules:
%     Char array specifying list of generated C files: model.c, model_data.c,
%     etc.
%
%   codeFormat:
%     Char array containing code format: 'RealTime', 'RealTimeMalloc',
%     'Embedded-C', and 'S-Function'
%
%   noninlinedSFcns:
%     Cell array specifying list of non-inlined S-Functions.
%
%   compilerEnvVal:
%     String specifying compiler environment variable value, e.g.,
%     D:\Applications\Microsoft Visual
%
% buildArgs:
%   Char array containing the argument to make_rtw.  When pressing the build
%   button through the Configuration Parameter Dialog, buildArgs is taken
%   verbatim from whatever follows make_rtw in the make command edit field.
%   From MATLAB, it's whatever is passed into make_rtw.  
%
%   This file implements these buildArgs:
%
% You are encouraged to add other configuration options, and extend the
% various callbacks to fully integrate ERT into your environment.
  
  switch hookMethod
   case 'error'
    % Called if an error occurs anywhere during the build.  If no error occurs
    % during the build, then this hook will not be called.  Valid arguments
    % at this stage are hookMethod and modelName. This enables cleaning up
    % any static or global data used by this hook file.
    disp(['### Real-Time Workshop build procedure for model: ''' modelName...
          ''' aborted due to an error.']);
    
   case 'entry'
    % Called at start of code generation process (before anything happens.)
    % Valid arguments at this stage are hookMethod, modelName, and buildArgs.
    disp(sprintf(['\n### Starting Real-Time Workshop build procedure for ', ...
                  'model: %s'],modelName));
    
   case 'before_tlc'
    % Called just prior to invoking TLC Compiler (actual code generation.)
    % Valid arguments at this stage are hookMethod, modelName, and
    % buildArgs
    
   case 'after_tlc'
    % Called just after to invoking TLC Compiler (actual code generation.)
    % Valid arguments at this stage are hookMethod, modelName, and
  
   case 'before_make'
    % Called after code generation is complete, and just prior to kicking
    % off make process (assuming code generation only is not selected.)  All
    % arguments are valid at this stage.
   case 'after_make'
    % Called after make process is complete. All arguments are valid at 
    % this stage.
    
    makertwObj = get_param(modelName, 'MakeRTWSettingsObject');
    buildDirPath = getfield(makertwObj, 'BuildDirectory');
    buildInfo = getfield(makertwObj, 'BuildInfo');
    
    % Get files to extract footprint information 
    nidx = 1;
    for idx=1:length(buildInfo.Src.Files)
        if (~strcmp(buildInfo.Src.Files(idx).FileName, 'ert_main.c'))
            fn = buildInfo.Src.Files(idx).FileName;
            file_names{nidx} = [fn(1:length(fn)-2) '.obj'];
            nidx = nidx + 1;
        end
    end
    nidx = nidx - 1;
    disp(['=== Number of obj files: ' num2str(nidx)]);
    
    outstr = get_footprint(buildDirPath, file_names);
    disp(outstr);
    
   case 'exit'
    % Called at the end of the RTW build process.  All arguments are valid
    % at this stage.
    disp(['### Successful completion of Real-Time Workshop build ',...
          'procedure for model: ', modelName]);    
  end

% LocalWords:  lasterr tlc hookMethod modelName buildArgs RTW disp args findstr
% LocalWords:  LocalParseArgList elseif locReportDifference cs iseq diffs diff
% LocalWords:  slprivate config msg sprintf rtwprivate rtw param getModel

Contact us