Skip to content

Commit 1598272

Browse files
committed
vtd: Add more timers for performance analysis
1 parent fc37331 commit 1598272

File tree

1 file changed

+34
-7
lines changed

1 file changed

+34
-7
lines changed

plugins/vtd/src/vtd_binding.cpp

+34-7
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,11 @@ namespace vtd {
5959
* The VtdStatistics struct contains all nominal statistics of the VTD binding.
6060
*/
6161
struct VtdStatistics {
62+
double last_frame_time_ms{0};
6263
cloe::utility::Accumulator frame_time_ms;
64+
cloe::utility::Accumulator task_control_time_ms;
65+
cloe::utility::Accumulator trigger_and_send;
66+
cloe::utility::Accumulator data_receive_time_ms;
6367
cloe::utility::Accumulator clock_drift_ns;
6468

6569
/**
@@ -68,15 +72,22 @@ struct VtdStatistics {
6872
* # JSON Output
6973
* ```json
7074
* {
71-
* {"connection_tries": number},
75+
* {"last_frame_time_ms", Milliseconds}
7276
* {"frame_time_ms", Accumulator},
77+
* {"task_control_time_ms", Accumulator},
78+
* {"data_receive_time_ms", Accumulator},
79+
* {"trigger_and_send", Accumulator},
7380
* {"clock_drift_ns", Accumulator}
7481
* }
7582
* ```
7683
*/
7784
friend void to_json(cloe::Json& j, const VtdStatistics& s) {
7885
j = cloe::Json{
86+
{"last_frame_time_ms", s.last_frame_time_ms},
7987
{"frame_time_ms", s.frame_time_ms},
88+
{"task_control_time_ms", s.task_control_time_ms},
89+
{"data_receive_time_ms", s.data_receive_time_ms},
90+
{"trigger_and_send", s.trigger_and_send},
8091
{"clock_drift_ns", s.clock_drift_ns},
8192
};
8293
}
@@ -364,8 +375,10 @@ class VtdBinding : public cloe::Simulator {
364375
assert(operational_);
365376

366377
// Statistics:
367-
timer::DurationTimer<timer::Milliseconds> t(
368-
[this](timer::Milliseconds d) { this->stats_.frame_time_ms.push_back(d.count()); });
378+
timer::DurationTimer<timer::Milliseconds> t([this](timer::Milliseconds d) {
379+
this->stats_.last_frame_time_ms = d.count();
380+
this->stats_.frame_time_ms.push_back(d.count());
381+
});
369382

370383
// Read all incoming SCP messages,
371384
// a) to empty the buffer, and
@@ -378,16 +391,30 @@ class VtdBinding : public cloe::Simulator {
378391
}
379392

380393
// Process task control messages
381-
task_control_->step(sync);
394+
{
395+
timer::DurationTimer<timer::Milliseconds> t([this](timer::Milliseconds d) {
396+
this->stats_.task_control_time_ms.push_back(d.count());
397+
});
398+
task_control_->step(sync);
399+
}
382400

383401
// Receive new data relating to all sensors
384402
cloe::Duration sensor_time{0};
385-
for (auto v : vehicles_) {
386-
sensor_time = v->vtd_step_sensors(sync);
403+
{
404+
timer::DurationTimer<timer::Milliseconds> t([this](timer::Milliseconds d) {
405+
this->stats_.data_receive_time_ms.push_back(d.count());
406+
});
407+
for (auto v : vehicles_) {
408+
sensor_time = v->vtd_step_sensors(sync);
409+
}
387410
}
388411

389412
// Trigger VTD to simulation the next step
390-
task_control_->add_trigger_and_send(sync.step_width());
413+
{
414+
timer::DurationTimer<timer::Milliseconds> t(
415+
[this](timer::Milliseconds d) { this->stats_.trigger_and_send.push_back(d.count()); });
416+
task_control_->add_trigger_and_send(sync.step_width());
417+
}
391418

392419
// Calculate error of previous timestep for timing statistics
393420
vtd_timestep_error_ = sync.time() - sensor_time;

0 commit comments

Comments
 (0)