forked from facebook/react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Encapsulate TracingAgent (facebook#46986)
Summary: # Changelog: [Internal] Encapsulate integration with `FuseboxTracer.cpp` into `TracingAgent.cpp`, which will be responsible for handling `Tracing` domain CDP events. Closer to the top of the stack, more changes will be added to it. Differential Revision: D64249695
- Loading branch information
1 parent
4dd47ee
commit c90247d
Showing
4 changed files
with
109 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#include "TracingAgent.h" | ||
|
||
#include <reactperflogger/fusebox/FuseboxTracer.h> | ||
|
||
namespace facebook::react::jsinspector_modern { | ||
|
||
bool TracingAgent::handleRequest(const cdp::PreparsedRequest& req) { | ||
if (req.method == "Tracing.start") { | ||
// @cdp Tracing.start support is experimental. | ||
if (FuseboxTracer::getFuseboxTracer().startTracing()) { | ||
frontendChannel_(cdp::jsonResult(req.id)); | ||
} else { | ||
frontendChannel_(cdp::jsonError( | ||
req.id, | ||
cdp::ErrorCode::InternalError, | ||
"Tracing session already started")); | ||
} | ||
|
||
return true; | ||
} else if (req.method == "Tracing.end") { | ||
// @cdp Tracing.end support is experimental. | ||
bool firstChunk = true; | ||
auto id = req.id; | ||
bool wasStopped = FuseboxTracer::getFuseboxTracer().stopTracing( | ||
[this, firstChunk, id](const folly::dynamic& eventsChunk) { | ||
if (firstChunk) { | ||
frontendChannel_(cdp::jsonResult(id)); | ||
} | ||
frontendChannel_(cdp::jsonNotification( | ||
"Tracing.dataCollected", | ||
folly::dynamic::object("value", eventsChunk))); | ||
}); | ||
|
||
if (!wasStopped) { | ||
frontendChannel_(cdp::jsonError( | ||
req.id, | ||
cdp::ErrorCode::InternalError, | ||
"Tracing session not started")); | ||
} else { | ||
frontendChannel_(cdp::jsonNotification( | ||
"Tracing.tracingComplete", | ||
folly::dynamic::object("dataLossOccurred", false))); | ||
} | ||
|
||
frontendChannel_(cdp::jsonResult(req.id)); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
} // namespace facebook::react::jsinspector_modern |
41 changes: 41 additions & 0 deletions
41
packages/react-native/ReactCommon/jsinspector-modern/TracingAgent.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright (c) Meta Platforms, Inc. and affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
#pragma once | ||