From 4f87c26575d378c4e7d77c516a5a4471c31183ac Mon Sep 17 00:00:00 2001 From: Nick Gerleman Date: Mon, 9 Mar 2020 12:48:50 -0700 Subject: [PATCH] [Cherry-Pick] Fix Support For SystraceSection (#4267) * Fix Support For SysTraceSection Addresses #4245, During deforking work I left a build logic typo which caused SysTraceSection to noop. When trying to reenable in deforked React Native, we end up having a compile error since stock Facebook code will pass doubles as an arg to SysTraceSection, and we will internally only accept string. This was fixed in microsof/react-native by commenting out the SysTraceSection call that passed a double. A real solution is to allow our implementation of FbSystraceSection to accept non-string args and convert to strings, as Facebook's seemingly does. - Use type traits to call std::to_string on args not convertible to string - Move functions to be private instead of public Still need a plan to validate this. * Simplify things a bit * Solely rely on is_convertible Constructable was sort of wrong before, because we're actually doing assignment, but even then we likely only want things that allow implicit conversions. --- ...e-windows-2020-03-07-06-25-07-fix-etw.json | 9 ++++ vnext/PropertySheets/React.Cpp.props | 2 +- vnext/ReactWindowsCore/tracing/fbsystrace.h | 47 ++++++++----------- 3 files changed, 30 insertions(+), 28 deletions(-) create mode 100644 change/react-native-windows-2020-03-07-06-25-07-fix-etw.json diff --git a/change/react-native-windows-2020-03-07-06-25-07-fix-etw.json b/change/react-native-windows-2020-03-07-06-25-07-fix-etw.json new file mode 100644 index 00000000000..64de1786ac4 --- /dev/null +++ b/change/react-native-windows-2020-03-07-06-25-07-fix-etw.json @@ -0,0 +1,9 @@ +{ + "type": "prerelease", + "comment": "Fix Support For SysTraceSection", + "packageName": "react-native-windows", + "email": "ngerlem@microsoft.com", + "commit": "6745910fa922e880c314c9581419a6a2cc3f2e2a", + "dependentChangeType": "patch", + "date": "2020-03-07T14:25:07.210Z" +} \ No newline at end of file diff --git a/vnext/PropertySheets/React.Cpp.props b/vnext/PropertySheets/React.Cpp.props index d07ebeb0c4b..7c4e4eb932b 100644 --- a/vnext/PropertySheets/React.Cpp.props +++ b/vnext/PropertySheets/React.Cpp.props @@ -41,7 +41,7 @@ ENABLE_ETW_TRACING;%(PreprocessorDefinitions) - ENABLE_JS_SYSTRACE_TO_ETW;WITH_FBSYSTRACE;%(PreprocessorDefinitions) + ENABLE_JS_SYSTRACE_TO_ETW;WITH_FBSYSTRACE;%(PreprocessorDefinitions) diff --git a/vnext/ReactWindowsCore/tracing/fbsystrace.h b/vnext/ReactWindowsCore/tracing/fbsystrace.h index 256ea90d209..edaaaa123ff 100644 --- a/vnext/ReactWindowsCore/tracing/fbsystrace.h +++ b/vnext/ReactWindowsCore/tracing/fbsystrace.h @@ -1,3 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + #pragma once #include @@ -6,6 +9,7 @@ #include #include #include +#include #include #define TRACE_TAG_REACT_CXX_BRIDGE 1 << 10 @@ -51,44 +55,33 @@ class FbSystraceSection { .count()); } - void init(std::string &&v) { - args_[index_++] = std::move(v); - begin_section(); + template + FbSystraceSection(uint64_t tag, std::string &&profileName, RestArg &&... rest) + : tag_(tag), profile_name_(std::move(profileName)) { + id_ = s_id_counter++; + init(std::forward(rest)...); } - void init(const std::string &v) { - args_[index_++] = v; // copy - begin_section(); + ~FbSystraceSection() { + end_section(); } + private: void init() { begin_section(); } - template - void init(std::string &&v, ConvertsToStringPiece &&... rest) { - args_[index_++] = std::move(v); - init(std::forward(rest)...); - } - - template - void init(const std::string &v, ConvertsToStringPiece &&... rest) { - args_[index_++] = v; // copy - init(std::forward(rest)...); - } - - template - FbSystraceSection(uint64_t tag, std::string &&v, ConvertsToStringPiece &&... rest) - : tag_(tag), profile_name_(std::move(v)) { - id_ = s_id_counter++; - init(std::forward(rest)...); - } + template + void init(Arg &&arg, RestArg &&... rest) { + if constexpr (std::is_convertible_v) { + args_[index_++] = std::forward(arg); + } else { + args_[index_++] = std::to_string(std::forward(arg)); + } - ~FbSystraceSection() { - end_section(); + init(std::forward(rest)...); } - private: std::array args_; uint64_t tag_{0};