PerfHint.cpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. const PerfHintItem s_perfHintContainer[] =
  7. {
  8. #define PERFHINT_REASON(name, isNotOptimized, level, desc, consequences, suggestion) {desc, consequences, suggestion, level, isNotOptimized},
  9. #include "PerfHintDescriptions.h"
  10. #undef PERFHINT_REASON
  11. };
  12. void WritePerfHint(PerfHints hint, Js::FunctionBody * functionBody, uint byteCodeOffset /*= Js::Constants::NoByteCodeOffset*/)
  13. {
  14. Assert(functionBody);
  15. Assert(((uint)hint) < _countof(s_perfHintContainer));
  16. PerfHintItem item = s_perfHintContainer[(uint)hint];
  17. int level = CONFIG_FLAG(PerfHintLevel);
  18. Assert(level <= (int)PerfHintLevels::VERBOSE);
  19. if ((int)item.level <= level)
  20. {
  21. ULONG lineNumber = functionBody->GetLineNumber();
  22. LONG columnNumber = functionBody->GetColumnNumber();
  23. if (byteCodeOffset != Js::Constants::NoByteCodeOffset)
  24. {
  25. functionBody->GetLineCharOffset(byteCodeOffset, &lineNumber, &columnNumber, false /*canAllocateLineCache*/);
  26. // returned values are 0-based. Adjusting.
  27. lineNumber++;
  28. columnNumber++;
  29. }
  30. // We will print the short name.
  31. TCHAR shortName[255];
  32. Js::FunctionBody::GetShortNameFromUrl(functionBody->GetSourceName(), shortName, 255);
  33. OUTPUT_TRACE(Js::PerfHintPhase, _u("%s : %s {\n Function : %s [%s @ %u, %u]\n Consequences : %s\n Suggestion : %s\n}\n"),
  34. item.isNotOptimized ? _u("Not optimized") : _u("Optimized"),
  35. item.description,
  36. functionBody->GetExternalDisplayName(),
  37. shortName,
  38. lineNumber,
  39. columnNumber,
  40. item.consequences,
  41. item.suggestion);
  42. Output::Flush();
  43. }
  44. }