diff options
author | Tony Wasserka <neobrainx@gmail.com> | 2015-03-07 15:30:40 +0100 |
---|---|---|
committer | Tony Wasserka <neobrainx@gmail.com> | 2015-03-07 15:30:40 +0100 |
commit | 93e32bce72905ac1bd0a5e75066fda5e6b7bf250 (patch) | |
tree | 4530e9d8db22955416543899b6c0e59abf8b9732 /src/common/profiler_reporting.h | |
parent | Merge pull request #630 from archshift/swap (diff) | |
parent | Profiler: Implement QPCClock to get better precision on Win32 (diff) | |
download | yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.tar yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.tar.gz yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.tar.bz2 yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.tar.lz yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.tar.xz yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.tar.zst yuzu-93e32bce72905ac1bd0a5e75066fda5e6b7bf250.zip |
Diffstat (limited to 'src/common/profiler_reporting.h')
-rw-r--r-- | src/common/profiler_reporting.h | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/common/profiler_reporting.h b/src/common/profiler_reporting.h new file mode 100644 index 000000000..3abb73315 --- /dev/null +++ b/src/common/profiler_reporting.h @@ -0,0 +1,108 @@ +// Copyright 2015 Citra Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include <array> +#include <chrono> +#include <mutex> +#include <utility> +#include <vector> + +#include "common/profiler.h" +#include "common/synchronized_wrapper.h" + +namespace Common { +namespace Profiling { + +struct TimingCategoryInfo { + static const unsigned int NO_PARENT = -1; + + TimingCategory* category; + const char* name; + unsigned int parent; +}; + +struct ProfilingFrameResult { + /// Time since the last delivered frame + Duration interframe_time; + + /// Time spent processing a frame, excluding VSync + Duration frame_time; + + /// Total amount of time spent inside each category in this frame. Indexed by the category id + std::vector<Duration> time_per_category; +}; + +class ProfilingManager final { +public: + ProfilingManager(); + + unsigned int RegisterTimingCategory(TimingCategory* category, const char* name); + void SetTimingCategoryParent(unsigned int category, unsigned int parent); + + const std::vector<TimingCategoryInfo>& GetTimingCategoriesInfo() const { + return timing_categories; + } + + /// This should be called after swapping screen buffers. + void BeginFrame(); + /// This should be called before swapping screen buffers. + void FinishFrame(); + + /// Get the timing results from the previous frame. This is updated when you call FinishFrame(). + const ProfilingFrameResult& GetPreviousFrameResults() const { + return results; + } + +private: + std::vector<TimingCategoryInfo> timing_categories; + Clock::time_point last_frame_end; + Clock::time_point this_frame_start; + + ProfilingFrameResult results; +}; + +struct AggregatedDuration { + Duration avg, min, max; +}; + +struct AggregatedFrameResult { + /// Time since the last delivered frame + AggregatedDuration interframe_time; + + /// Time spent processing a frame, excluding VSync + AggregatedDuration frame_time; + + float fps; + + /// Total amount of time spent inside each category in this frame. Indexed by the category id + std::vector<AggregatedDuration> time_per_category; +}; + +class TimingResultsAggregator final { +public: + TimingResultsAggregator(size_t window_size); + + void Clear(); + void SetNumberOfCategories(size_t n); + + void AddFrame(const ProfilingFrameResult& frame_result); + + AggregatedFrameResult GetAggregatedResults() const; + + size_t max_window_size; + size_t window_size; + size_t cursor; + + std::vector<Duration> interframe_times; + std::vector<Duration> frame_times; + std::vector<std::vector<Duration>> times_per_category; +}; + +ProfilingManager& GetProfilingManager(); +SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator(); + +} // namespace Profiling +} // namespace Common |