classdef StackTaskSection < coder.profile.StackSection
    %STACKTASKSECTION contains the stack information of a task

%   Copyright 2021-2022 The MathWorks, Inc.
    
    properties (GetAccess=public, SetAccess=private, Dependent = true, Hidden=true)
        SamplePeriod;
        SampleOffset;
        SlotUtilization;
    end

    properties (GetAccess=public, SetAccess=private)
        MaximumStackUsage;
        MaximumStackUsageTime;
        AverageStackUsage;
        MinimumStackUsage;
        MinimumStackUsageTime;
        MinimumCallDepth;
        MaximumCallDepth;
        MinimumCallDepthTime;
        MaximumCallDepthTime;
        StackUsage;
        StackTime;
    end
    
    methods 
       
        function val = get.SamplePeriod(this)
            lSampleTime = this.TraceInfo.getSampleTime;
            val = lSampleTime(1);
        end
        
        function val = get.SampleOffset(this)
            lSampleTime = this.TraceInfo.getSampleTime;
            val = lSampleTime(2);
        end
        
        function vals = get.SlotUtilization(this)
            lSampleTime = getSampleTime(getTraceInfo(this));
            lPeriod = lSampleTime(1);
            vals = getSlotUtilization(this.TimerData, this.SectionNumber, lPeriod);
        end
    end
    
    methods (Access=public, Hidden=true)
        function val = getName(this)
            lTraceInfo = this.getTraceInfo;
            val = lTraceInfo.getName();
        end
        
        function this = StackTaskSection(lStackData, lSectionNumber, lSectionId, lTraceInfo, lUniqueID)
            util = lStackData.getTaskUsage(lSectionId);
            this@coder.profile.StackSection(lSectionNumber, lSectionId, lTraceInfo, lUniqueID, util.numCalls);
            this.MinimumStackUsage = uint64(util.minUsage);
            this.MinimumStackUsageTime = util.minSimTime;
            this.AverageStackUsage = uint64(util.avgUsage);
            this.MaximumStackUsage = uint64(util.maxUsage);
            this.MaximumStackUsageTime = util.maxSimTime;
            this.MinimumCallDepth = util.minDepth;
            this.MaximumCallDepth = util.maxDepth;
            this.MinimumCallDepthTime = util.minDepthTime;
            this.MaximumCallDepthTime = util.maxDepthTime;
            this.StackUsage = util.stackUsage;
            this.StackTime = util.stackTime;
        end
    end
end
