Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add execution time metrics #1517

Merged
merged 58 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
c23236c
feat: implement ScopedElapsedTimeRecorder class
HansRobo Jan 28, 2025
b84bae2
feat: record execution time with ScopedElapsedTimeRecorder class
HansRobo Jan 28, 2025
5429178
feat: publish execution time from interpreter
HansRobo Jan 28, 2025
270dc1f
fix: correct time unit conversion
HansRobo Jan 28, 2025
a3c997c
fix: add activate and deactivate process for time publisher in interp…
HansRobo Jan 28, 2025
a484865
feat: add execution_time_test.yaml
HansRobo Jan 28, 2025
a42e4de
refactor: use anchor and aliases in execution_time_test.yaml
HansRobo Jan 28, 2025
017bad1
chore: update threshold for update time in execution_time_test.yaml
HansRobo Jan 28, 2025
a460ab0
Merge branch 'master' into feature/execution_time
HansRobo Jan 28, 2025
5ef2afb
feat: add execution_time_test.yaml into test scenario line-up
HansRobo Jan 28, 2025
fe036f8
fix: correct initialization order
HansRobo Jan 28, 2025
429ec95
refactor: simplify ScopedElapsedTimeRecorder class
HansRobo Jan 28, 2025
a3a3b97
Merge branch 'master' into feature/execution_time
yamacir-kit Jan 30, 2025
60976e7
Merge branch 'master' into feature/execution_time
HansRobo Feb 3, 2025
014bffc
refactor: rename TClock with Clock
HansRobo Feb 4, 2025
4d40bbf
refactor: use ExecutionTimer instead of ScopedElapsedTimeRecorder
HansRobo Feb 5, 2025
e36acb2
refactor: delete unused code
HansRobo Feb 5, 2025
23450f4
fix: delete unavailable include
HansRobo Feb 5, 2025
c7c59ff
chore: move execution_time_test.yaml into optional_workflow.txt
HansRobo Feb 6, 2025
868aae6
chore: change scenario condition for test
HansRobo Feb 6, 2025
2891d3e
feat: create outputs when workflow.sh is executed
HansRobo Feb 6, 2025
4ccc675
feat: add optional workflow execution to BuildAndRun.yaml
HansRobo Feb 6, 2025
75e9908
fix: divide comment step in BuildAndRun.yaml
HansRobo Feb 6, 2025
90e0b6d
Merge branch 'master' into feature/execution_time
HansRobo Feb 6, 2025
8a4bb4b
fix: use comment action
HansRobo Feb 6, 2025
38684cc
fix: correct reading file path
HansRobo Feb 6, 2025
b21f265
fix: set step id to use output correctly
HansRobo Feb 6, 2025
6c8e9e5
fix: handle multiple line output
HansRobo Feb 6, 2025
103f815
fix: use github script to commet file content
HansRobo Feb 7, 2025
8125c23
Merge branch 'master' into feature/execution_time
HansRobo Feb 7, 2025
16f08dc
fix: modify github script
HansRobo Feb 7, 2025
ee00f43
Merge branch 'master' into feature/execution_time
HansRobo Feb 12, 2025
2ad8c6c
chore: simplify failure report
HansRobo Feb 13, 2025
6b3842b
chore: post failure report only when failure scenarios exist
HansRobo Feb 13, 2025
28ddff3
fix: remove const from overwritten variable in github script
HansRobo Feb 13, 2025
34ee822
Merge branch 'master' into feature/execution_time
HansRobo Feb 14, 2025
4177209
Revert "chore: change scenario condition for test"
HansRobo Feb 14, 2025
1b62381
Merge branch 'master' into feature/execution_time
HansRobo Feb 14, 2025
bc38208
Merge branch 'master' into feature/execution_time
HansRobo Feb 14, 2025
0318510
Merge branch 'master' into feature/execution_time
HansRobo Feb 17, 2025
24ee675
refactor: generate UserDefinedValue message for each publishers
HansRobo Feb 18, 2025
2d999c5
chore: use seconds as time unit in execution_time topics
HansRobo Feb 18, 2025
ee50d60
refactor: use minimum captures for lambda
HansRobo Feb 18, 2025
5ece393
chore: make the meaning of test results in comments more accurate
HansRobo Feb 18, 2025
a18008b
Merge branch 'master' into feature/execution_time
HansRobo Feb 18, 2025
30e525c
chore: modify scenario threshold for test
HansRobo Feb 18, 2025
ec974ef
refactor: split workflow.sh into 2 scripts
HansRobo Feb 18, 2025
80cdeaf
refactor: format BuildAndRun.yaml
HansRobo Feb 18, 2025
cd0d1ea
refactor: use NOTE command in pull-request comment for optional scena…
HansRobo Feb 18, 2025
7ebaaed
Merge remote-tracking branch 'origin/master' into feature/execution_time
HansRobo Feb 18, 2025
603273f
Revert "chore: modify scenario threshold for test"
HansRobo Feb 19, 2025
7d343c5
Revert "Revert "chore: modify scenario threshold for test""
HansRobo Feb 20, 2025
ec3360f
refactor: simplify workflow.sh
HansRobo Feb 20, 2025
cefe388
refactor: continuous simplifying workflow.sh
HansRobo Feb 20, 2025
aff3cb4
fix: use correct file path
HansRobo Feb 20, 2025
8bb3cef
Merge branch 'master' into feature/execution_time
HansRobo Feb 20, 2025
b87875a
fix: optional-scenario-test step in BuildAndRun.yaml
HansRobo Feb 20, 2025
d86c9c0
Revert "Revert "Revert "chore: modify scenario threshold for test"""
HansRobo Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <rclcpp_lifecycle/lifecycle_node.hpp>
#include <scenario_simulator_exception/exception.hpp>
#include <simple_junit/junit5.hpp>
#include <tier4_simulation_msgs/msg/user_defined_value.hpp>
#include <utility>

