TestEtwEventSink.cpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. #include "RuntimeBasePch.h"
  6. #ifdef TEST_ETW_EVENTS
  7. #include "Base/EtwTrace.h"
  8. char const * const TestEtwEventSink::CreateEventSinkProcName = STRINGIZE(CREATE_EVENTSINK_PROC_NAME);
  9. TestEtwEventSink* TestEtwEventSink::Instance = NULL;
  10. bool TestEtwEventSink::Load()
  11. {
  12. char16 const * dllname = Js::Configuration::Global.flags.TestEtwDll;
  13. if(!dllname)
  14. {
  15. return false;
  16. }
  17. HMODULE hModule = ::LoadLibraryW(dllname);
  18. if (hModule == nullptr)
  19. {
  20. Output::Print(_u("ERROR: Unable to load ETW event sink %s\n"), dllname);
  21. Js::Throw::FatalInternalError();
  22. }
  23. CreateEventSink procAddress = (CreateEventSink)::GetProcAddress(hModule, CreateEventSinkProcName);
  24. if (procAddress == nullptr)
  25. {
  26. Output::Print(_u("ERROR: Unable to get function %S from dll %s\n"), CreateEventSinkProcName, dllname);
  27. Js::Throw::FatalInternalError();
  28. }
  29. // CONSIDER: pass null and skip rundown testing (if a command line switch is present).
  30. Instance = procAddress(&EtwTrace::PerformRundown, PHASE_TRACE1(Js::EtwPhase));
  31. if (Instance == nullptr)
  32. {
  33. Output::Print(_u("ERROR: Failed to create ETW event sink from dll %s\n"), dllname);
  34. Js::Throw::FatalInternalError();
  35. }
  36. return true;
  37. }
  38. bool TestEtwEventSink::IsLoaded()
  39. {
  40. return Instance != NULL;
  41. }
  42. void TestEtwEventSink::Unload()
  43. {
  44. if(Instance != NULL)
  45. {
  46. Instance->UnloadInstance();
  47. Instance = NULL;
  48. }
  49. }
  50. #endif