react-native 0.83.4 → 0.83.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. package/Libraries/Core/ReactNativeVersion.js +1 -1
  2. package/Libraries/Utilities/Appearance.js +6 -1
  3. package/React/Base/RCTVersion.m +1 -1
  4. package/React/DevSupport/RCTFrameTimingsObserver.h +24 -0
  5. package/React/DevSupport/RCTFrameTimingsObserver.mm +298 -0
  6. package/React/FBReactNativeSpec/FBReactNativeSpecJSI.h +16 -0
  7. package/ReactAndroid/api/ReactAndroid.api +0 -9
  8. package/ReactAndroid/gradle.properties +1 -1
  9. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/BridgelessDevSupportManager.kt +2 -2
  10. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.kt +7 -7
  11. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.kt +4 -0
  12. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/inspector/FrameTimingSequence.kt +16 -0
  13. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/inspector/FrameTimingsObserver.kt +275 -0
  14. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/inspector/TracingState.kt +17 -0
  15. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/inspector/TracingStateListener.kt +15 -0
  16. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/{interfaces → inspector}/TracingStateProvider.kt +1 -1
  17. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/perfmonitor/PerfMonitorInspectorTargetBinding.kt +1 -1
  18. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/perfmonitor/PerfMonitorOverlayManager.kt +4 -4
  19. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/perfmonitor/PerfMonitorOverlayView.kt +3 -3
  20. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/perfmonitor/PerfMonitorUpdateListener.kt +1 -1
  21. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +13 -1
  22. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +21 -1
  23. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +5 -1
  24. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +5 -1
  25. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +23 -1
  26. package/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +5 -1
  27. package/ReactAndroid/src/main/java/com/facebook/react/internal/tracing/PerformanceTracer.kt +39 -0
  28. package/ReactAndroid/src/main/java/com/facebook/react/modules/blob/BlobModule.kt +1 -1
  29. package/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkEventUtil.kt +20 -19
  30. package/ReactAndroid/src/main/java/com/facebook/react/modules/network/NetworkingModule.kt +6 -12
  31. package/ReactAndroid/src/main/java/com/facebook/react/modules/systeminfo/ReactNativeVersion.kt +1 -1
  32. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.kt +86 -4
  33. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImplDevHelper.kt +3 -3
  34. package/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostInspectorTarget.kt +10 -6
  35. package/ReactAndroid/src/main/jni/react/devsupport/JInspectorFlags.cpp +22 -0
  36. package/ReactAndroid/src/main/jni/react/devsupport/JInspectorFlags.h +2 -0
  37. package/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +29 -1
  38. package/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +7 -1
  39. package/ReactAndroid/src/main/jni/react/runtime/jni/JReactHostInspectorTarget.cpp +196 -17
  40. package/ReactAndroid/src/main/jni/react/runtime/jni/JReactHostInspectorTarget.h +168 -18
  41. package/ReactAndroid/src/main/jni/third-party/folly/CMakeLists.txt +1 -0
  42. package/ReactCommon/cxxreact/ReactNativeVersion.h +2 -2
  43. package/ReactCommon/jsinspector-modern/HostAgent.cpp +45 -10
  44. package/ReactCommon/jsinspector-modern/HostAgent.h +2 -2
  45. package/ReactCommon/jsinspector-modern/HostTarget.cpp +14 -7
  46. package/ReactCommon/jsinspector-modern/HostTarget.h +101 -14
  47. package/ReactCommon/jsinspector-modern/HostTargetTraceRecording.cpp +39 -8
  48. package/ReactCommon/jsinspector-modern/HostTargetTraceRecording.h +42 -5
  49. package/ReactCommon/jsinspector-modern/HostTargetTracing.cpp +54 -21
  50. package/ReactCommon/jsinspector-modern/HostTargetTracing.h +89 -0
  51. package/ReactCommon/jsinspector-modern/InspectorFlags.cpp +12 -0
  52. package/ReactCommon/jsinspector-modern/InspectorFlags.h +12 -0
  53. package/ReactCommon/jsinspector-modern/InspectorInterfaces.cpp +3 -7
  54. package/ReactCommon/jsinspector-modern/InstanceAgent.cpp +2 -11
  55. package/ReactCommon/jsinspector-modern/NetworkIOAgent.cpp +1 -1
  56. package/ReactCommon/jsinspector-modern/TracingAgent.cpp +29 -13
  57. package/ReactCommon/jsinspector-modern/TracingAgent.h +5 -4
  58. package/ReactCommon/jsinspector-modern/tests/HostTargetTest.cpp +65 -0
  59. package/ReactCommon/jsinspector-modern/tests/InspectorMocks.h +23 -2
  60. package/ReactCommon/jsinspector-modern/tests/JsiIntegrationTest.cpp +1 -0
  61. package/ReactCommon/jsinspector-modern/tests/NetworkReporterTest.cpp +1 -0
  62. package/ReactCommon/jsinspector-modern/tests/TracingTest.cpp +335 -0
  63. package/ReactCommon/jsinspector-modern/tests/TracingTest.h +95 -0
  64. package/ReactCommon/jsinspector-modern/tests/utils/InspectorFlagOverridesGuard.cpp +10 -0
  65. package/ReactCommon/jsinspector-modern/tests/utils/InspectorFlagOverridesGuard.h +3 -1
  66. package/ReactCommon/jsinspector-modern/tracing/CMakeLists.txt +1 -0
  67. package/ReactCommon/jsinspector-modern/tracing/FrameTimingSequence.h +61 -0
  68. package/ReactCommon/jsinspector-modern/tracing/HostTracingProfile.h +43 -0
  69. package/ReactCommon/jsinspector-modern/tracing/HostTracingProfileSerializer.cpp +165 -0
  70. package/ReactCommon/jsinspector-modern/tracing/HostTracingProfileSerializer.h +50 -0
  71. package/ReactCommon/jsinspector-modern/tracing/PerformanceTracer.cpp +16 -14
  72. package/ReactCommon/jsinspector-modern/tracing/PerformanceTracerSection.h +113 -0
  73. package/ReactCommon/jsinspector-modern/tracing/React-jsinspectortracing.podspec +1 -0
  74. package/ReactCommon/jsinspector-modern/tracing/TimeWindowedBuffer.h +158 -0
  75. package/ReactCommon/jsinspector-modern/tracing/TraceEvent.h +2 -1
  76. package/ReactCommon/jsinspector-modern/tracing/TraceEventGenerator.cpp +100 -0
  77. package/ReactCommon/jsinspector-modern/tracing/TraceEventGenerator.h +60 -0
  78. package/ReactCommon/jsinspector-modern/tracing/TraceEventSerializer.cpp +44 -1
  79. package/ReactCommon/jsinspector-modern/tracing/TraceEventSerializer.h +7 -0
  80. package/ReactCommon/jsinspector-modern/tracing/TraceRecordingState.h +18 -7
  81. package/ReactCommon/jsinspector-modern/tracing/TracingCategory.h +136 -0
  82. package/ReactCommon/jsinspector-modern/tracing/tests/TimeWindowedBufferTest.cpp +352 -0
  83. package/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +9 -1
  84. package/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +11 -1
  85. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +65 -29
  86. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +6 -2
  87. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +9 -1
  88. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h +19 -1
  89. package/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +3 -1
  90. package/ReactCommon/react/nativemodule/core/platform/ios/ReactCommon/RCTTurboModule.mm +3 -1
  91. package/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +11 -1
  92. package/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +5 -1
  93. package/ReactCommon/react/performance/timeline/PerformanceObserver.cpp +18 -6
  94. package/ReactCommon/react/performance/timeline/PerformanceObserver.h +2 -0
  95. package/ReactCommon/react/runtime/platform/ios/ReactCommon/RCTHost.mm +115 -0
  96. package/ReactCommon/{jsinspector-modern → react/utils}/Base64.h +2 -2
  97. package/gradle/libs.versions.toml +1 -1
  98. package/package.json +8 -8
  99. package/scripts/cocoapods/utils.rb +1 -0
  100. package/src/private/featureflags/ReactNativeFeatureFlags.js +11 -1
  101. package/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +3 -1
  102. package/third-party-podspecs/RCT-Folly.podspec +1 -1
  103. package/third-party-podspecs/fmt.podspec +2 -2
  104. package/ReactAndroid/src/main/java/com/facebook/react/devsupport/interfaces/TracingState.kt +0 -19
  105. package/ReactCommon/jsinspector-modern/tracing/TraceRecordingStateSerializer.cpp +0 -68
  106. package/ReactCommon/jsinspector-modern/tracing/TraceRecordingStateSerializer.h +0 -42
  107. package/ReactCommon/jsinspector-modern/tracing/TracingState.h +0 -24
