Extract CPU measurer from DVQA
Bug: b/196229820 Change-Id: I1f8f21ea5864f9ba98365e4699572fabd8cb1ece Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/228560 Reviewed-by: Mirko Bonadei <mbonadei@webrtc.org> Commit-Queue: Artem Titov <titovartem@webrtc.org> Cr-Commit-Position: refs/heads/master@{#34741}
This commit is contained in:
parent
da6a9d58f8
commit
40f7a5bab0
@ -639,10 +639,8 @@ if (!build_with_chromium) {
|
||||
"../../../rtc_base:criticalsection",
|
||||
"../../../rtc_base:logging",
|
||||
"../../../rtc_base:rtc_base_approved",
|
||||
"../../../rtc_base:rtc_base_tests_utils",
|
||||
"../../../rtc_base:rtc_event",
|
||||
"../../../rtc_base:rtc_numerics",
|
||||
"../../../rtc_base:timeutils",
|
||||
"../../../rtc_base/synchronization:mutex",
|
||||
"../../../rtc_tools:video_quality_analysis",
|
||||
"../../../system_wrappers",
|
||||
@ -657,6 +655,8 @@ if (!build_with_chromium) {
|
||||
|
||||
testonly = true
|
||||
sources = [
|
||||
"analyzer/video/default_video_quality_analyzer_cpu_measurer.cc",
|
||||
"analyzer/video/default_video_quality_analyzer_cpu_measurer.h",
|
||||
"analyzer/video/default_video_quality_analyzer_internal_shared_objects.cc",
|
||||
"analyzer/video/default_video_quality_analyzer_internal_shared_objects.h",
|
||||
]
|
||||
@ -666,7 +666,10 @@ if (!build_with_chromium) {
|
||||
"../../../api/numerics:numerics",
|
||||
"../../../api/units:timestamp",
|
||||
"../../../api/video:video_frame",
|
||||
"../../../rtc_base:rtc_base_tests_utils",
|
||||
"../../../rtc_base:stringutils",
|
||||
"../../../rtc_base:timeutils",
|
||||
"../../../rtc_base/synchronization:mutex",
|
||||
]
|
||||
absl_deps = [ "//third_party/abseil-cpp/absl/types:optional" ]
|
||||
}
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
#include "api/units/time_delta.h"
|
||||
#include "api/video/i420_buffer.h"
|
||||
#include "common_video/libyuv/include/webrtc_libyuv.h"
|
||||
#include "rtc_base/cpu_time.h"
|
||||
#include "rtc_base/logging.h"
|
||||
#include "rtc_base/platform_thread.h"
|
||||
#include "rtc_base/strings/string_builder.h"
|
||||
@ -132,7 +131,7 @@ void DefaultVideoQualityAnalyzer::Start(
|
||||
state_ = State::kActive;
|
||||
start_time_ = Now();
|
||||
}
|
||||
StartMeasuringCpuProcessTime();
|
||||
cpu_measurer_.StartMeasuringCpuProcessTime();
|
||||
}
|
||||
|
||||
uint16_t DefaultVideoQualityAnalyzer::OnFrameCaptured(
|
||||
@ -557,7 +556,7 @@ void DefaultVideoQualityAnalyzer::Stop() {
|
||||
}
|
||||
state_ = State::kStopped;
|
||||
}
|
||||
StopMeasuringCpuProcessTime();
|
||||
cpu_measurer_.StopMeasuringCpuProcessTime();
|
||||
comparison_available_event_.Set();
|
||||
thread_pool_.clear();
|
||||
|
||||
@ -663,7 +662,7 @@ void DefaultVideoQualityAnalyzer::AddComparison(
|
||||
absl::optional<VideoFrame> rendered,
|
||||
bool dropped,
|
||||
FrameStats frame_stats) {
|
||||
StartExcludingCpuThreadTime();
|
||||
cpu_measurer_.StartExcludingCpuThreadTime();
|
||||
analyzer_stats_.comparisons_queue_size.AddSample(
|
||||
StatsSample(comparisons_.size(), Now()));
|
||||
// If there too many computations waiting in the queue, we won't provide
|
||||
@ -682,7 +681,7 @@ void DefaultVideoQualityAnalyzer::AddComparison(
|
||||
std::move(frame_stats), overload_reason);
|
||||
}
|
||||
comparison_available_event_.Set();
|
||||
StopExcludingCpuThreadTime();
|
||||
cpu_measurer_.StopExcludingCpuThreadTime();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzer::ProcessComparisons() {
|
||||
@ -715,9 +714,9 @@ void DefaultVideoQualityAnalyzer::ProcessComparisons() {
|
||||
continue;
|
||||
}
|
||||
|
||||
StartExcludingCpuThreadTime();
|
||||
cpu_measurer_.StartExcludingCpuThreadTime();
|
||||
ProcessComparison(comparison.value());
|
||||
StopExcludingCpuThreadTime();
|
||||
cpu_measurer_.StopExcludingCpuThreadTime();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1001,31 +1000,8 @@ std::string DefaultVideoQualityAnalyzer::StatsKeyToMetricName(
|
||||
return key.ToString();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzer::StartMeasuringCpuProcessTime() {
|
||||
MutexLock lock(&cpu_measurement_lock_);
|
||||
cpu_time_ -= rtc::GetProcessCpuTimeNanos();
|
||||
wallclock_time_ -= rtc::SystemTimeNanos();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzer::StopMeasuringCpuProcessTime() {
|
||||
MutexLock lock(&cpu_measurement_lock_);
|
||||
cpu_time_ += rtc::GetProcessCpuTimeNanos();
|
||||
wallclock_time_ += rtc::SystemTimeNanos();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzer::StartExcludingCpuThreadTime() {
|
||||
MutexLock lock(&cpu_measurement_lock_);
|
||||
cpu_time_ += rtc::GetThreadCpuTimeNanos();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzer::StopExcludingCpuThreadTime() {
|
||||
MutexLock lock(&cpu_measurement_lock_);
|
||||
cpu_time_ -= rtc::GetThreadCpuTimeNanos();
|
||||
}
|
||||
|
||||
double DefaultVideoQualityAnalyzer::GetCpuUsagePercent() {
|
||||
MutexLock lock(&cpu_measurement_lock_);
|
||||
return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
|
||||
return cpu_measurer_.GetCpuUsagePercent();
|
||||
}
|
||||
|
||||
uint16_t DefaultVideoQualityAnalyzer::StreamState::PopFront(size_t peer) {
|
||||
|
||||
@ -29,6 +29,7 @@
|
||||
#include "rtc_base/platform_thread.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "system_wrappers/include/clock.h"
|
||||
#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_cpu_measurer.h"
|
||||
#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_internal_shared_objects.h"
|
||||
#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_shared_objects.h"
|
||||
#include "test/pc/e2e/analyzer/video/multi_head_queue.h"
|
||||
@ -338,11 +339,6 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface {
|
||||
std::string StatsKeyToMetricName(const StatsKey& key) const
|
||||
RTC_EXCLUSIVE_LOCKS_REQUIRED(lock_);
|
||||
|
||||
void StartMeasuringCpuProcessTime();
|
||||
void StopMeasuringCpuProcessTime();
|
||||
void StartExcludingCpuThreadTime();
|
||||
void StopExcludingCpuThreadTime();
|
||||
|
||||
// TODO(titovartem) restore const when old constructor will be removed.
|
||||
DefaultVideoQualityAnalyzerOptions options_;
|
||||
webrtc::Clock* const clock_;
|
||||
@ -398,9 +394,7 @@ class DefaultVideoQualityAnalyzer : public VideoQualityAnalyzerInterface {
|
||||
std::vector<rtc::PlatformThread> thread_pool_;
|
||||
rtc::Event comparison_available_event_;
|
||||
|
||||
Mutex cpu_measurement_lock_;
|
||||
int64_t cpu_time_ RTC_GUARDED_BY(cpu_measurement_lock_) = 0;
|
||||
int64_t wallclock_time_ RTC_GUARDED_BY(cpu_measurement_lock_) = 0;
|
||||
DefaultVideoQualityAnalyzerCpuMeasurer cpu_measurer_;
|
||||
};
|
||||
|
||||
} // namespace webrtc_pc_e2e
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer_cpu_measurer.h"
|
||||
|
||||
#include "rtc_base/cpu_time.h"
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
#include "rtc_base/system_time.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
void DefaultVideoQualityAnalyzerCpuMeasurer::StartMeasuringCpuProcessTime() {
|
||||
MutexLock lock(&mutex_);
|
||||
cpu_time_ -= rtc::GetProcessCpuTimeNanos();
|
||||
wallclock_time_ -= rtc::SystemTimeNanos();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzerCpuMeasurer::StopMeasuringCpuProcessTime() {
|
||||
MutexLock lock(&mutex_);
|
||||
cpu_time_ += rtc::GetProcessCpuTimeNanos();
|
||||
wallclock_time_ += rtc::SystemTimeNanos();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzerCpuMeasurer::StartExcludingCpuThreadTime() {
|
||||
MutexLock lock(&mutex_);
|
||||
cpu_time_ += rtc::GetThreadCpuTimeNanos();
|
||||
}
|
||||
|
||||
void DefaultVideoQualityAnalyzerCpuMeasurer::StopExcludingCpuThreadTime() {
|
||||
MutexLock lock(&mutex_);
|
||||
cpu_time_ -= rtc::GetThreadCpuTimeNanos();
|
||||
}
|
||||
|
||||
double DefaultVideoQualityAnalyzerCpuMeasurer::GetCpuUsagePercent() {
|
||||
MutexLock lock(&mutex_);
|
||||
return static_cast<double>(cpu_time_) / wallclock_time_ * 100.0;
|
||||
}
|
||||
|
||||
} // namespace webrtc
|
||||
@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright (c) 2021 The WebRTC project authors. All Rights Reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef TEST_PC_E2E_ANALYZER_VIDEO_DEFAULT_VIDEO_QUALITY_ANALYZER_CPU_MEASURER_H_
|
||||
#define TEST_PC_E2E_ANALYZER_VIDEO_DEFAULT_VIDEO_QUALITY_ANALYZER_CPU_MEASURER_H_
|
||||
|
||||
#include "rtc_base/synchronization/mutex.h"
|
||||
|
||||
namespace webrtc {
|
||||
|
||||
// This class is thread safe.
|
||||
class DefaultVideoQualityAnalyzerCpuMeasurer {
|
||||
public:
|
||||
double GetCpuUsagePercent();
|
||||
|
||||
void StartMeasuringCpuProcessTime();
|
||||
void StopMeasuringCpuProcessTime();
|
||||
void StartExcludingCpuThreadTime();
|
||||
void StopExcludingCpuThreadTime();
|
||||
|
||||
private:
|
||||
Mutex mutex_;
|
||||
int64_t cpu_time_ RTC_GUARDED_BY(mutex_) = 0;
|
||||
int64_t wallclock_time_ RTC_GUARDED_BY(mutex_) = 0;
|
||||
};
|
||||
|
||||
} // namespace webrtc
|
||||
|
||||
#endif // TEST_PC_E2E_ANALYZER_VIDEO_DEFAULT_VIDEO_QUALITY_ANALYZER_CPU_MEASURER_H_
|
||||
Loading…
x
Reference in New Issue
Block a user