How to extract execution timing (Initialization, Execution, Termination times) from Simulink Test?
    4 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I am trying to extract the execution timing (Initialization, Execution, and Termination times) from my Simulink Test Manager Baseline Tests to analyze different modes for faster execution.
What I Am Doing:
- run multiple Baseline Tests programmatically from a Simulink Test Suite using MATLAB code.
- tried to extract the Initialization, Execution, and Termination times after each test run.
- tried using Simulink.SimulationOutput.SimulationMetadata.TimingInfo. But this does not work in my case.
% Define the test file path
testFilePath = 'testfile.mldatx';
% Load the test file
sltest.testmanager.load(testFilePath);
% Get all test files currently loaded
testFiles = sltest.testmanager.getTestFiles();
% Debugging: Check if test files are loaded
if isempty(testFiles)
    error("[ERROR] No test files found! Ensure the test file exists and is valid.");
end
fprintf("[DEBUG] Number of Test Files: %d\n", numel(testFiles));
% List all test files
for i = 1:numel(testFiles)
    fprintf("[DEBUG] Test File %d: %s\n", i, testFiles(i).Name);
end
% Select the first test file
testFile = testFiles(1);
% Get all test suites inside the test file
testSuites = testFile.getTestSuites();
fprintf("[DEBUG] Number of Test Suites in File: %d\n", numel(testSuites));
% List all test suites
for i = 1:numel(testSuites)
    fprintf("[DEBUG] Test Suite %d: %s\n", i, testSuites(i).Name);
end
% Select the first test suite
testSuite = testSuites(1);
% Get all test cases in this suite
testCases = testSuite.getTestCases();
fprintf("[DEBUG] Number of Test Cases in Suite '%s': %d\n", testSuite.Name, numel(testCases));
% List all test cases
for i = 1:numel(testCases)
    fprintf("[DEBUG] Test Case %d: %s\n", i, testCases(i).Name);
end
% Select the first test case
testCase = testCases(1);
fprintf("[DEBUG] Selected Test Case: %s\n", testCase.Name);
% Run the test case
fprintf("[DEBUG] Running the test case: %s\n", testCase.Name);
resultSet = run(testCase);
% Get test case results
testCaseResults = resultSet.getTestCaseResults();
fprintf("[DEBUG] Number of Test Case Results: %d\n", numel(testCaseResults));
% List test case results
for i = 1:numel(testCaseResults)
    fprintf("[DEBUG] Test Case Result %d: %s\n", i, testCaseResults(i).Name);
end
% Select the first test case result
testResult = testCaseResults(1);
% Check available properties in test case result
fprintf("[DEBUG] Listing available properties in test case result:\n");
disp(properties(testResult));
% extracting Simulation Metadata
if isprop(testResult, 'SimulationMetadata')
    simMetadata = testResult.SimulationMetadata;
    fprintf("[DEBUG] Listing available properties in SimulationMetadata:\n");
    disp(properties(simMetadata));
    % extract Timing Info
    if isprop(simMetadata, 'TimingInfo')
        timingInfo = simMetadata.TimingInfo;
        fprintf("\nExecution Timing Summary:\n");
        fprintf("  Initialization Time   : %.4f sec\n", timingInfo.InitializationElapsedWallTime);
        fprintf("  Execution Time       : %.4f sec\n", timingInfo.ExecutionElapsedWallTime);
        fprintf("  Termination Time     : %.4f sec\n", timingInfo.TerminationElapsedWallTime);
        fprintf("  Total Simulation Time: %.4f sec\n", timingInfo.TotalElapsedWallTime);
    else
        fprintf("[ERROR] No 'TimingInfo' found in SimulationMetadata.\n");
    end
else
    fprintf("[ERROR] No 'SimulationMetadata' property found in test result.\n");
end
% extracting Baseline Run (in case the timing is stored there)
if isprop(testResult, 'Baseline')
    baselineRun = testResult.getBaselineRun();
    fprintf("[DEBUG] Listing available properties in Baseline Run:\n");
    disp(properties(baselineRun));
end
% Unload test file to free memory
fprintf("[DEBUG] Unloading test file to free memory.\n");
sltest.testmanager.clear;
0 comentarios
Respuestas (1)
  Karan Singh
      
 el 6 de Feb. de 2025
        How about using a "tic-toc". 
https://in.mathworks.com/help/matlab/ref/tic. || html https://in.mathworks.com/help/matlab/ref/toc.html 
This way you can manually measure execution time by wrapping "run(testCase)" inside "tic" and "toc".
tic; % Start timing
resultSet = run(testCase); % Run test
executionTime = toc; % End timing
fprintf("\nManual Execution Timing:\n");
fprintf("  Total Execution Time: %.4f sec\n", executionTime);
Karan
Ver también
Categorías
				Más información sobre Inputs en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