@@ -0,0 +1,100 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+
8
+ #include "TraceEventGenerator.h"
9
+ #include "Timing.h"
10
+ #include "TracingCategory.h"
11
+
12
+ #include <react/utils/Base64.h>
13
+
14
+ namespace facebook::react::jsinspector_modern::tracing {
15
+
16
+ /* static */ TraceEvent TraceEventGenerator::createSetLayerTreeIdEvent(
17
+ std::string frame,
18
+ int layerTreeId,
19
+ ProcessId processId,
20
+ ThreadId threadId,
21
+ HighResTimeStamp timestamp) {
22
+ folly::dynamic data = folly::dynamic::object("frame", std::move(frame))(
23
+ "layerTreeId", layerTreeId);
24
+
25
+ return TraceEvent{
26
+ .name = "SetLayerTreeId",
27
+ .cat = {Category::HiddenTimeline},
28
+ .ph = 'I',
29
+ .ts = timestamp,
30
+ .pid = processId,
31
+ .s = 't',
32
+ .tid = threadId,
33
+ .args = folly::dynamic::object("data", std::move(data)),
34
+ };
35
+ }
36
+
37
+ /* static */ std::pair<TraceEvent, TraceEvent>
38
+ TraceEventGenerator::createFrameTimingsEvents(
39
+ uint64_t sequenceId,
40
+ int layerTreeId,
41
+ HighResTimeStamp beginTimestamp,
42
+ HighResTimeStamp endTimestamp,
43
+ ProcessId processId,
44
+ ThreadId threadId) {
45
+ folly::dynamic args = folly::dynamic::object("frameSeqId", sequenceId)(
46
+ "layerTreeId", layerTreeId);
47
+
48
+ auto beginEvent = TraceEvent{
49
+ .name = "BeginFrame",
50
+ .cat = {Category::Frame},
51
+ .ph = 'I',
52
+ .ts = beginTimestamp,
53
+ .pid = processId,
54
+ .s = 't',
55
+ .tid = threadId,
56
+ .args = args,
57
+ };
58
+ auto drawEvent = TraceEvent{
59
+ .name = "DrawFrame",
60
+ .cat = {Category::Frame},
61
+ .ph = 'I',
62
+ .ts = endTimestamp,
63
+ .pid = processId,
64
+ .s = 't',
65
+ .tid = threadId,
66
+ .args = args,
67
+ };
68
+
69
+ return {std::move(beginEvent), std::move(drawEvent)};
70
+ }
71
+
72
+ /* static */ TraceEvent TraceEventGenerator::createScreenshotEvent(
73
+ FrameSequenceId frameSequenceId,
74
+ int sourceId,
75
+ std::vector<uint8_t>&& snapshot,
76
+ HighResTimeStamp expectedDisplayTime,
77
+ ProcessId processId,
78
+ ThreadId threadId) {
79
+ // Convert binary data to string for Base64 encoding
80
+ std::string snapshotBytes(snapshot.begin(), snapshot.end());
81
+ std::string base64Snapshot = base64Encode(snapshotBytes);
82
+
83
+ folly::dynamic args =
84
+ folly::dynamic::object("snapshot", std::move(base64Snapshot))(
85
+ "source_id", sourceId)("frame_sequence", frameSequenceId)(
86
+ "expected_display_time",
87
+ highResTimeStampToTracingClockTimeStamp(expectedDisplayTime));
88
+
89
+ return TraceEvent{
90
+ .name = "Screenshot",
91
+ .cat = {Category::Screenshot},
92
+ .ph = 'O',
93
+ .ts = expectedDisplayTime,
94
+ .pid = processId,
95
+ .tid = threadId,
96
+ .args = std::move(args),
97
+ };
98
+ }
99
+
100
+ }; // namespace facebook::react::jsinspector_modern::tracing
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+
8
+ #pragma once
9
+
10
+ #include "TraceEvent.h"
11
+
12
+ #include <jsinspector-modern/tracing/FrameTimingSequence.h>
13
+ #include <react/timing/primitives.h>
14
+
15
+ #include <cstdint>
16
+ #include <utility>
17
+ #include <vector>
18
+
19
+ namespace facebook::react::jsinspector_modern::tracing {
20
+
21
+ /**
22
+ * This class encapsulates the logic for generating canonical trace events that will be serialized and sent as part of
23
+ * Tracing.dataCollected CDP message.
24
+ */
25
+ class TraceEventGenerator {
26
+ public:
27
+ /**
28
+ * Creates canonical "SetLayerTreeId" trace event.
29
+ */
30
+ static TraceEvent createSetLayerTreeIdEvent(
31
+ std::string frame,
32
+ int layerTreeId,
33
+ ProcessId processId,
34
+ ThreadId threadId,
35
+ HighResTimeStamp timestamp);
36
+
37
+ /**
38
+ * Creates canonical "BeginFrame", "Commit", "DrawFrame" trace events.
39
+ */
40
+ static std::pair<TraceEvent, TraceEvent> createFrameTimingsEvents(
41
+ FrameSequenceId sequenceId,
42
+ int layerTreeId,
43
+ HighResTimeStamp beginTimestamp,
44
+ HighResTimeStamp endTimestamp,
45
+ ProcessId processId,
46
+ ThreadId threadId);
47
+
48
+ /**
49
+ * Creates canonical "Screenshot" trace event.
50
+ */
51
+ static TraceEvent createScreenshotEvent(
52
+ FrameSequenceId frameSequenceId,
53
+ int sourceId,
54
+ std::vector<uint8_t> &&snapshot,
55
+ HighResTimeStamp expectedDisplayTime,
56
+ ProcessId processId,
57
+ ThreadId threadId);
58
+ };
59
+
60
+ }; // namespace facebook::react::jsinspector_modern::tracing
@@ -7,6 +7,7 @@
7
7
 
