1 /* 2 * Copyright 2020 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "pc/usage_pattern.h" 12 13 #include "api/peer_connection_interface.h" 14 #include "rtc_base/logging.h" 15 #include "system_wrappers/include/metrics.h" 16 17 namespace webrtc { 18 NoteUsageEvent(UsageEvent event)19void UsagePattern::NoteUsageEvent(UsageEvent event) { 20 usage_event_accumulator_ |= static_cast<int>(event); 21 } 22 ReportUsagePattern(PeerConnectionObserver * observer) const23void UsagePattern::ReportUsagePattern(PeerConnectionObserver* observer) const { 24 RTC_DLOG(LS_INFO) << "Usage signature is " << usage_event_accumulator_; 25 RTC_HISTOGRAM_ENUMERATION_SPARSE("WebRTC.PeerConnection.UsagePattern", 26 usage_event_accumulator_, 27 static_cast<int>(UsageEvent::MAX_VALUE)); 28 const int bad_bits = 29 static_cast<int>(UsageEvent::SET_LOCAL_DESCRIPTION_SUCCEEDED) | 30 static_cast<int>(UsageEvent::CANDIDATE_COLLECTED); 31 const int good_bits = 32 static_cast<int>(UsageEvent::SET_REMOTE_DESCRIPTION_SUCCEEDED) | 33 static_cast<int>(UsageEvent::REMOTE_CANDIDATE_ADDED) | 34 static_cast<int>(UsageEvent::ICE_STATE_CONNECTED); 35 if ((usage_event_accumulator_ & bad_bits) == bad_bits && 36 (usage_event_accumulator_ & good_bits) == 0) { 37 // If called after close(), we can't report, because observer may have 38 // been deallocated, and therefore pointer is null. Write to log instead. 39 if (observer) { 40 observer->OnInterestingUsage(usage_event_accumulator_); 41 } else { 42 RTC_LOG(LS_INFO) << "Interesting usage signature " 43 << usage_event_accumulator_ 44 << " observed after observer shutdown"; 45 } 46 } 47 } 48 49 } // namespace webrtc 50