RtcEventLogImpl nits

1. Make |output_period_ms_| optional, so as to clarify where
   it gets assigned a value. (I.e. the value set by the ctor
   is not retained.)
2. Some extra const modifiers.

Bug: webrtc:8111
Change-Id: I9f3ad7ff763cfbc9c9385f7fd4325ba696772765
Reviewed-on: https://webrtc-review.googlesource.com/c/112588
Commit-Queue: Elad Alon <eladalon@webrtc.org>
Reviewed-by: Björn Terelius <terelius@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25877}
This commit is contained in:
Elad Alon
2018-12-03 12:54:40 +01:00
committed by Commit Bot
parent aa3d8ad71b
commit e7673cf922
2 changed files with 9 additions and 7 deletions

View File

@ -244,6 +244,7 @@ rtc_static_library("rtc_event_log_impl_base") {
"../rtc_base:safe_minmax",
"../rtc_base:sequenced_task_checker",
"//third_party/abseil-cpp/absl/memory",
"//third_party/abseil-cpp/absl/types:optional",
]
if (rtc_enable_protobuf) {

View File

@ -18,6 +18,7 @@
#include <vector>
#include "absl/memory/memory.h"
#include "absl/types/optional.h"
#include "api/rtceventlogoutput.h"
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_legacy.h"
#include "logging/rtc_event_log/encoder/rtc_event_log_encoder_new_format.h"
@ -127,7 +128,7 @@ class RtcEventLogImpl final : public RtcEventLog {
std::unique_ptr<RtcEventLogOutput> event_output_ RTC_GUARDED_BY(*task_queue_);
size_t num_config_events_written_ RTC_GUARDED_BY(*task_queue_);
int64_t output_period_ms_ RTC_GUARDED_BY(*task_queue_);
absl::optional<int64_t> output_period_ms_ RTC_GUARDED_BY(*task_queue_);
int64_t last_output_ms_ RTC_GUARDED_BY(*task_queue_);
bool output_scheduled_ RTC_GUARDED_BY(*task_queue_);
@ -147,7 +148,6 @@ RtcEventLogImpl::RtcEventLogImpl(
written_bytes_(0),
event_encoder_(std::move(event_encoder)),
num_config_events_written_(0),
output_period_ms_(kImmediateOutput),
last_output_ms_(rtc::TimeMillis()),
output_scheduled_(false),
task_queue_(std::move(task_queue)) {
@ -250,7 +250,8 @@ void RtcEventLogImpl::ScheduleOutput() {
return;
}
if (output_period_ms_ == kImmediateOutput) {
RTC_DCHECK(output_period_ms_.has_value());
if (*output_period_ms_ == kImmediateOutput) {
// We are already on the |task_queue_| so there is no reason to post a task
// if we want to output immediately.
LogEventsFromMemoryToOutput();
@ -268,10 +269,10 @@ void RtcEventLogImpl::ScheduleOutput() {
}
output_scheduled_ = false;
};
int64_t now_ms = rtc::TimeMillis();
int64_t time_since_output_ms = now_ms - last_output_ms_;
uint32_t delay = rtc::SafeClamp(output_period_ms_ - time_since_output_ms, 0,
output_period_ms_);
const int64_t now_ms = rtc::TimeMillis();
const int64_t time_since_output_ms = now_ms - last_output_ms_;
const uint32_t delay = rtc::SafeClamp(
*output_period_ms_ - time_since_output_ms, 0, *output_period_ms_);
task_queue_->PostDelayedTask(output_task, delay);
}
}