69 lines
2.3 KiB
C++
69 lines
2.3 KiB
C++
/*
|
|
* Copyright (C) 2025 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#include "CompositionStatsPoller.h"
|
|
|
|
#include <chrono>
|
|
|
|
#include "stats/CompositionStats.h"
|
|
#include "stats/CompositionStatsAtomReporter.h"
|
|
|
|
namespace android::drm_hwcomposer {
|
|
|
|
CompositionStatsPoller::CompositionStatsPoller(
|
|
std::unique_ptr<CompositionStatsAtomReporter> reporter,
|
|
CompositionStatsProvider* provider)
|
|
: tracker_(provider), reporter_(std::move(reporter)) {
|
|
thread_ = std::thread(&CompositionStatsPoller::PollFunc, this);
|
|
}
|
|
|
|
CompositionStatsPoller::~CompositionStatsPoller() {
|
|
{
|
|
std::lock_guard lock(mutex_);
|
|
exit_ = true;
|
|
}
|
|
condition_.notify_one();
|
|
thread_.join();
|
|
}
|
|
|
|
void CompositionStatsPoller::PollFunc() {
|
|
bool thread_exit = false;
|
|
while (!thread_exit) {
|
|
tracker_.ReportStats([this](const CompositionAttributes& attributes,
|
|
const CompositionStats& /*cumulative*/,
|
|
const CompositionStats& delta) {
|
|
if (delta.total_frames == 0) {
|
|
return;
|
|
}
|
|
reporter_->PushAtom(attributes.display_handle, attributes.present_failed,
|
|
attributes.validation_result,
|
|
attributes.flatten_reason, delta.total_frames,
|
|
delta.layer_count, delta.used_plane_count,
|
|
delta.total_pixops, delta.gpu_pixops);
|
|
});
|
|
|
|
constexpr std::chrono::seconds kPollFrequency = std::chrono::minutes(1);
|
|
std::unique_lock lock(mutex_);
|
|
base::ScopedLockAssertion lock_assertion(mutex_);
|
|
thread_exit = exit_ ||
|
|
condition_.wait_for(lock, kPollFrequency, [this]() -> bool {
|
|
base::ScopedLockAssertion lock_assertion(mutex_);
|
|
return exit_;
|
|
});
|
|
}
|
|
}
|
|
|
|
} // namespace android::drm_hwcomposer
|