Skip to content

Commit

Permalink
Small bugfixes (microsoft#94)
Browse files Browse the repository at this point in the history
* Fixed adding eventMask for initial method, fixed wait error for timeout

* nit fixes

* refactor waittime logic to Infinite only if debugger is attached, convert tabs to spaces
  • Loading branch information
WilliamXieMSFT authored Jun 28, 2019
1 parent eafedc4 commit 6b76e95
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 44 deletions.
3 changes: 1 addition & 2 deletions src/Extensions.Base.Api/BeginCallbacks.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
-->
<#+ // Copyright (c) Microsoft Corporation. All rights reserved. #>

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
Expand Down
3 changes: 1 addition & 2 deletions src/Extensions.Base.Api/EndCallbacks.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
-->
<#+ // Copyright (c) Microsoft Corporation. All rights reserved. #>

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
Expand Down
3 changes: 1 addition & 2 deletions src/Extensions.Base.Api/ExceptionCallbacks.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
-->
<#+ // Copyright (c) Microsoft Corporation. All rights reserved. #>

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
Expand Down
3 changes: 1 addition & 2 deletions src/Extensions.Base.Api/PublicContract.tt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved.
-->
<#+ // Copyright (c) Microsoft Corporation. All rights reserved. #>

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ assembly name="System.Core" #>
Expand Down
19 changes: 13 additions & 6 deletions src/InstrumentationEngine/ProfilerManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,23 @@ HRESULT MicrosoftInstrumentationEngine::CProfilerManager::SetupProfilingEnvironm
// to co create a free threaded version of msxml on a thread that it owns to avoid this.
CHandle hConfigThread(CreateThread(NULL, 0, InstrumentationMethodThreadProc, this, 0, NULL));

DWORD retVal = WaitForSingleObject(hConfigThread, 15000);
if (retVal == WAIT_ABANDONED)
DWORD waitTime = 60 * 1000; // Wait 1 minute for loading instrumentation methods
#ifdef Debug
if (IsDebuggerAttached())
{
waitTime = INFINITE;
}
#endif

DWORD retVal = WaitForSingleObject(hConfigThread, waitTime);
if (retVal == WAIT_TIMEOUT)
{
CLogging::LogError(_T("CProfilerManager::SetupProfilingEnvironment - instrumentation method configuration timeout exceeded"));
return CORPROF_E_PROFILER_CANCEL_ACTIVATION;
}
else if (retVal == WAIT_FAILED)
if (retVal != WAIT_OBJECT_0)
{
CLogging::LogError(_T("CProfilerManager::SetupProfilingEnvironment - instrumentation method configuration failed"));
CLogging::LogError(_T("CProfilerManager::SetupProfilingEnvironment - instrumentation method configuration failed with error 0x%08X"), HRESULT_FROM_WIN32(GetLastError()));
return CORPROF_E_PROFILER_CANCEL_ACTIVATION;
}

Expand Down Expand Up @@ -535,7 +543,7 @@ HRESULT MicrosoftInstrumentationEngine::CProfilerManager::AddInstrumentationMeth

if (!bInserted)
{
m_instrumentationMethods.push_back(TInstrumentationMethodsCollection::value_type(std::shared_ptr<CInstrumentationMethod>(pInstrumentationMethod), 0));
m_instrumentationMethods.push_back(TInstrumentationMethodsCollection::value_type(std::shared_ptr<CInstrumentationMethod>(pInstrumentationMethod), dwFlags));
}

}
Expand Down Expand Up @@ -793,7 +801,6 @@ DWORD MicrosoftInstrumentationEngine::CProfilerManager::GetInitializingInstrumen
return m_dwInstrumentationMethodFlags;
}


HRESULT MicrosoftInstrumentationEngine::CProfilerManager::GetEventMask(_Out_ DWORD* dwEventMask)
{
HRESULT hr = S_OK;
Expand Down
63 changes: 33 additions & 30 deletions tests/RawProfilerHook/RawProfilerHook/RawProfilerHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,61 +12,64 @@
using namespace ATL;

// Used to determine whether the DLL can be unloaded by OLE.
__control_entrypoint(DllExport)
STDAPI DllCanUnloadNow(void)
{
return _AtlModule.DllCanUnloadNow();
}
return _AtlModule.DllCanUnloadNow();
}

// Returns a class factory to create an object of the requested type.
_Check_return_
STDAPI DllGetClassObject(_In_ REFCLSID rclsid, _In_ REFIID riid, _Outptr_ LPVOID* ppv)
{
return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
return _AtlModule.DllGetClassObject(rclsid, riid, ppv);
}

// DllRegisterServer - Adds entries to the system registry.
__control_entrypoint(DllExport)
STDAPI DllRegisterServer(void)
{
// registers object, typelib and all interfaces in typelib
HRESULT hr = _AtlModule.DllRegisterServer();
return hr;
// registers object, typelib and all interfaces in typelib
HRESULT hr = _AtlModule.DllRegisterServer();
return hr;
}

// DllUnregisterServer - Removes entries from the system registry.
__control_entrypoint(DllExport)
STDAPI DllUnregisterServer(void)
{
HRESULT hr = _AtlModule.DllUnregisterServer();
return hr;
HRESULT hr = _AtlModule.DllUnregisterServer();
return hr;
}

// DllInstall - Adds/Removes entries to the system registry per user per machine.
STDAPI DllInstall(BOOL bInstall, _In_opt_ LPCWSTR pszCmdLine)
{
HRESULT hr = E_FAIL;
static const wchar_t szUserSwitch[] = L"user";
HRESULT hr = E_FAIL;
static const wchar_t szUserSwitch[] = L"user";

if (pszCmdLine != NULL)
{
if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
{
ATL::AtlSetPerUserRegistration(true);
}
}
if (pszCmdLine != NULL)
{
if (_wcsnicmp(pszCmdLine, szUserSwitch, _countof(szUserSwitch)) == 0)
{
ATL::AtlSetPerUserRegistration(true);
}
}

if (bInstall)
{
hr = DllRegisterServer();
if (FAILED(hr))
{
DllUnregisterServer();
}
}
else
{
hr = DllUnregisterServer();
}
if (bInstall)
{
hr = DllRegisterServer();
if (FAILED(hr))
{
DllUnregisterServer();
}
}
else
{
hr = DllUnregisterServer();
}

return hr;
return hr;
}


0 comments on commit 6b76e95

Please sign in to comment.