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