File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed
src/features/StartupProgress/Firedancer Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -4,8 +4,9 @@ import type { ByteSizeResult } from "byte-size";
44import byteSize from "byte-size" ;
55import clsx from "clsx" ;
66import { Bars } from "./Bars" ;
7+ import { useValuePerSecond } from "./useValuePerSecond" ;
78
8- const MAX_THROUGHPUT = 300000000 ;
9+ const MAX_THROUGHPUT_BYTES_PER_S = 300_000_000 ;
910
1011interface SnapshotLoadingCardProps {
1112 title : string ;
@@ -17,8 +18,7 @@ export function SnapshotLoadingCard({
1718 completed,
1819 total,
1920} : SnapshotLoadingCardProps ) {
20- // TODO: calculate throughput
21- const throughput = 0 ;
21+ const throughput = useValuePerSecond ( completed ) ;
2222
2323 const throughputObj = throughput == null ? undefined : byteSize ( throughput ) ;
2424 const completedObj = completed == null ? undefined : byteSize ( completed ) ;
@@ -58,7 +58,7 @@ export function SnapshotLoadingCard({
5858 ) }
5959 </ Flex >
6060
61- < Bars value = { throughput ?? 0 } max = { MAX_THROUGHPUT } />
61+ < Bars value = { throughput ?? 0 } max = { MAX_THROUGHPUT_BYTES_PER_S } />
6262 </ Flex >
6363 </ Card >
6464 ) ;
Original file line number Diff line number Diff line change 1+ import { useEffect , useMemo , useState } from "react" ;
2+
3+ export function useValuePerSecond ( cumulativeValue ?: number | null ) {
4+ const [ values , setValues ] = useState < [ number , number ] [ ] > ( [ ] ) ;
5+
6+ useEffect ( ( ) => {
7+ if ( cumulativeValue == null ) return ;
8+
9+ const now = performance . now ( ) ;
10+ setValues ( ( prev ) => {
11+ const newValues = [ ...prev , [ cumulativeValue , now ] ] satisfies [
12+ number ,
13+ number ,
14+ ] [ ] ;
15+ while ( newValues [ 0 ] && newValues [ 0 ] [ 1 ] <= now - 500 ) {
16+ newValues . shift ( ) ;
17+ }
18+ return newValues ;
19+ } ) ;
20+ } , [ cumulativeValue ] ) ;
21+
22+ return useMemo ( ( ) => {
23+ if ( values . length <= 1 ) return ;
24+
25+ return (
26+ ( 1_000 * ( values [ values . length - 1 ] [ 0 ] - values [ 0 ] [ 0 ] ) ) /
27+ ( values [ values . length - 1 ] [ 1 ] - values [ 0 ] [ 1 ] )
28+ ) ;
29+ } , [ values ] ) ;
30+ }
You can’t perform that action at this time.
0 commit comments