This change adds a new CompositionAttributes struct which tracks information about a given composition as it is validated and subsequently presented. Previously CompositionStats were tracked as totals for each display. This change splits the stats according to the CompositionAttributes for each presented composition. This change only affects the reporting behavior of CompositionStatsTracker. The stats logged by DumpState are totaled so as to not be affected. Change-Id: I050cce7f63891971cc807b9c5150d9b5d30f1f0b
98 lines
3.2 KiB
C++
98 lines
3.2 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <functional>
|
|
#include <map>
|
|
|
|
#include "backend/Backend.h"
|
|
|
|
namespace android::drm_hwcomposer {
|
|
|
|
enum class ValidationResult {
|
|
kUnspecified = 0,
|
|
kSuccess,
|
|
kFailure,
|
|
kSkip,
|
|
};
|
|
|
|
struct CompositionAttributes {
|
|
int64_t display_handle = 0;
|
|
bool present_failed = false;
|
|
ValidationResult validation_result = ValidationResult::kSkip;
|
|
Backend::FlattenReason flatten_reason = Backend::FlattenReason::kNone;
|
|
|
|
// When adding new attributes, update the operator< below as well as
|
|
// operator== which is implemented in the unit test file.
|
|
};
|
|
|
|
bool operator<(const CompositionAttributes& a, const CompositionAttributes& b);
|
|
|
|
struct CompositionStats {
|
|
uint32_t total_frames = 0;
|
|
uint64_t total_pixops = 0;
|
|
uint64_t gpu_pixops = 0;
|
|
uint32_t failed_kms_validate = 0;
|
|
uint32_t failed_kms_present = 0;
|
|
uint32_t frames_flattened = 0;
|
|
uint32_t cursor_plane_frames = 0;
|
|
uint32_t failed_kms_cursor_validate = 0;
|
|
|
|
// When adding new stats, update the operator+= and operator- below as well as
|
|
// operator== and operator<< which are implemented in the unit test file.
|
|
|
|
CompositionStats& operator+=(const CompositionStats& other);
|
|
};
|
|
|
|
// Used for calculating the delta between two CompositionStats.
|
|
CompositionStats operator-(const CompositionStats& a,
|
|
const CompositionStats& b);
|
|
|
|
// Interface for a reporter which pulls CompositionStats bucketed by
|
|
// CompositionAttributes.
|
|
class CompositionStatsProvider {
|
|
public:
|
|
// Get cumulative stats per unique attributes.
|
|
virtual auto PullCompositionStats()
|
|
-> std::map<CompositionAttributes, CompositionStats> = 0;
|
|
virtual ~CompositionStatsProvider() = default;
|
|
};
|
|
|
|
// CompositionStatsTracker pulls stats from a CompositionStatsProvider on-demand
|
|
// and keeps track of the previous stats state in order to calculate the deltas.
|
|
class CompositionStatsTracker {
|
|
public:
|
|
// Arguments are the attributes, the cumulative stats, and the stats delta.
|
|
using Callback = std::function<void(const CompositionAttributes& attributes,
|
|
const CompositionStats& cumulative,
|
|
const CompositionStats& delta)>;
|
|
explicit CompositionStatsTracker(CompositionStatsProvider* provider)
|
|
: provider_(provider) {
|
|
}
|
|
|
|
// Callback will be called for each unique attribute (empty entries are
|
|
// skipped), with the cumulative stats and the stats delta from the previous
|
|
// invocation.
|
|
void ReportStats(const Callback& callback);
|
|
|
|
private:
|
|
CompositionStatsProvider* provider_;
|
|
std::map<CompositionAttributes, CompositionStats> previous_stats_;
|
|
};
|
|
|
|
} // namespace android::drm_hwcomposer
|