8
8
  #include "TraceEventSerializer.h"
9
9
  #include "Timing.h"
10
+ #include "TracingCategory.h"
10
11
 
11
12
  #include <react/timing/primitives.h>
12
13
 
@@ -22,7 +23,7 @@ namespace facebook::react::jsinspector_modern::tracing {
22
23
  result["id"] = buffer.data();
23
24
  }
24
25
  result["name"] = std::move(event.name);
25
- result["cat"] = std::move(event.cat);
26
+ result["cat"] = serializeTracingCategories(event.cat);
26
27
  result["ph"] = std::string(1, event.ph);
27
28
  result["ts"] = highResTimeStampToTracingClockTimeStamp(event.ts);
28
29
  result["pid"] = event.pid;
@@ -111,4 +112,46 @@ TraceEventSerializer::serializeProfileChunkCPUProfileNodeCallFrame(
111
112
  return dynamicCallFrame;
112
113
  }
113
114
 
115
+ /* static */ size_t TraceEventSerializer::estimateJsonSize(
116
+ const folly::dynamic& value) {
117
+ switch (value.type()) {
118
+ case folly::dynamic::Type::NULLT:
119
+ return 4; // null
120
+ case folly::dynamic::Type::BOOL:
121
+ return 5; // false
122
+ case folly::dynamic::Type::INT64:
123
+ case folly::dynamic::Type::DOUBLE:
124
+ return 20; // conservative max for numeric values
125
+ case folly::dynamic::Type::STRING:
126
+ return value.stringPiece().size() + 2; // quotes
127
+ case folly::dynamic::Type::ARRAY: {
128
+ size_t size = 2; // []
129
+ bool first = true;
130
+ for (const auto& element : value) {
131
+ if (!first) {
132
+ size += 1; // comma
133
+ }
134
+ first = false;
135
+ size += estimateJsonSize(element);
136
+ }
137
+ return size;
138
+ }
139
+ case folly::dynamic::Type::OBJECT: {
140
+ size_t size = 2; // {}
141
+ bool first = true;
142
+ for (const auto& [key, val] : value.items()) {
143
+ if (!first) {
144
+ size += 1; // comma
145
+ }
146
+ first = false;
147
+ // key size + quotes + colon
148
+ size += key.stringPiece().size() + 3;
149
+ size += estimateJsonSize(val);
150
+ }
151
+ return size;
152
+ }
153
+ }
154
+ return 0;
155
+ }
156
+
114
157
  } // namespace facebook::react::jsinspector_modern::tracing
