profiler.tsx 14.8 KB
Newer Older
R
RotPublic 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
/**
 * 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<React.FunctionComponent<SelectProps<any>>>(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<T> = {
    value: T;
    label: string;
};
const Profiler: FunctionComponent = () => {
    const {t, i18n} = useTranslation(['profiler', 'common']);
    const [isCompared, setIsCompared] = useState(false);
    const [runs, setRuns] = useState<string>('');
    const [diffRuns1, setDiffRuns1] = useState<string>('');
    const [diffRuns2, setDiffRuns2] = useState<string>('');
    const [views, setViews] = useState<string>('');
    const [workers, setWorkers] = useState<string>('');
    const [diffWorker1, setDiffWorker1] = useState<string>('');
    const [diffWorker2, setDiffWorker2] = useState<string>('');
    const [spans, setSpans] = useState<string>('');
    const [units, setUnits] = useState<string>('us');
    const [diffSpan1, setDiffSpan1] = useState<string>('');
    const [diffSpan2, setDiffSpan2] = useState<string>('');
    const [runsList, setrunsList] = useState<SelectListItem<string>[]>();
    const [viewsList, setViewsList] = useState<SelectListItem<string>[]>();
    const [workersList, setWorkersList] = useState<SelectListItem<string>[]>();
    const [spansList, setSpansList] = useState<SelectListItem<string>[]>();
    const [unitsList, setUnitsList] = useState<SelectListItem<string>[]>();
    const [descriptions, setDescriptions] = useState<any>();
    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 (
    //             <DiffView
    //                 diffRuns1={diffRuns1}
    //                 diffWorkers1={diffWorker1}
    //                 diffSpans1={diffSpan1}
    //                 diffRuns2={diffRuns2}
    //                 diffWorkers2={diffWorker2}
    //                 diffSpans2={diffSpan2}
    //             />
    //         );
    //     } else {
    //         return <Empty></Empty>;
    //     }
    // }, [diffWorker2, diffSpan1, diffRuns2, diffWorker1, diffSpan2, diffRuns1]);
    // const [importanceDialogVisible, setImportanceDialogVisible] = useState(false);

    const aside = useMemo(
        () => (
            <Aside>
                <TitleContent>
                    <Titles>{t('performance-analysis')}</Titles>
                </TitleContent>
                {!isCompared ? (
                    <Selectlist>
                        <AsideSection>
                            <Field label={t('data-flow')}>
                                <FullWidthSelect list={runsList} value={runs} onChange={setRuns} />
                            </Field>
                        </AsideSection>
                        <AsideSection>
                            <Field label={t('view')}>
                                <FullWidthSelect list={viewsList} value={views} onChange={setViews} />
                            </Field>
                        </AsideSection>
                        <AsideSection>
                            <Field label={t('process')}>
                                <FullWidthSelect list={workersList} value={workers} onChange={setWorkers} />
                            </Field>
                        </AsideSection>
                        <AsideSection>
                            <Field label={t('process-span')}>
                                <FullWidthSelect list={spansList} value={spans} onChange={setSpans} />
                            </Field>
                        </AsideSection>
                        {views !== 'Trace' ? (
                            <AsideSection>
                                <Field label={t('time-unit')}>
                                    <FullWidthSelect list={unitsList} value={units} onChange={setUnits} />
                                </Field>
                            </AsideSection>
                        ) : null}
                    </Selectlist>
                ) : (
                    <CompareContent>
                        <div className="Groups">
                            <Grouptitle style={{border: 'none'}}>基线组</Grouptitle>
                            <div className="Selectlist">
                                <AsideSection>
                                    <Field label={'数据流'}>
                                        <FullWidthSelect list={runsList} value={diffRuns1} onChange={setDiffRuns1} />
                                    </Field>
                                </AsideSection>
                                <AsideSection>
                                    <Field label={'进程'}>
                                        <FullWidthSelect
                                            list={workersList}
                                            value={diffWorker1}
                                            onChange={setDiffWorker1}
                                        />
                                    </Field>
                                </AsideSection>
                                <AsideSection>
                                    <Field label={'进程跨度'}>
                                        <FullWidthSelect list={spansList} value={diffSpan1} onChange={setDiffSpan1} />
                                    </Field>
                                </AsideSection>
                            </div>
                        </div>
                        <div className="Groups">
                            <Grouptitle>基线组</Grouptitle>
                            <div className="Selectlist">
                                <AsideSection>
                                    <Field label={'数据流'}>
                                        <FullWidthSelect list={runsList} value={diffRuns2} onChange={setDiffRuns2} />
                                    </Field>
                                </AsideSection>
                                <AsideSection>
                                    <Field label={'进程'}>
                                        <FullWidthSelect
                                            list={workersList}
                                            value={diffWorker2}
                                            onChange={setDiffWorker2}
                                        />
                                    </Field>
                                </AsideSection>
                                <AsideSection>
                                    <Field label={'进程跨度'}>
                                        <FullWidthSelect list={spansList} value={diffSpan2} onChange={setDiffSpan2} />
                                    </Field>
                                </AsideSection>
                            </div>
                        </div>
                    </CompareContent>
                )}
            </Aside>
        ),
        [
            spansList,
            spans,
            workersList,
            workers,
            viewsList,
            views,
            runsList,
            runs,
            isCompared,
            diffWorker2,
            diffRuns2,
            diffWorker1,
            diffRuns1,
            diffSpan1,
            diffSpan2,
            units,
            unitsList,
            t
        ]
    );

    return (
        <>
            <Title>{t('common:hyper-parameter')}</Title>
            <Content aside={aside} isProfiler={true}>
                <HPWrapper>
                    <ViewWrapper>
                        {views === 'Overview' ? (
                            <OverView
                                runs={runs}
                                views={views}
                                workers={workers}
                                units={units}
                                spans={spans}
                                descriptions={descriptions}
                            />
                        ) : null}
                        {views === 'Operator' ? (
                            <OperatorView runs={runs} views={views} workers={workers} units={units} spans={spans} />
                        ) : null}
                        {views === 'Distributed' ? (
                            <Distributed
                                runs={runs}
                                views={views}
                                workers={workers}
                                units={units}
                                spans={spans}
                                descriptions={descriptions}
                            />
                        ) : null}
                        {views === 'GPU Kernel' ? (
                            <ComparedView runs={runs} views={views} workers={workers} units={units} spans={spans} />
                        ) : null}
                        {views === 'Memory' ? (
                            <MemoryView runs={runs} views={views} workers={workers} units={units} spans={spans} />
                        ) : null}
                        {views === 'Trace' ? (
                            <TracingView runs={runs} views={views} workers={workers} spans={spans} />
                        ) : null}
                    </ViewWrapper>
                </HPWrapper>
            </Content>
        </>
    );
};

export default Profiler;