SystraceSection.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #pragma once
  8. #ifdef WITH_FBSYSTRACE
  9. #include <fbsystrace.h>
  10. #endif
  11. namespace facebook {
  12. namespace react {
  13. /**
  14. * This is a convenience class to avoid lots of verbose profiling
  15. * #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will
  16. * remove this completely. If it is defined, it will behave as
  17. * FbSystraceSection, with the right tag provided. Use two separate classes to
  18. * to ensure that the ODR rule isn't violated, that is, if WITH_FBSYSTRACE has
  19. * different values in different files, there is no inconsistency in the sizes
  20. * of defined symbols.
  21. */
  22. #ifdef WITH_FBSYSTRACE
  23. struct ConcreteSystraceSection {
  24. public:
  25. template <typename... ConvertsToStringPiece>
  26. explicit ConcreteSystraceSection(
  27. const char *name,
  28. ConvertsToStringPiece &&... args)
  29. : m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) {}
  30. private:
  31. fbsystrace::FbSystraceSection m_section;
  32. };
  33. using SystraceSection = ConcreteSystraceSection;
  34. #else
  35. struct DummySystraceSection {
  36. public:
  37. template <typename... ConvertsToStringPiece>
  38. explicit DummySystraceSection(
  39. const char *name,
  40. ConvertsToStringPiece &&... args) {}
  41. };
  42. using SystraceSection = DummySystraceSection;
  43. #endif
  44. } // namespace react
  45. } // namespace facebook