mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Reduce visibility of LongStreamingStats (#39705)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/39705 Reduce visibility of LongStreamingStats bypass-github-export-checks changelog: [internal] internal Reviewed By: cortinico Differential Revision: D49656386 fbshipit-source-id: 763afa27353b2a6c127e0997444fd663bddfa886
This commit is contained in:
committed by
Facebook GitHub Bot
parent
cb46f4cff8
commit
6635474e34
+14
-78
@@ -7,92 +7,27 @@
|
||||
|
||||
package com.facebook.react.fabric;
|
||||
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.*;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_BATCH_EXECUTION_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_BATCH_EXECUTION_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_COMMIT_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_COMMIT_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_DIFF_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_DIFF_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_FINISH_TRANSACTION_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_FINISH_TRANSACTION_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_LAYOUT_AFFECTED_NODES;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_LAYOUT_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_LAYOUT_START;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_UPDATE_UI_MAIN_THREAD_END;
|
||||
import static com.facebook.react.bridge.ReactMarkerConstants.FABRIC_UPDATE_UI_MAIN_THREAD_START;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.react.bridge.ReactMarker;
|
||||
import com.facebook.react.bridge.ReactMarkerConstants;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
|
||||
class LongStreamingStats {
|
||||
// TODO(T138627466): Calculate median value with better algorithm after Android API 24.
|
||||
private Queue<Long> minHeap =
|
||||
new PriorityQueue<>(
|
||||
11,
|
||||
new Comparator<Long>() {
|
||||
@Override
|
||||
public int compare(Long first, Long second) {
|
||||
// Natural order
|
||||
return Long.compare(first, second);
|
||||
}
|
||||
});
|
||||
private Queue<Long> maxHeap =
|
||||
new PriorityQueue<>(
|
||||
11,
|
||||
new Comparator<Long>() {
|
||||
@Override
|
||||
public int compare(Long first, Long second) {
|
||||
// Reversed order
|
||||
return Long.compare(second, first);
|
||||
}
|
||||
});
|
||||
private double streamingAverage = 0.0;
|
||||
private int len = 0;
|
||||
private long max = 0;
|
||||
|
||||
LongStreamingStats() {}
|
||||
|
||||
public void add(long n) {
|
||||
// To make medians more useful, we discard all zero values
|
||||
// This isn't perfect and certainly makes this a totally invalid median, but, alas...
|
||||
if (n != 0) {
|
||||
if (minHeap.size() == maxHeap.size()) {
|
||||
maxHeap.offer(n);
|
||||
minHeap.offer(maxHeap.poll());
|
||||
} else {
|
||||
minHeap.offer(n);
|
||||
maxHeap.offer(minHeap.poll());
|
||||
}
|
||||
}
|
||||
|
||||
len++;
|
||||
if (len == 1) {
|
||||
streamingAverage = n;
|
||||
} else {
|
||||
streamingAverage = (streamingAverage / (len / (len - 1))) + (n / len);
|
||||
}
|
||||
|
||||
max = (n > max ? n : max);
|
||||
}
|
||||
|
||||
public double getMedian() {
|
||||
if (minHeap.size() == 0 && maxHeap.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long median;
|
||||
if (minHeap.size() > maxHeap.size()) {
|
||||
median = minHeap.peek();
|
||||
} else {
|
||||
median = (minHeap.peek() + maxHeap.peek()) / 2;
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
return streamingAverage;
|
||||
}
|
||||
|
||||
public long getMax() {
|
||||
return max;
|
||||
}
|
||||
}
|
||||
|
||||
public class DevToolsReactPerfLogger implements ReactMarker.FabricMarkerListener {
|
||||
|
||||
@@ -228,6 +163,7 @@ public class DevToolsReactPerfLogger implements ReactMarker.FabricMarkerListener
|
||||
return getBatchExecutionEnd() - getBatchExecutionStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder builder = new StringBuilder("FabricCommitPoint{");
|
||||
builder.append("mCommitNumber=").append(mCommitNumber);
|
||||
|
||||
+76
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package com.facebook.react.fabric;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.PriorityQueue;
|
||||
import java.util.Queue;
|
||||
|
||||
/* package */
|
||||
class LongStreamingStats {
|
||||
// TODO(T138627466): Calculate median value with better algorithm after Android API 24.
|
||||
private final Queue<Long> minHeap =
|
||||
new PriorityQueue<>(11, Comparator.comparingLong(aLong -> aLong));
|
||||
private final Queue<Long> maxHeap =
|
||||
new PriorityQueue<>(
|
||||
11,
|
||||
(first, second) -> {
|
||||
// Reversed order
|
||||
return Long.compare(second, first);
|
||||
});
|
||||
private double streamingAverage = 0.0;
|
||||
private int len = 0;
|
||||
private long max = 0;
|
||||
|
||||
LongStreamingStats() {}
|
||||
|
||||
public void add(long n) {
|
||||
// To make medians more useful, we discard all zero values
|
||||
// This isn't perfect and certainly makes this a totally invalid median, but, alas...
|
||||
if (n != 0) {
|
||||
if (minHeap.size() == maxHeap.size()) {
|
||||
maxHeap.offer(n);
|
||||
minHeap.offer(maxHeap.poll());
|
||||
} else {
|
||||
minHeap.offer(n);
|
||||
maxHeap.offer(minHeap.poll());
|
||||
}
|
||||
}
|
||||
|
||||
len++;
|
||||
if (len == 1) {
|
||||
streamingAverage = n;
|
||||
} else {
|
||||
streamingAverage = (streamingAverage / (len / (len - 1))) + (n / len);
|
||||
}
|
||||
|
||||
max = (n > max ? n : max);
|
||||
}
|
||||
|
||||
public double getMedian() {
|
||||
if (minHeap.size() == 0 && maxHeap.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
long median;
|
||||
if (minHeap.size() > maxHeap.size()) {
|
||||
median = minHeap.peek();
|
||||
} else {
|
||||
median = (minHeap.peek() + maxHeap.peek()) / 2;
|
||||
}
|
||||
return median;
|
||||
}
|
||||
|
||||
public double getAverage() {
|
||||
return streamingAverage;
|
||||
}
|
||||
|
||||
public long getMax() {
|
||||
return max;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user