Use RTC_UNUSED instead of conditional compilation in BWE simulator tool.

Mark ATTRIBUTE_UNUSED as deprecated since it only works with GCC and clang. I am not removing it now since typedefs.h is (perhaps incorrectly?) considered a public interface.

BUG=webrtc:7228

Review-Url: https://codereview.webrtc.org/2756483002
Cr-Commit-Position: refs/heads/master@{#17291}
This commit is contained in:
terelius
2017-03-17 06:34:47 -07:00
committed by Commit bot
parent dd20054e06
commit a2bb667a9b
6 changed files with 30 additions and 17 deletions

View File

@ -221,11 +221,12 @@ RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
packets_per_second_stats_(),
kbps_stats_(),
start_plotting_time_ms_(0),
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
flow_id_(flow_id),
#endif
name_(name),
algorithm_name_(algorithm_name) {}
algorithm_name_(algorithm_name) {
// Only used when compiling with BWE test logging enabled.
RTC_UNUSED(flow_id_);
}
RateCounterFilter::RateCounterFilter(PacketProcessorListener* listener,
const FlowIds& flow_ids,
@ -276,7 +277,6 @@ Stats<double> RateCounterFilter::GetBitrateStats() const {
void RateCounterFilter::Plot(int64_t timestamp_ms) {
// TODO(stefan): Reorganize logging configuration to reduce amount
// of preprocessor conditionals in the code.
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
uint32_t plot_kbps = 0;
if (timestamp_ms >= start_plotting_time_ms_) {
plot_kbps = rate_counter_.bits_per_second() / 1000.0;
@ -290,7 +290,7 @@ void RateCounterFilter::Plot(int64_t timestamp_ms) {
timestamp_ms, plot_kbps, flow_id_,
algorithm_name_);
}
#endif
RTC_UNUSED(plot_kbps);
}
void RateCounterFilter::RunFor(int64_t /*time_ms*/, Packets* in_out) {

View File

@ -34,6 +34,7 @@
#include "webrtc/modules/remote_bitrate_estimator/test/packet.h"
#include "webrtc/modules/rtp_rtcp/include/rtp_rtcp_defines.h"
#include "webrtc/system_wrappers/include/clock.h"
#include "webrtc/typedefs.h"
namespace webrtc {
@ -250,9 +251,7 @@ class RateCounterFilter : public PacketProcessor {
Stats<double> packets_per_second_stats_;
Stats<double> kbps_stats_;
int64_t start_plotting_time_ms_;
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
int flow_id_ = 0;
#endif
std::string name_;
// Algorithm name if single flow, Total link utilization if all flows.
std::string algorithm_name_;

View File

@ -17,6 +17,7 @@
#include "webrtc/modules/remote_bitrate_estimator/test/bwe_test_logging.h"
#include "webrtc/modules/rtp_rtcp/include/receive_statistics.h"
#include "webrtc/test/gtest.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace testing {
@ -65,9 +66,7 @@ int RembBweSender::GetFeedbackIntervalMs() const {
RembReceiver::RembReceiver(int flow_id, bool plot)
: BweReceiver(flow_id),
estimate_log_prefix_(),
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
plot_estimate_(plot),
#endif
clock_(0),
recv_stats_(ReceiveStatistics::Create(&clock_)),
latest_estimate_bps_(-1),
@ -121,13 +120,12 @@ FeedbackPacket* RembReceiver::GetFeedback(int64_t now_ms) {
estimated_bps, latest_report_block_);
last_feedback_ms_ = now_ms;
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
double estimated_kbps = static_cast<double>(estimated_bps) / 1000.0;
RTC_UNUSED(estimated_kbps);
if (plot_estimate_) {
BWE_TEST_LOGGING_PLOT(0, estimate_log_prefix_,
clock_.TimeInMilliseconds(), estimated_kbps);
}
#endif
}
return feedback;
}

View File

@ -70,9 +70,7 @@ class RembReceiver : public BweReceiver, public RemoteBitrateObserver {
bool LatestEstimate(uint32_t* estimate_bps);
std::string estimate_log_prefix_;
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
bool plot_estimate_ = false;
#endif
SimulatedClock clock_;
std::unique_ptr<ReceiveStatistics> recv_stats_;
int64_t latest_estimate_bps_;

View File

@ -13,6 +13,7 @@
#include <algorithm>
#include "webrtc/modules/remote_bitrate_estimator/test/packet_sender.h"
#include "webrtc/typedefs.h"
namespace webrtc {
namespace testing {
@ -262,7 +263,6 @@ void MetricRecorder::PlotThroughputHistogram(
size_t num_flows,
int64_t extra_offset_ms,
const std::string optimum_id) const {
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
double optimal_bitrate_per_flow_kbps = static_cast<double>(
optimal_throughput_bits_ / RunDurationMs(extra_offset_ms));
@ -290,7 +290,11 @@ void MetricRecorder::PlotThroughputHistogram(
"%lf %%",
100.0 * static_cast<double>(average_bitrate_kbps) /
optimal_bitrate_per_flow_kbps);
#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
RTC_UNUSED(pos_error);
RTC_UNUSED(neg_error);
RTC_UNUSED(extra_error);
RTC_UNUSED(optimal_bitrate_per_flow_kbps);
}
void MetricRecorder::PlotThroughputHistogram(const std::string& title,
@ -304,7 +308,6 @@ void MetricRecorder::PlotDelayHistogram(const std::string& title,
const std::string& bwe_name,
size_t num_flows,
int64_t one_way_path_delay_ms) const {
#if BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
double average_delay_ms =
static_cast<double>(sum_delays_ms_) / num_packets_received_;
int64_t percentile_5_ms = NthDelayPercentile(5);
@ -322,7 +325,10 @@ void MetricRecorder::PlotDelayHistogram(const std::string& title,
"%ld ms", percentile_5_ms - one_way_path_delay_ms);
BWE_TEST_LOGGING_LOG1("RESULTS >>> " + bwe_name + " Delay 95th percentile : ",
"%ld ms", percentile_95_ms - one_way_path_delay_ms);
#endif // BWE_TEST_LOGGING_COMPILE_TIME_ENABLE
RTC_UNUSED(average_delay_ms);
RTC_UNUSED(percentile_5_ms);
RTC_UNUSED(percentile_95_ms);
}
void MetricRecorder::PlotLossHistogram(const std::string& title,

View File

@ -80,6 +80,8 @@
// Put after a variable that might not be used, to prevent compiler warnings:
// int result ATTRIBUTE_UNUSED = DoSomething();
// assert(result == 17);
// Deprecated since it only works with GCC & clang. See RTC_UNUSED below.
// TODO(terelius): Remove.
#ifndef ATTRIBUTE_UNUSED
#if defined(__GNUC__) || defined(__clang__)
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
@ -109,4 +111,14 @@
#endif
#endif
// Prevent the compiler from warning about an unused variable. For example:
// int result = DoSomething();
// assert(result == 17);
// RTC_UNUSED(result);
// Note: In most cases it is better to remove the unused variable rather than
// suppressing the compiler warning.
#ifndef RTC_UNUSED
#define RTC_UNUSED(x) static_cast<void>(x)
#endif // RTC_UNUSED
#endif // WEBRTC_TYPEDEFS_H_