-
Notifications
You must be signed in to change notification settings - Fork 24.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement native logic for performance event reporting (#35526)
Summary: Pull Request resolved: #35526 [Changelog][Internal] This closes the full loop according to the [technical design](https://fb.quip.com/MdqgAk1Eb2dV) of the WebPerf API implementation, with the main components and the working central data flow in place. The next step is to add some buffering/throttling, as in this diff we just spawn an idle-priority task after every performance entry coming (even though they still naturally do come in batches, because they manage to accumulate before the task is executed). Reviewed By: christophpurrer Differential Revision: D41496082 fbshipit-source-id: 5fd4cf22e75806f7bc98d1d1b6691596ccadf8b9
- Loading branch information
1 parent
e2c4941
commit 14e69db
Showing
5 changed files
with
151 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
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,52 @@ | ||
/* | ||
* 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 "PerformanceEntryReporter.h" | ||
#include <glog/logging.h> | ||
#include <react/renderer/runtimescheduler/RuntimeScheduler.h> | ||
#include "NativePerformanceObserver.h" | ||
|
||
namespace facebook::react { | ||
void PerformanceEntryReporter::setReportingCallback( | ||
std::optional<AsyncCallback<>> callback) { | ||
callback_ = callback; | ||
} | ||
|
||
void PerformanceEntryReporter::startReporting(PerformanceEntryType entryType) { | ||
reportingType_[static_cast<int>(entryType)] = true; | ||
} | ||
void PerformanceEntryReporter::stopReporting(PerformanceEntryType entryType) { | ||
reportingType_[static_cast<int>(entryType)] = false; | ||
} | ||
|
||
std::vector<RawPerformanceEntry> PerformanceEntryReporter::getPendingEntries() | ||
const { | ||
return entries_; | ||
} | ||
|
||
std::vector<RawPerformanceEntry> PerformanceEntryReporter::popPendingEntries() { | ||
auto entriesToReturn = std::move(entries_); | ||
entries_ = {}; | ||
return entriesToReturn; | ||
} | ||
|
||
void PerformanceEntryReporter::clearPendingEntries() { | ||
entries_.clear(); | ||
} | ||
|
||
void PerformanceEntryReporter::logEntry(const RawPerformanceEntry &entry) { | ||
if (!isReportingType(static_cast<PerformanceEntryType>(entry.entryType))) { | ||
return; | ||
} | ||
|
||
entries_.emplace_back(entry); | ||
|
||
// TODO: Add buffering/throttling - but for testing this works as well, for | ||
// now | ||
callback_->callWithPriority(SchedulerPriority::IdlePriority); | ||
} | ||
} // namespace facebook::react |
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,44 @@ | ||
/* | ||
* 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 <react/bridging/Function.h> | ||
#include <array> | ||
#include <optional> | ||
#include "NativePerformanceObserver.h" | ||
|
||
namespace facebook::react { | ||
|
||
enum class PerformanceEntryType { | ||
UNDEFINED = 0, | ||
MARK = 1, | ||
_COUNT = 2, | ||
}; | ||
|
||
class PerformanceEntryReporter { | ||
public: | ||
void setReportingCallback(std::optional<AsyncCallback<>> callback); | ||
void startReporting(PerformanceEntryType entryType); | ||
void stopReporting(PerformanceEntryType entryType); | ||
|
||
std::vector<RawPerformanceEntry> getPendingEntries() const; | ||
std::vector<RawPerformanceEntry> popPendingEntries(); | ||
void clearPendingEntries(); | ||
void logEntry(const RawPerformanceEntry &entry); | ||
|
||
bool isReportingType(PerformanceEntryType entryType) const { | ||
return reportingType_[static_cast<int>(entryType)]; | ||
} | ||
|
||
private: | ||
std::optional<AsyncCallback<>> callback_; | ||
std::vector<RawPerformanceEntry> entries_; | ||
std::array<bool, (size_t)PerformanceEntryType::_COUNT> reportingType_{false}; | ||
}; | ||
|
||
} // namespace facebook::react |
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