Use different symbols for SystraceSection depending on WITH_FBYSTRACE

Reviewed By: tmikov

Differential Revision: D6365162

fbshipit-source-id: d1e13b0012528305506c368d5e60f3754a576df3
This commit is contained in:
Peter Ammon 2017-11-27 14:30:42 -08:00 committed by Facebook Github Bot
parent 028b64bcd3
commit 03956c4ecf
1 changed files with 19 additions and 7 deletions

View File

@ -13,21 +13,33 @@ namespace react {
* This is a convenience class to avoid lots of verbose profiling
* #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will
* remove this completely. If it is defined, it will behave as
* FbSystraceSection, with the right tag provided.
* FbSystraceSection, with the right tag provided. Use two separate classes to
* to ensure that the ODR rule isn't violated, that is, if WITH_FBSYSTRACE has
* different values in different files, there is no inconsistency in the sizes
* of defined symbols.
*/
struct SystraceSection {
#ifdef WITH_FBSYSTRACE
struct ConcreteSystraceSection {
public:
template<typename... ConvertsToStringPiece>
explicit SystraceSection(const char* name, ConvertsToStringPiece&&... args)
#ifdef WITH_FBSYSTRACE
explicit
ConcreteSystraceSection(const char* name, ConvertsToStringPiece&&... args)
: m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...)
#endif
{}
private:
#ifdef WITH_FBSYSTRACE
fbsystrace::FbSystraceSection m_section;
#endif
};
using SystraceSection = ConcreteSystraceSection;
#else
struct DummySystraceSection {
public:
template<typename... ConvertsToStringPiece>
explicit
DummySystraceSection(const char* name, ConvertsToStringPiece&&... args)
{}
};
using SystraceSection = DummySystraceSection;
#endif
}}