-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#59 move profiler top function build to use-profiler
- Loading branch information
Showing
5 changed files
with
109 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
import type { ServerEvent, NormalizedEvent } from '~/src/shared/types'; | ||
import type { Profiler } from "../../types"; | ||
import {useProfilerRequests} from "~/src/shared/lib/io/use-profiler-requests"; | ||
import type {ServerEvent, NormalizedEvent, EventId} from '~/src/shared/types'; | ||
import type {Profiler, ProfilerTopFunctions} from "../../types"; | ||
import { normalizeProfilerEvent } from "./normalize-profile-event"; | ||
|
||
type TUseProfiler = () => { | ||
normalizeProfilerEvent: (event: ServerEvent<Profiler>) => NormalizedEvent<Profiler> | ||
getTopFunctions: (id: EventId, params?: Record<string, string>) => Promise<ProfilerTopFunctions> | ||
} | ||
|
||
export const useProfiler: TUseProfiler = () => ({ | ||
normalizeProfilerEvent | ||
}) | ||
export const useProfiler: TUseProfiler = () => { | ||
const { getTopFunctions } = useProfilerRequests(); | ||
|
||
return { | ||
normalizeProfilerEvent, | ||
getTopFunctions, | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import type {ProfilerTopFunctions} from "~/src/entities/profiler/types"; | ||
import {useProfileStore} from "../../stores"; | ||
import type { EventId } from "../../types"; | ||
import { REST_API_URL } from "./constants"; | ||
|
||
type TUseProfilerRequests = () => { | ||
getTopFunctions: (id: EventId, params?: Record<string, string>) => Promise<ProfilerTopFunctions> | ||
} | ||
|
||
enum ProfilerPartType { | ||
FlameChart = 'flame_chart', | ||
CallGraph = 'call_graph', | ||
TopFunctions = 'top' | ||
} | ||
// TODO: add 403 response handling | ||
|
||
export const useProfilerRequests: TUseProfilerRequests = () => { | ||
const { token } = storeToRefs(useProfileStore()) | ||
|
||
const headers = {"X-Auth-Token": token.value } | ||
|
||
const getProfilerPartsRestUrl = ({ | ||
id, | ||
params, | ||
type, | ||
}: { | ||
id: EventId, | ||
params?: Record<string, string>, | ||
type: ProfilerPartType | ||
}): string => { | ||
const url = `${REST_API_URL}/api/profiler/${id}/${type}` | ||
|
||
const searchParams = new URLSearchParams(params).toString() | ||
|
||
return searchParams ? `${url}?${searchParams}` : url | ||
} | ||
|
||
const getTopFunctions = (id: EventId, params?: Record<string, string>) => fetch(getProfilerPartsRestUrl({ id, params, type: ProfilerPartType.TopFunctions }), { headers }) | ||
.then((response) => response.json()) | ||
.then((response) => { | ||
if (response) { | ||
return response | ||
} | ||
|
||
if (response?.code === 403) { | ||
console.error('Forbidden') | ||
return {}; | ||
} | ||
|
||
console.error('Fetch Error') | ||
|
||
return {}; | ||
}) | ||
|
||
return { | ||
getTopFunctions, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters