Skip to content

Commit 792c999

Browse files
refactor(results): Add refresh rate to results model
For consistency, refresh rate is added to the DeviceSpecs property of the TestCaseResult and AveragedTestCaseResult chore(test): update snapshots refactor: remove unneeded changes
1 parent c1d658a commit 792c999

File tree

15 files changed

+87
-149
lines changed

15 files changed

+87
-149
lines changed

packages/commands/measure/src/__tests__/__snapshots__/measure.test.tsx.snap

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,16 @@ Time taken to run the test.
1212
Can be helpful to measure Time To Interactive of your app, if the test is checking app start for instance.
1313
Average FPS
1414
60 FPS
15-
Frame Per Second. Your app should display
16-
60
17-
Frames Per Second to give an impression of fluidity. This number should be close to
18-
60
19-
, otherwise it will seem laggy.
15+
Frame Per Second. Your app should display 60 Frames Per Second to give an impression of fluidity. This number should be close to 60, otherwise it will seem laggy.
16+
2017
See
2118
2219
this video
2320
2421
for more details
2522
Average CPU usage
2623
83 %
27-
An app might run at 60FPS but might be using too much processing power, so it's important to check CPU usage.
24+
An app might run at high frame rates, such as 60 FPS or higher, but might be using too much processing power, so it's important to check CPU usage.
2825
Depending on the device, this value can go up to
2926
100% x number of cores
3027
. For instance, a Samsung A10s has 4 cores, so the max value would be 400%.
@@ -859,7 +856,7 @@ exports[`flashlight measure interactive it displays measures: Web app with measu
859856
<div
860857
class="text-neutral-400 text-sm"
861858
>
862-
An app might run at 60FPS but might be using too much processing power, so it's important to check CPU usage.
859+
An app might run at high frame rates, such as 60 FPS or higher, but might be using too much processing power, so it's important to check CPU usage.
863860
<br />
864861
Depending on the device, this value can go up to
865862
<code>
@@ -3816,19 +3813,16 @@ Time taken to run the test.
38163813
Can be helpful to measure Time To Interactive of your app, if the test is checking app start for instance.
38173814
Average FPS
38183815
-
3819-
Frame Per Second. Your app should display
3820-
60
3821-
Frames Per Second to give an impression of fluidity. This number should be close to
3822-
60
3823-
, otherwise it will seem laggy.
3816+
Frame Per Second. Your app should display 60 Frames Per Second to give an impression of fluidity. This number should be close to 60, otherwise it will seem laggy.
3817+
38243818
See
38253819
38263820
this video
38273821
38283822
for more details
38293823
Average CPU usage
38303824
-
3831-
An app might run at 60FPS but might be using too much processing power, so it's important to check CPU usage.
3825+
An app might run at high frame rates, such as 60 FPS or higher, but might be using too much processing power, so it's important to check CPU usage.
38323826
Depending on the device, this value can go up to
38333827
100% x number of cores
38343828
. For instance, a Samsung A10s has 4 cores, so the max value would be 400%.
@@ -4226,7 +4220,7 @@ exports[`flashlight measure interactive it displays measures: Web app with no me
42264220
<div
42274221
class="text-neutral-400 text-sm"
42284222
>
4229-
An app might run at 60FPS but might be using too much processing power, so it's important to check CPU usage.
4223+
An app might run at high frame rates, such as 60 FPS or higher, but might be using too much processing power, so it's important to check CPU usage.
42304224
<br />
42314225
Depending on the device, this value can go up to
42324226
<code>

packages/commands/measure/src/server/socket/socketState.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ export const addNewResultReducer = (state: SocketData, name: string): SocketData
5555
name,
5656
iterations: [],
5757
status: "SUCCESS",
58+
specs: {
59+
refreshRate: state.refreshRate,
60+
},
5861
},
5962
],
6063
});

packages/commands/measure/src/webapp/MeasureWebApp.tsx

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,8 @@ import { SocketState } from "./components/SocketState";
1616
setThemeAtRandom();
1717

1818
export const MeasureWebApp = () => {
19-
const {
20-
autodetect,
21-
bundleId,
22-
start,
23-
stop,
24-
results,
25-
isMeasuring,
26-
reset,
27-
setBundleId,
28-
refreshRate,
29-
} = useMeasures();
19+
const { autodetect, bundleId, start, stop, results, isMeasuring, reset, setBundleId } =
20+
useMeasures();
3021

3122
return (
3223
<div className="bg-light-charcoal h-full text-black">
@@ -46,7 +37,7 @@ export const MeasureWebApp = () => {
4637
</div>
4738
) : null}
4839
</AppBar>
49-
<IterationsReporterView deviceSpecs={{ refreshRate }} results={results} />
40+
<IterationsReporterView results={results} />
5041
</div>
5142
);
5243
};

packages/commands/report/src/App.tsx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React from "react";
2-
import { DeviceSpecs, TestCaseResult } from "@perf-profiler/types";
2+
import { TestCaseResult } from "@perf-profiler/types";
33
import {
44
IterationsReporterView,
55
PageBackground,
@@ -13,10 +13,6 @@ let testCaseResults: TestCaseResult[] =
1313
// Use very long string so that Parcel won't use it more than once, would be nice to find a better solution
1414
"THIS_IS_A_VERY_LONG_STRING_THAT_IS_UNLIKELY_TO_BE_FOUND_IN_A_TEST_CASE_RESULT";
1515

16-
const deviceSpecs: DeviceSpecs = {
17-
refreshRate: 60,
18-
};
19-
2016
// Uncomment with when locally testing
2117
// // Without videos
2218
// testCaseResults = [
@@ -65,7 +61,7 @@ export function App() {
6561
return (
6662
<>
6763
<PageBackground />
68-
<IterationsReporterView results={testCaseResults} deviceSpecs={deviceSpecs} />
64+
<IterationsReporterView results={testCaseResults} />
6965
</>
7066
);
7167
}

packages/commands/test/src/writeReport.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export const writeReport = (
1616
}: {
1717
filePath: string;
1818
title: string;
19-
overrideScore?: (result: AveragedTestCaseResult, refreshRate: number) => number;
19+
overrideScore?: (result: AveragedTestCaseResult) => number;
2020
}
2121
) => {
2222
const testCase: TestCaseResult = {
@@ -34,7 +34,7 @@ export const writeReport = (
3434
*/
3535
if (overrideScore) {
3636
const averagedResult: AveragedTestCaseResult = averageTestCaseResult(testCase);
37-
testCase.score = Math.max(0, Math.min(overrideScore(averagedResult, 60), 100));
37+
testCase.score = Math.max(0, Math.min(overrideScore(averagedResult), 100));
3838
}
3939

4040
fs.writeFileSync(filePath, JSON.stringify(testCase));

packages/core/reporter/src/reporting/Report.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { TestCaseResult, AveragedTestCaseResult, DeviceSpecs } from "@perf-profiler/types";
1+
import { TestCaseResult, AveragedTestCaseResult } from "@perf-profiler/types";
22
import { roundToDecimal } from "../utils/round";
33
import { averageTestCaseResult } from "./averageIterations";
44
import { getScore } from "./getScore";
@@ -29,13 +29,11 @@ export class Report {
2929
private result: TestCaseResult;
3030
private averagedResult: AveragedTestCaseResult;
3131
private averageMetrics: ReportMetrics;
32-
private deviceSpecs: DeviceSpecs;
3332

34-
constructor(result: TestCaseResult, deviceSpecs: DeviceSpecs) {
33+
constructor(result: TestCaseResult) {
3534
this.result = Report.filterSuccessfulIterations(result);
3635
this.averagedResult = averageTestCaseResult(this.result);
3736
this.averageMetrics = Report.getAverageMetrics(this.averagedResult);
38-
this.deviceSpecs = deviceSpecs;
3937
}
4038

4139
private static getAverageMetrics(averagedResult: AveragedTestCaseResult): ReportMetrics {
@@ -77,7 +75,7 @@ export class Report {
7775
}
7876

7977
public get score() {
80-
return this.averagedResult.score ?? getScore(this.averagedResult, this.deviceSpecs.refreshRate);
78+
return this.averagedResult.score ?? getScore(this.averagedResult);
8179
}
8280

8381
public getIterationCount() {
@@ -93,13 +91,10 @@ export class Report {
9391
}
9492

9593
public selectIteration(iterationIndex: number): Report {
96-
return new Report(
97-
{
98-
...this.result,
99-
iterations: [this.result.iterations[iterationIndex]],
100-
},
101-
this.deviceSpecs
102-
);
94+
return new Report({
95+
...this.result,
96+
iterations: [this.result.iterations[iterationIndex]],
97+
});
10398
}
10499

105100
public getAveragedResult() {
@@ -122,4 +117,8 @@ export class Report {
122117
threads: getThreadsStats(iterations),
123118
};
124119
}
120+
121+
public getRefreshRate() {
122+
return this.result.specs?.refreshRate ?? 60;
123+
}
125124
}

packages/core/reporter/src/reporting/getScore.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { canComputeHighCpuUsage } from "./highCpu";
1313
*/
1414
const calculateCpuScore = (x: number) => Math.min(Math.max(0, -0.31666666666667 * x + 116), 100);
1515

16-
export const getScore = (result: AveragedTestCaseResult, refreshRate: number) => {
16+
export const getScore = (result: AveragedTestCaseResult) => {
1717
const averageUIFPS = getAverageFPSUsage(result.average.measures);
1818
const averageCPUUsage = getAverageCpuUsage(result.average.measures);
1919
const totalTimeThreadlocked = Object.keys(result.averageHighCpuUsage).reduce(
@@ -26,7 +26,7 @@ export const getScore = (result: AveragedTestCaseResult, refreshRate: number) =>
2626
const scores = [cpuScore];
2727

2828
if (averageUIFPS !== undefined) {
29-
const fpsScore = (averageUIFPS * 100) / refreshRate;
29+
const fpsScore = (averageUIFPS * 100) / (result?.specs?.refreshRate ?? 60);
3030
scores.push(fpsScore);
3131
}
3232

packages/core/types/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export interface TestCaseResult {
3939
status: TestCaseResultStatus;
4040
iterations: TestCaseIterationResult[];
4141
type?: TestCaseResultType;
42+
specs?: DeviceSpecs;
4243
}
4344

4445
export interface AveragedTestCaseResult {
@@ -49,6 +50,7 @@ export interface AveragedTestCaseResult {
4950
average: TestCaseIterationResult;
5051
averageHighCpuUsage: { [processName: string]: number };
5152
type?: TestCaseResultType;
53+
specs?: DeviceSpecs;
5254
}
5355

5456
// Shouldn't really be here but @perf-profiler/types is imported by everyone and doesn't contain any logic

packages/core/web-reporter-ui/ReporterView.tsx

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useMemo } from "react";
2-
import { Measure, POLLING_INTERVAL, TestCaseResult, DeviceSpecs } from "@perf-profiler/types";
2+
import { Measure, POLLING_INTERVAL, TestCaseResult } from "@perf-profiler/types";
33
import { CPUReport } from "./src/sections/CPUReport";
44
import { ReportSummary } from "./src/sections/ReportSummary/ReportSummary.component";
55
import { RAMReport } from "./src/sections/RAMReport";
@@ -30,17 +30,12 @@ const theme = createTheme({
3030
const Report = ({
3131
results: rawResults,
3232
additionalMenuOptions,
33-
deviceSpecs,
3433
}: {
3534
results: TestCaseResult[];
3635
additionalMenuOptions?: MenuOption[];
37-
deviceSpecs: DeviceSpecs;
3836
}) => {
3937
const results = mapThreadNames(rawResults);
40-
const reports = useMemo(
41-
() => results.map((result) => new ReportModel(result, deviceSpecs)),
42-
[results, deviceSpecs]
43-
);
38+
const reports = useMemo(() => results.map((result) => new ReportModel(result)), [results]);
4439
const minIterationCount = Math.min(...reports.map((report) => report.getIterationCount()));
4540
const iterationSelector = useIterationSelector(minIterationCount);
4641

@@ -71,7 +66,7 @@ const Report = ({
7166
]}
7267
/>
7368
<Padding />
74-
<ReportSummary reports={selectedReports} deviceSpecs={deviceSpecs} />
69+
<ReportSummary reports={selectedReports} />
7570
<div className="h-16" />
7671

7772
{hasMeasures ? (
@@ -108,34 +103,21 @@ const Report = ({
108103
export const IterationsReporterView = ({
109104
results,
110105
additionalMenuOptions,
111-
deviceSpecs,
112106
}: {
113107
results: TestCaseResult[];
114108
additionalMenuOptions?: MenuOption[];
115-
deviceSpecs: DeviceSpecs;
116109
}) => {
117110
return results.length > 0 ? (
118111
<ThemeProvider theme={theme}>
119-
<Report
120-
deviceSpecs={deviceSpecs}
121-
results={results}
122-
additionalMenuOptions={additionalMenuOptions}
123-
/>
112+
<Report results={results} additionalMenuOptions={additionalMenuOptions} />
124113
</ThemeProvider>
125114
) : null;
126115
};
127116

128-
export const ReporterView = ({
129-
measures,
130-
deviceSpecs,
131-
}: {
132-
measures: Measure[];
133-
deviceSpecs: DeviceSpecs;
134-
}) => (
117+
export const ReporterView = ({ measures }: { measures: Measure[] }) => (
135118
<>
136119
{measures.length > 1 ? (
137120
<IterationsReporterView
138-
deviceSpecs={deviceSpecs}
139121
results={[
140122
{
141123
name: "Results",

packages/core/web-reporter-ui/__tests__/ReporterView.test.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,9 @@ describe("<ReporterView />", () => {
1010
require("../../../commands/report/src/example-reports/results1.json"),
1111
require("../../../commands/report/src/example-reports/results2.json"),
1212
];
13-
const deviceSpecs = {
14-
refreshRate: 60,
15-
};
1613

1714
const { asFragment, baseElement } = render(
18-
<IterationsReporterView deviceSpecs={deviceSpecs} results={testCaseResults} />
15+
<IterationsReporterView results={testCaseResults} />
1916
);
2017
expect(screen.getAllByLabelText("Score")[0].textContent).toEqual("69");
2118

@@ -50,12 +47,9 @@ describe("<ReporterView />", () => {
5047
require("../../../commands/report/src/example-reports/video/results_417dd25e-d901-4b1e-9d43-3b78305a48e2.json"),
5148
require("../../../commands/report/src/example-reports/video/results_c7d5d17d-42ed-4354-8b43-bb26e2d6feee.json"),
5249
];
53-
const deviceSpecs = {
54-
refreshRate: 60,
55-
};
5650

5751
const { asFragment, baseElement } = render(
58-
<IterationsReporterView deviceSpecs={deviceSpecs} results={testCaseResults} />
52+
<IterationsReporterView results={testCaseResults} />
5953
);
6054
expect(screen.getAllByLabelText("Score")[0].textContent).toEqual("51");
6155

0 commit comments

Comments
 (0)