Revert "Refactor AnalyzerConfig to use Timestamps instead of microseconds."

This reverts commit 43fb16921b29ecd3a2d87876dda75c575e05f66a.

Reason for revert: New type breaks downstream projects.

Original change's description:
> Refactor AnalyzerConfig to use Timestamps instead of microseconds.
>
> Add optional offset-to-UTC parameter to output. This allows aligning
> the x-axis in the generated charts to other UTC-based logs.
>
> Bug: b/215140373
> Change-Id: I65bcd295718acbb8c94e363907c1abc458067bfd
> Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/250203
> Reviewed-by: Kristoffer Erlandsson <kerl@google.com>
> Commit-Queue: Björn Terelius <terelius@webrtc.org>
> Cr-Commit-Position: refs/heads/main@{#35992}

TBR=terelius@webrtc.org,kerl@google.com,webrtc-scoped@luci-project-accounts.iam.gserviceaccount.com

Change-Id: If4f2330b9731f26a0e55c9ce9a500322a111b783
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: b/215140373
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/251691
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Evan Shrubsole <eshr@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Christoffer Jansson <jansson@google.com>
Cr-Commit-Position: refs/heads/main@{#35994}
This commit is contained in:
Christoffer Jansson
2022-02-14 14:56:38 +00:00
committed by WebRTC LUCI CQ
parent e7b4c137cc
commit 66bfd6f57d
36 changed files with 129 additions and 203 deletions

View File

@ -22,7 +22,6 @@
namespace webrtc {
constexpr int kNumMicrosecsPerSec = 1000000;
constexpr int kNumMillisecsPerSec = 1000;
constexpr float kLeftMargin = 0.01f;
constexpr float kRightMargin = 0.02f;
constexpr float kBottomMargin = 0.02f;
@ -30,38 +29,25 @@ constexpr float kTopMargin = 0.05f;
class AnalyzerConfig {
public:
float GetCallTimeSec(Timestamp timestamp) const {
Timestamp offset = normalize_time_ ? begin_time_ : Timestamp::Zero();
return static_cast<float>((timestamp - offset).us()) / 1000000;
}
float GetCallTimeSecFromMs(int64_t timestamp_ms) const {
return GetCallTimeSec(Timestamp::Millis(timestamp_ms));
float GetCallTimeSec(int64_t timestamp_us) const {
int64_t offset = normalize_time_ ? begin_time_ : 0;
return static_cast<float>(timestamp_us - offset) / 1000000;
}
float CallBeginTimeSec() const { return GetCallTimeSec(begin_time_); }
float CallEndTimeSec() const { return GetCallTimeSec(end_time_); }
int64_t CallTimeToUtcOffsetMs() {
if (normalize_time_) {
Timestamp utc_begin_time_ = begin_time_ + rtc_to_utc_offset_;
return utc_begin_time_.ms();
}
return rtc_to_utc_offset_.ms();
}
// Window and step size used for calculating moving averages, e.g. bitrate.
// The generated data points will be `step_.ms()` milliseconds apart.
// Only events occurring at most `window_duration_.ms()` milliseconds before
// the current data point will be part of the average.
TimeDelta window_duration_ = TimeDelta::Millis(250);
TimeDelta step_ = TimeDelta::Millis(10);
// The generated data points will be `step_` microseconds apart.
// Only events occurring at most `window_duration_` microseconds before the
// current data point will be part of the average.
int64_t window_duration_;
int64_t step_;
// First and last events of the log.
Timestamp begin_time_ = Timestamp::MinusInfinity();
Timestamp end_time_ = Timestamp::MinusInfinity();
TimeDelta rtc_to_utc_offset_ = TimeDelta::Zero();
int64_t begin_time_;
int64_t end_time_;
bool normalize_time_;
};
@ -166,17 +152,17 @@ void MovingAverage(
size_t window_index_end = 0;
ResultType sum_in_window = 0;
for (Timestamp t = config.begin_time_; t < config.end_time_ + config.step_;
for (int64_t t = config.begin_time_; t < config.end_time_ + config.step_;
t += config.step_) {
while (window_index_end < data_view.size() &&
data_view[window_index_end].log_time() < t) {
data_view[window_index_end].log_time_us() < t) {
absl::optional<ResultType> value = fy(data_view[window_index_end]);
if (value)
sum_in_window += *value;
++window_index_end;
}
while (window_index_begin < data_view.size() &&
data_view[window_index_begin].log_time() <
data_view[window_index_begin].log_time_us() <
t - config.window_duration_) {
absl::optional<ResultType> value = fy(data_view[window_index_begin]);
if (value)
@ -184,7 +170,7 @@ void MovingAverage(
++window_index_begin;
}
float window_duration_s =
static_cast<float>(config.window_duration_.us()) / kNumMicrosecsPerSec;
static_cast<float>(config.window_duration_) / kNumMicrosecsPerSec;
float x = config.GetCallTimeSec(t);
float y = sum_in_window / window_duration_s;
result->points.emplace_back(x, y);