|
9 | 9 | #include <fbsystrace.h>
|
10 | 10 | #endif
|
11 | 11 |
|
12 |
| -#include <string> |
13 |
| -#include <chrono> |
14 |
| - |
15 | 12 | namespace facebook {
|
16 | 13 | namespace react {
|
17 | 14 |
|
18 |
| -void SystraceBeginSection(const char* name, const char* args) noexcept; |
19 |
| -void SystraceEndSection(const char* name, const char* args, std::chrono::nanoseconds duration) noexcept; |
20 |
| - |
21 | 15 | /**
|
22 | 16 | * This is a convenience class to avoid lots of verbose profiling
|
23 | 17 | * #ifdefs. If WITH_FBSYSTRACE is not defined, the optimizer will
|
24 | 18 | * remove this completely. If it is defined, it will behave as
|
25 |
| - * FbSystraceSection, with the right tag provided. |
| 19 | + * FbSystraceSection, with the right tag provided. Use two separate classes to |
| 20 | + * to ensure that the ODR rule isn't violated, that is, if WITH_FBSYSTRACE has |
| 21 | + * different values in different files, there is no inconsistency in the sizes |
| 22 | + * of defined symbols. |
26 | 23 | */
|
27 |
| -struct SystraceSection { |
28 |
| -public: |
29 |
| - template<typename... ConvertsToStringPiece> |
30 |
| - explicit SystraceSection(const char* name, ConvertsToStringPiece&&... args) |
31 | 24 | #ifdef WITH_FBSYSTRACE
|
32 |
| - : m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, std::forward<ConvertsToStringPiece>(args)...) |
33 |
| -#elif defined(WITH_OFFICE_TRACING) |
34 |
| - : m_start(std::chrono::steady_clock::now()) |
35 |
| - , m_name{name} |
36 |
| - , m_args{concatArgs(std::forward<ConvertsToStringPiece>(args)...)} |
37 |
| - { |
38 |
| - SystraceBeginSection(m_name.c_str(), m_args.c_str()); |
39 |
| - } |
40 |
| - |
41 |
| - ~SystraceSection() |
42 |
| - { |
43 |
| - SystraceEndSection(m_name.c_str(), m_args.c_str(), std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now()-m_start)); |
44 |
| - } |
45 |
| - |
46 |
| -private: |
47 |
| - std::string concatArgs() noexcept |
48 |
| - { |
49 |
| - return ""; |
50 |
| - } |
51 |
| - |
| 25 | +struct ConcreteSystraceSection { |
| 26 | +public: |
52 | 27 | template<typename... ConvertsToStringPiece>
|
53 |
| - std::string concatArgs(const char* name, const std::string& value, ConvertsToStringPiece&&... rest) noexcept |
54 |
| - { |
55 |
| - return std::string(name) + "=" + value + "|" + concatArgs(std::forward<ConvertsToStringPiece>(rest)...); |
56 |
| - } |
57 |
| -#else |
| 28 | + explicit |
| 29 | + ConcreteSystraceSection(__unused const char* name, __unused ConvertsToStringPiece&&... args) |
| 30 | + : m_section(TRACE_TAG_REACT_CXX_BRIDGE, name, args...) |
58 | 31 | {}
|
59 |
| -#endif |
60 | 32 |
|
61 |
| -#ifdef WITH_FBSYSTRACE |
| 33 | +private: |
62 | 34 | fbsystrace::FbSystraceSection m_section;
|
63 |
| -#elif defined(WITH_OFFICE_TRACING) |
64 |
| - std::string m_name; |
65 |
| - std::string m_args; |
66 |
| - std::chrono::time_point<std::chrono::steady_clock> m_start; |
67 |
| -#endif |
68 | 35 | };
|
69 |
| - |
70 |
| -// Some placeholder definitions to satisfy linker.. as we are enabling some unintented code paths when enabling these macros. |
71 |
| -#if defined(WITH_OFFICE_TRACING) |
72 |
| -#define TRACE_TAG_REACT_CXX_BRIDGE 0 |
73 |
| -struct FbSystraceAsyncFlow{ |
74 |
| - static void begin(uint64_t /*tag*/, const char* /*name*/, int /*cookie*/) {} |
75 |
| - static void end(uint64_t /*tag*/, const char* /*name*/, int /*cookie*/) {} |
| 36 | +using SystraceSection = ConcreteSystraceSection; |
| 37 | +#else |
| 38 | +struct DummySystraceSection { |
| 39 | +public: |
| 40 | + template<typename... ConvertsToStringPiece> |
| 41 | + explicit |
| 42 | + DummySystraceSection(__unused const char* name, __unused ConvertsToStringPiece&&... args) |
| 43 | + {} |
76 | 44 | };
|
| 45 | +using SystraceSection = DummySystraceSection; |
77 | 46 | #endif
|
78 | 47 |
|
79 | 48 | }}
|
0 commit comments