#define INTERPRETER_INFO_STREAM(...) \
Expand All @@ -52,6 +53,15 @@ class Interpreter : public rclcpp_lifecycle::LifecycleNode,

const rclcpp_lifecycle::LifecyclePublisher<Context>::SharedPtr publisher_of_context;

rclcpp_lifecycle::LifecyclePublisher<tier4_simulation_msgs::msg::UserDefinedValue>::SharedPtr
evaluate_time_publisher;

rclcpp_lifecycle::LifecyclePublisher<tier4_simulation_msgs::msg::UserDefinedValue>::SharedPtr
update_time_publisher;

rclcpp_lifecycle::LifecyclePublisher<tier4_simulation_msgs::msg::UserDefinedValue>::SharedPtr
output_time_publisher;

double local_frame_rate;

double local_real_time_factor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2015 TIER IV, Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef OPENSCENARIO_INTERPRETER__UTILITY__SCOPED_ELAPSED_TIME_RECORDER_HPP_
#define OPENSCENARIO_INTERPRETER__UTILITY__SCOPED_ELAPSED_TIME_RECORDER_HPP_

#include <chrono>
#include <cmath>

template <typename TClock = std::chrono::high_resolution_clock>
class ScopedElapsedTimeRecorder
{
public:
explicit ScopedElapsedTimeRecorder(double & output_seconds) : output_seconds(output_seconds) {}

~ScopedElapsedTimeRecorder()
{
output_seconds = std::abs(std::chrono::duration<double>(TClock::now() - start).count());
}

private:
std::chrono::time_point<TClock> start = TClock::now();

double & output_seconds;
};

#endif // OPENSCENARIO_INTERPRETER__UTILITY__SCOPED_ELAPSED_TIME_RECORDER_HPP_
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <openscenario_interpreter/syntax/scenario_object.hpp>
#include <openscenario_interpreter/syntax/speed_condition.hpp>
#include <openscenario_interpreter/utility/overload.hpp>
#include <openscenario_interpreter/utility/scoped_elapsed_time_recorder.hpp>
#include <status_monitor/status_monitor.hpp>
#include <traffic_simulator/data_type/lanelet_pose.hpp>

