diff options
| author | 2015-02-05 14:53:25 -0200 | |
|---|---|---|
| committer | 2015-03-01 21:47:13 -0300 | |
| commit | cd1fbfcf1b70e365d81480ec0f56db19ed02454f (patch) | |
| tree | b220b105d1b8016bb258047683bf2d03795c8881 /src/common/profiler_reporting.h | |
| parent | Merge pull request #616 from archshift/5551 (diff) | |
| download | yuzu-cd1fbfcf1b70e365d81480ec0f56db19ed02454f.tar.gz yuzu-cd1fbfcf1b70e365d81480ec0f56db19ed02454f.tar.xz yuzu-cd1fbfcf1b70e365d81480ec0f56db19ed02454f.zip | |
Add profiling infrastructure and widget
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 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #pragma once | ||
| 6 | |||
| 7 | #include <array> | ||
| 8 | #include <chrono> | ||
| 9 | #include <mutex> | ||
| 10 | #include <utility> | ||
| 11 | #include <vector> | ||
| 12 | |||
| 13 | #include "common/profiler.h" | ||
| 14 | #include "common/synchronized_wrapper.h" | ||
| 15 | |||
| 16 | namespace Common { | ||
| 17 | namespace Profiling { | ||
| 18 | |||
| 19 | struct TimingCategoryInfo { | ||
| 20 | static const unsigned int NO_PARENT = -1; | ||
| 21 | |||
| 22 | TimingCategory* category; | ||
| 23 | const char* name; | ||
| 24 | unsigned int parent; | ||
| 25 | }; | ||
| 26 | |||
| 27 | struct ProfilingFrameResult { | ||
| 28 | /// Time since the last delivered frame | ||
| 29 | Duration interframe_time; | ||
| 30 | |||
| 31 | /// Time spent processing a frame, excluding VSync | ||
| 32 | Duration frame_time; | ||
| 33 | |||
| 34 | /// Total amount of time spent inside each category in this frame. Indexed by the category id | ||
| 35 | std::vector<Duration> time_per_category; | ||
| 36 | }; | ||
| 37 | |||
| 38 | class ProfilingManager final { | ||
| 39 | public: | ||
| 40 | ProfilingManager(); | ||
| 41 | |||
| 42 | unsigned int RegisterTimingCategory(TimingCategory* category, const char* name); | ||
| 43 | void SetTimingCategoryParent(unsigned int category, unsigned int parent); | ||
| 44 | |||
| 45 | const std::vector<TimingCategoryInfo>& GetTimingCategoriesInfo() const { | ||
| 46 | return timing_categories; | ||
| 47 | } | ||
| 48 | |||
| 49 | /// This should be called after swapping screen buffers. | ||
| 50 | void BeginFrame(); | ||
| 51 | /// This should be called before swapping screen buffers. | ||
| 52 | void FinishFrame(); | ||
| 53 | |||
| 54 | /// Get the timing results from the previous frame. This is updated when you call FinishFrame(). | ||
| 55 | const ProfilingFrameResult& GetPreviousFrameResults() const { | ||
| 56 | return results; | ||
| 57 | } | ||
| 58 | |||
| 59 | private: | ||
| 60 | std::vector<TimingCategoryInfo> timing_categories; | ||
| 61 | Clock::time_point last_frame_end; | ||
| 62 | Clock::time_point this_frame_start; | ||
| 63 | |||
| 64 | ProfilingFrameResult results; | ||
| 65 | }; | ||
| 66 | |||
| 67 | struct AggregatedDuration { | ||
| 68 | Duration avg, min, max; | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct AggregatedFrameResult { | ||
| 72 | /// Time since the last delivered frame | ||
| 73 | AggregatedDuration interframe_time; | ||
| 74 | |||
| 75 | /// Time spent processing a frame, excluding VSync | ||
| 76 | AggregatedDuration frame_time; | ||
| 77 | |||
| 78 | float fps; | ||
| 79 | |||
| 80 | /// Total amount of time spent inside each category in this frame. Indexed by the category id | ||
| 81 | std::vector<AggregatedDuration> time_per_category; | ||
| 82 | }; | ||
| 83 | |||
| 84 | class TimingResultsAggregator final { | ||
| 85 | public: | ||
| 86 | TimingResultsAggregator(size_t window_size); | ||
| 87 | |||
| 88 | void Clear(); | ||
| 89 | void SetNumberOfCategories(size_t n); | ||
| 90 | |||
| 91 | void AddFrame(const ProfilingFrameResult& frame_result); | ||
| 92 | |||
| 93 | AggregatedFrameResult GetAggregatedResults() const; | ||
| 94 | |||
| 95 | size_t max_window_size; | ||
| 96 | size_t window_size; | ||
| 97 | size_t cursor; | ||
| 98 | |||
| 99 | std::vector<Duration> interframe_times; | ||
| 100 | std::vector<Duration> frame_times; | ||
| 101 | std::vector<std::vector<Duration>> times_per_category; | ||
| 102 | }; | ||
| 103 | |||
| 104 | ProfilingManager& GetProfilingManager(); | ||
| 105 | SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator(); | ||
| 106 | |||
| 107 | } // namespace Profiling | ||
| 108 | } // namespace Common | ||