mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
46acfcb8fc
Summary: The `TransactionalTelemetryTest`s are flaky because they use a real clock and assert on how much time has passed (with a threshold, but that's no good either). Using the real clock in the test is the cause for the test to be flaky because it depends on the assumption that it's the sole process running, never risking to be put in the process-queue of the OS. However, that's not the case and is why the test sporadically fails if the OS decided to schedule other threads/process in the middle of the test. This diff allows parametrising the `TransactionTelemetry` class with the clock implementation so that tests can use a Mock Clock if desired (separate diff). Changelog: [Internal] Fabric-specific internal change. Reviewed By: sammy-SC Differential Revision: D27618516 fbshipit-source-id: 5a08e115b388398ca2b05b9d5ae0fd281dfe3b04
88 lines
2.3 KiB
C++
88 lines
2.3 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.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <chrono>
|
|
#include <cstdint>
|
|
#include <functional>
|
|
|
|
#include <react/utils/Telemetry.h>
|
|
|
|
namespace facebook {
|
|
namespace react {
|
|
|
|
/*
|
|
* Represents telemetry data associated with a particular revision of
|
|
* `ShadowTree`.
|
|
*/
|
|
class TransactionTelemetry final {
|
|
public:
|
|
/*
|
|
* Thread-local Telemetry instance
|
|
*/
|
|
static TransactionTelemetry *threadLocalTelemetry();
|
|
|
|
TransactionTelemetry();
|
|
TransactionTelemetry(std::function<TelemetryTimePoint()> now);
|
|
|
|
void setAsThreadLocal();
|
|
void unsetAsThreadLocal();
|
|
|
|
/*
|
|
* Signaling
|
|
*/
|
|
void willDiff();
|
|
void didDiff();
|
|
void willCommit();
|
|
void didCommit();
|
|
void willLayout();
|
|
void willMeasureText();
|
|
void didMeasureText();
|
|
void didLayout();
|
|
void willMount();
|
|
void didMount();
|
|
|
|
void setRevisionNumber(int revisionNumber);
|
|
|
|
/*
|
|
* Reading
|
|
*/
|
|
TelemetryTimePoint getDiffStartTime() const;
|
|
TelemetryTimePoint getDiffEndTime() const;
|
|
TelemetryTimePoint getLayoutStartTime() const;
|
|
TelemetryTimePoint getLayoutEndTime() const;
|
|
TelemetryTimePoint getCommitStartTime() const;
|
|
TelemetryTimePoint getCommitEndTime() const;
|
|
TelemetryTimePoint getMountStartTime() const;
|
|
TelemetryTimePoint getMountEndTime() const;
|
|
|
|
TelemetryDuration getTextMeasureTime() const;
|
|
int getNumberOfTextMeasurements() const;
|
|
int getRevisionNumber() const;
|
|
|
|
private:
|
|
TelemetryTimePoint diffStartTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint diffEndTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint commitStartTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint commitEndTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint layoutStartTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint layoutEndTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint mountStartTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryTimePoint mountEndTime_{kTelemetryUndefinedTimePoint};
|
|
|
|
TelemetryTimePoint lastTextMeasureStartTime_{kTelemetryUndefinedTimePoint};
|
|
TelemetryDuration textMeasureTime_{0};
|
|
|
|
int numberOfTextMeasurements_{0};
|
|
int revisionNumber_{0};
|
|
std::function<TelemetryTimePoint()> now_;
|
|
};
|
|
|
|
} // namespace react
|
|
} // namespace facebook
|