Expand All @@ -37,6 +38,12 @@ namespace openscenario_interpreter
Interpreter::Interpreter(const rclcpp::NodeOptions & options)
: rclcpp_lifecycle::LifecycleNode("openscenario_interpreter", options),
publisher_of_context(create_publisher<Context>("context", rclcpp::QoS(1).transient_local())),
evaluate_time_publisher(create_publisher<tier4_simulation_msgs::msg::UserDefinedValue>(
"/simulation/interpreter/execution_time_ms/evaluate", rclcpp::QoS(1).transient_local())),
update_time_publisher(create_publisher<tier4_simulation_msgs::msg::UserDefinedValue>(
"/simulation/interpreter/execution_time_ms/update", rclcpp::QoS(1).transient_local())),
output_time_publisher(create_publisher<tier4_simulation_msgs::msg::UserDefinedValue>(
"/simulation/interpreter/execution_time_ms/output", rclcpp::QoS(1).transient_local())),
local_frame_rate(30),
local_real_time_factor(1.0),
osc_path(""),
Expand Down Expand Up @@ -186,23 +193,40 @@ auto Interpreter::on_activate(const rclcpp_lifecycle::State &) -> Result
},
[this]() {
withTimeoutHandler(defaultTimeoutHandler(), [this]() {
if (std::isnan(evaluateSimulationTime())) {
if (not waiting_for_engagement_to_be_completed and engageable()) {
engage();
waiting_for_engagement_to_be_completed = true; // NOTE: DIRTY HACK!!!
} else if (engaged()) {
activateNonUserDefinedControllers();
waiting_for_engagement_to_be_completed = false; // NOTE: DIRTY HACK!!!
double evaluate_time, update_time, context_time;
{
ScopedElapsedTimeRecorder evaluate_time_recorder(evaluate_time);
if (std::isnan(evaluateSimulationTime())) {
if (not waiting_for_engagement_to_be_completed and engageable()) {
engage();
waiting_for_engagement_to_be_completed = true; // NOTE: DIRTY HACK!!!
} else if (engaged()) {
activateNonUserDefinedControllers();
waiting_for_engagement_to_be_completed = false; // NOTE: DIRTY HACK!!!
}
} else if (currentScenarioDefinition()) {
currentScenarioDefinition()->evaluate();
} else {
throw Error("No script evaluable.");
}
} else if (currentScenarioDefinition()) {
currentScenarioDefinition()->evaluate();
} else {
throw Error("No script evaluable.");
}
{
ScopedElapsedTimeRecorder update_time_recorder(update_time);
SimulatorCore::update();
}
{
ScopedElapsedTimeRecorder context_time_recorder(context_time);
publishCurrentContext();
}

SimulatorCore::update();

publishCurrentContext();
tier4_simulation_msgs::msg::UserDefinedValue msg;
msg.type.data = tier4_simulation_msgs::msg::UserDefinedValueType::DOUBLE;
msg.value = std::to_string(evaluate_time * 1e3);
evaluate_time_publisher->publish(msg);
msg.value = std::to_string(update_time * 1e3);
update_time_publisher->publish(msg);
msg.value = std::to_string(context_time * 1e3);
output_time_publisher->publish(msg);
});
});
};
Expand Down Expand Up @@ -240,6 +264,9 @@ auto Interpreter::on_activate(const rclcpp_lifecycle::State &) -> Result
execution_timer.clear();

publisher_of_context->on_activate();
evaluate_time_publisher->on_activate();
update_time_publisher->on_activate();
output_time_publisher->on_activate();

assert(publisher_of_context->is_activated());

Expand Down Expand Up @@ -311,6 +338,15 @@ auto Interpreter::reset() -> void
if (publisher_of_context->is_activated()) {
publisher_of_context->on_deactivate();
}
if (evaluate_time_publisher->is_activated()) {
evaluate_time_publisher->on_deactivate();
}
if (update_time_publisher->is_activated()) {
update_time_publisher->on_deactivate();
}
if (output_time_publisher->is_activated()) {
output_time_publisher->on_deactivate();
}

