1ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch/* 2ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * libjingle 3ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * Copyright 2015 Google Inc. 4ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * 5ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * Redistribution and use in source and binary forms, with or without 6ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * modification, are permitted provided that the following conditions are met: 7ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * 8ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * 1. Redistributions of source code must retain the above copyright notice, 9ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * this list of conditions and the following disclaimer. 10ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * 2. Redistributions in binary form must reproduce the above copyright notice, 11ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * this list of conditions and the following disclaimer in the documentation 12ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * and/or other materials provided with the distribution. 13ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * 3. The name of the author may not be used to endorse or promote products 14ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * derived from this software without specific prior written permission. 15ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * 16ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 17ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO 19ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 21ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 22ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 23ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 24ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 25ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch */ 27ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch 28ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch#include "talk/app/webrtc/fakemetricsobserver.h" 29ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch#include "webrtc/base/checks.h" 30ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch 31ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauchnamespace webrtc { 32ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch 33ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauchFakeMetricsObserver::FakeMetricsObserver() { 34ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch Reset(); 35ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch} 36ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch 37ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauchvoid FakeMetricsObserver::Reset() { 38ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch RTC_DCHECK(thread_checker_.CalledOnValidThread()); 39ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch counters_.clear(); 40ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch memset(histogram_samples_, 0, sizeof(histogram_samples_)); 41ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch} 42ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch 43ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauchvoid FakeMetricsObserver::IncrementEnumCounter( 443d564c10157d7de1d2d4236f4e2a13ff1363d52bGuo-wei Shieh PeerConnectionEnumCounterType type, 453d564c10157d7de1d2d4236f4e2a13ff1363d52bGuo-wei Shieh int counter, 463d564c10157d7de1d2d4236f4e2a13ff1363d52bGuo-wei Shieh int counter_max) { 47ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch RTC_DCHECK(thread_checker_.CalledOnValidThread()); 48ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch if (counters_.size() <= static_cast<size_t>(type)) { 49ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch counters_.resize(type + 1); 50ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch } 513d564c10157d7de1d2d4236f4e2a13ff1363d52bGuo-wei Shieh auto& counters = counters_[type]; 52456696a9c1bbd586701dcca3e4b2695e419a10baGuo-wei Shieh ++counters[counter]; 53ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch} 54ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch 55ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauchvoid FakeMetricsObserver::AddHistogramSample(PeerConnectionMetricsName type, 56ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch int value) { 57ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch RTC_DCHECK(thread_checker_.CalledOnValidThread()); 58ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch RTC_DCHECK_EQ(histogram_samples_[type], 0); 59456696a9c1bbd586701dcca3e4b2695e419a10baGuo-wei Shieh histogram_samples_[type] = value; 60456696a9c1bbd586701dcca3e4b2695e419a10baGuo-wei Shieh} 61456696a9c1bbd586701dcca3e4b2695e419a10baGuo-wei Shieh 62456696a9c1bbd586701dcca3e4b2695e419a10baGuo-wei Shiehint FakeMetricsObserver::GetEnumCounter(PeerConnectionEnumCounterType type, 63456696a9c1bbd586701dcca3e4b2695e419a10baGuo-wei Shieh int counter) const { 64ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch RTC_DCHECK(thread_checker_.CalledOnValidThread()); 65ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch RTC_CHECK(counters_.size() > static_cast<size_t>(type)); 66ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch const auto& it = counters_[type].find(counter); 67ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch if (it == counters_[type].end()) { 68ac8869ec5a606e0a0ab71e70937c8fbf403630cejbauch return 0; 69 } 70 return it->second; 71} 72 73int FakeMetricsObserver::GetHistogramSample( 74 PeerConnectionMetricsName type) const { 75 RTC_DCHECK(thread_checker_.CalledOnValidThread()); 76 return histogram_samples_[type]; 77} 78 79} // namespace webrtc 80