You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

debugger-mixin.vue 56 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677
  1. <script>
  2. import RequestService from '@/services/request-service';
  3. import {select, selectAll, zoom, dispatch} from 'd3';
  4. import 'd3-graphviz';
  5. const d3 = {select, selectAll, zoom, dispatch};
  6. export default {
  7. data() {
  8. return {
  9. conditionRulesMap: this.$t('debugger.tensorTuningRule'),
  10. };
  11. },
  12. methods: {
  13. showOrigin() {
  14. this.loadOriginalTree();
  15. this.queryWatchPoints();
  16. },
  17. /**
  18. * Initialize the condition
  19. */
  20. initCondition() {
  21. RequestService.queryConditions(this.trainId).then((res) => {
  22. if (res && res.data) {
  23. this.conditionCollections = res.data;
  24. }
  25. });
  26. },
  27. transCondition(str) {
  28. if (!str) {
  29. return '';
  30. }
  31. let temp;
  32. if (this.conditionRulesMap[str]) {
  33. temp = this.conditionRulesMap[str];
  34. } else if (str.endsWith('_lt')) {
  35. temp = str.replace(/_lt$/, ' <');
  36. } else if (str.endsWith('_gt')) {
  37. temp = str.replace(/_gt$/, ' >');
  38. } else if (str.endsWith('_ge')) {
  39. temp = str.replace(/_ge$/, ' >=');
  40. } else {
  41. temp = str;
  42. }
  43. if (temp.includes('max_min')) {
  44. temp = temp.replace('max_min', 'max-min');
  45. }
  46. return temp;
  47. },
  48. /**
  49. * Collaspe btn click function
  50. */
  51. collapseBtnClick() {
  52. this.leftShow = !this.leftShow;
  53. setTimeout(() => {
  54. this.resizeCallback();
  55. }, 500);
  56. },
  57. /**
  58. * Step input validation
  59. */
  60. stepChange() {
  61. if (this.step === '') {
  62. return;
  63. }
  64. const maxStep = 2147483648;
  65. this.step = this.step
  66. .toString()
  67. .replace(/[^\.\d]/g, '')
  68. .replace(/\./g, '');
  69. this.step = Number(this.step);
  70. if (this.step === 0) {
  71. this.step = 1;
  72. }
  73. if (this.step >= maxStep) {
  74. this.step = maxStep - 1;
  75. }
  76. },
  77. /**
  78. * Query current node info
  79. */
  80. getCurrentNodeInfo() {
  81. let name = this.currentNodeName;
  82. const params = {
  83. mode: 'node',
  84. params: {
  85. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  86. name,
  87. single_node: true,
  88. node_type: 'leaf',
  89. },
  90. };
  91. if (this.graphFiles.value === this.$t('debugger.all')) {
  92. name = `${this.metadata.graph_name}/${this.currentNodeName}`;
  93. params.params.name = name;
  94. } else {
  95. if (this.metadata.graph_name !== this.graphFiles.value) {
  96. this.graphFiles.value = this.metadata.graph_name;
  97. this.isCurrentGraph = false;
  98. }
  99. params.params.graph_name = this.graphFiles.value;
  100. }
  101. RequestService.retrieve(params).then(
  102. (res) => {
  103. if (res.data) {
  104. if (res.data.metadata) {
  105. this.dealMetadata(res.data.metadata);
  106. }
  107. if (res.data.graph) {
  108. const graph = res.data.graph;
  109. if (graph.nodes && !this.isCurrentGraph) {
  110. this.node.childNodes = [];
  111. this.origialTree = graph.nodes.map((val) => {
  112. return {
  113. label: val.name.split('/').pop(),
  114. leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
  115. ...val,
  116. showCheckbox: val.type !== this.unCheckedNodeType,
  117. };
  118. });
  119. this.resolve(this.origialTree);
  120. // watched 0:unchecked 1:indeterminate 2:checked
  121. this.node.childNodes.forEach((val) => {
  122. if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
  123. val.checked = true;
  124. }
  125. if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
  126. val.indeterminate = true;
  127. }
  128. });
  129. this.isCurrentGraph = true;
  130. this.firstFloorNodes = [];
  131. this.allGraphData = {};
  132. d3.select('#graph svg').remove();
  133. this.selectedNode.name = '';
  134. this.packageDataToObject('', true, JSON.parse(JSON.stringify(graph.nodes)));
  135. this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
  136. } else {
  137. this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
  138. }
  139. if (graph.children) {
  140. this.dealTreeData(graph.children, name);
  141. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  142. }
  143. }
  144. }
  145. },
  146. (err) => {
  147. this.showErrorMsg(err);
  148. },
  149. );
  150. },
  151. /**
  152. * Query next node info
  153. */
  154. getNextNodeInfo() {
  155. this.watchPointHits = [];
  156. const params = {
  157. mode: 'continue',
  158. level: 'node',
  159. name: '',
  160. graph_name: this.graphFiles.value,
  161. };
  162. if (this.graphFiles.value === this.$t('debugger.all')) {
  163. delete params.graph_name;
  164. }
  165. RequestService.control(params).then(
  166. (res) => {},
  167. (err) => {
  168. this.showErrorMsg(err);
  169. },
  170. );
  171. },
  172. /**
  173. * In Ascend environment,query node info.
  174. * @param {Boolean} ascend previous or next
  175. */
  176. getNodeByBfs(ascend) {
  177. const data = this.$refs.tree.getCurrentNode();
  178. let name = this.$refs.tree.getCurrentKey();
  179. if (
  180. (data && (data.type === 'name_scope' || data.type === 'aggregation_scope')) ||
  181. this.curLeafNodeName === null
  182. ) {
  183. name = this.curLeafNodeName;
  184. }
  185. const params = {
  186. ascend,
  187. name,
  188. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  189. graph_name: this.graphFiles.value,
  190. };
  191. if (this.graphFiles.value === this.$t('debugger.all')) {
  192. delete params.graph_name;
  193. }
  194. RequestService.retrieveNodeByBfs(params).then(
  195. (res) => {
  196. if (res.data && res.data.graph && res.data.name) {
  197. this.retrieveTensorHistory({name: res.data.name});
  198. const graph = res.data.graph;
  199. this.curLeafNodeName = res.data.name;
  200. this.nodeName = res.data.name;
  201. if (graph.children) {
  202. this.dealTreeData(graph.children, name);
  203. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  204. }
  205. this.querySingleNode(JSON.parse(JSON.stringify(graph)), res.data.name);
  206. } else if (ascend) {
  207. this.$message.success(this.$t('debugger.nextNodeTip'));
  208. } else {
  209. this.$message.success(this.$t('debugger.previousNodeTip'));
  210. }
  211. },
  212. (err) => {
  213. this.showErrorMsg(err);
  214. },
  215. );
  216. },
  217. /**
  218. * Terminate current training
  219. */
  220. terminate() {
  221. this.$confirm(this.$t('debugger.ternimateConfirm'), this.$t('public.notice'), {
  222. confirmButtonText: this.$t('public.sure'),
  223. cancelButtonText: this.$t('public.cancel'),
  224. type: 'warning',
  225. }).then(
  226. () => {
  227. this.control(2);
  228. },
  229. (err) => {
  230. this.showErrorMsg(err);
  231. },
  232. );
  233. },
  234. /**
  235. * Table row add className
  236. * @return { String }
  237. */
  238. tableRowClassName({row}) {
  239. if (row.is_hit) {
  240. return 'success-row';
  241. }
  242. return '';
  243. },
  244. /**
  245. * Table merged cells
  246. * @return { Object }
  247. */
  248. objectSpanMethod({row, column, rowIndex, columnIndex}) {
  249. let inputLength = 0;
  250. let outputLength = 0;
  251. if (this.tabs.activeName === 'tensor') {
  252. inputLength = this.inputLength;
  253. outputLength = this.outputLength;
  254. } else {
  255. inputLength = this.selectedNode.inputNum;
  256. outputLength = this.selectedNode.outputNum;
  257. }
  258. if (columnIndex === 0 && outputLength > 0) {
  259. if (rowIndex === 0) {
  260. return {
  261. rowspan: outputLength,
  262. colspan: 1,
  263. };
  264. } else if (rowIndex > 0 && rowIndex < outputLength) {
  265. return {
  266. rowspan: 0,
  267. colspan: 0,
  268. };
  269. } else if (rowIndex === outputLength) {
  270. return {
  271. rowspan: inputLength,
  272. colspan: 1,
  273. };
  274. } else {
  275. return {
  276. rowspan: 0,
  277. colspan: 0,
  278. };
  279. }
  280. }
  281. },
  282. /**
  283. * Table header merged cells
  284. * @return { Object }
  285. */
  286. discountHeaderStyle({row, column, rowIndex, columnIndex}) {
  287. if (rowIndex === 1) {
  288. return {display: 'none'};
  289. }
  290. },
  291. /**
  292. * Handle node click
  293. * @param { Object } data node data
  294. */
  295. handleNodeClick(data) {
  296. this.isIntoView = false;
  297. this.selectedNode.name = data.name;
  298. if (this.treeFlag) {
  299. this.querySingleNode({}, data.name, true);
  300. } else {
  301. if (this.graphFiles.value === this.$t('debugger.all')) {
  302. const graphName = data.name.split('/')[0];
  303. this.queryAllTreeData(data.name.replace(`${graphName}/`, ''), true, graphName);
  304. } else {
  305. this.queryAllTreeData(data.name, true, this.graphFiles.value);
  306. }
  307. }
  308. },
  309. /**
  310. * Query tensor value
  311. * @param { Object } data node info
  312. * @param { String } graphName Graph name
  313. */
  314. retrieveTensorHistory(data, graphName) {
  315. const params = {
  316. name: data.name,
  317. };
  318. if (this.graphFiles.value === this.$t('debugger.all')) {
  319. params.name = `${graphName}/${data.name}`;
  320. } else {
  321. params.graph_name = graphName;
  322. }
  323. RequestService.retrieveTensorHistory(params).then(
  324. (res) => {
  325. if (res.data && res.data.metadata) {
  326. this.dealMetadata(res.data.metadata);
  327. }
  328. if (data.name === this.nodeName) {
  329. if (res.data && res.data.tensor_history) {
  330. this.tableData = res.data.tensor_history;
  331. this.dealTableData(this.tableData);
  332. } else {
  333. this.tableData = [];
  334. }
  335. }
  336. },
  337. (err) => {
  338. this.showErrorMsg(err);
  339. },
  340. );
  341. },
  342. /**
  343. * Deal tensor history table data
  344. * @param {Array} arr tensor history data
  345. */
  346. dealTableData(arr) {
  347. const output = arr.filter((val) => val.type === 'output');
  348. const input = arr.filter((val) => val.type === 'input');
  349. this.outputLength = output.length;
  350. this.inputLength = input.length;
  351. arr.splice(0, arr.length, ...output.concat(input));
  352. arr.forEach((val) => {
  353. if (Array.isArray(val.shape)) {
  354. val.shape = `[${val.shape.toString()}]`;
  355. } else {
  356. if (val.shape !== undefined) {
  357. val.shape = val.shape + '';
  358. }
  359. }
  360. if (val.value === 'click to view') {
  361. } else {
  362. if (Array.isArray(val.value)) {
  363. val.value = `[${val.value.toString()}]`;
  364. } else {
  365. if (val.value !== undefined) {
  366. val.value = val.value + '';
  367. }
  368. }
  369. }
  370. if (val.dtype !== undefined) {
  371. val.dtype = val.dtype + '';
  372. }
  373. });
  374. },
  375. /**
  376. * Deal metadata
  377. * @param {Object} metadata metadata
  378. * @param {Boolean} isQuery wheather to query tree data
  379. */
  380. dealMetadata(metadata) {
  381. if (
  382. metadata.graph_name &&
  383. metadata.graph_name !== this.graphFiles.value &&
  384. this.graphFiles.value !== this.$t('debugger.all')
  385. ) {
  386. this.graphFiles.value = metadata.graph_name;
  387. this.isCurrentGraph = false;
  388. }
  389. this.metadata.pos = metadata.pos;
  390. this.enableRecheck = metadata.enable_recheck;
  391. if (metadata.state) {
  392. this.metadata.state = metadata.state;
  393. }
  394. if (metadata.debugger_version) {
  395. this.debuggerVersion = metadata.debugger_version;
  396. }
  397. if (metadata.node_name !== undefined && metadata.step !== undefined) {
  398. const nodeName = metadata.node_name;
  399. if ((nodeName !== this.currentNodeName && nodeName !== '') || this.metadata.step !== metadata.step) {
  400. this.nodeName = nodeName ? nodeName : this.nodeName;
  401. this.currentNodeName = nodeName ? nodeName : this.currentNodeName;
  402. this.metadata.step = metadata.step;
  403. this.metadata.graph_name = metadata.graph_name ? metadata.graph_name : this.metadata.graph_name;
  404. let graphName = this.graphFiles.value === this.$t('debugger.all') ? '' : this.graphFiles.value;
  405. if (this.graphFiles.value === this.$t('debugger.all') && this.selectedNode.name) {
  406. graphName = this.selectedNode.name.split('/')[0];
  407. }
  408. if (metadata.graph_name) {
  409. graphName = metadata.graph_name;
  410. }
  411. if (this.nodeName) {
  412. this.queryAllTreeData(this.nodeName, true, graphName);
  413. }
  414. }
  415. }
  416. if (metadata.step && metadata.step > this.metadata.step) {
  417. this.metadata.step = metadata.step;
  418. }
  419. if (metadata.graph_name && metadata.tensor_name && this.tensorCompareFlag) {
  420. const debTensor = this.$refs['deb-tensor'];
  421. if (debTensor) {
  422. debTensor.updateGraphData(metadata.graph_name, metadata.tensor_name);
  423. }
  424. }
  425. },
  426. /**
  427. * Long polling,update some info
  428. */
  429. pollData() {
  430. const params = {
  431. pos: this.metadata.pos,
  432. graph_name: this.graphFiles.value,
  433. };
  434. if (this.graphFiles.value === this.$t('debugger.all')) {
  435. delete params.graph_name;
  436. }
  437. RequestService.pollData(params).then(
  438. (res) => {
  439. if (res.data) {
  440. if (res.data.metadata) {
  441. this.dealMetadata(res.data.metadata);
  442. }
  443. let name = null;
  444. if (this.$refs.tree && this.$refs.tree.getCurrentKey()) {
  445. name = this.$refs.tree.getCurrentKey();
  446. }
  447. let graphName = this.graphFiles.value;
  448. if (
  449. res.data.receive_tensor &&
  450. res.data.metadata &&
  451. res.data.metadata.step >= this.metadata.step &&
  452. res.data.receive_tensor.node_name === name
  453. ) {
  454. if (this.graphFiles.value === this.$t('debugger.all')) {
  455. graphName = name.split('/')[0];
  456. name = name.replace(`${graphName}/`, '');
  457. }
  458. this.retrieveTensorHistory(
  459. {
  460. name,
  461. },
  462. graphName,
  463. );
  464. }
  465. if (res.data.watch_point_hits && res.data.watch_point_hits.length > 0) {
  466. this.radio1 = 'hit';
  467. this.dealWatchpointHits(res.data.watch_point_hits);
  468. }
  469. this.pollData();
  470. }
  471. },
  472. (err) => {
  473. if (!err || (err && err.message !== 'routeJump')) {
  474. this.initFail = true;
  475. this.dialogVisible = true;
  476. }
  477. },
  478. );
  479. },
  480. /**
  481. * Step,continue,pause,terminate opesssrate
  482. * @param {Number} type
  483. */
  484. control(type) {
  485. if (type !== 3) {
  486. this.watchPointHits = [];
  487. }
  488. const params = {};
  489. if (type === 0) {
  490. if (!this.step) {
  491. return;
  492. }
  493. params.mode = 'continue';
  494. params.steps = parseInt(this.step);
  495. } else if (type === 1) {
  496. params.mode = 'continue';
  497. params.steps = -1;
  498. } else if (type === 2) {
  499. params.mode = 'terminate';
  500. } else if (type === 3) {
  501. params.mode = 'pause';
  502. }
  503. RequestService.control(params).then(
  504. (res) => {
  505. if (res.data && res.data.metadata) {
  506. const h = this.$createElement;
  507. this.$message({
  508. message: h('p', null, [
  509. h('span', null, this.$t('debugger.backstageStatus')),
  510. h('i', {style: 'color: teal'}, res.data.metadata.state),
  511. ]),
  512. });
  513. this.metadata.state = res.data.metadata.state;
  514. }
  515. },
  516. (err) => {
  517. this.showErrorMsg(err);
  518. },
  519. );
  520. },
  521. /**
  522. * Show orginal tree
  523. */
  524. loadOriginalTree() {
  525. this.node.childNodes = [];
  526. this.curWatchPointId = null;
  527. this.defaultCheckedArr = [];
  528. this.resolve(JSON.parse(JSON.stringify(this.origialTree)));
  529. this.resetGraph();
  530. },
  531. recheckWatchpoint() {
  532. RequestService.recheckWatchPoints().then(
  533. (res) => {
  534. if (res && res.data && res.data.metadata) {
  535. this.enableRecheck = res.data.metadata.enable_recheck;
  536. }
  537. this.$message.success(this.$t('debugger.recheckSucess'));
  538. },
  539. (err) => {},
  540. );
  541. },
  542. /**
  543. * Add watchpoint
  544. */
  545. addWatchPoint() {
  546. this.createWatchPointArr.push({
  547. collection: {
  548. selectedId: this.conditionCollections[0].id,
  549. },
  550. condition: {
  551. selectedId: '',
  552. options: [],
  553. },
  554. param: {
  555. options: [],
  556. name: '',
  557. value: '',
  558. type: '',
  559. },
  560. compositeParams: {
  561. options: [],
  562. selections: [],
  563. },
  564. });
  565. this.collectionChange(this.createWatchPointArr[0]);
  566. this.createWPDialogVisible = true;
  567. this.curWatchPointId = null;
  568. },
  569. /**
  570. * Delete new watchpoint
  571. * @param {Object} item watchpoint data
  572. */
  573. deleteWatchpoint(item) {
  574. if (!this.watchPointArr.length) {
  575. return;
  576. }
  577. if ((item && item.id) || !item) {
  578. const msg = item ? this.$t('debugger.deleteWatchpointConfirm') : this.$t('debugger.clearWatchpointConfirm');
  579. this.$confirm(msg, this.$t('public.notice'), {
  580. confirmButtonText: this.$t('public.sure'),
  581. cancelButtonText: this.$t('public.cancel'),
  582. type: 'warning',
  583. }).then(() => {
  584. if (!item) {
  585. this.curWatchPointId = null;
  586. this.watchPointArr = [];
  587. }
  588. const params = {watch_point_id: item ? item.id : null};
  589. RequestService.deleteWatchpoint(params).then(
  590. (res) => {
  591. this.loadOriginalTree();
  592. this.queryWatchPoints();
  593. this.$message.success(this.$t('debugger.successDeleteWP'));
  594. if (res && res.data && res.data.metadata) {
  595. this.enableRecheck = res.data.metadata.enable_recheck;
  596. }
  597. this.curWatchPointId = null;
  598. },
  599. (err) => {
  600. this.showErrorMsg(err);
  601. },
  602. );
  603. });
  604. } else {
  605. this.curWatchPointId = null;
  606. }
  607. },
  608. validateParam(item) {
  609. this.$forceUpdate();
  610. const reg = /^(\-|\+)?\d+(\.\d+)?$/;
  611. this.validPram = reg.test(item.param.value);
  612. item.compositeParams.selections.forEach((i) => {
  613. this.validPram = this.validPram && reg.test(i.value);
  614. });
  615. },
  616. /**
  617. * Create new watchpoint
  618. * @param {Boolean} creatFlag Whether create watchpoint
  619. */
  620. createWatchPoint(creatFlag) {
  621. if (creatFlag) {
  622. const item = this.createWatchPointArr[0];
  623. const params = {
  624. condition: {
  625. id: item.condition.selectedId,
  626. params: [],
  627. },
  628. watch_nodes: [],
  629. graph_name: this.graphFiles.value,
  630. };
  631. if (this.graphFiles.value === this.$t('debugger.all')) {
  632. delete params.graph_name;
  633. }
  634. if (item.param.options.length) {
  635. params.condition.params = [
  636. {
  637. name: item.param.name,
  638. value: item.param.type === 'BOOL' ? Boolean(item.param.value) : Number(item.param.value),
  639. },
  640. ];
  641. }
  642. if (item.compositeParams.selections.length) {
  643. item.compositeParams.selections.forEach((i) => {
  644. params.condition.params.push({
  645. name: i.name,
  646. value: i.type === 'BOOL' ? Boolean(i.value) : Number(i.value),
  647. });
  648. });
  649. }
  650. RequestService.createWatchpoint(params).then(
  651. (res) => {
  652. this.createWatchPointArr = [];
  653. this.createWPDialogVisible = false;
  654. this.$message.success(this.$t('debugger.successCreateWP'));
  655. if (res && res.data && res.data.metadata) {
  656. this.enableRecheck = res.data.metadata.enable_recheck;
  657. }
  658. this.queryWatchPoints(true);
  659. },
  660. (err) => {
  661. this.loadOriginalTree();
  662. this.queryWatchPoints();
  663. this.showErrorMsg(err);
  664. },
  665. );
  666. } else {
  667. this.createWatchPointArr = [];
  668. this.createWPDialogVisible = false;
  669. }
  670. },
  671. /**
  672. * Collection change processing
  673. * @param {Object} item
  674. */
  675. collectionChange(item) {
  676. const collection = this.conditionCollections.filter((i) => {
  677. return i.id === item.collection.selectedId;
  678. })[0];
  679. if (collection.conditions && collection.conditions.length) {
  680. item.condition.options = collection.conditions;
  681. item.condition.selectedId = item.condition.options[0].id;
  682. this.conditionChange(item);
  683. } else {
  684. item.condition.options = [];
  685. item.condition.selectedId = '';
  686. item.param.options = [];
  687. item.param.name = '';
  688. item.param.type = '';
  689. item.param.value = '';
  690. this.validPram = false;
  691. }
  692. },
  693. /**
  694. * Condition change processing
  695. * @param {Object} item
  696. */
  697. conditionChange(item) {
  698. const condition = item.condition.options.filter((i) => {
  699. return i.id === item.condition.selectedId;
  700. })[0];
  701. if (condition.parameters && condition.parameters.length) {
  702. item.param.options = condition.parameters.filter((i) => {
  703. return i.param_type !== 'SUPPORT_PARAM';
  704. });
  705. item.compositeParams.options = condition.parameters.filter((i) => {
  706. return i.param_type === 'SUPPORT_PARAM';
  707. });
  708. item.param.name = item.param.options[0].name;
  709. this.paramChange(item);
  710. } else {
  711. item.param.options = [];
  712. item.param.name = '';
  713. item.param.type = '';
  714. item.param.value = '';
  715. this.validPram = true;
  716. item.compositeParams.options = [];
  717. item.compositeParams.selections = [];
  718. }
  719. },
  720. /**
  721. * Parameter change processing
  722. * @param {Object} item
  723. */
  724. paramChange(item) {
  725. const param = item.param.options.filter((i) => {
  726. return i.name === item.param.name;
  727. })[0];
  728. if (param.required_params && param.required_params.length) {
  729. item.compositeParams.selections = item.compositeParams.options.filter((i) => {
  730. return param.required_params.includes(i.name);
  731. });
  732. item.compositeParams.selections.forEach((i) => {
  733. i.value = i.type === 'BOOL' ? true : '';
  734. });
  735. } else {
  736. item.compositeParams.selections = [];
  737. }
  738. item.param.type = param.type;
  739. item.param.value = '';
  740. this.validPram = false;
  741. if (item.param.type === 'BOOL') {
  742. item.param.value = true;
  743. this.validPram = true;
  744. }
  745. },
  746. /** Draw the tree
  747. * @param {Object} obj Current checked obj
  748. */
  749. check(obj) {
  750. const node = this.$refs.tree.getNode(obj.name);
  751. const check = node.checked;
  752. if (this.treeFlag && node.childNodes) {
  753. this.dealCheckPro(node.childNodes, node.indeterminate || check);
  754. }
  755. if (this.curWatchPointId) {
  756. this.$refs.tree.getCheckedKeys().forEach((val) => {
  757. const node = this.$refs.tree.getNode(val);
  758. if (node.data.type === this.unCheckedNodeType) {
  759. node.checked = false;
  760. }
  761. });
  762. const checkedKeys = this.$refs.tree.getCheckedKeys();
  763. const watchNodes = [];
  764. if (this.defaultCheckedArr.length === checkedKeys.length) {
  765. return;
  766. } else if (this.defaultCheckedArr.length > checkedKeys.length) {
  767. watchNodes.push(obj.name);
  768. } else {
  769. checkedKeys.forEach((val) => {
  770. if (this.defaultCheckedArr.indexOf(val) === -1) {
  771. watchNodes.push(val);
  772. }
  773. });
  774. }
  775. const params = {
  776. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  777. watch_nodes: watchNodes,
  778. mode: node.indeterminate || check ? 1 : 0,
  779. graph_name: this.graphFiles.value,
  780. };
  781. if (this.graphFiles.value === this.$t('debugger.all')) {
  782. delete params.graph_name;
  783. }
  784. if (this.searchWord !== '') {
  785. params.name = this.searchWord;
  786. params.watch_nodes = [obj.name];
  787. params.mode = check ? 1 : 0;
  788. }
  789. RequestService.updateWatchpoint(params).then(
  790. (res) => {
  791. this.defaultCheckedArr = checkedKeys;
  792. this.enableRecheck = res.data.metadata.enable_recheck;
  793. this.$nextTick(() => {
  794. if (node.indeterminate) {
  795. node.checked = true;
  796. node.indeterminate = false;
  797. }
  798. if (check) {
  799. this.dealParentNode(node);
  800. }
  801. });
  802. },
  803. (err) => {
  804. this.showErrorMsg(err);
  805. },
  806. );
  807. }
  808. },
  809. dealParentNode(node) {
  810. const parent = node.parent;
  811. if (
  812. parent &&
  813. !parent.childNodes
  814. .filter((val) => val.data.type !== this.unCheckedNodeType)
  815. .find((val) => val.checked === false)
  816. ) {
  817. parent.checked = true;
  818. parent.indeterminate = false;
  819. this.dealParentNode(parent);
  820. }
  821. },
  822. searchCheck(obj) {
  823. const node = this.$refs.searchTree.getNode(obj.name);
  824. const check = node.checked;
  825. if (node.childNodes) {
  826. this.dealCheckPro(node.childNodes, node.indeterminate || check);
  827. }
  828. const params = {
  829. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  830. watch_nodes: [obj.name],
  831. mode: check ? 1 : 0,
  832. graph_name: this.graphFiles.value,
  833. search_pattern: {name: this.searchedWord, node_category: obj.type},
  834. };
  835. if (this.graphFiles.value === this.$t('debugger.all')) {
  836. delete params.graph_name;
  837. }
  838. RequestService.updateWatchpoint(params).then(
  839. (res) => {
  840. this.enableRecheck = res.data.metadata.enable_recheck;
  841. },
  842. (err) => {
  843. this.showErrorMsg(err);
  844. },
  845. );
  846. },
  847. /** Deal tree data
  848. * @param {Object} childNodes tree node
  849. * @param { Boolean } check check status
  850. */
  851. dealCheckPro(childNodes, check) {
  852. childNodes.forEach((val) => {
  853. val.indeterminate = false;
  854. if (val.data.type !== this.unCheckedNodeType) {
  855. val.checked = check;
  856. } else {
  857. val.checked = false;
  858. }
  859. if (val.childNodes) {
  860. this.dealCheckPro(val.childNodes, check);
  861. }
  862. });
  863. },
  864. /**
  865. * Collapse node
  866. * @param {Object} _
  867. * @param {Object} node node data
  868. */
  869. nodeCollapse(_, node) {
  870. node.loaded = false;
  871. node.childNodes = [];
  872. if (this.treeFlag) {
  873. this.dealDoubleClick(node.data.name);
  874. }
  875. },
  876. /**
  877. * Function to be executed after the search value changes
  878. */
  879. filterChange() {
  880. if (this.searchWord === '' && this.nodeTypes.value === 'all') {
  881. this.treeFlag = true;
  882. this.$nextTick(() => {
  883. setTimeout(() => {
  884. const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
  885. if (dom) {
  886. dom.scrollIntoView();
  887. }
  888. }, 800);
  889. });
  890. }
  891. },
  892. /**
  893. * Filter tree data by node name
  894. */
  895. filter() {
  896. this.treeFlag = this.searchWord === '' && this.nodeTypes.value === 'all';
  897. if (this.searchWord || this.nodeTypes.value !== 'all') {
  898. this.searchedWord = this.searchWord;
  899. const params = {
  900. name: this.searchWord,
  901. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  902. graph_name: this.graphFiles.value,
  903. };
  904. if (this.graphFiles.value === this.$t('debugger.all')) {
  905. delete params.graph_name;
  906. }
  907. if (this.nodeTypes.value !== 'all') {
  908. params.node_category = this.nodeTypes.value;
  909. }
  910. RequestService.search(params).then(
  911. (res) => {
  912. if (res.data && res.data.nodes) {
  913. this.searchTreeData = res.data.nodes;
  914. this.searchHalfCheckedArr = [];
  915. this.dealSearchResult(this.searchTreeData);
  916. this.defaultCheckedArr = this.searchCheckedArr;
  917. this.searchNode.childNodes = [];
  918. const data = res.data.nodes.map((val) => {
  919. return {
  920. label: val.name.split('/').pop(),
  921. ...val,
  922. };
  923. });
  924. const currentData = JSON.parse(JSON.stringify(data));
  925. currentData.forEach((val) => {
  926. val.nodes = [];
  927. });
  928. this.searchResolve(currentData);
  929. // watched 0:unchecked 1:indeterminate 2:checked
  930. this.searchNode.childNodes.forEach((val) => {
  931. if (val.data.watched === 1) {
  932. val.indeterminate = true;
  933. }
  934. if (val.data.watched === 2) {
  935. val.checked = true;
  936. }
  937. });
  938. data.forEach((val, key) => {
  939. if (val.nodes && val.nodes.length) {
  940. val.nodes.forEach((value) => {
  941. value.parentName = val.name;
  942. });
  943. this.dealSearchTreeData(val.nodes);
  944. }
  945. });
  946. this.searchHalfCheckedArr.forEach((val) => {
  947. this.$refs.searchTree.getNode(val).indeterminate = true;
  948. });
  949. }
  950. },
  951. (err) => {
  952. this.showErrorMsg(err);
  953. },
  954. );
  955. }
  956. },
  957. dealSearchTreeData(children) {
  958. children.forEach((val) => {
  959. const node = this.$refs.searchTree.getNode(val.parentName);
  960. val.label = val.name.split('/').pop();
  961. val.leaf = val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true;
  962. this.$refs.searchTree.append(val, node);
  963. node.expanded = true;
  964. // watched 0:unchecked 1:indeterminate 2:checked
  965. node.childNodes.forEach((value) => {
  966. if (value.data.watched === 1) {
  967. value.indeterminate = true;
  968. }
  969. if (value.data.watched === 2) {
  970. value.checked = true;
  971. }
  972. });
  973. if (val.nodes && val.nodes.length) {
  974. val.nodes.forEach((value) => {
  975. value.parentName = val.name;
  976. });
  977. this.dealSearchTreeData(val.nodes);
  978. }
  979. });
  980. },
  981. /**
  982. * Deal search data
  983. * @param {Array} arr search tree data
  984. */
  985. dealSearchResult(arr) {
  986. arr.forEach((val) => {
  987. if (val.nodes) {
  988. this.dealSearchResult(val.nodes);
  989. }
  990. // watched 0:unchecked 1:indeterminate 2:checked
  991. if (val.watched === 2 && val.type !== this.unCheckedNodeType) {
  992. this.searchCheckedArr.push(val.name);
  993. }
  994. val.label = val.name.split('/').pop();
  995. });
  996. },
  997. /**
  998. * Draw the tree
  999. * @param {Object} node tree root node
  1000. * @param {Function} resolve callback function ,return next node data
  1001. */
  1002. loadNode(node, resolve) {
  1003. if (node.level === 0) {
  1004. const loadingInstance = this.$loading(this.loadingOption);
  1005. node.childNodes = [];
  1006. if (!this.node && !this.resolve) {
  1007. this.node = node;
  1008. this.resolve = resolve;
  1009. }
  1010. const params = {
  1011. mode: 'all',
  1012. };
  1013. RequestService.retrieve(params).then(
  1014. (res) => {
  1015. loadingInstance.close();
  1016. this.initFail = false;
  1017. this.dialogVisible = false;
  1018. if (res.data) {
  1019. if (res.data.graph && res.data.graph.nodes) {
  1020. this.graphFiles.options = res.data.graph.graph_names || [];
  1021. if (this.graphFiles.options.length > 1) {
  1022. this.graphFiles.options.unshift(this.$t('debugger.all'));
  1023. }
  1024. this.graphFiles.value = this.graphFiles.options[0];
  1025. this.origialTree = res.data.graph.nodes.map((val) => {
  1026. return {
  1027. label: val.name.split('/').pop(),
  1028. leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
  1029. ...val,
  1030. };
  1031. });
  1032. resolve(this.origialTree);
  1033. this.dealGraphData(JSON.parse(JSON.stringify(res.data.graph.nodes)));
  1034. }
  1035. if (res.data.watch_points) {
  1036. this.watchPointArr = res.data.watch_points.map((val) => {
  1037. return {
  1038. id: val.id,
  1039. condition: val.watch_condition.id,
  1040. params: val.watch_condition.params || [],
  1041. selected: false,
  1042. };
  1043. });
  1044. }
  1045. if (res.data.metadata) {
  1046. if (res.data.metadata.debugger_version) {
  1047. this.debuggerVersion = res.data.metadata.debugger_version;
  1048. }
  1049. this.metadata = res.data.metadata;
  1050. this.enableRecheck = res.data.metadata.enable_recheck;
  1051. if (this.metadata.backend) {
  1052. this.version = this.metadata.backend;
  1053. }
  1054. this.trainId = encodeURIComponent(res.data.metadata.ip);
  1055. if (this.trainId) {
  1056. this.initCondition();
  1057. }
  1058. if (!res.data.metadata.recommendation_confirmed && this.trainId) {
  1059. this.recommendWatchPointDialog = true;
  1060. }
  1061. this.nodeName = this.metadata.node_name;
  1062. this.currentNodeName = this.nodeName;
  1063. if (this.pollInit) {
  1064. this.pollData();
  1065. this.pollInit = false;
  1066. }
  1067. }
  1068. }
  1069. },
  1070. (err) => {
  1071. this.initFail = true;
  1072. this.dialogVisible = true;
  1073. loadingInstance.close();
  1074. },
  1075. );
  1076. } else if (node.level >= 1) {
  1077. this.isIntoView = false;
  1078. const curHalfCheckedKeys = this.$refs.tree.getHalfCheckedKeys();
  1079. const params = {
  1080. mode: 'node',
  1081. params: {
  1082. node_type: node.data.type,
  1083. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1084. name: node.data.name,
  1085. graph_name: this.graphFiles.value,
  1086. },
  1087. };
  1088. if (this.graphFiles.value === this.$t('debugger.all')) {
  1089. delete params.params.graph_name;
  1090. }
  1091. RequestService.retrieve(params).then(
  1092. (res) => {
  1093. if (res.data && res.data.metadata) {
  1094. this.dealMetadata(res.data.metadata);
  1095. }
  1096. if (res.data && res.data.graph) {
  1097. const graph = res.data.graph;
  1098. this.curNodeData = graph.nodes.map((val) => {
  1099. return {
  1100. label: val.name.split('/').pop(),
  1101. leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
  1102. ...val,
  1103. showCheckbox: val.type !== this.unCheckedNodeType,
  1104. };
  1105. });
  1106. resolve(this.curNodeData);
  1107. // watched 0:unchecked 1:indeterminate 2:checked
  1108. this.defaultCheckedArr = this.defaultCheckedArr.concat(
  1109. this.curNodeData
  1110. .filter((val) => {
  1111. return val.watched === 2 && val.type !== this.unCheckedNodeType;
  1112. })
  1113. .map((val) => val.name),
  1114. );
  1115. const halfSelectArr = this.curNodeData
  1116. .filter((val) => {
  1117. return val.watched === 1 && val.type !== this.unCheckedNodeType;
  1118. })
  1119. .map((val) => val.name);
  1120. node.childNodes.forEach((val) => {
  1121. if (halfSelectArr.indexOf(val.data.name) !== -1) {
  1122. val.indeterminate = true;
  1123. node.indeterminate = true;
  1124. [...new Set(curHalfCheckedKeys.concat(this.$refs.tree.getHalfCheckedKeys()))].forEach((val) => {
  1125. this.$refs.tree.getNode(val).indeterminate = true;
  1126. });
  1127. }
  1128. });
  1129. this.selectedNode.name = node.data.name;
  1130. if (!this.allGraphData[node.data.name].isUnfold) {
  1131. this.dealGraphData(JSON.parse(JSON.stringify(graph.nodes)), node.data.name);
  1132. } else {
  1133. this.selectNode(true);
  1134. }
  1135. } else {
  1136. this.selectedNode.name = node.data.name;
  1137. this.selectNode(true);
  1138. resolve([]);
  1139. }
  1140. },
  1141. (err) => {
  1142. this.showErrorMsg(err);
  1143. resolve([]);
  1144. },
  1145. );
  1146. }
  1147. },
  1148. /**
  1149. * Draw the tree
  1150. * @param {Object} node tree root node
  1151. * @param {Function} resolve callback function ,return next node data
  1152. */
  1153. loadSearchNode(node, resolve) {
  1154. if (node.level === 0) {
  1155. node.childNodes = [];
  1156. if (!this.searchNode && !this.searchResolve) {
  1157. this.searchNode = node;
  1158. this.searchResolve = resolve;
  1159. }
  1160. } else if (node.level >= 1) {
  1161. const curHalfCheckedKeys = this.$refs.searchTree.getHalfCheckedKeys();
  1162. if (node.childNodes && node.childNodes.length) {
  1163. node.expanded = true;
  1164. node.loaded = true;
  1165. node.loading = false;
  1166. return;
  1167. }
  1168. const params = {
  1169. mode: 'node',
  1170. params: {
  1171. node_type: node.data.type,
  1172. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1173. name: node.data.name,
  1174. graph_name: this.graphFiles.value,
  1175. },
  1176. };
  1177. if (this.graphFiles.value === this.$t('debugger.all')) {
  1178. delete params.params.graph_name;
  1179. }
  1180. RequestService.retrieve(params).then((res) => {
  1181. if (res.data && res.data.metadata) {
  1182. this.dealMetadata(res.data.metadata);
  1183. }
  1184. if (res.data && res.data.graph && res.data.graph.nodes) {
  1185. this.curNodeData = res.data.graph.nodes.map((val) => {
  1186. return {
  1187. label: val.name.split('/').pop(),
  1188. leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
  1189. ...val,
  1190. showCheckbox: val.type !== this.unCheckedNodeType,
  1191. };
  1192. });
  1193. resolve(this.curNodeData);
  1194. // watched 0:unchecked 1:indeterminate 2:checked
  1195. const halfSelectArr = this.curNodeData
  1196. .filter((val) => {
  1197. return val.watched === 1;
  1198. })
  1199. .map((val) => val.name);
  1200. node.childNodes.forEach((val) => {
  1201. if (val.data.watched === 2) {
  1202. val.checked = true;
  1203. }
  1204. if (halfSelectArr.indexOf(val.data.name) !== -1) {
  1205. val.indeterminate = true;
  1206. node.indeterminate = true;
  1207. [...new Set(curHalfCheckedKeys.concat(this.$refs.searchTree.getHalfCheckedKeys()))].forEach((val) => {
  1208. this.$refs.searchTree.getNode(val).indeterminate = true;
  1209. });
  1210. }
  1211. });
  1212. }
  1213. });
  1214. }
  1215. },
  1216. initRecommendWatchPoints(value) {
  1217. this.recommendWatchPointDialog = false;
  1218. const params = {
  1219. trainId: this.trainId,
  1220. body: {
  1221. requestBody: {
  1222. set_recommended: value,
  1223. },
  1224. },
  1225. };
  1226. RequestService.setRecommendWatchPoints(params).then((res) => {
  1227. if (res && res.data) {
  1228. if (value) {
  1229. this.queryWatchPoints(false);
  1230. }
  1231. }
  1232. });
  1233. },
  1234. /**
  1235. * Show data of current selected watchpoint
  1236. * @param {Number} key watchpoint id
  1237. */
  1238. selectWatchPoint(key) {
  1239. this.curLeafNodeName = null;
  1240. this.curHalfCheckedKeys = [];
  1241. this.watchPointArr.forEach((val, index) => {
  1242. if (index === key) {
  1243. if (val.id) {
  1244. val.selected = true;
  1245. this.curWatchPointId = val.id;
  1246. if (this.searchWord === '') {
  1247. this.queryGraphByWatchpoint(val.id);
  1248. } else {
  1249. this.filter();
  1250. }
  1251. } else {
  1252. this.loadOriginalTree();
  1253. }
  1254. } else {
  1255. if (val.selected) {
  1256. val.selected = false;
  1257. }
  1258. }
  1259. });
  1260. },
  1261. /**
  1262. * Query WatchPoints
  1263. * @param {Boolean} focusLast
  1264. */
  1265. queryWatchPoints(focusLast) {
  1266. const params = {
  1267. mode: 'watchpoint',
  1268. graph_name: this.graphFiles.value,
  1269. };
  1270. if (this.graphFiles.value === this.$t('debugger.all')) {
  1271. delete params.graph_name;
  1272. }
  1273. RequestService.retrieve(params).then(
  1274. (res) => {
  1275. if (res.data.watch_points) {
  1276. this.watchPointArr = res.data.watch_points.map((val) => {
  1277. return {
  1278. id: val.id,
  1279. condition: val.watch_condition.id,
  1280. params: val.watch_condition.params || [],
  1281. selected: false,
  1282. };
  1283. });
  1284. if (focusLast) {
  1285. this.selectWatchPoint(this.watchPointArr.length - 1);
  1286. this.$nextTick(() => {
  1287. const newWatchPointDom = document.querySelector('#watch-point-list>li:last-child');
  1288. if (newWatchPointDom) {
  1289. newWatchPointDom.scrollIntoView();
  1290. }
  1291. });
  1292. }
  1293. }
  1294. },
  1295. (err) => {
  1296. this.showErrorMsg(err);
  1297. },
  1298. );
  1299. },
  1300. /**
  1301. * Tree linkage with graph Expand of current node
  1302. * @param {Obejct} nodes Data of children of current node
  1303. * @param {Obejct} name The name of the current node
  1304. */
  1305. nodeExpandLinkage(nodes, name) {
  1306. const curNodeData = nodes.map((val) => {
  1307. return {
  1308. label: val.name.split('/').pop(),
  1309. ...val,
  1310. showCheckbox: val.type !== this.unCheckedNodeType,
  1311. };
  1312. });
  1313. const node = this.$refs.tree.getNode(name);
  1314. curNodeData.forEach((val) => {
  1315. this.$refs.tree.append(val, name);
  1316. });
  1317. // watched 0:unchecked 1:indeterminate 2:checked
  1318. node.childNodes.forEach((val) => {
  1319. if (
  1320. node.checked &&
  1321. !node.childNodes.find((val) => val.data.watched !== 2) &&
  1322. val.data.type !== this.unCheckedNodeType
  1323. ) {
  1324. val.checked = true;
  1325. }
  1326. if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
  1327. val.checked = true;
  1328. }
  1329. if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
  1330. val.indeterminate = true;
  1331. }
  1332. if (val.data.type !== 'name_scope' && val.data.type !== 'aggregation_scope') {
  1333. val.isLeaf = true;
  1334. }
  1335. });
  1336. node.expanded = true;
  1337. node.loading = false;
  1338. this.$refs.tree.setCurrentKey(name);
  1339. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  1340. this.$nextTick(() => {
  1341. if (
  1342. node.indeterminate &&
  1343. !node.childNodes
  1344. .filter((val) => val.data.type !== this.unCheckedNodeType)
  1345. .find((val) => val.checked === false)
  1346. ) {
  1347. node.indeterminate = false;
  1348. node.checked = true;
  1349. this.dealParentNode(node);
  1350. }
  1351. setTimeout(() => {
  1352. const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
  1353. if (dom) {
  1354. dom.scrollIntoView();
  1355. }
  1356. }, 800);
  1357. });
  1358. },
  1359. /**
  1360. * Query WatchpointHits
  1361. */
  1362. getWatchpointHits() {
  1363. if (this.radio1 === 'hit') {
  1364. const params = {
  1365. mode: 'watchpoint_hit',
  1366. graph_name: this.graphFiles.value,
  1367. };
  1368. if (this.graphFiles.value === this.$t('debugger.all')) {
  1369. delete params.graph_name;
  1370. }
  1371. RequestService.retrieve(params).then(
  1372. (res) => {
  1373. if (res.data.metadata) {
  1374. this.dealMetadata(res.data.metadata);
  1375. }
  1376. if (res.data && res.data.watch_point_hits) {
  1377. this.hitsOutdated = res.data.outdated;
  1378. this.dealWatchpointHits(res.data.watch_point_hits);
  1379. }
  1380. },
  1381. (err) => {
  1382. this.showErrorMsg(err);
  1383. },
  1384. );
  1385. } else {
  1386. this.$nextTick(() => {
  1387. setTimeout(() => {
  1388. const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
  1389. if (dom) {
  1390. dom.scrollIntoView();
  1391. }
  1392. }, 200);
  1393. });
  1394. }
  1395. },
  1396. dealWatchpointHits(data) {
  1397. this.watchPointHits = [];
  1398. const tipsMapping = {1: 'NAN', 2: 'INF', 3: 'NAN, INF'};
  1399. if (data && data.length) {
  1400. data.forEach((hit) => {
  1401. const obj = {
  1402. name: hit.node_name,
  1403. lists: [],
  1404. selected: false,
  1405. id: hit.node_name,
  1406. graph_name: hit.graph_name,
  1407. };
  1408. if (hit.tensors && hit.tensors.length) {
  1409. hit.tensors.forEach((i) => {
  1410. const tensorName = `slot: ${i.slot}, `;
  1411. if (i.watch_points && i.watch_points.length) {
  1412. i.watch_points.forEach((j, key) => {
  1413. let item = `${tensorName} Watch Point Id: ${j.id}, `;
  1414. if (j.watch_condition) {
  1415. item += ` ${this.transCondition(j.watch_condition.id)}`;
  1416. const param = (j.watch_condition.params || [])
  1417. .map((k) =>
  1418. !k.actual_value
  1419. ? `${this.transCondition(k.name)}: ${this.$t('debugger.setValue')}:${k.value}`
  1420. : `${this.transCondition(k.name)}: ${this.$t('debugger.setValue')}:${k.value}${this.$t(
  1421. 'debugger.actualValue',
  1422. )}:${k.actual_value}`,
  1423. )
  1424. .join(', ');
  1425. if (param) {
  1426. item += ` (${param})`;
  1427. }
  1428. }
  1429. obj.lists.push({
  1430. name: item,
  1431. id: `${key}${hit.node_name}`,
  1432. tip: j.watch_condition.error_code
  1433. ? this.$t('debugger.checkTips', {msg: tipsMapping[j.watch_condition.error_code]})
  1434. : '',
  1435. });
  1436. });
  1437. }
  1438. });
  1439. }
  1440. this.watchPointHits.push(obj);
  1441. });
  1442. this.focusWatchpointHit();
  1443. }
  1444. },
  1445. focusWatchpointHit() {
  1446. if (this.selectedNode.name) {
  1447. let selectedNodeName = this.selectedNode.name;
  1448. if (this.graphFiles.value === this.$t('debugger.all')) {
  1449. selectedNodeName = selectedNodeName.replace(`${selectedNodeName.split('/')[0]}/`, '');
  1450. }
  1451. this.expandKeys = [];
  1452. this.watchPointHits.forEach((val) => {
  1453. if (val.name === selectedNodeName) {
  1454. val.selected = true;
  1455. this.expandKeys.push(val.id);
  1456. } else {
  1457. val.selected = false;
  1458. }
  1459. });
  1460. this.$nextTick(() => {
  1461. setTimeout(() => {
  1462. const dom = document.querySelector('.hit-item.selected');
  1463. if (dom) {
  1464. dom.scrollIntoView();
  1465. }
  1466. }, 200);
  1467. });
  1468. }
  1469. },
  1470. /**
  1471. * Update tensor value
  1472. * @param {number} key The index of the node of the watchPointHits currently clicked
  1473. */
  1474. updateTensorValue(key) {
  1475. const currentHit = this.watchPointHits[key];
  1476. const name = currentHit.name;
  1477. const temName = this.nodeName;
  1478. this.nodeName = name;
  1479. this.isHitIntoView = false;
  1480. const params = {
  1481. mode: 'watchpoint_hit',
  1482. params: {
  1483. name,
  1484. single_node: true,
  1485. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1486. graph_name: currentHit.graph_name,
  1487. },
  1488. };
  1489. if (this.graphFiles.value === this.$t('debugger.all')) {
  1490. delete params.params.graph_name;
  1491. params.params.name = `${currentHit.graph_name}/${name}`;
  1492. }
  1493. this.watchPointHits.forEach((val, index) => {
  1494. if (key === index) {
  1495. val.selected = true;
  1496. } else {
  1497. val.selected = false;
  1498. }
  1499. });
  1500. this.watchPointHits = JSON.parse(JSON.stringify(this.watchPointHits));
  1501. RequestService.retrieve(params).then(
  1502. (res) => {
  1503. if (res.data.metadata) {
  1504. this.dealMetadata(res.data.metadata);
  1505. }
  1506. this.retrieveTensorHistory({name: this.nodeName}, currentHit.graph_name);
  1507. if (res.data && res.data.graph) {
  1508. const graph = res.data.graph;
  1509. if (
  1510. this.graphFiles.value !== currentHit.graph_name &&
  1511. this.graphFiles.value !== this.$t('debugger.all')
  1512. ) {
  1513. this.graphFiles.value = currentHit.graph_name;
  1514. this.resetAllData(graph, params.params.name);
  1515. } else {
  1516. this.querySingleNode(JSON.parse(JSON.stringify(graph)), params.params.name, true);
  1517. }
  1518. if (graph.children) {
  1519. this.dealTreeData(graph.children, name);
  1520. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  1521. }
  1522. }
  1523. },
  1524. (err) => {
  1525. this.showErrorMsg(err);
  1526. this.nodeName = temName;
  1527. },
  1528. );
  1529. },
  1530. /**
  1531. * Query the graph data
  1532. * @param {String} nodeName The name of the node that needs to be query
  1533. * @param {Boolean} isQueryTensor The name of the node that needs to be query
  1534. * @param {String} graphName Graph file name
  1535. */
  1536. queryAllTreeData(nodeName, isQueryTensor, graphName) {
  1537. let name = nodeName ? nodeName.split(':')[0] : '';
  1538. const params = {
  1539. mode: 'node',
  1540. params: {
  1541. name,
  1542. single_node: true,
  1543. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1544. },
  1545. };
  1546. if (this.graphFiles.value === this.$t('debugger.all') && graphName && name) {
  1547. name = `${graphName}/${name}`;
  1548. params.params.name = name;
  1549. } else {
  1550. params.params.graph_name = graphName;
  1551. }
  1552. RequestService.retrieve(params).then(
  1553. (res) => {
  1554. if (res.data && res.data.metadata) {
  1555. this.dealMetadata(res.data.metadata);
  1556. }
  1557. if (res.data && res.data.graph) {
  1558. const graph = res.data.graph;
  1559. if (graph.nodes && !this.isCurrentGraph) {
  1560. this.resetAllData(graph, name);
  1561. this.isCurrentGraph = true;
  1562. } else {
  1563. this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
  1564. }
  1565. if (graph.children) {
  1566. this.dealTreeData(graph.children, name);
  1567. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  1568. }
  1569. }
  1570. },
  1571. (err) => {
  1572. this.showErrorMsg(err);
  1573. },
  1574. );
  1575. },
  1576. /**
  1577. * Draw the tree
  1578. * @param {Object} children child node
  1579. * @param {String} name The name of the node that needs to be highlighted
  1580. */
  1581. dealTreeData(children, name) {
  1582. if (children.nodes) {
  1583. const data = children.nodes.map((val) => {
  1584. return {
  1585. label: val.name.split('/').pop(),
  1586. ...val,
  1587. showCheckbox: val.type !== this.unCheckedNodeType,
  1588. };
  1589. });
  1590. data.forEach((val) => {
  1591. const node = this.$refs.tree.getNode(children.scope_name);
  1592. if (node.childNodes) {
  1593. if (node.childNodes.map((value) => value.data.name).indexOf(val.name) === -1) {
  1594. this.$refs.tree.append(val, node);
  1595. }
  1596. } else {
  1597. this.$refs.tree.append(val, node);
  1598. }
  1599. });
  1600. const node = this.$refs.tree.getNode(children.scope_name);
  1601. // watched 0:unchecked 1:indeterminate 2:checked
  1602. node.childNodes.forEach((val) => {
  1603. if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
  1604. val.checked = true;
  1605. }
  1606. if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
  1607. val.indeterminate = true;
  1608. }
  1609. if (val.data.type !== 'name_scope' && val.data.type !== 'aggregation_scope') {
  1610. val.isLeaf = true;
  1611. }
  1612. });
  1613. node.expanded = true;
  1614. node.loading = false;
  1615. } else {
  1616. this.$refs.tree.setCurrentKey(name);
  1617. this.$nextTick(() => {
  1618. setTimeout(() => {
  1619. const dom = document.querySelector('.el-tree-node.is-current.is-focusable');
  1620. if (dom) {
  1621. dom.scrollIntoView();
  1622. }
  1623. }, 800);
  1624. });
  1625. }
  1626. if (children.children) {
  1627. this.dealTreeData(children.children, name);
  1628. }
  1629. },
  1630. resetAllData(graph, name) {
  1631. this.node.childNodes = [];
  1632. this.origialTree = graph.nodes.map((val) => {
  1633. return {
  1634. label: val.name.split('/').pop(),
  1635. leaf: val.type === 'name_scope' || val.type === 'aggregation_scope' ? false : true,
  1636. ...val,
  1637. showCheckbox: val.type !== this.unCheckedNodeType,
  1638. };
  1639. });
  1640. this.resolve(this.origialTree);
  1641. // watched 0:unchecked 1:indeterminate 2:checked
  1642. this.node.childNodes.forEach((val) => {
  1643. if (val.data.watched === 2 && val.data.type !== this.unCheckedNodeType) {
  1644. val.checked = true;
  1645. }
  1646. if (val.data.watched === 1 && val.data.type !== this.unCheckedNodeType) {
  1647. val.indeterminate = true;
  1648. }
  1649. });
  1650. this.firstFloorNodes = [];
  1651. this.allGraphData = {};
  1652. d3.select('#graph svg').remove();
  1653. this.packageDataToObject('', true, JSON.parse(JSON.stringify(graph.nodes)));
  1654. if (name) {
  1655. this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
  1656. } else {
  1657. this.resetGraph();
  1658. }
  1659. },
  1660. },
  1661. };
  1662. </script>