@@ -84,6 +84,13 @@ class TraceEventSerializer {
84
84
  */
85
85
  static folly::dynamic serializeProfileChunkCPUProfileNodeCallFrame(
86
86
  TraceEventProfileChunk::CPUProfile::Node::CallFrame &&callFrame);
87
+
88
+ /**
89
+ * Estimates the JSON-serialized byte size of a folly::dynamic value.
90
+ * This is a rough but conservative estimate to avoid the cost of
91
+ * double-serialization (once to measure, once to emit).
92
+ */
93
+ static size_t estimateJsonSize(const folly::dynamic &value);
87
94
  };
88
95
 
89
96
  } // namespace facebook::react::jsinspector_modern::tracing
@@ -18,22 +18,33 @@
18
18
 
19
19
  namespace facebook::react::jsinspector_modern::tracing {
20
20
 
21
+ /**
22
+ * The global state for the given Trace Recording.
23
+ * Shared with Tracing Agents, which could use it to stash the corresponding target profiles during reloads.
24
+ */
21
25
  struct TraceRecordingState {
26
+ TraceRecordingState(
27
+ tracing::Mode tracingMode,
28
+ std::set<tracing::Category> enabledCategories,
29
+ std::optional<HighResDuration> windowSize = std::nullopt)
30
+ : mode(tracingMode), enabledCategories(std::move(enabledCategories)), windowSize(windowSize)
31
+ {
32
+ }
33
+
22
34
  // The mode of this Trace Recording.
23
35
  tracing::Mode mode;
24
36
 
25
- // The ID of the OS-level process that this Trace Recording is associated
26
- // with.
27
- ProcessId processId = oscompat::getCurrentProcessId();
28
-
29
- // The timestamp at which this Trace Recording started.
30
- HighResTimeStamp startTime;
31
-
32
37
  // All captured Runtime Sampling Profiles during this Trace Recording.
33
38
  std::vector<RuntimeSamplingProfile> runtimeSamplingProfiles{};
34
39
 
35
40
  // All captures Instance Tracing Profiles during this Trace Recording.
36
41
  std::vector<InstanceTracingProfile> instanceTracingProfiles{};
42
+
43
+ // The list of categories that are enabled for this recording.
44
+ std::set<tracing::Category> enabledCategories;
45
+
46
+ // The size of the time window for this recording.
47
+ std::optional<HighResDuration> windowSize;
37
48
  };
38
49
 
39
50
  } // namespace facebook::react::jsinspector_modern::tracing
