2015-02-05 17:53:25 +01:00
|
|
|
// Copyright 2015 Citra Emulator Project
|
|
|
|
// Licensed under GPLv2 or any later version
|
|
|
|
// Refer to the license.txt file included.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
2016-04-29 09:07:10 +02:00
|
|
|
#include <chrono>
|
2015-06-21 00:36:19 +02:00
|
|
|
#include <cstddef>
|
2015-02-05 17:53:25 +01:00
|
|
|
#include <vector>
|
|
|
|
#include "common/synchronized_wrapper.h"
|
|
|
|
|
|
|
|
namespace Common {
|
|
|
|
namespace Profiling {
|
|
|
|
|
2016-04-29 09:07:10 +02:00
|
|
|
using Clock = std::chrono::high_resolution_clock;
|
|
|
|
using Duration = Clock::duration;
|
2015-02-05 17:53:25 +01:00
|
|
|
|
|
|
|
struct ProfilingFrameResult {
|
|
|
|
/// Time since the last delivered frame
|
|
|
|
Duration interframe_time;
|
|
|
|
|
|
|
|
/// Time spent processing a frame, excluding VSync
|
|
|
|
Duration frame_time;
|
|
|
|
};
|
|
|
|
|
|
|
|
class ProfilingManager final {
|
|
|
|
public:
|
|
|
|
ProfilingManager();
|
|
|
|
|
|
|
|
/// 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:
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
class TimingResultsAggregator final {
|
|
|
|
public:
|
|
|
|
TimingResultsAggregator(size_t window_size);
|
|
|
|
|
|
|
|
void Clear();
|
|
|
|
|
|
|
|
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;
|
|
|
|
};
|
|
|
|
|
|
|
|
ProfilingManager& GetProfilingManager();
|
|
|
|
SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator();
|
|
|
|
|
|
|
|
} // namespace Profiling
|
|
|
|
} // namespace Common
|