You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

219 lines
5.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * Copyright 2019 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. #include "test/scenario/performance_stats.h"
  11. #include <algorithm>
  12. namespace webrtc {
  13. namespace test {
  14. void EventRateCounter::AddEvent(Timestamp event_time) {
  15. if (first_time_.IsFinite())
  16. interval_.AddSample(event_time - last_time_);
  17. first_time_ = std::min(first_time_, event_time);
  18. last_time_ = std::max(last_time_, event_time);
  19. event_count_++;
  20. }
  21. void EventRateCounter::AddEvents(EventRateCounter other) {
  22. first_time_ = std::min(first_time_, other.first_time_);
  23. last_time_ = std::max(last_time_, other.last_time_);
  24. event_count_ += other.event_count_;
  25. interval_.AddSamples(other.interval_);
  26. }
  27. bool EventRateCounter::IsEmpty() const {
  28. return first_time_ == last_time_;
  29. }
  30. double EventRateCounter::Rate() const {
  31. if (event_count_ == 0)
  32. return 0;
  33. if (event_count_ == 1)
  34. return NAN;
  35. return (event_count_ - 1) / (last_time_ - first_time_).seconds<double>();
  36. }
  37. TimeDelta EventRateCounter::TotalDuration() const {
  38. if (first_time_.IsInfinite()) {
  39. return TimeDelta::Zero();
  40. }
  41. return last_time_ - first_time_;
  42. }
  43. double SampleStats<double>::Max() {
  44. if (IsEmpty())
  45. return INFINITY;
  46. return GetMax();
  47. }
  48. double SampleStats<double>::Mean() {
  49. if (IsEmpty())
  50. return 0;
  51. return GetAverage();
  52. }
  53. double SampleStats<double>::Median() {
  54. return Quantile(0.5);
  55. }
  56. double SampleStats<double>::Quantile(double quantile) {
  57. if (IsEmpty())
  58. return 0;
  59. return GetPercentile(quantile);
  60. }
  61. double SampleStats<double>::Min() {
  62. if (IsEmpty())
  63. return -INFINITY;
  64. return GetMin();
  65. }
  66. double SampleStats<double>::Variance() {
  67. if (IsEmpty())
  68. return 0;
  69. return GetVariance();
  70. }
  71. double SampleStats<double>::StandardDeviation() {
  72. return sqrt(Variance());
  73. }
  74. int SampleStats<double>::Count() {
  75. return static_cast<int>(GetSamples().size());
  76. }
  77. void SampleStats<TimeDelta>::AddSample(TimeDelta delta) {
  78. RTC_DCHECK(delta.IsFinite());
  79. stats_.AddSample(delta.seconds<double>());
  80. }
  81. void SampleStats<TimeDelta>::AddSampleMs(double delta_ms) {
  82. AddSample(TimeDelta::ms(delta_ms));
  83. }
  84. void SampleStats<TimeDelta>::AddSamples(const SampleStats<TimeDelta>& other) {
  85. stats_.AddSamples(other.stats_);
  86. }
  87. bool SampleStats<TimeDelta>::IsEmpty() {
  88. return stats_.IsEmpty();
  89. }
  90. TimeDelta SampleStats<TimeDelta>::Max() {
  91. return TimeDelta::seconds(stats_.Max());
  92. }
  93. TimeDelta SampleStats<TimeDelta>::Mean() {
  94. return TimeDelta::seconds(stats_.Mean());
  95. }
  96. TimeDelta SampleStats<TimeDelta>::Median() {
  97. return Quantile(0.5);
  98. }
  99. TimeDelta SampleStats<TimeDelta>::Quantile(double quantile) {
  100. return TimeDelta::seconds(stats_.Quantile(quantile));
  101. }
  102. TimeDelta SampleStats<TimeDelta>::Min() {
  103. return TimeDelta::seconds(stats_.Min());
  104. }
  105. TimeDelta SampleStats<TimeDelta>::Variance() {
  106. return TimeDelta::seconds(stats_.Variance());
  107. }
  108. TimeDelta SampleStats<TimeDelta>::StandardDeviation() {
  109. return TimeDelta::seconds(stats_.StandardDeviation());
  110. }
  111. int SampleStats<TimeDelta>::Count() {
  112. return stats_.Count();
  113. }
  114. void SampleStats<DataRate>::AddSample(DataRate sample) {
  115. stats_.AddSample(sample.bps<double>());
  116. }
  117. void SampleStats<DataRate>::AddSampleBps(double rate_bps) {
  118. stats_.AddSample(rate_bps);
  119. }
  120. void SampleStats<DataRate>::AddSamples(const SampleStats<DataRate>& other) {
  121. stats_.AddSamples(other.stats_);
  122. }
  123. bool SampleStats<DataRate>::IsEmpty() {
  124. return stats_.IsEmpty();
  125. }
  126. DataRate SampleStats<DataRate>::Max() {
  127. return DataRate::bps(stats_.Max());
  128. }
  129. DataRate SampleStats<DataRate>::Mean() {
  130. return DataRate::bps(stats_.Mean());
  131. }
  132. DataRate SampleStats<DataRate>::Median() {
  133. return Quantile(0.5);
  134. }
  135. DataRate SampleStats<DataRate>::Quantile(double quantile) {
  136. return DataRate::bps(stats_.Quantile(quantile));
  137. }
  138. DataRate SampleStats<DataRate>::Min() {
  139. return DataRate::bps(stats_.Min());
  140. }
  141. DataRate SampleStats<DataRate>::Variance() {
  142. return DataRate::bps(stats_.Variance());
  143. }
  144. DataRate SampleStats<DataRate>::StandardDeviation() {
  145. return DataRate::bps(stats_.StandardDeviation());
  146. }
  147. int SampleStats<DataRate>::Count() {
  148. return stats_.Count();
  149. }
  150. void VideoFramesStats::AddFrameInfo(const VideoFrameBuffer& frame,
  151. Timestamp at_time) {
  152. ++count;
  153. RTC_DCHECK(at_time.IsFinite());
  154. pixels.AddSample(frame.width() * frame.height());
  155. resolution.AddSample(std::max(frame.width(), frame.height()));
  156. frames.AddEvent(at_time);
  157. }
  158. void VideoFramesStats::AddStats(const VideoFramesStats& other) {
  159. count += other.count;
  160. pixels.AddSamples(other.pixels);
  161. resolution.AddSamples(other.resolution);
  162. frames.AddEvents(other.frames);
  163. }
  164. void VideoQualityStats::AddStats(const VideoQualityStats& other) {
  165. capture.AddStats(other.capture);
  166. render.AddStats(other.render);
  167. lost_count += other.lost_count;
  168. freeze_count += other.freeze_count;
  169. capture_to_decoded_delay.AddSamples(other.capture_to_decoded_delay);
  170. end_to_end_delay.AddSamples(other.end_to_end_delay);
  171. psnr.AddSamples(other.psnr);
  172. psnr_with_freeze.AddSamples(other.psnr_with_freeze);
  173. skipped_between_rendered.AddSamples(other.skipped_between_rendered);
  174. freeze_duration.AddSamples(other.freeze_duration);
  175. time_between_freezes.AddSamples(other.time_between_freezes);
  176. }
  177. } // namespace test
  178. } // namespace webrtc