提交 5373c853 编写于 作者: V vlin17 提交者: Liangliang Zhang

Dreamview: calculate latencies from module headers

上级 59a0a556
......@@ -16,7 +16,6 @@
#include "modules/dreamview/backend/simulation_world/simulation_world_service.h"
#include <algorithm>
#include <chrono>
#include <unordered_set>
#include <vector>
......@@ -335,6 +334,7 @@ void SimulationWorldService::Update() {
}
UpdateDelays();
UpdateLatencies();
world_.set_sequence_num(world_.sequence_num() + 1);
world_.set_timestamp(apollo::common::time::AsInt64<millis>(Clock::Now()));
......@@ -353,6 +353,15 @@ void SimulationWorldService::UpdateDelays() {
delays->set_control(SecToMs(control_command_reader_->GetDelaySec()));
}
void SimulationWorldService::UpdateLatencies() {
UpdateLatency("chassis", chassis_reader_.get());
UpdateLatency("localization", localization_reader_.get());
UpdateLatency("perception", perception_obstacle_reader_.get());
UpdateLatency("planning", planning_reader_.get());
UpdateLatency("prediction", prediction_obstacle_reader_.get());
UpdateLatency("control", control_command_reader_.get());
}
void SimulationWorldService::GetWireFormatString(
double radius, std::string *sim_world,
std::string *sim_world_with_planning_data) {
......
......@@ -21,6 +21,7 @@
#ifndef MODULES_DREAMVIEW_BACKEND_SIMULATION_WORLD_SIM_WORLD_H_
#define MODULES_DREAMVIEW_BACKEND_SIMULATION_WORLD_SIM_WORLD_H_
#include <algorithm>
#include <functional>
#include <list>
#include <memory>
......@@ -250,7 +251,29 @@ class SimulationWorldService {
void ReadRoutingFromFile(const std::string &routing_response_file);
template <typename MessageT>
void UpdateLatency(const std::string module_name,
cybertron::Reader<MessageT> *reader) {
if (reader->Empty()) {
return;
}
const auto header = reader->GetLatestObserved()->header();
const double publish_time_sec = header.timestamp_sec();
const double sensor_time_sec =
apollo::cybertron::Time(
std::max({header.lidar_timestamp(), header.camera_timestamp(),
header.radar_timestamp()}))
.ToSecond();
Latency latency;
latency.set_timestamp_sec(publish_time_sec);
latency.set_total_time_ms((publish_time_sec - sensor_time_sec) * 1.0e3);
(*world_.mutable_latency())[module_name] = latency;
}
void UpdateDelays();
void UpdateLatencies();
template <typename Points>
void DownsampleSpeedPointsByInterval(const Points &points,
......@@ -346,6 +369,7 @@ class SimulationWorldService {
FRIEND_TEST(SimulationWorldServiceTest, UpdateMonitorRemove);
FRIEND_TEST(SimulationWorldServiceTest, UpdateMonitorTruncate);
FRIEND_TEST(SimulationWorldServiceTest, UpdateChassisInfo);
FRIEND_TEST(SimulationWorldServiceTest, UpdateLatency);
FRIEND_TEST(SimulationWorldServiceTest, UpdateLocalization);
FRIEND_TEST(SimulationWorldServiceTest, UpdatePerceptionObstacles);
FRIEND_TEST(SimulationWorldServiceTest, UpdatePlanningTrajectory);
......
......@@ -19,6 +19,7 @@
#include <iostream>
#include "gtest/gtest.h"
#include "modules/common/adapters/adapter_gflags.h"
#include "modules/common/configs/vehicle_config_helper.h"
#include "modules/common/math/quaternion.h"
......@@ -53,6 +54,8 @@ class SimulationWorldServiceTest : public ::testing::Test {
"modules/dreamview/backend/testdata/routing.pb.txt";
apollo::common::VehicleConfigHelper::Init();
sim_world_service_.reset(new SimulationWorldService(map_service_.get()));
SetupCybertron();
}
protected:
......@@ -62,11 +65,29 @@ class SimulationWorldServiceTest : public ::testing::Test {
FLAGS_sim_world_with_routing_path = true;
map_service_.reset(new MapService(false));
}
void SetupCybertron();
std::unique_ptr<SimulationWorldService> sim_world_service_;
std::unique_ptr<MapService> map_service_;
bool is_cybertron_initialized_ = false;
std::shared_ptr<cybertron::Writer<apollo::control::ControlCommand>>
control_writer_;
};
void SimulationWorldServiceTest::SetupCybertron() {
if (is_cybertron_initialized_) {
return;
}
std::unique_ptr<cybertron::Node> node =
cybertron::CreateNode("sim_world_service_test");
control_writer_ = node->CreateWriter<apollo::control::ControlCommand>(
FLAGS_control_command_topic);
is_cybertron_initialized_ = true;
}
TEST_F(SimulationWorldServiceTest, UpdateMonitorSuccess) {
MonitorMessage monitor;
monitor.add_item()->set_msg("I am the latest message.");
......@@ -577,5 +598,25 @@ TEST_F(SimulationWorldServiceTest, DownsampleSpeedPointsByInterval) {
}
}
TEST_F(SimulationWorldServiceTest, UpdateLatency) {
std::shared_ptr<apollo::control::ControlCommand> control_command =
std::make_shared<apollo::control::ControlCommand>();
auto* header = control_command->mutable_header();
header->set_timestamp_sec(2000.9);
header->set_radar_timestamp(2000 * 1e9);
header->set_lidar_timestamp(2000.1 * 1e9);
header->set_camera_timestamp(2000.2 * 1e9);
control_writer_->Write(control_command);
BlockerManager::Instance()->Observe();
sim_world_service_->UpdateLatency(
"control", sim_world_service_->control_command_reader_.get());
EXPECT_EQ(1, sim_world_service_->world_.latency_size());
const Latency latency = sim_world_service_->world_.latency().at("control");
EXPECT_DOUBLE_EQ(2000.9, latency.timestamp_sec());
EXPECT_NEAR(0.7 * 1e3, latency.total_time_ms(), kEpsilon);
}
} // namespace dreamview
} // namespace apollo
因为 它太大了无法显示 source diff 。你可以改为 查看blob
......@@ -982,30 +982,6 @@
}
}
},
"Scenario": {
"fields": {
"type": {
"type": "Type",
"id": 1,
"options": {
"default": "UNKNOWN"
}
}
},
"nested": {
"Type": {
"values": {
"UNKNOWN": 0,
"CRUISE_UNKNOWN": 1000,
"CRUISE_URBAN": 1001,
"CRUISE_HIGHWAY": 1002,
"JUNCTION_UNKNOWN": 2000,
"JUNCTION_TRAFFIC_LIGHT": 2001,
"JUNCTION_STOP_SIGN": 2002
}
}
}
},
"VehicleSignal": {
"fields": {
"turnSignal": {
......@@ -1079,7 +1055,11 @@
"HMI": 12,
"RELATIVE_MAP": 13,
"GNSS": 14,
"CONTI_RADAR": 15
"CONTI_RADAR": 15,
"RACOBIT_RADAR": 16,
"ULTRASONIC_RADAR": 17,
"MOBILEYE": 18,
"DELPHI_ESR": 19
}
},
"LogLevel": {
......@@ -2807,6 +2787,10 @@
"selected": {
"type": "bool",
"id": 6
},
"cameraName": {
"type": "string",
"id": 7
}
}
},
......@@ -2847,7 +2831,30 @@
},
"cameraId": {
"type": "int32",
"id": 9
"id": 9,
"options": {
"deprecated": true
}
},
"cropRoi": {
"rule": "repeated",
"type": "TrafficLightBox",
"id": 10
},
"projectedRoi": {
"rule": "repeated",
"type": "TrafficLightBox",
"id": 11
},
"rectifiedRoi": {
"rule": "repeated",
"type": "TrafficLightBox",
"id": 12
},
"debugRoi": {
"rule": "repeated",
"type": "TrafficLightBox",
"id": 13
}
}
},
......@@ -2871,6 +2878,14 @@
"trackingTime": {
"type": "double",
"id": 4
},
"blink": {
"type": "bool",
"id": 5
},
"remainingTime": {
"type": "double",
"id": 6
}
},
"nested": {
......@@ -2903,22 +2918,120 @@
"containLights": {
"type": "bool",
"id": 4
},
"cameraId": {
"type": "CameraID",
"id": 5
}
},
"nested": {
"CameraID": {
"values": {
"CAMERA_FRONT_LONG": 0,
"CAMERA_FRONT_NARROW": 1,
"CAMERA_FRONT_SHORT": 2,
"CAMERA_FRONT_WIDE": 3
}
}
}
},
"BBox2D": {
"fields": {
"xmin": {
"type": "double",
"id": 1
},
"ymin": {
"type": "double",
"id": 2
},
"xmax": {
"type": "double",
"id": 3
},
"ymax": {
"type": "double",
"id": 4
}
}
},
"Point": {
"LightStatus": {
"fields": {
"x": {
"brakeVisible": {
"type": "double",
"id": 1
},
"y": {
"brakeSwitchOn": {
"type": "double",
"id": 2
},
"z": {
"leftTurnVisible": {
"type": "double",
"id": 3
},
"leftTurnSwitchOn": {
"type": "double",
"id": 4
},
"rightTurnVisible": {
"type": "double",
"id": 5
},
"rightTurnSwitchOn": {
"type": "double",
"id": 6
}
}
},
"SensorMeasurement": {
"fields": {
"sensorId": {
"type": "string",
"id": 1
},
"id": {
"type": "int32",
"id": 2
},
"position": {
"type": "common.Point3D",
"id": 3
},
"theta": {
"type": "double",
"id": 4
},
"length": {
"type": "double",
"id": 5
},
"width": {
"type": "double",
"id": 6
},
"height": {
"type": "double",
"id": 7
},
"velocity": {
"type": "common.Point3D",
"id": 8
},
"type": {
"type": "PerceptionObstacle.Type",
"id": 9
},
"subType": {
"type": "PerceptionObstacle.SubType",
"id": 10
},
"timestamp": {
"type": "double",
"id": 11
},
"box": {
"type": "BBox2D",
"id": 12
}
}
},
......@@ -2929,7 +3042,7 @@
"id": 1
},
"position": {
"type": "Point",
"type": "common.Point3D",
"id": 2
},
"theta": {
......@@ -2937,7 +3050,7 @@
"id": 3
},
"velocity": {
"type": "Point",
"type": "common.Point3D",
"id": 4
},
"length": {
......@@ -2954,7 +3067,7 @@
},
"polygonPoint": {
"rule": "repeated",
"type": "Point",
"type": "common.Point3D",
"id": 8
},
"trackingTime": {
......@@ -2978,20 +3091,70 @@
"type": "double",
"id": 13,
"options": {
"default": 1
"deprecated": true
}
},
"confidenceType": {
"type": "ConfidenceType",
"id": 14,
"options": {
"default": "CONFIDENCE_CNN"
"deprecated": true
}
},
"drops": {
"rule": "repeated",
"type": "Point",
"id": 15
"type": "common.Point3D",
"id": 15,
"options": {
"deprecated": true
}
},
"acceleration": {
"type": "common.Point3D",
"id": 16
},
"anchorPoint": {
"type": "common.Point3D",
"id": 17
},
"bbox2d": {
"type": "BBox2D",
"id": 18
},
"subType": {
"type": "SubType",
"id": 19
},
"measurements": {
"rule": "repeated",
"type": "SensorMeasurement",
"id": 20
},
"heightAboveGround": {
"type": "double",
"id": 21,
"options": {
"default": null
}
},
"positionCovariance": {
"rule": "repeated",
"type": "double",
"id": 22
},
"velocityCovariance": {
"rule": "repeated",
"type": "double",
"id": 23
},
"accelerationCovariance": {
"rule": "repeated",
"type": "double",
"id": 24
},
"lightStatus": {
"type": "LightStatus",
"id": 25
}
},
"nested": {
......@@ -3011,21 +3174,21 @@
"CONFIDENCE_CNN": 1,
"CONFIDENCE_RADAR": 2
}
}
}
},
"CIPVInfo": {
"fields": {
"cipvId": {
"type": "int32",
"id": 1
},
"potentialCipvId": {
"rule": "repeated",
"type": "int32",
"id": 2,
"options": {
"packed": false
"SubType": {
"values": {
"ST_UNKNOWN": 0,
"ST_UNKNOWN_MOVABLE": 1,
"ST_UNKNOWN_UNMOVABLE": 2,
"ST_CAR": 3,
"ST_VAN": 4,
"ST_TRUCK": 5,
"ST_BUS": 6,
"ST_CYCLIST": 7,
"ST_MOTORCYCLIST": 8,
"ST_TRICYCLIST": 9,
"ST_PEDESTRIAN": 10,
"ST_TRAFFICCONE": 11
}
}
}
......@@ -3096,6 +3259,22 @@
}
}
},
"CIPVInfo": {
"fields": {
"cipvId": {
"type": "int32",
"id": 1
},
"potentialCipvId": {
"rule": "repeated",
"type": "int32",
"id": 2,
"options": {
"packed": false
}
}
}
},
"PerceptionObstacles": {
"fields": {
"perceptionObstacle": {
......@@ -3104,11 +3283,11 @@
"id": 1
},
"header": {
"type": "apollo.common.Header",
"type": "common.Header",
"id": 2
},
"errorCode": {
"type": "apollo.common.ErrorCode",
"type": "common.ErrorCode",
"id": 3,
"options": {
"default": "OK"
......
......@@ -13,10 +13,10 @@ export default class LatencyMonitor extends React.Component {
return null;
}
const graphs = Object.keys(data).map(moduleName => {
setting.title = moduleName;
return generateScatterGraph(setting, { data: data[moduleName] });
const graphs = {};
Object.keys(data).forEach(moduleName => {
graphs[moduleName] = data[moduleName];
});
return <div>{graphs}</div>;
return generateScatterGraph(setting, graphs);
}
}
options:
legend:
display: false
display: true
axes:
x:
labelString: 'timestampe (sec)'
......@@ -8,9 +8,39 @@ options:
labelString: 'latency (ms)'
properties:
lines:
data:
color: 'rgba(27, 249, 105, 0.5)' # green
chassis:
color: 'rgba(241, 113, 112, 0.5)' # red
borderWidth: 2
pointRadius: 0
fill: false
showLine: true
localization:
color: 'rgba(254, 208,114, 0.5)' # yellow
borderWidth: 2
pointRadius: 0
fill: false
showLine: true
prediction:
color: 'rgba(162, 212, 113, 0.5)' # lime green
borderWidth: 2
pointRadius: 0
fill: false
showLine: true
perception:
color: 'rgba(113, 226, 208, 0.5)' # aqua
borderWidth: 2
pointRadius: 0
fill: false
showLine: true
planning:
color: 'rgba(113, 208, 255, 0.5)' # aqua
borderWidth: 2
pointRadius: 0
fill: false
showLine: true
control:
color: 'rgba(179, 164, 238, 0.5)' # lavender
borderWidth: 2
pointRadius: 0
fill: false
showLine: true
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册