/* eslint-disable react-hooks/exhaustive-deps */ /** * Copyright 2020 Baidu Inc. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import Aside from '~/components/Aside'; import type {SelectProps} from '~/components/Select'; import React, {FunctionComponent, useEffect, useMemo, useState} from 'react'; import {asideWidth, rem} from '~/utils/style'; import Content from '~/components/Content'; import OverView from '~/components/ProfilerPage/overview/overview'; import OperatorView from '~/components/ProfilerPage/OperatorView/OperatorView'; // import DiffView from '~/components/ProfilerPage/DiffView'; import MemoryView from '~/components/ProfilerPage/MemoryView/MemoryView'; import TracingView from '~/components/ProfilerPage/TracingView'; import Distributed from '~/components/ProfilerPage/Distributed/Distributed'; import ComparedView from '~/components/ProfilerPage/ComparedView/ComparedView'; import Select from '~/components/Select'; import {fetcher} from '~/utils/fetch'; import Field from '~/components/Field'; import Title from '~/components/Title'; import styled from 'styled-components'; import {useTranslation} from 'react-i18next'; // const ImportanceButton = styled(Button)` // width: 100%; // `; // const HParamsImportanceDialog = styled(ImportanceDialog)` // position: fixed; // right: calc(${asideWidth} + ${rem(20)}); // bottom: ${rem(20)}; // `; // NOTICE: remove it!!! asideWidth; const TitleContent = styled.div` padding: ${rem(20)}; border-bottom: 1px solid #dddddd; `; const FullWidthSelect = styled>>(Select)` width: 100%; `; const Titles = styled.div` font-family: PingFangSC-Regular; font-size: ${rem(14)}; color: #000000; letter-spacing: 0; line-height: ${rem(14)}; font-weight: 400; // margin-bottom: ${rem(20)}; `; const Selectlist = styled.div` width: 100%; border-radius: 4px; padding: ${rem(20)}; `; const AsideSection = styled.div` margin-bottom: ${rem(20)}; `; const CompareContent = styled.div` padding: ${rem(0)} ${rem(20)}; padding-bottom: 0px; .Groups { .Selectlist { width: 100%; border-radius: ${rem(4)}; padding-bottom: ${rem(20)}; } } `; const Grouptitle = styled.div` border-top: 1px solid #dddddd; padding-top: ${rem(20)}; margin-bottom: ${rem(20)}; font-family: PingFangSC-Regular; font-size: ${rem(14)}; color: #999999; -webkit-letter-spacing: 0; -moz-letter-spacing: 0; -ms-letter-spacing: 0; letter-spacing: 0; line-height: ${rem(14)}; font-weight: 400; `; const HPWrapper = styled.div` width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: stretch; align-items: stretch; `; const ViewWrapper = styled.div` width: 100%; flex-grow: 1; position: relative; `; type SelectListItem = { value: T; label: string; }; const isCompared = false; const Profiler: FunctionComponent = () => { const {t, i18n} = useTranslation(['profiler', 'common']); const [runs, setRuns] = useState(''); const [diffRuns1, setDiffRuns1] = useState(''); const [diffRuns2, setDiffRuns2] = useState(''); const [views, setViews] = useState(''); const [workers, setWorkers] = useState(''); const [diffWorker1, setDiffWorker1] = useState(''); const [diffWorker2, setDiffWorker2] = useState(''); const [spans, setSpans] = useState(''); const [units, setUnits] = useState('us'); const [diffSpan1, setDiffSpan1] = useState(''); const [diffSpan2, setDiffSpan2] = useState(''); const [runsList, setrunsList] = useState[]>(); const [viewsList, setViewsList] = useState[]>(); const [workersList, setWorkersList] = useState[]>(); const [spansList, setSpansList] = useState[]>(); const [unitsList, setUnitsList] = useState[]>(); const [descriptions, setDescriptions] = useState(); useEffect(() => { if (i18n.language) { // 训练步数耗时 fetcher('/profiler/descriptions' + `?lang=${i18n.language}`).then((res: unknown) => { const Data = res; setDescriptions(Data); }); } }, [i18n.language]); useEffect(() => { fetcher('/profiler/runs').then((res: unknown) => { const runsData = res as string[]; const runsList = runsData.map(item => { return {label: item, value: item}; }); setrunsList(runsList); setRuns(runsData[0]); }); fetcher('/profiler/timeunits').then((res: unknown) => { const runsData = res as string[]; const runsList = runsData.map(item => { return {label: item, value: item}; }); setUnitsList(runsList); }); }, []); useEffect(() => { fetcher('/profiler/timeunits').then((res: unknown) => { const runsData = res as string[]; const runsList = runsData.map(item => { return {label: item, value: item}; }); setUnitsList(runsList); }); }, []); useEffect(() => { if (runs) { fetcher('/profiler/views' + `?run=${runs}`).then((res: unknown) => { const viewData = res as string[]; const viewList = viewData.map(item => { return {label: item, value: item}; }); setViewsList(viewList); setViews(viewData[0]); }); } }, [runs]); useEffect(() => { if (runs && views) { fetcher('/profiler/workers' + `?run=${runs}` + `&view=${views}`).then((res: unknown) => { const workerData = res as string[]; const workerList = workerData.map(item => { return {label: item, value: item}; }); setWorkersList(workerList); setWorkers(workerData[0]); }); } }, [runs, views]); useEffect(() => { if (runs && workers) { fetcher('/profiler/spans' + `?run=${runs}` + `&worker=${workers}`).then((res: unknown) => { const spanData = res as string[]; const spanList = spanData.map(item => { return {label: item, value: item}; }); setSpansList(spanList); setSpans(spanData[0]); }); } }, [runs, workers]); // const diffView = useMemo(() => { // if (diffWorker2 && diffSpan1 && diffRuns1 && diffWorker1 && diffSpan2 && diffRuns1) { // return ( // // ); // } else { // return ; // } // }, [diffWorker2, diffSpan1, diffRuns2, diffWorker1, diffSpan2, diffRuns1]); // const [importanceDialogVisible, setImportanceDialogVisible] = useState(false); const aside = useMemo( () => ( ), [ spansList, spans, workersList, workers, viewsList, views, runsList, runs, isCompared, diffWorker2, diffRuns2, diffWorker1, diffRuns1, diffSpan1, diffSpan2, units, unitsList, t ] ); return ( <> {t('common:hyper-parameter')} {views === 'Overview' ? ( ) : null} {views === 'Operator' ? ( ) : null} {views === 'Distributed' ? ( ) : null} {views === 'GPU Kernel' ? ( ) : null} {views === 'Memory' ? ( ) : null} {views === 'Trace' ? ( ) : null} ); }; export default Profiler;