Propagate Environment into RtcEventLogImpl

With intention to propagte it futher into RtcEventLogEncoderNewFormat
where it can replace usage of the global field trials

Same environment can be saved in RtcEventLogImpl itself wthere it can
replace usage of the global clock

Bug: webrtc:10335
Change-Id: Ia147d7073af5aab54190fdf192cd5c046c3d40a1
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/330423
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Danil Chapovalov <danilchap@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#41472}
This commit is contained in:
Danil Chapovalov 2024-01-04 12:51:15 +01:00 committed by WebRTC LUCI CQ
parent 78a57efb29
commit c41977d303
4 changed files with 20 additions and 23 deletions

View file

@ -31,12 +31,7 @@ absl::Nonnull<std::unique_ptr<RtcEventLog>> RtcEventLogFactory::Create(
if (env.field_trials().IsEnabled("WebRTC-RtcEventLogKillSwitch")) {
return std::make_unique<RtcEventLogNull>();
}
RtcEventLog::EncodingType encoding_type =
env.field_trials().IsDisabled("WebRTC-RtcEventLogNewFormat")
? RtcEventLog::EncodingType::Legacy
: RtcEventLog::EncodingType::NewFormat;
return std::make_unique<RtcEventLogImpl>(
RtcEventLogImpl::CreateEncoder(encoding_type), &env.task_queue_factory());
return std::make_unique<RtcEventLogImpl>(env);
#endif
}

View file

@ -450,8 +450,10 @@ if (rtc_enable_protobuf) {
":ice_log",
":rtc_event_log_api",
":rtc_event_log_impl_encoder",
"../api:field_trials_view",
"../api:libjingle_logging_api",
"../api:sequence_checker",
"../api/environment",
"../api/rtc_event_log",
"../api/task_queue",
"../api/units:time_delta",

View file

@ -17,6 +17,8 @@
#include <vector>
#include "absl/strings/string_view.h"
#include "api/environment/environment.h"
#include "api/field_trials_view.h"
#include "api/task_queue/task_queue_base.h"
#include "api/units/time_delta.h"
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
@ -29,24 +31,23 @@
#include "rtc_base/time_utils.h"
namespace webrtc {
namespace {
std::unique_ptr<RtcEventLogEncoder> RtcEventLogImpl::CreateEncoder(
RtcEventLog::EncodingType type) {
switch (type) {
case RtcEventLog::EncodingType::Legacy:
RTC_DLOG(LS_INFO) << "Creating legacy encoder for RTC event log.";
return std::make_unique<RtcEventLogEncoderLegacy>();
case RtcEventLog::EncodingType::NewFormat:
RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log.";
return std::make_unique<RtcEventLogEncoderNewFormat>();
default:
RTC_LOG(LS_ERROR) << "Unknown RtcEventLog encoder type (" << int(type)
<< ")";
RTC_DCHECK_NOTREACHED();
return std::unique_ptr<RtcEventLogEncoder>(nullptr);
std::unique_ptr<RtcEventLogEncoder> CreateEncoder(const Environment& env) {
if (env.field_trials().IsDisabled("WebRTC-RtcEventLogNewFormat")) {
RTC_DLOG(LS_INFO) << "Creating legacy encoder for RTC event log.";
return std::make_unique<RtcEventLogEncoderLegacy>();
} else {
RTC_DLOG(LS_INFO) << "Creating new format encoder for RTC event log.";
return std::make_unique<RtcEventLogEncoderNewFormat>();
}
}
} // namespace
RtcEventLogImpl::RtcEventLogImpl(const Environment& env)
: RtcEventLogImpl(CreateEncoder(env), &env.task_queue_factory()) {}
RtcEventLogImpl::RtcEventLogImpl(std::unique_ptr<RtcEventLogEncoder> encoder,
TaskQueueFactory* task_queue_factory,
size_t max_events_in_history,

View file

@ -18,6 +18,7 @@
#include <string>
#include "absl/strings/string_view.h"
#include "api/environment/environment.h"
#include "api/rtc_event_log/rtc_event.h"
#include "api/rtc_event_log/rtc_event_log.h"
#include "api/rtc_event_log_output.h"
@ -39,6 +40,7 @@ class RtcEventLogImpl final : public RtcEventLog {
// bound to prevent an attack via unreasonable memory use.
static constexpr size_t kMaxEventsInConfigHistory = 1000;
explicit RtcEventLogImpl(const Environment& env);
RtcEventLogImpl(
std::unique_ptr<RtcEventLogEncoder> encoder,
TaskQueueFactory* task_queue_factory,
@ -49,9 +51,6 @@ class RtcEventLogImpl final : public RtcEventLog {
~RtcEventLogImpl() override;
static std::unique_ptr<RtcEventLogEncoder> CreateEncoder(
EncodingType encoding_type);
// TODO(eladalon): We should change these name to reflect that what we're
// actually starting/stopping is the output of the log, not the log itself.
bool StartLogging(std::unique_ptr<RtcEventLogOutput> output,