| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. | 2 * Copyright 2016 The WebRTC Project Authors. All rights reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include "webrtc/stats/rtcstatscollector.h" | 11 #include "webrtc/stats/rtcstatscollector.h" |
| 12 | 12 |
| 13 #include <memory> | 13 #include <memory> |
| 14 #include <utility> | 14 #include <utility> |
| 15 #include <vector> | 15 #include <vector> |
| 16 | 16 |
| 17 #include "webrtc/api/peerconnection.h" | 17 #include "webrtc/api/peerconnection.h" |
| 18 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/timing.h" | |
| 20 | 19 |
| 21 namespace webrtc { | 20 namespace webrtc { |
| 22 | 21 |
| 23 RTCStatsCollector::RTCStatsCollector( | 22 RTCStatsCollector::RTCStatsCollector( |
| 24 PeerConnection* pc, | 23 PeerConnection* pc, |
| 25 int64_t cache_lifetime_us) | 24 int64_t cache_lifetime_us) |
| 26 : pc_(pc), | 25 : pc_(pc), |
| 27 cache_timestamp_us_(0), | 26 cache_timestamp_us_(0), |
| 28 cache_lifetime_us_(cache_lifetime_us) { | 27 cache_lifetime_us_(cache_lifetime_us) { |
| 29 RTC_DCHECK(pc_); | 28 RTC_DCHECK(pc_); |
| 30 RTC_DCHECK(IsOnSignalingThread()); | 29 RTC_DCHECK(IsOnSignalingThread()); |
| 31 RTC_DCHECK_GE(cache_lifetime_us_, 0); | 30 RTC_DCHECK_GE(cache_lifetime_us_, 0); |
| 32 } | 31 } |
| 33 | 32 |
| 34 rtc::scoped_refptr<const RTCStatsReport> RTCStatsCollector::GetStatsReport() { | 33 rtc::scoped_refptr<const RTCStatsReport> RTCStatsCollector::GetStatsReport() { |
| 35 RTC_DCHECK(IsOnSignalingThread()); | 34 RTC_DCHECK(IsOnSignalingThread()); |
| 36 // "Now" using a monotonically increasing timer. | 35 // "Now" using a monotonically increasing timer. |
| 37 int64_t cache_now_us = rtc::TimeMicros(); | 36 int64_t cache_now_us = rtc::TimeMicros(); |
| 38 if (cached_report_ && | 37 if (cached_report_ && |
| 39 cache_now_us - cache_timestamp_us_ <= cache_lifetime_us_) { | 38 cache_now_us - cache_timestamp_us_ <= cache_lifetime_us_) { |
| 40 return cached_report_; | 39 return cached_report_; |
| 41 } | 40 } |
| 42 cache_timestamp_us_ = cache_now_us; | 41 cache_timestamp_us_ = cache_now_us; |
| 43 // "Now" using a system clock, relative to the UNIX epoch (Jan 1, 1970, UTC), | 42 // "Now" using a system clock, relative to the UNIX epoch (Jan 1, 1970, UTC), |
| 44 // in microseconds. The system clock could be modified and is not necessarily | 43 // in microseconds. The system clock could be modified and is not necessarily |
| 45 // monotonically increasing. | 44 // monotonically increasing. |
| 46 int64_t timestamp_us = static_cast<int64_t>( | 45 int64_t timestamp_us = rtc::TimeUTCMicros(); |
| 47 rtc::Timing::WallTimeNow() * rtc::kNumMicrosecsPerSec); | |
| 48 | 46 |
| 49 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); | 47 rtc::scoped_refptr<RTCStatsReport> report = RTCStatsReport::Create(); |
| 50 report->AddStats(ProducePeerConnectionStats(timestamp_us)); | 48 report->AddStats(ProducePeerConnectionStats(timestamp_us)); |
| 51 | 49 |
| 52 cached_report_ = report; | 50 cached_report_ = report; |
| 53 return cached_report_; | 51 return cached_report_; |
| 54 } | 52 } |
| 55 | 53 |
| 56 void RTCStatsCollector::ClearCachedStatsReport() { | 54 void RTCStatsCollector::ClearCachedStatsReport() { |
| 57 RTC_DCHECK(IsOnSignalingThread()); | 55 RTC_DCHECK(IsOnSignalingThread()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 78 // constant. | 76 // constant. |
| 79 std::unique_ptr<RTCPeerConnectionStats> stats( | 77 std::unique_ptr<RTCPeerConnectionStats> stats( |
| 80 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); | 78 new RTCPeerConnectionStats("RTCPeerConnection", timestamp_us)); |
| 81 stats->data_channels_opened = data_channels_opened; | 79 stats->data_channels_opened = data_channels_opened; |
| 82 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - | 80 stats->data_channels_closed = static_cast<uint32_t>(data_channels.size()) - |
| 83 data_channels_opened; | 81 data_channels_opened; |
| 84 return stats; | 82 return stats; |
| 85 } | 83 } |
| 86 | 84 |
| 87 } // namespace webrtc | 85 } // namespace webrtc |
| OLD | NEW |