Merge pull request #2587 from yuriks/status-bar

Replace built-in Profiler with indicators in status bar
This commit is contained in:
Yuri Kunde Schlesner 2017-02-26 17:51:15 -08:00 committed by GitHub
commit b250ce21b9
28 changed files with 321 additions and 449 deletions

View file

@ -35,7 +35,6 @@ set(SRCS
memory_util.cpp
microprofile.cpp
misc.cpp
profiler.cpp
scm_rev.cpp
string_util.cpp
symbols.cpp
@ -68,7 +67,6 @@ set(HEADERS
microprofile.h
microprofileui.h
platform.h
profiler_reporting.h
quaternion.h
scm_rev.h
scope_exit.h

View file

@ -1,101 +0,0 @@
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include <algorithm>
#include <cstddef>
#include <vector>
#include "common/assert.h"
#include "common/profiler_reporting.h"
#include "common/synchronized_wrapper.h"
namespace Common {
namespace Profiling {
ProfilingManager::ProfilingManager()
: last_frame_end(Clock::now()), this_frame_start(Clock::now()) {}
void ProfilingManager::BeginFrame() {
this_frame_start = Clock::now();
}
void ProfilingManager::FinishFrame() {
Clock::time_point now = Clock::now();
results.interframe_time = now - last_frame_end;
results.frame_time = now - this_frame_start;
last_frame_end = now;
}
TimingResultsAggregator::TimingResultsAggregator(size_t window_size)
: max_window_size(window_size), window_size(0) {
interframe_times.resize(window_size, Duration::zero());
frame_times.resize(window_size, Duration::zero());
}
void TimingResultsAggregator::Clear() {
window_size = cursor = 0;
}
void TimingResultsAggregator::AddFrame(const ProfilingFrameResult& frame_result) {
interframe_times[cursor] = frame_result.interframe_time;
frame_times[cursor] = frame_result.frame_time;
++cursor;
if (cursor == max_window_size)
cursor = 0;
if (window_size < max_window_size)
++window_size;
}
static AggregatedDuration AggregateField(const std::vector<Duration>& v, size_t len) {
AggregatedDuration result;
result.avg = Duration::zero();
result.min = result.max = (len == 0 ? Duration::zero() : v[0]);
for (size_t i = 0; i < len; ++i) {
Duration value = v[i];
result.avg += value;
result.min = std::min(result.min, value);
result.max = std::max(result.max, value);
}
if (len != 0)
result.avg /= len;
return result;
}
static float tof(Common::Profiling::Duration dur) {
using FloatMs = std::chrono::duration<float, std::chrono::milliseconds::period>;
return std::chrono::duration_cast<FloatMs>(dur).count();
}
AggregatedFrameResult TimingResultsAggregator::GetAggregatedResults() const {
AggregatedFrameResult result;
result.interframe_time = AggregateField(interframe_times, window_size);
result.frame_time = AggregateField(frame_times, window_size);
if (result.interframe_time.avg != Duration::zero()) {
result.fps = 1000.0f / tof(result.interframe_time.avg);
} else {
result.fps = 0.0f;
}
return result;
}
ProfilingManager& GetProfilingManager() {
// Takes advantage of "magic" static initialization for race-free initialization.
static ProfilingManager manager;
return manager;
}
SynchronizedRef<TimingResultsAggregator> GetTimingResultsAggregator() {
static SynchronizedWrapper<TimingResultsAggregator> aggregator(30);
return SynchronizedRef<TimingResultsAggregator>(aggregator);
}
} // namespace Profiling
} // namespace Common

View file

@ -1,83 +0,0 @@
// Copyright 2015 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#pragma once
#include <chrono>
#include <cstddef>
#include <vector>
#include "common/synchronized_wrapper.h"
namespace Common {
namespace Profiling {
using Clock = std::chrono::high_resolution_clock;
using Duration = Clock::duration;
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

View file

@ -9,25 +9,8 @@
namespace Common {
/**
* Wraps an object, only allowing access to it via a locking reference wrapper. Good to ensure no
* one forgets to lock a mutex before acessing an object. To access the wrapped object construct a
* SyncronizedRef on this wrapper. Inspired by Rust's Mutex type
* (http://doc.rust-lang.org/std/sync/struct.Mutex.html).
*/
template <typename T>
class SynchronizedWrapper {
public:
template <typename... Args>
SynchronizedWrapper(Args&&... args) : data(std::forward<Args>(args)...) {}
private:
template <typename U>
friend class SynchronizedRef;
std::mutex mutex;
T data;
};
class SynchronizedWrapper;
/**
* Synchronized reference, that keeps a SynchronizedWrapper's mutex locked during its lifetime. This
@ -75,4 +58,28 @@ private:
SynchronizedWrapper<T>* wrapper;
};
/**
* Wraps an object, only allowing access to it via a locking reference wrapper. Good to ensure no
* one forgets to lock a mutex before acessing an object. To access the wrapped object construct a
* SyncronizedRef on this wrapper. Inspired by Rust's Mutex type
* (http://doc.rust-lang.org/std/sync/struct.Mutex.html).
*/
template <typename T>
class SynchronizedWrapper {
public:
template <typename... Args>
SynchronizedWrapper(Args&&... args) : data(std::forward<Args>(args)...) {}
SynchronizedRef<T> Lock() {
return {*this};
}
private:
template <typename U>
friend class SynchronizedRef;
std::mutex mutex;
T data;
};
} // namespace Common