add function-scope timer for debug.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -60,6 +60,8 @@ const std::unique_ptr<MonitorManager>& GetMonitorManager()
|
||||
|
||||
LUID GetUnityAdapterLuid()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto device = GetDevice();
|
||||
|
||||
Microsoft::WRL::ComPtr<IDXGIDevice1> dxgiDevice;
|
||||
|
||||
@@ -21,6 +21,8 @@ Cursor::~Cursor()
|
||||
|
||||
void Cursor::UpdateBuffer(Duplicator* duplicator, const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (frameInfo.LastMouseUpdateTime.QuadPart == 0)
|
||||
{
|
||||
return;
|
||||
@@ -66,6 +68,8 @@ void Cursor::UpdateTexture(
|
||||
Duplicator* duplicator,
|
||||
const ComPtr<ID3D11Texture2D>& desktopTexture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
auto monitor = duplicator->GetMonitor();
|
||||
|
||||
// Check desktop texure
|
||||
@@ -369,6 +373,8 @@ void Cursor::UpdateTexture(
|
||||
|
||||
void Cursor::Draw(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (texture == nullptr)
|
||||
{
|
||||
Debug::Error("Cursor::UpdateTexture() => Desktop texture is null.");
|
||||
@@ -384,6 +390,8 @@ void Cursor::Draw(const Microsoft::WRL::ComPtr<ID3D11Texture2D>& texture)
|
||||
|
||||
void Cursor::GetTexture(ID3D11Texture2D* texture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!bgraBuffer_)
|
||||
{
|
||||
Debug::Error("Cursor::GetTexture() => bgra32Buffer is null.");
|
||||
|
||||
@@ -39,4 +39,18 @@ void Debug::Finalize()
|
||||
}
|
||||
Debug::SetLogFunc(nullptr);
|
||||
Debug::SetErrorFunc(nullptr);
|
||||
}
|
||||
|
||||
|
||||
decltype(DebugFunctionScopedTimer::currentId) DebugFunctionScopedTimer::currentId = 0;
|
||||
|
||||
|
||||
DebugFunctionScopedTimer::DebugFunctionScopedTimer(const char* name)
|
||||
: ScopedTimer([this](std::chrono::microseconds us) {
|
||||
Debug::Log("<< [", id_, "]", name_, " : ", us.count(), "[us]");
|
||||
})
|
||||
, name_(name)
|
||||
, id_(currentId++)
|
||||
{
|
||||
Debug::Log(">> [", id_, "]", name_);
|
||||
}
|
||||
@@ -10,7 +10,9 @@
|
||||
|
||||
|
||||
// Debug flag
|
||||
#ifdef _DEBUG
|
||||
#define UDD_DEBUG_ON
|
||||
#endif
|
||||
|
||||
|
||||
// Logging
|
||||
@@ -156,16 +158,25 @@ private:
|
||||
};
|
||||
|
||||
|
||||
class DebugFunctionScopedTimer : public ScopedTimer
|
||||
{
|
||||
public:
|
||||
explicit DebugFunctionScopedTimer(const char* name);
|
||||
|
||||
private:
|
||||
static unsigned int currentId;
|
||||
const char* const name_;
|
||||
const unsigned int id_;
|
||||
};
|
||||
|
||||
|
||||
#ifdef UDD_DEBUG_ON
|
||||
#define UDD_FUNCTION_SCOPE_TIMER \
|
||||
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
||||
{ \
|
||||
Debug::Log(__FUNCTION__, "@", __FILE__, ":", __LINE__, " => ", us.count(), " [us]"); \
|
||||
});
|
||||
DebugFunctionScopedTimer _timer_##__COUNTER__(__FUNCTION__);
|
||||
#define UDD_SCOPE_TIMER(Name) \
|
||||
ScopedTimer _timer_##__COUNTER__([](std::chrono::microseconds us) \
|
||||
{ \
|
||||
Debug::Log(#Name, " => ", us.count(), " [us]"); \
|
||||
Debug::Log(#Name, " : ", us.count(), " [us]"); \
|
||||
});
|
||||
#else
|
||||
#define UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
@@ -27,6 +27,8 @@ IsolatedD3D11Device::~IsolatedD3D11Device()
|
||||
|
||||
HRESULT IsolatedD3D11Device::Create(const ComPtr<IDXGIAdapter>& adapter)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto driverType = adapter ?
|
||||
D3D_DRIVER_TYPE_UNKNOWN :
|
||||
D3D_DRIVER_TYPE_HARDWARE;
|
||||
@@ -68,6 +70,8 @@ ComPtr<ID3D11Device> IsolatedD3D11Device::GetDevice()
|
||||
Microsoft::WRL::ComPtr<ID3D11Texture2D> IsolatedD3D11Device::GetCompatibleSharedTexture(
|
||||
const ComPtr<ID3D11Texture2D>& src)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
D3D11_TEXTURE2D_DESC srcDesc;
|
||||
src->GetDesc(&srcDesc);
|
||||
|
||||
|
||||
@@ -33,6 +33,8 @@ Duplicator::~Duplicator()
|
||||
|
||||
void Duplicator::InitializeDevice()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
device_ = std::make_shared<IsolatedD3D11Device>();
|
||||
|
||||
if (FAILED(device_->Create(monitor_->GetAdapter())))
|
||||
@@ -45,6 +47,8 @@ void Duplicator::InitializeDevice()
|
||||
|
||||
void Duplicator::InitializeDuplication()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
ComPtr<IDXGIOutput1> output1;
|
||||
if (FAILED(monitor_->GetOutput().As(&output1)))
|
||||
{
|
||||
@@ -107,6 +111,8 @@ void Duplicator::InitializeDuplication()
|
||||
|
||||
void Duplicator::CheckUnityAdapter()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
DXGI_ADAPTER_DESC desc;
|
||||
monitor_->GetAdapter()->GetDesc(&desc);
|
||||
|
||||
@@ -125,6 +131,8 @@ void Duplicator::CheckUnityAdapter()
|
||||
|
||||
void Duplicator::Start()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (state_ != State::Ready) return;
|
||||
|
||||
Stop();
|
||||
@@ -170,6 +178,8 @@ void Duplicator::Start()
|
||||
|
||||
void Duplicator::Stop()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
shouldRun_ = false;
|
||||
|
||||
if (thread_.joinable())
|
||||
@@ -226,6 +236,8 @@ const Duplicator::Frame& Duplicator::GetLastFrame() const
|
||||
|
||||
void Duplicator::Duplicate(UINT timeout)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!dupl_ || !device_) return;
|
||||
|
||||
Release();
|
||||
@@ -312,6 +324,8 @@ void Duplicator::Duplicate(UINT timeout)
|
||||
|
||||
void Duplicator::Release()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!isFrameAcquired_) return;
|
||||
|
||||
const auto hr = dupl_->ReleaseFrame();
|
||||
@@ -347,6 +361,8 @@ void Duplicator::UpdateCursor(
|
||||
const ComPtr<ID3D11Texture2D>& texture,
|
||||
const DXGI_OUTDUPL_FRAME_INFO& frameInfo)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
auto& manager = GetMonitorManager();
|
||||
|
||||
if (frameInfo.PointerPosition.Visible)
|
||||
@@ -365,6 +381,8 @@ void Duplicator::UpdateCursor(
|
||||
|
||||
void Duplicator::UpdateMetadata(UINT totalBufferSize)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
metaData_.buffer.ExpandIfNeeded(totalBufferSize);
|
||||
if (!metaData_.buffer.Empty())
|
||||
{
|
||||
@@ -376,6 +394,8 @@ void Duplicator::UpdateMetadata(UINT totalBufferSize)
|
||||
|
||||
void Duplicator::UpdateMoveRects()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto hr = dupl_->GetFrameMoveRects(
|
||||
metaData_.buffer.Size(),
|
||||
metaData_.buffer.As<DXGI_OUTDUPL_MOVE_RECT>(),
|
||||
@@ -418,6 +438,8 @@ void Duplicator::UpdateMoveRects()
|
||||
|
||||
void Duplicator::UpdateDirtyRects()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto hr = dupl_->GetFrameDirtyRects(
|
||||
metaData_.buffer.Size() - metaData_.moveRectSize,
|
||||
metaData_.buffer.As<RECT>(metaData_.moveRectSize /* offset */),
|
||||
|
||||
@@ -29,6 +29,8 @@ void Monitor::Initialize(
|
||||
const ComPtr<IDXGIOutput> &output
|
||||
)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
adapter_ = adapter;
|
||||
output_ = output;
|
||||
|
||||
@@ -75,12 +77,16 @@ void Monitor::Initialize(
|
||||
|
||||
void Monitor::Finalize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
StopCapture();
|
||||
}
|
||||
|
||||
|
||||
void Monitor::Render()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto& frame = duplicator_->GetLastFrame();
|
||||
|
||||
if (frame.id == lastFrameId_) return;
|
||||
@@ -133,6 +139,8 @@ void Monitor::Render()
|
||||
|
||||
void Monitor::StartCapture()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (duplicator_->GetState() == DuplicatorState::Ready)
|
||||
{
|
||||
duplicator_->Start();
|
||||
@@ -142,6 +150,8 @@ void Monitor::StartCapture()
|
||||
|
||||
void Monitor::StopCapture()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
duplicator_->Stop();
|
||||
}
|
||||
|
||||
@@ -302,6 +312,8 @@ bool Monitor::UseGetPixels() const
|
||||
|
||||
void Monitor::CopyTextureFromGpuToCpu(ID3D11Texture2D* texture)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
const auto monitorRot = static_cast<DXGI_MODE_ROTATION>(GetRotation());
|
||||
const auto monitorWidth = GetWidth();
|
||||
const auto monitorHeight = GetHeight();
|
||||
@@ -367,6 +379,8 @@ void Monitor::CopyTextureFromGpuToCpu(ID3D11Texture2D* texture)
|
||||
|
||||
bool Monitor::GetPixels(BYTE* output, int x, int y, int width, int height)
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (!UseGetPixels())
|
||||
{
|
||||
Debug::Error("Monitor::GetPixels() => UseGetPixels(true) must have been called when you want to use GetPixels().");
|
||||
|
||||
@@ -30,6 +30,8 @@ MonitorManager::~MonitorManager()
|
||||
|
||||
void MonitorManager::Initialize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
ComPtr<IDXGIFactory1> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||
{
|
||||
@@ -69,6 +71,8 @@ void MonitorManager::Initialize()
|
||||
|
||||
void MonitorManager::Finalize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
for (const auto& monitor : monitors_)
|
||||
{
|
||||
monitor->Finalize();
|
||||
@@ -80,6 +84,8 @@ void MonitorManager::Finalize()
|
||||
|
||||
void MonitorManager::Update()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
if (isReinitializationRequired_)
|
||||
{
|
||||
Reinitialize();
|
||||
@@ -97,6 +103,8 @@ void MonitorManager::RequireReinitilization()
|
||||
|
||||
void MonitorManager::Reinitialize()
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
Debug::Log("MonitorManager::Reinitialize()");
|
||||
Finalize();
|
||||
Initialize();
|
||||
@@ -106,6 +114,8 @@ void MonitorManager::Reinitialize()
|
||||
|
||||
bool MonitorManager::HasMonitorCountChanged() const
|
||||
{
|
||||
UDD_FUNCTION_SCOPE_TIMER
|
||||
|
||||
ComPtr<IDXGIFactory1> factory;
|
||||
if (FAILED(CreateDXGIFactory1(IID_PPV_ARGS(&factory))))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user