function profilingFinalizeCallback(modelName, buildDir, profData)
    % This function is called to finalize the Execution-Time Profiling probes
    % The ExecutionTime variable is created in the workspace and the annotation
    % window is opened

%   Copyright 2017 The MathWorks, Inc.

    workspaceVarName = get_param(modelName, 'CodeExecutionProfileVariable');
    lSaveOptions = get_param(modelName, 'CodeProfilingSaveOptions');
    lTargetInfo = coder.profile.CoderInstrumentationInfo.getTargetInfo(...
                      buildDir, true);
    if lTargetInfo.ticksPerSecond == 0
        lTicksPerSecond = [];
    else
        lTicksPerSecond = lTargetInfo.ticksPerSecond;
    end

    if isfield(lTargetInfo, 'HWCounterUnit')
        lHWCounterUnit = lTargetInfo.HWCounterUnit;
    else
        lHWCounterUnit = '';
    end

    [~, createdVar] = coder.profile.finalizeProfiling(modelName, modelName, ...
                                                      workspaceVarName, profData, ...
                                                      buildDir, buildDir, ...
                                                      lTicksPerSecond, ....
                                                      lHWCounterUnit, ...
                                                      'instrumented', ...
                                                      modelName, ...
                                                      [], ...
                                                      true, ...
                                                      true, ...
                                                      lSaveOptions);
    if ~createdVar
        error(['Variable ' workspaceVarName ' already in the workspace']);
    end
end
