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.
Create ReactPerfLogger to log to Perfetto and Fusebox (facebook#46793)
Summary: Pull Request resolved: facebook#46793 Currently performance logging has several problems: - We have widly different APIs. It's hard to know which to use for what. - Most of these APIs don't allow retroactive timestamp which is important for hero logging and react flame graphs - These APIs aren't accessible from JS/C++/Java/Koltin (this part will be fixed in another diff) - Logging doesn't go to the right place. It either only goes to Systrace, or Perfetto but with broken async timeline etc... This diff start addressing the problem by refactoring. Currently performance.measure/performance.mark are the best APIs. Let's start with refactoring them so that we can call them directly without the otherwise PerformanceEntry side effects. Changelog: [Internal] Reviewed By: cortinico Differential Revision: D63560473 fbshipit-source-id: 86755b3e8491a7cf6919173a07ba9421cd30e663
- Loading branch information
1 parent
4b82922
commit b3bc6ea
Showing
4 changed files
with
110 additions
and
39 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
65 changes: 65 additions & 0 deletions
65
packages/react-native/ReactCommon/reactperflogger/reactperflogger/ReactPerfLogger.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,65 @@ | ||
/* | ||
* 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 "ReactPerfLogger.h" | ||
|
||
#include <react/timing/primitives.h> | ||
#if __has_include(<reactperflogger/fusebox/FuseboxTracer.h>) | ||
#include <reactperflogger/fusebox/FuseboxTracer.h> | ||
#define HAS_FUSEBOX | ||
#endif | ||
#include <chrono> | ||
|
||
#include "ReactPerfetto.h" | ||
|
||
namespace facebook::react { | ||
|
||
/* static */ void ReactPerfLogger::measure( | ||
const std::string_view& eventName, | ||
double startTime, | ||
double endTime, | ||
const std::string_view& trackName) { | ||
#ifdef HAS_FUSEBOX | ||
FuseboxTracer::getFuseboxTracer().addEvent( | ||
eventName, (uint64_t)startTime, (uint64_t)endTime, trackName); | ||
#endif | ||
|
||
#ifdef WITH_PERFETTO | ||
if (TRACE_EVENT_CATEGORY_ENABLED("react-native")) { | ||
auto track = getPerfettoWebPerfTrackAsync(std::string(trackName)); | ||
TRACE_EVENT_BEGIN( | ||
"react-native", | ||
perfetto::DynamicString(eventName.data(), eventName.size()), | ||
track, | ||
performanceNowToPerfettoTraceTime(startTime)); | ||
TRACE_EVENT_END( | ||
"react-native", track, performanceNowToPerfettoTraceTime(endTime)); | ||
} | ||
#endif | ||
} | ||
|
||
/* static */ void ReactPerfLogger::mark( | ||
const std::string_view& eventName, | ||
double startTime, | ||
const std::string_view& trackName) { | ||
// TODO(T203046480) Support mark in FuseboxTracer | ||
|
||
#ifdef WITH_PERFETTO | ||
if (TRACE_EVENT_CATEGORY_ENABLED("react-native")) { | ||
TRACE_EVENT_INSTANT( | ||
"react-native", | ||
perfetto::DynamicString(eventName.data(), eventName.size()), | ||
getPerfettoWebPerfTrackSync(std::string(trackName)), | ||
performanceNowToPerfettoTraceTime(startTime)); | ||
} | ||
#endif | ||
} | ||
|
||
/* static */ double ReactPerfLogger::performanceNow() { | ||
return chronoToDOMHighResTimeStamp(std::chrono::steady_clock::now()); | ||
} | ||
} // namespace facebook::react |
35 changes: 35 additions & 0 deletions
35
packages/react-native/ReactCommon/reactperflogger/reactperflogger/ReactPerfLogger.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,35 @@ | ||
/* | ||
* 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 | ||
|
||
#include <reactperflogger/ReactPerfettoCategories.h> | ||
#include <string> | ||
|
||
namespace facebook::react { | ||
|
||
class ReactPerfLogger { | ||
public: | ||
static void mark( | ||
const std::string_view& eventName, | ||
double startTime, | ||
const std::string_view& trackName); | ||
|
||
/** | ||
* This accepts performance events that should go to internal tracing | ||
* frameworks like Perfetto, and should go to DevTools like Fusebox. | ||
*/ | ||
static void measure( | ||
const std::string_view& eventName, | ||
double startTime, | ||
double endTime, | ||
const std::string_view& trackName); | ||
|
||
static double performanceNow(); | ||
}; | ||
|
||
} // namespace facebook::react |