@@ -15,7 +15,7 @@ import {Dispatch, SetStateAction, useEffect, useMemo, useRef, useState} from 're
1515
1616import { RpcError } from '@protobuf-ts/runtime-rpc' ;
1717
18- import { ProfileTypesResponse , QueryServiceClient } from '@parca/client' ;
18+ import { ProfileTypesRequest , ProfileTypesResponse , QueryServiceClient } from '@parca/client' ;
1919import {
2020 DateTimeRange ,
2121 IconButton ,
@@ -26,7 +26,7 @@ import {
2626import { CloseIcon } from '@parca/icons' ;
2727import { Query } from '@parca/parser' ;
2828import { TEST_IDS , testId } from '@parca/test-utils' ;
29- import { type NavigateFunction } from '@parca/utilities' ;
29+ import { millisToProtoTimestamp , type NavigateFunction } from '@parca/utilities' ;
3030
3131import { ProfileSelection } from '..' ;
3232import { useLabelNames } from '../MatchersInput/index' ;
@@ -36,6 +36,7 @@ import {useDefaultSumBy, useSumBySelection} from '../useSumBy';
3636import { MetricsGraphSection } from './MetricsGraphSection' ;
3737import { QueryControls } from './QueryControls' ;
3838import { useAutoQuerySelector } from './useAutoQuerySelector' ;
39+ import useGrpcQuery from '../useGrpcQuery' ;
3940
4041export interface QuerySelection {
4142 expression : string ;
@@ -104,24 +105,30 @@ export interface IProfileTypesResult {
104105 error ?: RpcError ;
105106}
106107
107- export const useProfileTypes = ( client : QueryServiceClient ) : IProfileTypesResult => {
108- const [ result , setResult ] = useState < ProfileTypesResponse | undefined > ( undefined ) ;
109- const [ error , setError ] = useState < RpcError | undefined > ( undefined ) ;
110- const [ loading , setLoading ] = useState ( true ) ;
108+ export const useProfileTypes = ( client :
109+ QueryServiceClient , start ?: number , end ?: number ) :
110+ IProfileTypesResult => {
111111 const metadata = useGrpcMetadata ( ) ;
112+ const metadataString = useMemo ( ( ) => JSON . stringify ( metadata ) , [ metadata ] ) ;
113+ const request : ProfileTypesRequest = { } ;
114+
115+ if ( start != null && end != null ) {
116+ request . start = millisToProtoTimestamp ( start ) ;
117+ request . end = millisToProtoTimestamp ( end ) ;
118+ }
119+
120+ const { isLoading, data, error } = useGrpcQuery ( {
121+ key : [ 'profileTypes' , metadataString , start , end ] ,
122+ queryFn : async ( abort ) => {
123+ const { response } = await client . profileTypes ( request , {
124+ meta : metadata ,
125+ abort,
126+ } ) ;
127+ return response ;
128+ } ,
129+ } ) ;
112130
113- useEffect ( ( ) => {
114- if ( ! loading ) {
115- return ;
116- }
117- const call = client . profileTypes ( { } , { meta : metadata } ) ;
118- call . response
119- . then ( response => setResult ( response ) )
120- . catch ( error => setError ( error ) )
121- . finally ( ( ) => setLoading ( false ) ) ;
122- } , [ client , metadata , loading ] ) ;
123-
124- return { loading, data : result , error} ;
131+ return { loading : isLoading , data, error : error as RpcError } ;
125132} ;
126133
127134const ProfileSelector = ( {
@@ -144,11 +151,6 @@ const ProfileSelector = ({
144151 utilizationLabels,
145152 onUtilizationSeriesSelect,
146153} : ProfileSelectorProps ) : JSX . Element => {
147- const {
148- loading : profileTypesLoading ,
149- data : profileTypesData ,
150- error,
151- } = useProfileTypes ( queryClient ) ;
152154 const { heightStyle} = useMetricsGraphDimensions ( comparing , utilizationMetrics != null ) ;
153155 const { viewComponent} = useParcaContext ( ) ;
154156 const [ queryBrowserMode , setQueryBrowserMode ] = useURLState ( 'query_browser_mode' ) ;
@@ -174,6 +176,12 @@ const ProfileSelector = ({
174176 const from = timeRangeSelection . getFromMs ( ) ;
175177 const to = timeRangeSelection . getToMs ( ) ;
176178
179+ const {
180+ loading : profileTypesLoading ,
181+ data : profileTypesData ,
182+ error,
183+ } = useProfileTypes ( queryClient , from , to ) ;
184+
177185 const { loading : labelNamesLoading , result} = useLabelNames (
178186 queryClient ,
179187 profileType . toString ( ) ,
0 commit comments