* -------------------------------------------------------------------------
* This file is part of the MindStudio project.
* Copyright (c) 2025 Huawei Technologies Co.,Ltd.
*
* MindStudio is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
* -------------------------------------------------------------------------
*/
import { makeAutoObservable } from 'mobx';
import {
Communicator,
communicatorContainerData,
RankDyeingData,
} from '../components/communicatorContainer/ContainerUtils';
import type { ChartZoomData, ClickOperatorItem, IndicatorsItem, PerformanceDataItem } from '../utils/interface';
export type PerformanceDataMap = Map<number, PerformanceDataItem>;
export interface ClusterInfo {
name: string;
path: string;
dbPath?: string;
parsed: boolean;
durationParsed: boolean;
}
export class Session {
language: 'zhCN' | 'enUS' = 'enUS';
parseCompleted: boolean = false;
unitcount: number = 0;
renderId: number = 1;
isFullDb: boolean = false;
id = '';
selectedProjectName: string = '';
selectedClusterPath: string = '';
allRankIds: any[] = [];
communicatorData: communicatorContainerData = {
clusterPath: '',
partitionModes: [],
defaultPPSize: 0,
};
activeCommunicator: Communicator | undefined;
rankCount: number = 0;
arrangementRankCount: number = 0;
indicatorList: IndicatorsItem[] = [];
dynamicsIndicatorList: IndicatorsItem[] = [];
performanceData: PerformanceDataItem[] = [];
performanceDataMap: PerformanceDataMap = new Map();
rankDyeingData: RankDyeingData = {};
rankDbPathMap: Map<string, string> = new Map();
communicationDomains: string[] = [];
ppCommunicationDomains: string[] = [];
stepList: string[] = [];
baselineStepList: string[] = [];
isCompare: boolean = false;
targetOperator: ClickOperatorItem | undefined = undefined;
communicationChartZoomData?: ChartZoomData;
profilingExpertDataParsed: boolean | null = null;
private _clusterList: ClusterInfo[] = [];
constructor(conf?: Partial<Session>) {
makeAutoObservable(this);
window.closeWaiting = (): void => {
this.parseCompleted = true;
};
}
get dataTypeOptions(): IndicatorsItem[] {
return this.indicatorList.filter(item => item.renderHeatMap);
}
get performanceChartsIndicators(): IndicatorsItem[] {
return this.indicatorList.filter(item => item.renderChart);
}
get indicatorMap(): Map<string, IndicatorsItem> {
const map: Map<string, IndicatorsItem> = new Map();
this.indicatorList.forEach(item => {
map.set(item.key, item);
});
return map;
}
get dynamicsIndicatorMap(): Map<string, IndicatorsItem> {
const map: Map<string, IndicatorsItem> = new Map();
this.dynamicsIndicatorList.forEach(item => {
map.set(item.key, item);
});
return map;
}
get clusterCompleted(): boolean {
return this._clusterList.find(({ path }) => path === this.selectedClusterPath)?.parsed ?? false;
}
get durationFileCompleted(): boolean {
return this._clusterList.find(({ path }) => path === this.selectedClusterPath)?.durationParsed ?? false;
}
get clusterList(): ClusterInfo[] {
return this._clusterList;
}
set clusterList(value) {
this._clusterList = value;
}
setRankDyeingData(): void {
const data: Record<string, { min: number; max: number }> = {};
this.dataTypeOptions.forEach(dataType => {
data[dataType.key] = { min: Number.MAX_SAFE_INTEGER, max: 0 };
});
this.performanceData.forEach(item => {
this.dataTypeOptions.forEach(dataType => {
const key = dataType.key;
data[key].max = Math.max(data[key].max, item[key]);
data[key].min = Math.min(data[key].min, item[key]);
});
Object.keys(item.commCompare).forEach(key => {
if (!(key in data)) {
data[key] = { min: Number.MAX_SAFE_INTEGER, max: 0 };
}
data[key].max = Math.max(data[key].max, item.commCompare[key]);
data[key].min = Math.min(data[key].min, item.commCompare[key]);
});
});
this.rankDyeingData = data;
}
resetForProjectChange(): void {
this.selectedProjectName = '';
this.selectedClusterPath = '';
this._clusterList = [];
this.parseCompleted = false;
this.unitcount = 0;
this.communicatorData = { clusterPath: '', partitionModes: [], defaultPPSize: 0 };
this.resetForClusterChange();
}
resetForClusterChange(): void {
this.allRankIds = [];
this.activeCommunicator = undefined;
this.indicatorList = [];
this.performanceData = [];
this.performanceDataMap = new Map();
this.communicationDomains = [];
this.ppCommunicationDomains = [];
this.stepList = [];
this.rankDyeingData = {};
this.arrangementRankCount = 0;
this.targetOperator = undefined;
this.profilingExpertDataParsed = null;
}
}