Refactor of GoogCC debug printer.

Simplifying the code to better fit with how it is used.

Bug: webrtc:9883
Change-Id: I2bd52f26b829413e516dee4f551cf36574275019
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/136681
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#27994}
This commit is contained in:
Sebastian Jansson 2019-05-17 17:53:44 +02:00 committed by Commit Bot
parent f4e085a499
commit 871ac42597
12 changed files with 100 additions and 334 deletions

View File

@ -81,23 +81,6 @@ rtc_static_library("transport_feedback") {
}
if (rtc_include_tests) {
rtc_source_set("test_controller_printer") {
testonly = true
sources = [
"test/controller_printer.cc",
"test/controller_printer.h",
]
deps = [
"../../api/transport:network_control",
"../../api/units:data_rate",
"../../api/units:data_size",
"../../api/units:time_delta",
"../../api/units:timestamp",
"../../rtc_base:checks",
"../../test/logging:log_writer",
"//third_party/abseil-cpp/absl/types:optional",
]
}
rtc_source_set("congestion_controller_unittests") {
testonly = true

View File

@ -116,22 +116,6 @@ rtc_source_set("windowed_filter") {
]
}
if (rtc_include_tests) {
rtc_source_set("test_bbr_printer") {
testonly = true
sources = [
"test/bbr_printer.cc",
"test/bbr_printer.h",
]
deps = [
":bbr",
":bbr_controller",
"..:test_controller_printer",
"../../../api/transport:network_control",
"../../../api/units:timestamp",
"../../../logging:rtc_event_log_api",
"../../../rtc_base:checks",
]
}
rtc_source_set("bbr_unittests") {
testonly = true
sources = [

View File

@ -1,61 +0,0 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/congestion_controller/bbr/test/bbr_printer.h"
#include "rtc_base/checks.h"
namespace webrtc {
BbrStatePrinter::BbrStatePrinter() = default;
BbrStatePrinter::~BbrStatePrinter() = default;
void BbrStatePrinter::Attach(bbr::BbrNetworkController* controller) {
controller_ = controller;
}
bool BbrStatePrinter::Attached() const {
return controller_ != nullptr;
}
void BbrStatePrinter::PrintHeaders(RtcEventLogOutput* out) {
LogWriteFormat(
out, "bbr_mode bbr_recovery_state round_trip_count gain_cycle_index");
}
void BbrStatePrinter::PrintValues(RtcEventLogOutput* out) {
RTC_CHECK(controller_);
bbr::BbrNetworkController::DebugState debug(*controller_);
LogWriteFormat(out, "%i %i %i %i", debug.mode, debug.recovery_state,
static_cast<int>(debug.round_trip_count),
debug.gain_cycle_index);
}
NetworkControlUpdate BbrStatePrinter::GetState(Timestamp at_time) const {
RTC_CHECK(controller_);
return controller_->CreateRateUpdate(at_time);
}
BbrDebugFactory::BbrDebugFactory(BbrStatePrinter* printer)
: printer_(printer) {}
std::unique_ptr<NetworkControllerInterface> BbrDebugFactory::Create(
NetworkControllerConfig config) {
RTC_CHECK(controller_ == nullptr);
auto controller = BbrNetworkControllerFactory::Create(config);
controller_ = static_cast<bbr::BbrNetworkController*>(controller.get());
printer_->Attach(controller_);
return controller;
}
bbr::BbrNetworkController* BbrDebugFactory::BbrController() {
return controller_;
}
} // namespace webrtc

View File

@ -1,54 +0,0 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_CONGESTION_CONTROLLER_BBR_TEST_BBR_PRINTER_H_
#define MODULES_CONGESTION_CONTROLLER_BBR_TEST_BBR_PRINTER_H_
#include <stdio.h>
#include <memory>
#include "api/transport/network_control.h"
#include "api/transport/network_types.h"
#include "api/units/timestamp.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "modules/congestion_controller/bbr/bbr_factory.h"
#include "modules/congestion_controller/bbr/bbr_network_controller.h"
#include "modules/congestion_controller/test/controller_printer.h"
namespace webrtc {
class BbrStatePrinter : public DebugStatePrinter {
public:
BbrStatePrinter();
~BbrStatePrinter() override;
void Attach(bbr::BbrNetworkController*);
bool Attached() const override;
void PrintHeaders(RtcEventLogOutput* out) override;
void PrintValues(RtcEventLogOutput* out) override;
NetworkControlUpdate GetState(Timestamp at_time) const override;
private:
bbr::BbrNetworkController* controller_ = nullptr;
};
class BbrDebugFactory : public BbrNetworkControllerFactory {
public:
explicit BbrDebugFactory(BbrStatePrinter* printer);
std::unique_ptr<NetworkControllerInterface> Create(
NetworkControllerConfig config) override;
bbr::BbrNetworkController* BbrController();
private:
BbrStatePrinter* printer_;
bbr::BbrNetworkController* controller_ = nullptr;
};
} // namespace webrtc
#endif // MODULES_CONGESTION_CONTROLLER_BBR_TEST_BBR_PRINTER_H_

View File

@ -204,12 +204,12 @@ if (rtc_include_tests) {
":delay_based_bwe",
":estimators",
":goog_cc",
"..:test_controller_printer",
"../../../api/transport:goog_cc",
"../../../api/transport:network_control",
"../../../api/units:timestamp",
"../../../logging:rtc_event_log_api",
"../../../rtc_base:checks",
"../../../test/logging:log_writer",
"../../remote_bitrate_estimator",
"//third_party/abseil-cpp/absl/types:optional",
]

View File

@ -31,9 +31,16 @@ void WriteTypedValue(RtcEventLogOutput* out, double value) {
void WriteTypedValue(RtcEventLogOutput* out, absl::optional<DataRate> value) {
LogWriteFormat(out, "%.0f", value ? value->bytes_per_sec<double>() : NAN);
}
void WriteTypedValue(RtcEventLogOutput* out, absl::optional<DataSize> value) {
LogWriteFormat(out, "%.0f", value ? value->bytes<double>() : NAN);
}
void WriteTypedValue(RtcEventLogOutput* out, absl::optional<TimeDelta> value) {
LogWriteFormat(out, "%.3f", value ? value->seconds<double>() : NAN);
}
void WriteTypedValue(RtcEventLogOutput* out, absl::optional<Timestamp> value) {
LogWriteFormat(out, "%.3f", value ? value->seconds<double>() : NAN);
}
template <typename F>
class TypedFieldLogger : public FieldLogger {
public:
@ -60,13 +67,7 @@ GoogCcStatePrinter::GoogCcStatePrinter() {
loggers_.emplace_back(logger);
}
}
const NetworkStateEstimate& GoogCcStatePrinter::GetEst() {
static NetworkStateEstimate kFallback;
if (controller_->network_estimator_ &&
controller_->network_estimator_->GetCurrentEstimate())
return *controller_->network_estimator_->GetCurrentEstimate();
return kFallback;
}
std::deque<FieldLogger*> GoogCcStatePrinter::CreateLoggers() {
auto stable_estimate = [this] {
return DataRate::kbps(
@ -85,6 +86,13 @@ std::deque<FieldLogger*> GoogCcStatePrinter::CreateLoggers() {
return controller_->acknowledged_bitrate_estimator_->bitrate();
};
std::deque<FieldLogger*> loggers({
Log("time", [=] { return target_.at_time; }),
Log("bandwidth", [=] { return target_.network_estimate.bandwidth; }),
Log("rtt", [=] { return target_.network_estimate.round_trip_time; }),
Log("target", [=] { return target_.target_rate; }),
Log("pacing", [=] { return pacing_.data_rate(); }),
Log("padding", [=] { return pacing_.pad_rate(); }),
Log("window", [=] { return congestion_window_; }),
Log("rate_control_state", [=] { return rate_control_state(); }),
Log("stable_estimate", [=] { return stable_estimate(); }),
Log("trendline", [=] { return trend()->prev_trend_; }),
@ -92,62 +100,82 @@ std::deque<FieldLogger*> GoogCcStatePrinter::CreateLoggers() {
[=] { return trend()->prev_modified_trend_; }),
Log("trendline_offset_threshold", [=] { return trend()->threshold_; }),
Log("acknowledged_rate", [=] { return acknowledged_rate(); }),
Log("est_capacity", [=] { return GetEst().link_capacity; }),
Log("est_capacity_dev", [=] { return GetEst().link_capacity_std_dev; }),
Log("est_capacity_min", [=] { return GetEst().link_capacity_min; }),
Log("est_cross_traffic", [=] { return GetEst().cross_traffic_ratio; }),
Log("est_cross_delay", [=] { return GetEst().cross_delay_rate; }),
Log("est_spike_delay", [=] { return GetEst().spike_delay_rate; }),
Log("est_pre_buffer", [=] { return GetEst().pre_link_buffer_delay; }),
Log("est_post_buffer", [=] { return GetEst().post_link_buffer_delay; }),
Log("est_propagation", [=] { return GetEst().propagation_delay; }),
Log("est_capacity", [=] { return est_.link_capacity; }),
Log("est_capacity_dev", [=] { return est_.link_capacity_std_dev; }),
Log("est_capacity_min", [=] { return est_.link_capacity_min; }),
Log("est_cross_traffic", [=] { return est_.cross_traffic_ratio; }),
Log("est_cross_delay", [=] { return est_.cross_delay_rate; }),
Log("est_spike_delay", [=] { return est_.spike_delay_rate; }),
Log("est_pre_buffer", [=] { return est_.pre_link_buffer_delay; }),
Log("est_post_buffer", [=] { return est_.post_link_buffer_delay; }),
Log("est_propagation", [=] { return est_.propagation_delay; }),
});
return loggers;
}
GoogCcStatePrinter::~GoogCcStatePrinter() = default;
void GoogCcStatePrinter::Attach(GoogCcNetworkController* controller) {
void GoogCcStatePrinter::PrintHeaders(RtcEventLogOutput* log) {
int ix = 0;
for (const auto& logger : loggers_) {
if (ix++)
log->Write(" ");
log->Write(logger->name());
}
log->Write("\n");
log->Flush();
}
void GoogCcStatePrinter::PrintState(RtcEventLogOutput* log,
GoogCcNetworkController* controller,
Timestamp at_time) {
controller_ = controller;
}
auto state_update = controller_->GetNetworkState(at_time);
target_ = state_update.target_rate.value();
pacing_ = state_update.pacer_config.value();
if (state_update.congestion_window)
congestion_window_ = *state_update.congestion_window;
if (controller_->network_estimator_) {
est_ = controller_->network_estimator_->GetCurrentEstimate().value_or(
NetworkStateEstimate());
}
bool GoogCcStatePrinter::Attached() const {
return controller_ != nullptr;
}
void GoogCcStatePrinter::PrintHeaders(RtcEventLogOutput* out) {
int ix = 0;
for (const auto& logger : loggers_) {
if (ix++)
out->Write(" ");
out->Write(logger->name());
log->Write(" ");
logger->WriteValue(log);
}
log->Write("\n");
log->Flush();
}
void GoogCcStatePrinter::PrintValues(RtcEventLogOutput* out) {
RTC_CHECK(controller_);
int ix = 0;
for (const auto& logger : loggers_) {
if (ix++)
out->Write(" ");
logger->WriteValue(out);
}
}
GoogCcDebugFactory::GoogCcDebugFactory()
: GoogCcDebugFactory(GoogCcFactoryConfig()) {}
NetworkControlUpdate GoogCcStatePrinter::GetState(Timestamp at_time) const {
RTC_CHECK(controller_);
return controller_->GetNetworkState(at_time);
}
GoogCcDebugFactory::GoogCcDebugFactory(GoogCcStatePrinter* printer)
: printer_(printer) {}
GoogCcDebugFactory::GoogCcDebugFactory(GoogCcFactoryConfig config)
: GoogCcNetworkControllerFactory(std::move(config)) {}
std::unique_ptr<NetworkControllerInterface> GoogCcDebugFactory::Create(
NetworkControllerConfig config) {
RTC_CHECK(controller_ == nullptr);
auto controller = GoogCcNetworkControllerFactory::Create(config);
controller_ = static_cast<GoogCcNetworkController*>(controller.get());
printer_->Attach(controller_);
return controller;
}
void GoogCcDebugFactory::PrintState(const Timestamp at_time) {
if (controller_ && log_writer_) {
printer_.PrintState(log_writer_.get(), controller_, at_time);
}
}
void GoogCcDebugFactory::AttachWriter(
std::unique_ptr<RtcEventLogOutput> log_writer) {
if (log_writer) {
log_writer_ = std::move(log_writer);
printer_.PrintHeaders(log_writer_.get());
}
}
} // namespace webrtc

View File

@ -20,7 +20,7 @@
#include "api/units/timestamp.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "modules/congestion_controller/goog_cc/goog_cc_network_control.h"
#include "modules/congestion_controller/test/controller_printer.h"
#include "test/logging/log_writer.h"
namespace webrtc {
@ -31,37 +31,44 @@ class FieldLogger {
virtual void WriteValue(RtcEventLogOutput* out) = 0;
};
class GoogCcStatePrinter : public DebugStatePrinter {
class GoogCcStatePrinter {
public:
GoogCcStatePrinter();
GoogCcStatePrinter(const GoogCcStatePrinter&) = delete;
GoogCcStatePrinter& operator=(const GoogCcStatePrinter&) = delete;
~GoogCcStatePrinter() override;
void Attach(GoogCcNetworkController*);
bool Attached() const override;
~GoogCcStatePrinter();
void PrintHeaders(RtcEventLogOutput* out) override;
void PrintValues(RtcEventLogOutput* out) override;
NetworkControlUpdate GetState(Timestamp at_time) const override;
void PrintHeaders(RtcEventLogOutput* log);
void PrintState(RtcEventLogOutput* log,
GoogCcNetworkController* controller,
Timestamp at_time);
private:
const NetworkStateEstimate& GetEst();
std::deque<FieldLogger*> CreateLoggers();
std::deque<std::unique_ptr<FieldLogger>> loggers_;
GoogCcNetworkController* controller_ = nullptr;
TargetTransferRate target_;
PacerConfig pacing_;
DataSize congestion_window_ = DataSize::PlusInfinity();
NetworkStateEstimate est_;
};
class GoogCcDebugFactory : public GoogCcNetworkControllerFactory {
public:
explicit GoogCcDebugFactory(GoogCcStatePrinter* printer);
GoogCcDebugFactory();
explicit GoogCcDebugFactory(GoogCcFactoryConfig config);
std::unique_ptr<NetworkControllerInterface> Create(
NetworkControllerConfig config) override;
void PrintState(const Timestamp at_time);
void AttachWriter(std::unique_ptr<RtcEventLogOutput> log_writer);
private:
GoogCcStatePrinter* printer_;
GoogCcStatePrinter printer_;
GoogCcNetworkController* controller_ = nullptr;
std::unique_ptr<RtcEventLogOutput> log_writer_;
};
} // namespace webrtc

View File

@ -1,68 +0,0 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "modules/congestion_controller/test/controller_printer.h"
#include <limits>
#include <utility>
#include "absl/types/optional.h"
#include "api/units/data_rate.h"
#include "api/units/data_size.h"
#include "api/units/time_delta.h"
namespace webrtc {
ControlStatePrinter::ControlStatePrinter(
std::unique_ptr<RtcEventLogOutput> output,
std::unique_ptr<DebugStatePrinter> debug_printer)
: output_(std::move(output)), debug_printer_(std::move(debug_printer)) {}
ControlStatePrinter::~ControlStatePrinter() = default;
void ControlStatePrinter::PrintHeaders() {
output_->Write("time bandwidth rtt target pacing padding window");
if (debug_printer_) {
output_->Write(" ");
debug_printer_->PrintHeaders(output_.get());
}
output_->Write("\n");
output_->Flush();
}
void ControlStatePrinter::PrintState(const Timestamp time,
const NetworkControlUpdate state) {
double timestamp = time.seconds<double>();
auto estimate = state.target_rate->network_estimate;
double bandwidth = estimate.bandwidth.bps() / 8.0;
double rtt = estimate.round_trip_time.seconds<double>();
double target_rate = state.target_rate->target_rate.bps() / 8.0;
double pacing_rate = state.pacer_config->data_rate().bps() / 8.0;
double padding_rate = state.pacer_config->pad_rate().bps() / 8.0;
double congestion_window = state.congestion_window
? state.congestion_window->bytes<double>()
: std::numeric_limits<double>::infinity();
LogWriteFormat(output_.get(), "%f %f %f %f %f %f %f", timestamp, bandwidth,
rtt, target_rate, pacing_rate, padding_rate,
congestion_window);
if (debug_printer_) {
output_->Write(" ");
debug_printer_->PrintValues(output_.get());
}
output_->Write("\n");
output_->Flush();
}
void ControlStatePrinter::PrintState(const Timestamp time) {
if (debug_printer_ && debug_printer_->Attached()) {
PrintState(time, debug_printer_->GetState(time));
}
}
} // namespace webrtc

View File

@ -1,44 +0,0 @@
/*
* Copyright 2018 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef MODULES_CONGESTION_CONTROLLER_TEST_CONTROLLER_PRINTER_H_
#define MODULES_CONGESTION_CONTROLLER_TEST_CONTROLLER_PRINTER_H_
#include <memory>
#include "api/transport/network_types.h"
#include "api/units/timestamp.h"
#include "test/logging/log_writer.h"
namespace webrtc {
class DebugStatePrinter {
public:
virtual bool Attached() const = 0;
virtual void PrintHeaders(RtcEventLogOutput* out) = 0;
virtual void PrintValues(RtcEventLogOutput* out) = 0;
virtual NetworkControlUpdate GetState(Timestamp at_time) const = 0;
virtual ~DebugStatePrinter() = default;
};
class ControlStatePrinter {
public:
ControlStatePrinter(std::unique_ptr<RtcEventLogOutput> output,
std::unique_ptr<DebugStatePrinter> debug_printer);
~ControlStatePrinter();
void PrintHeaders();
void PrintState(const Timestamp time, const NetworkControlUpdate state);
void PrintState(const Timestamp time);
private:
std::unique_ptr<RtcEventLogOutput> output_;
std::unique_ptr<DebugStatePrinter> debug_printer_;
};
} // namespace webrtc
#endif // MODULES_CONGESTION_CONTROLLER_TEST_CONTROLLER_PRINTER_H_

View File

@ -114,7 +114,6 @@ if (rtc_include_tests) {
"../../modules/audio_device:mock_audio_device",
"../../modules/audio_mixer:audio_mixer_impl",
"../../modules/audio_processing",
"../../modules/congestion_controller:test_controller_printer",
"../../modules/congestion_controller/goog_cc:test_goog_cc_printer",
"../../modules/rtp_rtcp",
"../../modules/rtp_rtcp:mock_rtp_rtcp",

View File

@ -13,7 +13,6 @@
#include "absl/memory/memory.h"
#include "modules/audio_mixer/audio_mixer_impl.h"
#include "modules/congestion_controller/goog_cc/test/goog_cc_printer.h"
namespace webrtc {
namespace test {
@ -96,18 +95,11 @@ LoggingNetworkControllerFactory::LoggingNetworkControllerFactory(
<< "Can't log controller state for injected network controllers";
} else {
if (log_writer_factory) {
auto goog_printer = absl::make_unique<GoogCcStatePrinter>();
owned_cc_factory_.reset(new GoogCcDebugFactory(goog_printer.get()));
cc_factory_ = owned_cc_factory_.get();
cc_printer_.reset(
new ControlStatePrinter(log_writer_factory->Create(".cc_state.txt"),
std::move(goog_printer)));
cc_printer_->PrintHeaders();
} else {
owned_cc_factory_.reset(
new GoogCcNetworkControllerFactory(GoogCcFactoryConfig()));
cc_factory_ = owned_cc_factory_.get();
goog_cc_factory_.AttachWriter(
log_writer_factory->Create(".cc_state.txt"));
print_cc_state_ = true;
}
cc_factory_ = &goog_cc_factory_;
}
}
@ -116,8 +108,8 @@ LoggingNetworkControllerFactory::~LoggingNetworkControllerFactory() {
void LoggingNetworkControllerFactory::LogCongestionControllerStats(
Timestamp at_time) {
if (cc_printer_)
cc_printer_->PrintState(at_time);
if (print_cc_state_)
goog_cc_factory_.PrintState(at_time);
}
std::unique_ptr<NetworkControllerInterface>

View File

@ -19,7 +19,7 @@
#include "call/call.h"
#include "logging/rtc_event_log/rtc_event_log.h"
#include "modules/audio_device/include/test_audio_device.h"
#include "modules/congestion_controller/test/controller_printer.h"
#include "modules/congestion_controller/goog_cc/test/goog_cc_printer.h"
#include "modules/rtp_rtcp/include/rtp_header_parser.h"
#include "rtc_base/constructor_magic.h"
#include "rtc_base/task_queue_for_test.h"
@ -47,9 +47,9 @@ class LoggingNetworkControllerFactory
void LogCongestionControllerStats(Timestamp at_time);
private:
std::unique_ptr<NetworkControllerFactoryInterface> owned_cc_factory_;
GoogCcDebugFactory goog_cc_factory_;
NetworkControllerFactoryInterface* cc_factory_ = nullptr;
std::unique_ptr<ControlStatePrinter> cc_printer_;
bool print_cc_state_ = false;
};
struct CallClientFakeAudio {