From b9877e0d3850223ae6c2df3a68c3d888ca5be628 Mon Sep 17 00:00:00 2001 From: Lucas De Marchi Date: Wed, 2 Aug 2017 02:23:07 -0700 Subject: [PATCH] GCS_MAVLink: make per channel perf counter non-static Otherwise the perf counter from one channel may affect the other if during an update of one channel the update function of the other gets called. --- libraries/GCS_MAVLink/GCS.h | 6 +++--- libraries/GCS_MAVLink/GCS_Common.cpp | 17 ++++++++--------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/libraries/GCS_MAVLink/GCS.h b/libraries/GCS_MAVLink/GCS.h index e556eb6026..668d962520 100644 --- a/libraries/GCS_MAVLink/GCS.h +++ b/libraries/GCS_MAVLink/GCS.h @@ -361,9 +361,9 @@ private: uint8_t stream_slowdown; // perf counters - static AP_HAL::Util::perf_counter_t _perf_packet; - static AP_HAL::Util::perf_counter_t _perf_update; - + AP_HAL::Util::perf_counter_t _perf_packet; + AP_HAL::Util::perf_counter_t _perf_update; + // deferred message handling. We size the deferred_message // ringbuffer so we can defer every message type enum ap_message deferred_messages[MSG_LAST]; diff --git a/libraries/GCS_MAVLink/GCS_Common.cpp b/libraries/GCS_MAVLink/GCS_Common.cpp index 308866cd5b..a9244da62d 100644 --- a/libraries/GCS_MAVLink/GCS_Common.cpp +++ b/libraries/GCS_MAVLink/GCS_Common.cpp @@ -23,6 +23,7 @@ #include "AP_Common/AP_FWVersion.h" #include "GCS.h" +#include #if CONFIG_HAL_BOARD == HAL_BOARD_PX4 || CONFIG_HAL_BOARD == HAL_BOARD_VRBRAIN #include #include @@ -37,9 +38,6 @@ uint8_t GCS_MAVLINK::mavlink_active = 0; uint8_t GCS_MAVLINK::chan_is_streaming = 0; uint32_t GCS_MAVLINK::reserve_param_space_start_ms; -AP_HAL::Util::perf_counter_t GCS_MAVLINK::_perf_packet; -AP_HAL::Util::perf_counter_t GCS_MAVLINK::_perf_update; - GCS *GCS::_singleton = nullptr; GCS_MAVLINK::GCS_MAVLINK() @@ -61,12 +59,13 @@ GCS_MAVLINK::init(AP_HAL::UARTDriver *port, mavlink_channel_t mav_chan) initialised = true; _queued_parameter = nullptr; - if (!_perf_packet) { - _perf_packet = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, "GCS_Packet"); - } - if (!_perf_update) { - _perf_update = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, "GCS_Update"); - } + char perf_name[16]; + + snprintf(perf_name, sizeof(perf_name), "GCS_Packet_%u", chan); + _perf_packet = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, perf_name); + + snprintf(perf_name, sizeof(perf_name), "GCS_Update_%u", chan); + _perf_update = hal.util->perf_alloc(AP_HAL::Util::PC_ELAPSED, perf_name); }