@@ -0,0 +1,136 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and 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
+
8
+ #pragma once
9
+
10
+ #include <folly/container/small_vector.h>
11
+
12
+ #include <optional>
13
+ #include <set>
14
+ #include <string>
15
+
16
+ namespace facebook::react::jsinspector_modern::tracing {
17
+
18
+ enum class Category {
19
+ HiddenTimeline, /* disabled-by-default-devtools.timeline */
20
+ JavaScriptSampling, /* disabled-by-default-v8.cpu_profiler */
21
+ RuntimeExecution, /* v8.execute */
22
+ Timeline, /* devtools.timeline */
23
+ UserTiming, /* blink.user_timing */
24
+ Frame, /* disabled-by-default-devtools.timeline.frame */
25
+ Screenshot, /* disabled-by-default-devtools.screenshot */
26
+ };
27
+
28
+ inline std::string tracingCategoryToString(const Category &category)
29
+ {
30
+ switch (category) {
31
+ case Category::Timeline:
32
+ return "devtools.timeline";
33
+ case Category::HiddenTimeline:
34
+ return "disabled-by-default-devtools.timeline";
35
+ case Category::UserTiming:
36
+ return "blink.user_timing";
37
+ case Category::JavaScriptSampling:
38
+ return "disabled-by-default-v8.cpu_profiler";
39
+ case Category::RuntimeExecution:
40
+ return "v8.execute";
41
+ case Category::Frame:
42
+ return "disabled-by-default-devtools.timeline.frame";
43
+ case Category::Screenshot:
44
+ return "disabled-by-default-devtools.screenshot";
45
+ }
46
+ }
47
+
48
+ inline std::optional<Category> getTracingCategoryFromString(const std::string &str)
49
+ {
50
+ if (str == "blink.user_timing") {
51
+ return Category::UserTiming;
52
+ } else if (str == "devtools.timeline") {
53
+ return Category::Timeline;
54
+ } else if (str == "disabled-by-default-devtools.timeline") {
55
+ return Category::HiddenTimeline;
56
+ } else if (str == "disabled-by-default-v8.cpu_profiler") {
57
+ return Category::JavaScriptSampling;
58
+ } else if (str == "v8.execute") {
59
+ return Category::RuntimeExecution;
60
+ } else if (str == "disabled-by-default-devtools.timeline.frame") {
61
+ return Category::Frame;
62
+ } else if (str == "disabled-by-default-devtools.screenshot") {
63
+ return Category::Screenshot;
64
+ } else {
65
+ return std::nullopt;
66
+ }
67
+ }
68
+
69
+ /**
70
+ * The Trace Event could have multiple categories, but this is extremely rare case.
71
+ */
72
+ using Categories = folly::small_vector<Category, 1>;
73
+
74
+ // { Timeline, UserTiming } => "devtools.timeline,blink.user_timing"
75
+ inline std::string serializeTracingCategories(const Categories &categories)
76
+ {
77
+ if (categories.size() == 1) {
78
+ return tracingCategoryToString(categories.front());
79
+ }
80
+
81
+ std::string serializedValue;
82
+ for (size_t i = 0; i < categories.size(); ++i) {
83
+ serializedValue += tracingCategoryToString(categories[i]);
84
+ if (i < categories.size() - 1) {
85
+ serializedValue += ",";
86
+ }
87
+ }
88
+ return serializedValue;
89
+ }
90
+
91
+ // { Timeline, UserTiming } => "devtools.timeline,blink.user_timing"
92
+ inline std::string serializeTracingCategories(const std::set<Category> &categories)
93
+ {
94
+ std::string serializedValue;
95
+
96
+ auto current = categories.begin();
97
+ while (current != categories.end()) {
98
+ serializedValue += tracingCategoryToString(*current);
99
+
100
+ ++current;
101
+ if (current != categories.end()) {
102
+ serializedValue += ",";
103
+ }
104
+ }
105
+
106
+ return serializedValue;
107
+ }
108
+
109
+ // "devtools.timeline,blink.user_timing" => { Timeline, UserTiming }
110
+ inline std::set<Category> parseSerializedTracingCategories(const std::string &serializedCategories)
111
+ {
112
+ std::set<Category> categories;
113
+ if (serializedCategories.empty()) {
114
+ return categories;
115
+ }
116
+
117
+ size_t start = 0;
118
+ size_t end = serializedCategories.find(',');
119
+ while (end != std::string::npos) {
120
+ std::string token = serializedCategories.substr(start, end - start);
121
+ if (auto category = getTracingCategoryFromString(token)) {
122
+ categories.insert(*category);
123
+ }
124
+ start = end + 1;
125
+ end = serializedCategories.find(',', start);
126
+ }
127
+
128
+ std::string lastToken = serializedCategories.substr(start);
129
+ if (auto category = getTracingCategoryFromString(lastToken)) {
130
+ categories.insert(*category);
131
+ }
132
+
133
+ return categories;
134
+ }
135
+
136
+ } // namespace facebook::react::jsinspector_modern::tracing