if (not has_parameter("initialize_duration")) {
declare_parameter<int>("initialize_duration", 30);
Expand Down
1 change: 1 addition & 0 deletions test_runner/scenario_test_runner/config/workflow.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $(find-pkg-share scenario_test_runner)/scenario/ByEntityCondition.EntityConditio
$(find-pkg-share scenario_test_runner)/scenario/ByEntityCondition.EntityCondition.RelativeSpeedCondition.yaml
$(find-pkg-share scenario_test_runner)/scenario/ByEntityCondition.EntityCondition.TimeToCollisionCondition.yaml
$(find-pkg-share scenario_test_runner)/scenario/ControllerAction.AssignControllerAction.yaml
$(find-pkg-share scenario_test_runner)/scenario/execution_time_test.yaml
$(find-pkg-share scenario_test_runner)/scenario/LateralAction.LaneChangeAction-RoadShoulder.yaml
$(find-pkg-share scenario_test_runner)/scenario/LongitudinalAction.SpeedAction.yaml
$(find-pkg-share scenario_test_runner)/scenario/Property.isBlind.yaml
Expand Down
201 changes: 201 additions & 0 deletions test_runner/scenario_test_runner/scenario/execution_time_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
OpenSCENARIO:
FileHeader:
author: 'Kotaro Yoshimoto'
date: '2025-01-28T18:06:53+09:00'
description: 'scenario for execution time test'
revMajor: 1
revMinor: 3
ParameterDeclarations:
ParameterDeclaration: []
CatalogLocations:
VehicleCatalog:
Directory:
path: $(ros2 pkg prefix --share openscenario_experimental_catalog)/vehicle
RoadNetwork:
LogicFile:
filepath: $(ros2 pkg prefix --share kashiwanoha_map)/map
Entities:
ScenarioObject:
- name: Car1
CatalogReference: &SAMPLE_VEHICLE
catalogName: sample_vehicle
entryName: sample_vehicle
- name: Car2
CatalogReference: *SAMPLE_VEHICLE
- name: Car3
CatalogReference: *SAMPLE_VEHICLE
- name: Car4
CatalogReference: *SAMPLE_VEHICLE
- name: Car5
CatalogReference: *SAMPLE_VEHICLE
- name: Car6
CatalogReference: *SAMPLE_VEHICLE
Storyboard:
Init:
Actions:
Private:
- entityRef: Car1
PrivateAction:
- TeleportAction:
Position:
LanePosition: &DEFAULT_LANE_POSITION
roadId: ''
laneId: 34513
s: 0
offset: 0
Orientation: &DEFAULT_ORIENTATION
type: relative
h: 0
p: 0
r: 0
- entityRef: Car2
PrivateAction:
- TeleportAction:
Position:
LanePosition:
<<: *DEFAULT_LANE_POSITION
s: 5
- entityRef: Car3
PrivateAction:
- TeleportAction:
Position:
LanePosition:
<<: *DEFAULT_LANE_POSITION
s: 10
- entityRef: Car4
PrivateAction:
- TeleportAction:
Position:
LanePosition:
<<: *DEFAULT_LANE_POSITION
s: 15
- entityRef: Car5
PrivateAction:
- TeleportAction:
Position:
LanePosition:
<<: *DEFAULT_LANE_POSITION
s: 20
- entityRef: Car6
PrivateAction:
- TeleportAction:
Position:
LanePosition:
<<: *DEFAULT_LANE_POSITION
s: 25
Story:
- name: ''
Act:
- name: _EndCondition
ManeuverGroup:
- maximumExecutionCount: 1
name: ''
Actors:
selectTriggeringEntities: false
EntityRef:
- entityRef: Car1
Maneuver:
- name: ''
Event:
- name: ''
priority: parallel
StartTrigger:
ConditionGroup:
- Condition:
- name: ''
delay: 0
conditionEdge: none
ByEntityCondition:
TriggeringEntities:
triggeringEntitiesRule: any
EntityRef:
- entityRef: Car1
EntityCondition:
ReachPositionCondition:
Position:
LanePosition:
<<: *DEFAULT_LANE_POSITION
s: 40
tolerance: 0.5
Action:
- name: ''
UserDefinedAction:
CustomCommandAction:
type: exitSuccess
- name: ''
priority: parallel
StartTrigger:
ConditionGroup:
- Condition:
- name: ''
delay: 0
conditionEdge: none
ByValueCondition:
SimulationTimeCondition:
value: 60
rule: greaterThan
- Condition:
- name: 'evaluate time checker'
delay: 0
conditionEdge: none
ByValueCondition:
UserDefinedValueCondition:
name: /simulation/interpreter/execution_time_ms/evaluate
rule: greaterThan
value: 1
- name: 'avoid startup'
delay: 0
conditionEdge: none
ByValueCondition:
SimulationTimeCondition:
value: 1
rule: greaterThan
- Condition:
- name: 'update time checker'
delay: 0
conditionEdge: none
ByValueCondition:
UserDefinedValueCondition:
name: /simulation/interpreter/execution_time_ms/update
rule: greaterThan
value: 5
- name: 'avoid startup'
delay: 0
conditionEdge: none
ByValueCondition:
SimulationTimeCondition:
value: 1
rule: greaterThan
- Condition:
- name: 'output time checker'
delay: 0
conditionEdge: none
ByValueCondition:
UserDefinedValueCondition:
name: /simulation/interpreter/execution_time_ms/output
rule: greaterThan
value: 1
- name: 'avoid startup'
delay: 0
conditionEdge: none
ByValueCondition:
SimulationTimeCondition:
value: 1
rule: greaterThan
Action:
- name: ''
UserDefinedAction:
CustomCommandAction:
type: exitFailure
StartTrigger:
ConditionGroup:
- Condition:
- name: ''
delay: 0
conditionEdge: none
ByValueCondition:
SimulationTimeCondition:
value: 0
rule: greaterThan
StopTrigger:
ConditionGroup: []
Loading