mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-01-07 20:07:56 +08:00
Add some basic tracing
This commit is contained in:
parent
24fca9df02
commit
ff6bcca3ab
@ -4,6 +4,7 @@
|
|||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
#include "dllmain.h"
|
#include "dllmain.h"
|
||||||
|
#include "Trace.h"
|
||||||
|
|
||||||
// Implementations of inherited IUnknown methods
|
// Implementations of inherited IUnknown methods
|
||||||
|
|
||||||
@ -130,6 +131,7 @@ IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UI
|
|||||||
if (!InsertMenuItem(hmenu, indexMenu, TRUE, &mii))
|
if (!InsertMenuItem(hmenu, indexMenu, TRUE, &mii))
|
||||||
{
|
{
|
||||||
hr = HRESULT_FROM_WIN32(GetLastError());
|
hr = HRESULT_FROM_WIN32(GetLastError());
|
||||||
|
Trace::QueryContextMenuError(hr);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -142,15 +144,18 @@ IFACEMETHODIMP ExplorerCommand::QueryContextMenu(HMENU hmenu, UINT indexMenu, UI
|
|||||||
|
|
||||||
IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici)
|
IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici)
|
||||||
{
|
{
|
||||||
|
Trace::Invoked();
|
||||||
ipc::Writer writer;
|
ipc::Writer writer;
|
||||||
|
|
||||||
if (HRESULT result = writer.start(); FAILED(result))
|
if (HRESULT result = writer.start(); FAILED(result))
|
||||||
{
|
{
|
||||||
|
Trace::InvokedRet(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HRESULT result = LaunchUI(pici, &writer); FAILED(result))
|
if (HRESULT result = LaunchUI(pici, &writer); FAILED(result))
|
||||||
{
|
{
|
||||||
|
Trace::InvokedRet(result);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -182,6 +187,7 @@ IFACEMETHODIMP ExplorerCommand::InvokeCommand(CMINVOKECOMMANDINFO* pici)
|
|||||||
shell_item_array->Release();
|
shell_item_array->Release();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Trace::InvokedRet(S_OK);
|
||||||
return S_OK;
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -167,6 +167,7 @@
|
|||||||
<ClInclude Include="pch.h" />
|
<ClInclude Include="pch.h" />
|
||||||
<ClInclude Include="Registry.h" />
|
<ClInclude Include="Registry.h" />
|
||||||
<ClInclude Include="Settings.h" />
|
<ClInclude Include="Settings.h" />
|
||||||
|
<ClInclude Include="Trace.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="ClassFactory.cpp" />
|
<ClCompile Include="ClassFactory.cpp" />
|
||||||
@ -181,6 +182,7 @@
|
|||||||
<ClCompile Include="PowerToysModule.cpp" />
|
<ClCompile Include="PowerToysModule.cpp" />
|
||||||
<ClCompile Include="Registry.cpp" />
|
<ClCompile Include="Registry.cpp" />
|
||||||
<ClCompile Include="Settings.cpp" />
|
<ClCompile Include="Settings.cpp" />
|
||||||
|
<ClCompile Include="Trace.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="dll.def" />
|
<None Include="dll.def" />
|
||||||
|
@ -36,6 +36,9 @@
|
|||||||
<ClInclude Include="Settings.h">
|
<ClInclude Include="Settings.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="Trace.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="dllmain.cpp">
|
<ClCompile Include="dllmain.cpp">
|
||||||
@ -59,6 +62,9 @@
|
|||||||
<ClCompile Include="Settings.cpp">
|
<ClCompile Include="Settings.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<ClCompile Include="Trace.cpp">
|
||||||
|
<Filter>Source Files</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<None Include="dll.def">
|
<None Include="dll.def">
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "dllmain.h"
|
#include "dllmain.h"
|
||||||
#include "Settings.h"
|
#include "Settings.h"
|
||||||
|
#include "Trace.h"
|
||||||
|
|
||||||
class FileLocksmithModule : public PowertoyModuleIface
|
class FileLocksmithModule : public PowertoyModuleIface
|
||||||
{
|
{
|
||||||
@ -70,6 +71,7 @@ public:
|
|||||||
Logger::info(L"File Locksmith enabled");
|
Logger::info(L"File Locksmith enabled");
|
||||||
m_enabled = true;
|
m_enabled = true;
|
||||||
save_settings();
|
save_settings();
|
||||||
|
Trace::EnableFileLocksmith(m_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void disable() override
|
virtual void disable() override
|
||||||
@ -77,6 +79,7 @@ public:
|
|||||||
Logger::info(L"File Locksmith disabled");
|
Logger::info(L"File Locksmith disabled");
|
||||||
m_enabled = false;
|
m_enabled = false;
|
||||||
save_settings();
|
save_settings();
|
||||||
|
Trace::EnableFileLocksmith(m_enabled);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual bool is_enabled() override
|
virtual bool is_enabled() override
|
||||||
|
60
src/modules/FileLocksmith/FileLocksmithExt/Trace.cpp
Normal file
60
src/modules/FileLocksmith/FileLocksmithExt/Trace.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
#include "Trace.h"
|
||||||
|
#include "../common/Telemetry/ProjectTelemetry.h"
|
||||||
|
|
||||||
|
TRACELOGGING_DEFINE_PROVIDER(
|
||||||
|
g_hProvider,
|
||||||
|
"Microsoft.PowerToys",
|
||||||
|
// {38e8889b-9731-53f5-e901-e8a7c1753074}
|
||||||
|
(0x38e8889b, 0x9731, 0x53f5, 0xe9, 0x01, 0xe8, 0xa7, 0xc1, 0x75, 0x30, 0x74),
|
||||||
|
TraceLoggingOptionProjectTelemetry());
|
||||||
|
|
||||||
|
void Trace::RegisterProvider() noexcept
|
||||||
|
{
|
||||||
|
TraceLoggingRegister(g_hProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trace::UnregisterProvider() noexcept
|
||||||
|
{
|
||||||
|
TraceLoggingUnregister(g_hProvider);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trace::EnableFileLocksmith(_In_ bool enabled) noexcept
|
||||||
|
{
|
||||||
|
TraceLoggingWrite(
|
||||||
|
g_hProvider,
|
||||||
|
"FileLocksmith_EnableFileLocksmith",
|
||||||
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||||
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE),
|
||||||
|
TraceLoggingBoolean(enabled, "Enabled"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trace::Invoked() noexcept
|
||||||
|
{
|
||||||
|
TraceLoggingWrite(
|
||||||
|
g_hProvider,
|
||||||
|
"FileLocksmith_Invoked",
|
||||||
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||||
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trace::InvokedRet(_In_ HRESULT hr) noexcept
|
||||||
|
{
|
||||||
|
TraceLoggingWrite(
|
||||||
|
g_hProvider,
|
||||||
|
"FileLocksmith_InvokedRet",
|
||||||
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||||
|
TraceLoggingHResult(hr),
|
||||||
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Trace::QueryContextMenuError(_In_ HRESULT hr) noexcept
|
||||||
|
{
|
||||||
|
TraceLoggingWrite(
|
||||||
|
g_hProvider,
|
||||||
|
"FileLocksmith_QueryContextMenuError",
|
||||||
|
ProjectTelemetryPrivacyDataTag(ProjectTelemetryTag_ProductAndServicePerformance),
|
||||||
|
TraceLoggingHResult(hr),
|
||||||
|
TraceLoggingKeyword(PROJECT_KEYWORD_MEASURE));
|
||||||
|
}
|
14
src/modules/FileLocksmith/FileLocksmithExt/Trace.h
Normal file
14
src/modules/FileLocksmith/FileLocksmithExt/Trace.h
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "pch.h"
|
||||||
|
|
||||||
|
class Trace
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
static void RegisterProvider() noexcept;
|
||||||
|
static void UnregisterProvider() noexcept;
|
||||||
|
static void EnableFileLocksmith(_In_ bool enabled) noexcept;
|
||||||
|
static void Invoked() noexcept;
|
||||||
|
static void InvokedRet(_In_ HRESULT hr) noexcept;
|
||||||
|
static void QueryContextMenuError(_In_ HRESULT hr) noexcept;
|
||||||
|
};
|
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#include "Registry.h"
|
#include "Registry.h"
|
||||||
#include "ClassFactory.h"
|
#include "ClassFactory.h"
|
||||||
|
#include "Trace.h"
|
||||||
|
|
||||||
namespace globals
|
namespace globals
|
||||||
{
|
{
|
||||||
@ -23,16 +24,15 @@ BOOL APIENTRY DllMain( HMODULE hModule,
|
|||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
globals::instance = hModule;
|
globals::instance = hModule;
|
||||||
|
Trace::RegisterProvider();
|
||||||
break;
|
break;
|
||||||
case DLL_THREAD_ATTACH:
|
|
||||||
case DLL_THREAD_DETACH:
|
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
|
Trace::UnregisterProvider();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
STDAPI DllRegisterServer()
|
STDAPI DllRegisterServer()
|
||||||
{
|
{
|
||||||
if (!add_registry_keys())
|
if (!add_registry_keys())
|
||||||
@ -68,14 +68,3 @@ STDAPI DllCanUnloadNow(void)
|
|||||||
{
|
{
|
||||||
return globals::ref_count == 0 ? S_OK : S_FALSE;
|
return globals::ref_count == 0 ? S_OK : S_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Things to implement:
|
|
||||||
// 1. (DONE) A class which implements IExplorerCommand
|
|
||||||
// 2. (DONE) A class which implements IClassFactory
|
|
||||||
// 3. (DONE) DLL register/unregister functions which will create registry entries
|
|
||||||
// 4. (DONE) Other DLL exported functions
|
|
||||||
// 5. (DONE) Implement IShellExtInit in ExplorerCommand
|
|
||||||
// 6. (DONE) Implement IContextMenu in ExplorerCommand
|
|
||||||
// 7. (DONE) Extract useful functions from HandlesExperiment to a static library
|
|
||||||
// 8. (DONE) Implement IPC in Lib - to be used between UI and DLL
|
|
||||||
// 9. Implement UI
|
|
||||||
|
Loading…
Reference in New Issue
Block a user