2015-07-03 01:36:14 -07:00
|
|
|
/*
|
2016-02-10 07:54:43 -08:00
|
|
|
* Copyright 2015 The WebRTC project authors. All Rights Reserved.
|
2015-07-03 01:36:14 -07:00
|
|
|
*
|
2016-02-10 07:54:43 -08:00
|
|
|
* 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.
|
2015-07-03 01:36:14 -07:00
|
|
|
*/
|
|
|
|
|
|
2016-02-10 10:53:12 +01:00
|
|
|
#include "webrtc/api/fakemetricsobserver.h"
|
2015-07-03 01:36:14 -07:00
|
|
|
#include "webrtc/base/checks.h"
|
|
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
|
|
|
|
|
FakeMetricsObserver::FakeMetricsObserver() {
|
|
|
|
|
Reset();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeMetricsObserver::Reset() {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-08-21 09:06:28 -07:00
|
|
|
counters_.clear();
|
2015-09-30 21:48:54 -07:00
|
|
|
memset(histogram_samples_, 0, sizeof(histogram_samples_));
|
2015-07-03 01:36:14 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-19 16:51:15 -07:00
|
|
|
void FakeMetricsObserver::IncrementEnumCounter(
|
|
|
|
|
PeerConnectionEnumCounterType type,
|
|
|
|
|
int counter,
|
|
|
|
|
int counter_max) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-08-19 16:51:15 -07:00
|
|
|
if (counters_.size() <= static_cast<size_t>(type)) {
|
|
|
|
|
counters_.resize(type + 1);
|
|
|
|
|
}
|
|
|
|
|
auto& counters = counters_[type];
|
|
|
|
|
++counters[counter];
|
2015-07-03 01:36:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type,
|
|
|
|
|
int value) {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-09-30 21:48:54 -07:00
|
|
|
RTC_DCHECK_EQ(histogram_samples_[type], 0);
|
|
|
|
|
histogram_samples_[type] = value;
|
2015-07-03 01:36:14 -07:00
|
|
|
}
|
|
|
|
|
|
2015-08-19 16:51:15 -07:00
|
|
|
int FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type,
|
|
|
|
|
int counter) const {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2016-10-05 11:47:22 -07:00
|
|
|
if (counters_.size() <= static_cast<size_t>(type)) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-09-30 21:48:54 -07:00
|
|
|
const auto& it = counters_[type].find(counter);
|
|
|
|
|
if (it == counters_[type].end()) {
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
return it->second;
|
2015-07-03 01:36:14 -07:00
|
|
|
}
|
|
|
|
|
|
2015-09-30 21:48:54 -07:00
|
|
|
int FakeMetricsObserver::GetHistogramSample(
|
2015-07-03 01:36:14 -07:00
|
|
|
PeerConnectionMetricsName type) const {
|
2015-09-17 00:24:34 -07:00
|
|
|
RTC_DCHECK(thread_checker_.CalledOnValidThread());
|
2015-09-30 21:48:54 -07:00
|
|
|
return histogram_samples_[type];
|
2015-07-03 01:36:14 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace webrtc
|