Files
react-native/ReactCommon/fabric/mounting/TelemetryController.cpp
T
Valentin Shergin 35f2cd26ae Fabric: Introducing TelemetryController as part of MountingManager
Summary:
This diff implements TelemetryController, a small tool that can be used to instrument mounting transactions. It abstracts the logic of merging telemetry data of multiple transactions in a thread-safe manner.

Changelog: [Internal] Fabric-specific internal change.

Reviewed By: sammy-SC

Differential Revision: D22490580

fbshipit-source-id: 3f3425b88d38fddb555c1390fd8f1ff3ef1c475a
2020-07-15 23:30:33 -07:00

59 lines
1.6 KiB
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include "TelemetryController.h"
#include <react/mounting/MountingCoordinator.h>
namespace facebook {
namespace react {
TelemetryController::TelemetryController(
MountingCoordinator const &mountingCoordinator) noexcept
: mountingCoordinator_(mountingCoordinator) {}
bool TelemetryController::pullTransaction(
std::function<void(MountingTransactionMetadata metadata)> willMount,
std::function<void(ShadowViewMutationList const &mutations)> doMount,
std::function<void(MountingTransactionMetadata metadata)> didMount) const
noexcept {
auto optional = mountingCoordinator_.pullTransaction();
if (!optional.has_value()) {
return false;
}
auto transaction = std::move(*optional);
auto surfaceId = transaction.getSurfaceId();
auto number = transaction.getNumber();
auto telemetry = transaction.getTelemetry();
auto numberOfMutations = transaction.getMutations().size();
mutex_.lock();
auto compoundTelemetry = compoundTelemetry_;
mutex_.unlock();
willMount({surfaceId, number, telemetry, compoundTelemetry});
telemetry.willMount();
doMount(std::move(transaction.getMutations()));
telemetry.didMount();
compoundTelemetry.incorporate(telemetry, numberOfMutations);
didMount({surfaceId, number, telemetry, compoundTelemetry});
mutex_.lock();
compoundTelemetry_ = compoundTelemetry;
mutex_.unlock();
return true;
}
} // namespace react
} // namespace facebook