Skip to content

Commit 9773e9a

Browse files
Add more comments.
1 parent 8757b15 commit 9773e9a

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

firebase-perf/src/main/java/com/google/firebase/perf/metrics/FrameMetricsCalculator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,9 @@ public int getTotalFrames() {
5353

5454
/**
5555
* Calculate total frames, slow frames, and frozen frames from SparseIntArray[] recorded by {@link
56-
* FrameMetricsAggregator}. For a given non-null SparseIntArray, the results stored are the number
57-
* of samples at each millisecond value (rounded).
56+
* FrameMetricsAggregator}.
5857
*
59-
* @param arr the metrics data collected by {@link FrameMetricsAggregator}
58+
* @param arr the metrics data collected by {@link FrameMetricsAggregator#getMetrics()}
6059
* @return the frame metrics
6160
*/
6261
public static @NonNull FrameMetrics calculateFrameMetrics(@Nullable SparseIntArray[] arr) {

firebase-perf/src/test/java/com/google/firebase/perf/metrics/FrameMetricsCalculatorTest.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ public void calculateFrameMetrics_sparseIntArrayIsNull_returnsFrameMetricsWithAl
2323

2424
@Test
2525
public void calculateFrameMetrics_validSparseIntArray_returnsCorrectFrameMetrics() {
26-
// For a given non-null SparseIntArray, the results stored are the number of samples at each
27-
// millisecond value (rounded).
28-
// Slow frames are duration greater than 16ms and frozen frames are duration greater than 700ms.
26+
// Slow frames have duration greater than 16ms and frozen frames have duration greater than
27+
// 700ms. The key value pair means (duration, num_of_samples).
2928
SparseIntArray sparseIntArray = new SparseIntArray();
3029
sparseIntArray.append(5, 3);
3130
sparseIntArray.append(20, 2);
@@ -34,6 +33,8 @@ public void calculateFrameMetrics_validSparseIntArray_returnsCorrectFrameMetrics
3433
arr[FrameMetricsAggregator.TOTAL_INDEX] = sparseIntArray;
3534

3635
FrameMetricsCalculator.FrameMetrics metrics = FrameMetricsCalculator.calculateFrameMetrics(arr);
36+
37+
// we should expect 3+2+5=10 total frames, 2+5=7 slow frames, and 5 frozen frames.
3738
assertThat(metrics.getTotalFrames()).isEqualTo(10);
3839
assertThat(metrics.getSlowFrames()).isEqualTo(7);
3940
assertThat(metrics.getFrozenFrames()).isEqualTo(5);
@@ -42,16 +43,17 @@ public void calculateFrameMetrics_validSparseIntArray_returnsCorrectFrameMetrics
4243
@Test
4344
public void
4445
calculateFrameMetrics_validSparseIntArrayWithoutFrozenFrames_returnsCorrectFrameMetrics() {
45-
// For a given non-null SparseIntArray, the results stored are the number of samples at each
46-
// millisecond value (rounded).
47-
// Slow frames are duration greater than 16ms and frozen frames are duration greater than 700ms.
46+
// Slow frames have duration greater than 16ms and frozen frames have duration greater than
47+
// 700ms. The key value pair means (duration, num_of_samples).
4848
SparseIntArray sparseIntArray = new SparseIntArray();
4949
sparseIntArray.append(5, 3);
5050
sparseIntArray.append(20, 2);
5151
SparseIntArray[] arr = new SparseIntArray[1];
5252
arr[FrameMetricsAggregator.TOTAL_INDEX] = sparseIntArray;
5353

5454
FrameMetricsCalculator.FrameMetrics metrics = FrameMetricsCalculator.calculateFrameMetrics(arr);
55+
56+
// we should expect 3+2=5 total frames, 2 slow frames, and 0 frozen frames.
5557
assertThat(metrics.getTotalFrames()).isEqualTo(5);
5658
assertThat(metrics.getSlowFrames()).isEqualTo(2);
5759
assertThat(metrics.getFrozenFrames()).isEqualTo(0);
@@ -60,16 +62,17 @@ public void calculateFrameMetrics_validSparseIntArray_returnsCorrectFrameMetrics
6062
@Test
6163
public void
6264
calculateFrameMetrics_validSparseIntArrayWithoutSlowFrames_returnsCorrectFrameMetrics() {
63-
// For a given non-null SparseIntArray, the results stored are the number of samples at each
64-
// millisecond value (rounded).
65-
// Slow frames are duration greater than 16ms and frozen frames are duration greater than 700ms.
65+
// Slow frames have duration greater than 16ms and frozen frames have duration greater than
66+
// 700ms. The key value pair means (duration, num_of_samples).
6667
SparseIntArray sparseIntArray = new SparseIntArray();
6768
sparseIntArray.append(5, 3);
6869
sparseIntArray.append(701, 2);
6970
SparseIntArray[] arr = new SparseIntArray[1];
7071
arr[FrameMetricsAggregator.TOTAL_INDEX] = sparseIntArray;
7172

7273
FrameMetricsCalculator.FrameMetrics metrics = FrameMetricsCalculator.calculateFrameMetrics(arr);
74+
75+
// we should expect 3+2=5 total frames, 0+2=2 slow frames, and 2 frozen frames.
7376
assertThat(metrics.getTotalFrames()).isEqualTo(5);
7477
assertThat(metrics.getSlowFrames()).isEqualTo(2);
7578
assertThat(metrics.getFrozenFrames()).isEqualTo(2);

0 commit comments

Comments
 (0)