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 73 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228
  1. <!--
  2. Copyright 2020-2021 Huawei Technologies Co., Ltd.All Rights Reserved.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. -->
  13. <script>
  14. import RequestService from '@/services/request-service';
  15. import {select, selectAll, zoom, dispatch} from 'd3';
  16. import 'd3-graphviz';
  17. const d3 = {select, selectAll, zoom, dispatch};
  18. export default {
  19. data() {
  20. return {
  21. conditionRulesMap: this.$t('debugger.tensorTuningRule'),
  22. };
  23. },
  24. methods: {
  25. editStep() {
  26. this.isShowInp = true;
  27. this.newStep = this.metadata.step;
  28. },
  29. newStepChange(val) {
  30. if (val === '') {
  31. return;
  32. }
  33. val = val.replace(/[^0-9]+/g, '');
  34. if (Number(val) <= this.metadata.total_step_num) {
  35. this.newStep = Number(val);
  36. } else {
  37. this.newStep = this.metadata.total_step_num;
  38. }
  39. },
  40. saveStepValue() {
  41. this.isShowInp = false;
  42. if (this.newStep === '' || this.newStep === this.metadata.step) {
  43. return;
  44. }
  45. this.metadata.step = this.newStep;
  46. const params = {
  47. mode: 'reset',
  48. level: 'step',
  49. steps: this.metadata.step,
  50. graph_name: this.graphFiles.value,
  51. rank_id: this.logicCard.value,
  52. };
  53. if (this.graphFiles.value === this.$t('debugger.all')) {
  54. delete params.graph_name;
  55. }
  56. RequestService.control(params, this.sessionId).then(
  57. (res) => {
  58. this.queryTensorHistory();
  59. if (this.radio1 === 'hit') {
  60. this.searchWatchpointHits(true);
  61. }
  62. },
  63. (err) => {
  64. this.showErrorMsg(err);
  65. },
  66. );
  67. },
  68. getSession() {
  69. const params = {
  70. dump_dir: null,
  71. session_type: 'ONLINE',
  72. };
  73. RequestService.getSession(params).then((res) => {
  74. if (res) {
  75. this.sessionId = res.data;
  76. this.retrieveAll();
  77. }
  78. });
  79. },
  80. deleteSession() {
  81. RequestService.deleteSession(this.sessionId).then((res) => {
  82. this.$router.push({
  83. path: '/summary-manage',
  84. });
  85. });
  86. },
  87. handleCurrentChange(page) {
  88. this.pagination.currentPage = page;
  89. this.searchWatchpointHits(false);
  90. },
  91. showOrigin() {
  92. this.loadOriginalTree();
  93. this.queryWatchPoints();
  94. },
  95. /**
  96. * Initialize the condition
  97. */
  98. initCondition() {
  99. if (
  100. this.metadata.state === this.state.running ||
  101. this.metadata.state === this.state.sending
  102. ) {
  103. return;
  104. }
  105. RequestService.queryConditions(this.sessionId).then((res) => {
  106. if (res && res.data) {
  107. this.conditionCollections = res.data;
  108. this.addWatchPoint();
  109. }
  110. });
  111. },
  112. transCondition(str) {
  113. if (!str) {
  114. return '';
  115. }
  116. let temp;
  117. if (this.conditionRulesMap[str]) {
  118. temp = this.conditionRulesMap[str];
  119. } else if (str.endsWith('_lt')) {
  120. temp = str.replace(/_lt$/, ' <');
  121. } else if (str.endsWith('_gt')) {
  122. temp = str.replace(/_gt$/, ' >');
  123. } else if (str.endsWith('_ge')) {
  124. temp = str.replace(/_ge$/, ' >=');
  125. } else {
  126. temp = str;
  127. }
  128. if (temp.includes('max_min')) {
  129. temp = temp.replace('max_min', 'max-min');
  130. }
  131. return temp;
  132. },
  133. /**
  134. * Collaspe btn click function
  135. */
  136. collapseBtnClick() {
  137. this.leftShow = !this.leftShow;
  138. this.initSvgSize();
  139. },
  140. /**
  141. * Step input validation
  142. */
  143. stepChange() {
  144. if (this.step === '') {
  145. return;
  146. }
  147. const maxStep = this.metadata.total_step_num;
  148. this.step = this.step
  149. .toString()
  150. .replace(/[^\.\d]/g, '')
  151. .replace(/\./g, '');
  152. this.step = Number(this.step);
  153. if (this.step === 0) {
  154. this.step = 1;
  155. }
  156. if (this.step >= maxStep) {
  157. this.step = maxStep;
  158. }
  159. },
  160. /**
  161. * Query current node info
  162. */
  163. getCurrentNodeInfo() {
  164. this.loadingInstance = this.$loading(this.loadingOption);
  165. let name = this.currentNodeName;
  166. const params = {
  167. mode: 'node',
  168. params: {
  169. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  170. name,
  171. single_node: true,
  172. node_type: 'leaf',
  173. },
  174. };
  175. if (this.graphFiles.value === this.$t('debugger.all')) {
  176. name = `${this.metadata.graph_name}/${this.currentNodeName}`;
  177. params.params.name = name;
  178. } else {
  179. if (this.metadata.graph_name !== this.graphFiles.value) {
  180. this.graphFiles.value = this.metadata.graph_name;
  181. this.isCurrentGraph = false;
  182. }
  183. params.params.graph_name = this.graphFiles.value;
  184. }
  185. RequestService.retrieve(params, this.sessionId).then(
  186. (res) => {
  187. if (res.data) {
  188. if (res.data.metadata) {
  189. this.dealMetadata(res.data.metadata);
  190. }
  191. if (res.data.graph) {
  192. const graph = res.data.graph;
  193. if (graph.nodes && !this.isCurrentGraph) {
  194. this.node.childNodes = [];
  195. this.origialTree = graph.nodes.map((val) => {
  196. return {
  197. label: val.name.split('/').pop(),
  198. leaf:
  199. val.type === 'name_scope' ||
  200. val.type === 'aggregation_scope'
  201. ? false
  202. : true,
  203. ...val,
  204. showCheckbox: val.watched !== -1,
  205. };
  206. });
  207. this.resolve(this.origialTree);
  208. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  209. this.node.childNodes.forEach((val) => {
  210. if (val.data.watched === this.checkboxStatus.checked) {
  211. val.checked = true;
  212. }
  213. if (val.data.watched === this.checkboxStatus.indeterminate) {
  214. val.indeterminate = true;
  215. }
  216. });
  217. this.isCurrentGraph = true;
  218. this.firstFloorNodes = [];
  219. this.allGraphData = {};
  220. d3.select('#graph svg').remove();
  221. this.selectedNode.name = '';
  222. this.packageDataToObject(
  223. '',
  224. true,
  225. JSON.parse(JSON.stringify(graph.nodes)),
  226. );
  227. this.querySingleNode(
  228. JSON.parse(JSON.stringify(graph)),
  229. name,
  230. true,
  231. );
  232. } else {
  233. this.querySingleNode(
  234. JSON.parse(JSON.stringify(graph)),
  235. name,
  236. true,
  237. );
  238. }
  239. if (graph.children) {
  240. this.dealTreeData(graph.children, name);
  241. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  242. }
  243. }
  244. }
  245. this.loadingInstance.close();
  246. },
  247. (err) => {
  248. this.showErrorMsg(err);
  249. this.loadingInstance.close();
  250. },
  251. );
  252. },
  253. /**
  254. * Query next node info
  255. */
  256. getNextNodeInfo() {
  257. this.loadingInstance = this.$loading(this.loadingOption);
  258. this.pagination.currentPage = 1;
  259. this.watchPointHits = [];
  260. this.pagination.total = 0;
  261. const params = {
  262. mode: 'continue',
  263. level: 'node',
  264. name: '',
  265. graph_name: this.graphFiles.value,
  266. rank_id: this.logicCard.value,
  267. };
  268. if (this.graphFiles.value === this.$t('debugger.all')) {
  269. delete params.graph_name;
  270. }
  271. RequestService.control(params, this.sessionId).then(
  272. (res) => {},
  273. (err) => {
  274. this.showErrorMsg(err);
  275. },
  276. );
  277. },
  278. /**
  279. * In Ascend environment,query node info.
  280. * @param {Boolean} ascend previous or next
  281. */
  282. getNodeByBfs(ascend) {
  283. const data = this.$refs.tree.getCurrentNode();
  284. let name = this.$refs.tree.getCurrentKey();
  285. if (
  286. (data &&
  287. (data.type === 'name_scope' || data.type === 'aggregation_scope')) ||
  288. this.curLeafNodeName === null
  289. ) {
  290. name = this.curLeafNodeName;
  291. }
  292. const params = {
  293. ascend,
  294. name,
  295. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  296. graph_name: this.graphFiles.value,
  297. };
  298. if (this.graphFiles.value === this.$t('debugger.all')) {
  299. delete params.graph_name;
  300. }
  301. RequestService.retrieveNodeByBfs(params).then(
  302. (res) => {
  303. if (res.data && res.data.graph && res.data.name) {
  304. this.retrieveTensorHistory({name: res.data.name});
  305. const graph = res.data.graph;
  306. this.curLeafNodeName = res.data.name;
  307. this.nodeName = res.data.name;
  308. if (graph.children) {
  309. this.dealTreeData(graph.children, name);
  310. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  311. }
  312. this.querySingleNode(
  313. JSON.parse(JSON.stringify(graph)),
  314. res.data.name,
  315. );
  316. } else if (ascend) {
  317. this.$message.success(this.$t('debugger.nextNodeTip'));
  318. } else {
  319. this.$message.success(this.$t('debugger.previousNodeTip'));
  320. }
  321. },
  322. (err) => {
  323. this.showErrorMsg(err);
  324. },
  325. );
  326. },
  327. /**
  328. * Terminate current training
  329. */
  330. terminate() {
  331. this.$confirm(
  332. this.$t('debugger.ternimateConfirm'),
  333. this.$t('public.notice'),
  334. {
  335. confirmButtonText: this.$t('public.sure'),
  336. cancelButtonText: this.$t('public.cancel'),
  337. type: 'warning',
  338. },
  339. ).then(
  340. () => {
  341. if (this.trainId) {
  342. this.deleteSession();
  343. } else {
  344. this.control(2);
  345. }
  346. },
  347. (err) => {
  348. this.showErrorMsg(err);
  349. },
  350. );
  351. },
  352. /**
  353. * Table row add className
  354. * @return { String }
  355. */
  356. tableRowClassName({row}) {
  357. if (row.is_hit) {
  358. return 'success-row';
  359. }
  360. return '';
  361. },
  362. /**
  363. * Table merged cells
  364. * @return { Object }
  365. */
  366. objectSpanMethod({row, column, rowIndex, columnIndex}) {
  367. let inputLength = 0;
  368. let outputLength = 0;
  369. if (this.tabs.activeName === 'tensor') {
  370. inputLength = this.inputLength;
  371. outputLength = this.outputLength;
  372. } else {
  373. inputLength = this.selectedNode.inputNum;
  374. outputLength = this.selectedNode.outputNum;
  375. }
  376. if (columnIndex === 0 && outputLength > 0) {
  377. if (rowIndex === 0) {
  378. return {
  379. rowspan: outputLength,
  380. colspan: 1,
  381. };
  382. } else if (rowIndex > 0 && rowIndex < outputLength) {
  383. return {
  384. rowspan: 0,
  385. colspan: 0,
  386. };
  387. } else if (rowIndex === outputLength) {
  388. return {
  389. rowspan: inputLength,
  390. colspan: 1,
  391. };
  392. } else {
  393. return {
  394. rowspan: 0,
  395. colspan: 0,
  396. };
  397. }
  398. }
  399. },
  400. /**
  401. * Table header merged cells
  402. * @return { Object }
  403. */
  404. discountHeaderStyle({row, column, rowIndex, columnIndex}) {
  405. if (rowIndex === 1) {
  406. return {display: 'none'};
  407. }
  408. },
  409. /**
  410. * Handle node click
  411. * @param { Object } data node data
  412. */
  413. handleNodeClick(data) {
  414. this.isIntoView = false;
  415. this.selectedNode.name = data.name;
  416. if (this.treeFlag) {
  417. this.querySingleNode({}, data.name, true);
  418. } else {
  419. if (this.graphFiles.value === this.$t('debugger.all')) {
  420. if (data.name.includes('/')) {
  421. const graphName = data.name.split('/')[0];
  422. this.queryAllTreeData(
  423. data.name.replace(`${graphName}/`, ''),
  424. true,
  425. graphName,
  426. true,
  427. );
  428. } else {
  429. this.queryAllTreeData(data.name, true, data.name, true);
  430. }
  431. } else {
  432. this.queryAllTreeData(data.name, true, this.graphFiles.value, true);
  433. }
  434. }
  435. },
  436. /**
  437. * Query tensor value
  438. * @param { Object } data node info
  439. * @param { String } graphName Graph name
  440. */
  441. retrieveTensorHistory(data, graphName) {
  442. const params = {
  443. name: data.name,
  444. rank_id: this.logicCard.value,
  445. };
  446. if (this.graphFiles.value === this.$t('debugger.all')) {
  447. params.name = `${graphName}/${data.name}`;
  448. } else {
  449. params.graph_name = graphName;
  450. }
  451. RequestService.retrieveTensorHistory(params, this.sessionId).then(
  452. (res) => {
  453. if (res.data && res.data.metadata) {
  454. this.dealMetadata(res.data.metadata);
  455. }
  456. if (data.name === this.nodeName) {
  457. if (res.data && res.data.tensor_history) {
  458. this.tableData = res.data.tensor_history;
  459. this.dealTableData(this.tableData);
  460. } else {
  461. this.tableData = [];
  462. }
  463. }
  464. },
  465. (err) => {
  466. this.showErrorMsg(err);
  467. },
  468. );
  469. },
  470. /**
  471. * Deal tensor history table data
  472. * @param {Array} arr tensor history data
  473. */
  474. dealTableData(arr) {
  475. const output = arr.filter((val) => val.type === 'output');
  476. const input = arr.filter((val) => val.type === 'input');
  477. this.outputLength = output.length;
  478. this.inputLength = input.length;
  479. arr.splice(0, arr.length, ...output.concat(input));
  480. arr.forEach((val) => {
  481. if (Array.isArray(val.shape)) {
  482. val.shape = `[${val.shape.toString()}]`;
  483. } else {
  484. if (val.shape !== undefined) {
  485. val.shape = val.shape + '';
  486. }
  487. }
  488. if (val.value === 'click to view') {
  489. } else {
  490. if (Array.isArray(val.value)) {
  491. val.value = `[${val.value.toString()}]`;
  492. } else {
  493. if (val.value !== undefined) {
  494. val.value = val.value + '';
  495. }
  496. }
  497. }
  498. if (val.dtype !== undefined) {
  499. val.dtype = val.dtype + '';
  500. }
  501. });
  502. },
  503. /**
  504. * Deal metadata
  505. * @param {Object} metadata metadata
  506. * @param {Boolean} isQuery whether to query tree data
  507. */
  508. dealMetadata(metadata) {
  509. if (
  510. metadata.graph_name &&
  511. metadata.graph_name !== this.graphFiles.value &&
  512. this.graphFiles.value !== this.$t('debugger.all')
  513. ) {
  514. this.graphFiles.value = metadata.graph_name;
  515. this.isCurrentGraph = false;
  516. }
  517. this.metadata.pos = metadata.pos;
  518. if (metadata.enable_recheck !== undefined) {
  519. this.enableRecheck = metadata.enable_recheck;
  520. }
  521. const temState = this.metadata.state;
  522. if (metadata.state) {
  523. this.metadata.state = metadata.state;
  524. }
  525. if (metadata.debugger_version) {
  526. this.debuggerVersion = metadata.debugger_version;
  527. }
  528. if (metadata.node_name !== undefined && metadata.step !== undefined) {
  529. const nodeName = metadata.node_name;
  530. if (
  531. (nodeName !== this.currentNodeName && nodeName !== '') ||
  532. this.metadata.step !== metadata.step ||
  533. (this.metadata.state === this.state.waiting &&
  534. (temState === this.state.sending ||
  535. temState === this.state.running))
  536. ) {
  537. if (nodeName) {
  538. if (this.metadata.state !== this.state.running) {
  539. this.nodeName = nodeName;
  540. }
  541. this.currentNodeName = nodeName;
  542. }
  543. this.metadata.step = metadata.step;
  544. let graphName =
  545. this.graphFiles.value === this.$t('debugger.all')
  546. ? ''
  547. : this.graphFiles.value;
  548. if (
  549. this.graphFiles.value === this.$t('debugger.all') &&
  550. this.selectedNode.name
  551. ) {
  552. graphName = this.selectedNode.name.split('/')[0];
  553. }
  554. if (metadata.graph_name) {
  555. this.metadata.graph_name = metadata.graph_name;
  556. graphName = metadata.graph_name;
  557. }
  558. if (nodeName && this.metadata.state !== this.state.running) {
  559. if (this.selectedNode.name) {
  560. if (nodeName === this.selectedNode.name) {
  561. this.queryTensorHistory();
  562. } else {
  563. this.queryAllTreeData(nodeName, true, graphName);
  564. }
  565. } else {
  566. this.queryAllTreeData(nodeName, true, graphName);
  567. }
  568. } else {
  569. if (this.selectedNode.name) {
  570. this.queryTensorHistory();
  571. }
  572. }
  573. } else {
  574. this.loadingInstance.close();
  575. }
  576. }
  577. if (metadata.step && metadata.step > this.metadata.step) {
  578. this.metadata.step = metadata.step;
  579. }
  580. },
  581. /**
  582. * Update tensor history by current selected node
  583. */
  584. queryTensorHistory() {
  585. if (this.selectedNode.name) {
  586. const path = this.selectedNode.name.split('^');
  587. const type = this.allGraphData[path[0].replace('_unfold', '')].type;
  588. const ignoreType = ['name_scope', 'aggregation_scope'];
  589. if (
  590. !this.selectedNode.name.includes('more...') &&
  591. !ignoreType.includes(type)
  592. ) {
  593. const name = path[0].replace('_unfold', '');
  594. if (this.graphFiles.value === this.$t('debugger.all')) {
  595. this.retrieveTensorHistory(
  596. {name: name.replace(`${name.split('/')[0]}/`, '')},
  597. name.split('/')[0],
  598. );
  599. } else {
  600. this.retrieveTensorHistory(
  601. {
  602. name,
  603. },
  604. this.graphFiles.value,
  605. );
  606. }
  607. }
  608. }
  609. },
  610. /**
  611. * Long polling,update some info
  612. */
  613. pollData() {
  614. const params = {
  615. pos: this.metadata.pos,
  616. graph_name: this.graphFiles.value,
  617. rank_id: this.logicCard.value,
  618. };
  619. if (this.graphFiles.value === this.$t('debugger.all')) {
  620. delete params.graph_name;
  621. }
  622. RequestService.pollData(params, this.sessionId).then(
  623. (res) => {
  624. if (res.data) {
  625. if (res.data.metadata) {
  626. this.dealMetadata(res.data.metadata);
  627. }
  628. let name = null;
  629. if (this.$refs.tree && this.$refs.tree.getCurrentKey()) {
  630. name = this.$refs.tree.getCurrentKey();
  631. }
  632. let graphName = this.graphFiles.value;
  633. if (
  634. res.data.receive_tensor &&
  635. res.data.metadata &&
  636. res.data.metadata.step >= this.metadata.step &&
  637. res.data.receive_tensor.node_name === name
  638. ) {
  639. if (this.graphFiles.value === this.$t('debugger.all')) {
  640. graphName = name.split('/')[0];
  641. name = name.replace(`${graphName}/`, '');
  642. }
  643. this.retrieveTensorHistory(
  644. {
  645. name,
  646. },
  647. graphName,
  648. );
  649. }
  650. if (res.data.receive_watchpoint_hits) {
  651. this.radio1 = 'hit';
  652. this.pagination.currentPage = 1;
  653. this.watchPointHits = [];
  654. this.pagination.total = 0;
  655. this.searchWatchpointHits(true);
  656. }
  657. if (
  658. res.data.receive_tensor &&
  659. res.data.receive_tensor.graph_name &&
  660. res.data.receive_tensor.tensor_name &&
  661. this.tensorCompareFlag
  662. ) {
  663. const debTensor = this.$refs['deb-tensor'];
  664. if (debTensor) {
  665. debTensor.updateGraphData(
  666. res.data.receive_tensor.graph_name,
  667. res.data.receive_tensor.tensor_name,
  668. );
  669. }
  670. }
  671. this.pollData();
  672. }
  673. },
  674. (err) => {
  675. if (!err || (err && err.message !== 'routeJump')) {
  676. this.initFail = true;
  677. this.dialogVisible = true;
  678. }
  679. },
  680. );
  681. },
  682. /**
  683. * Step,continue,pause,terminate opesssrate
  684. * @param {Number} type
  685. */
  686. control(type) {
  687. if (type !== 3) {
  688. this.pagination.currentPage = 1;
  689. this.watchPointHits = [];
  690. this.pagination.total = 0;
  691. }
  692. const params = {};
  693. if (type === 0) {
  694. if (!this.step) {
  695. return;
  696. }
  697. params.mode = 'continue';
  698. params.steps = parseInt(this.step);
  699. } else if (type === 1) {
  700. params.mode = 'continue';
  701. params.steps = -1;
  702. } else if (type === 2) {
  703. params.mode = 'terminate';
  704. } else if (type === 3) {
  705. params.mode = 'pause';
  706. }
  707. RequestService.control(params, this.sessionId).then(
  708. (res) => {
  709. if (res.data && res.data.metadata) {
  710. setTimeout(() => {
  711. let msg = '';
  712. if (this.metadata.state === this.state.sending) {
  713. msg = this.$t('debugger.stateMsg.sending');
  714. } else if (this.metadata.state === this.state.running) {
  715. msg = this.$t('debugger.stateMsg.running');
  716. } else {
  717. msg = `${this.$t('debugger.backstageStatus')}${
  718. this.metadata.state
  719. }`;
  720. }
  721. this.$message(msg);
  722. }, 500);
  723. this.metadata.state = res.data.metadata.state;
  724. }
  725. },
  726. (err) => {
  727. this.showErrorMsg(err);
  728. },
  729. );
  730. },
  731. /**
  732. * Show original tree
  733. */
  734. loadOriginalTree() {
  735. this.node.childNodes = [];
  736. this.curWatchPointId = null;
  737. this.defaultCheckedArr = [];
  738. this.resolve(JSON.parse(JSON.stringify(this.origialTree)));
  739. this.resetGraph();
  740. this.tabledata = [];
  741. },
  742. recheckWatchpoint() {
  743. if (!this.enableRecheck) {
  744. return;
  745. }
  746. RequestService.recheckWatchPoints(this.sessionId).then(
  747. (res) => {
  748. if (res && res.data && res.data.metadata) {
  749. if (res.data.metadata.enable_recheck !== undefined) {
  750. this.enableRecheck = res.data.metadata.enable_recheck;
  751. this.pagination.currentPage = 1;
  752. this.watchPointHits = [];
  753. this.pagination.total = 0;
  754. }
  755. if (res.data.metadata.state) {
  756. this.metadata.state = res.data.metadata.state;
  757. }
  758. }
  759. this.$message.success(this.$t('debugger.recheckSuccess'));
  760. },
  761. (err) => {},
  762. );
  763. },
  764. /**
  765. * Add watchpoint
  766. */
  767. addWatchPoint() {
  768. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.errorType');
  769. this.createWatchPointArr = [];
  770. this.createWatchPointArr.push({
  771. collection: {
  772. selectedId: this.conditionCollections[0].id,
  773. },
  774. condition: {
  775. selectedId: '',
  776. options: [],
  777. },
  778. param: {
  779. options: [],
  780. name: '',
  781. value: '',
  782. type: '',
  783. },
  784. compositeParams: {
  785. options: [],
  786. selections: [],
  787. },
  788. });
  789. this.collectionChange(this.createWatchPointArr[0]);
  790. this.createWPDialogVisible = true;
  791. },
  792. /**
  793. * Delete new watchpoint
  794. * @param {Object} item watchpoint data
  795. */
  796. deleteWatchpoint(item) {
  797. if (
  798. !this.watchPointArr.length ||
  799. this.metadata.state === this.state.running ||
  800. this.metadata.state === this.state.sending
  801. ) {
  802. return;
  803. }
  804. if ((item && item.id) || !item) {
  805. const msg = item
  806. ? this.$t('debugger.deleteWatchpointConfirm')
  807. : this.$t('debugger.clearWatchpointConfirm');
  808. this.$confirm(msg, this.$t('public.notice'), {
  809. confirmButtonText: this.$t('public.sure'),
  810. cancelButtonText: this.$t('public.cancel'),
  811. type: 'warning',
  812. }).then(() => {
  813. const params = {watch_point_id: item ? item.id : null};
  814. RequestService.deleteWatchpoint(params, this.sessionId).then(
  815. (res) => {
  816. if (!item) {
  817. this.curWatchPointId = null;
  818. this.watchPointArr = [];
  819. }
  820. this.loadOriginalTree();
  821. this.queryWatchPoints();
  822. this.$message.success(this.$t('debugger.successDeleteWP'));
  823. if (
  824. res &&
  825. res.data &&
  826. res.data.metadata &&
  827. res.data.metadata.enable_recheck !== undefined
  828. ) {
  829. this.enableRecheck = res.data.metadata.enable_recheck;
  830. }
  831. this.curWatchPointId = null;
  832. },
  833. (err) => {
  834. this.showErrorMsg(err);
  835. },
  836. );
  837. });
  838. } else {
  839. this.curWatchPointId = null;
  840. }
  841. },
  842. validateParam(item) {
  843. const reg = /^(\-|\+)?\d+(\.\d+)?$/;
  844. this.validPram = reg.test(item.param.value);
  845. item.compositeParams.selections.forEach((i) => {
  846. this.validPram = this.validPram && reg.test(i.value);
  847. });
  848. if (!this.validPram) {
  849. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.errorType');
  850. } else {
  851. this.paramErrorMsg = '';
  852. const inputValue = parseFloat(item.param.value);
  853. const absParams = [
  854. 'abs_mean_gt',
  855. 'abs_mean_lt',
  856. 'rtol',
  857. 'abs_mean_update_ratio_gt',
  858. 'abs_mean_update_ratio_lt',
  859. ];
  860. if (absParams.includes(item.param.name) && inputValue < 0) {
  861. this.validPram = false;
  862. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.nonnegative');
  863. }
  864. const positiveParams = ['max_min_lt', 'max_min_gt'];
  865. if (positiveParams.includes(item.param.name) && inputValue <= 0) {
  866. this.validPram = false;
  867. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.allPositive');
  868. }
  869. if (this.percentParams.includes(item.param.name)) {
  870. const percentRange = {min: 0, max: 100};
  871. if (inputValue < percentRange.min || inputValue > percentRange.max) {
  872. this.validPram = false;
  873. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.percentError');
  874. }
  875. }
  876. if (this.validPram && item.compositeParams.selections.length) {
  877. const rangeKey = ['range_start_inclusive', 'range_end_inclusive'];
  878. const rangeStart = item.compositeParams.selections.filter((i) => {
  879. return i.name === rangeKey[0];
  880. });
  881. const rangeEnd = item.compositeParams.selections.filter((i) => {
  882. return i.name === rangeKey[1];
  883. });
  884. if (rangeStart.length && rangeEnd.length) {
  885. const start = parseFloat(rangeStart[0].value);
  886. const end = parseFloat(rangeEnd[0].value);
  887. if (start > end) {
  888. this.validPram = false;
  889. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.rangeError');
  890. }
  891. }
  892. }
  893. }
  894. this.$forceUpdate();
  895. },
  896. /**
  897. * Create new watchpoint
  898. * @param {Boolean} creatFlag Whether create watchpoint
  899. */
  900. createWatchPoint(creatFlag) {
  901. if (creatFlag) {
  902. const item = this.createWatchPointArr[0];
  903. const params = {
  904. condition: {
  905. id: item.condition.selectedId,
  906. params: [],
  907. },
  908. watch_nodes: [],
  909. graph_name: this.graphFiles.value,
  910. rank_id: this.logicCard.value,
  911. };
  912. if (this.graphFiles.value === this.$t('debugger.all')) {
  913. delete params.graph_name;
  914. }
  915. if (item.param.options.length) {
  916. params.condition.params = [
  917. {
  918. name: item.param.name,
  919. value:
  920. item.param.type === 'BOOL'
  921. ? Boolean(item.param.value)
  922. : Number(item.param.value),
  923. },
  924. ];
  925. }
  926. if (item.compositeParams.selections.length) {
  927. item.compositeParams.selections.forEach((i) => {
  928. params.condition.params.push({
  929. name: i.name,
  930. value: i.type === 'BOOL' ? Boolean(i.value) : Number(i.value),
  931. });
  932. });
  933. }
  934. RequestService.createWatchpoint(params, this.sessionId).then(
  935. (res) => {
  936. this.createWatchPointArr = [];
  937. this.createWPDialogVisible = false;
  938. this.$message.success(this.$t('debugger.successCreateWP'));
  939. if (
  940. res &&
  941. res.data &&
  942. res.data.metadata &&
  943. res.data.metadata.enable_recheck !== undefined
  944. ) {
  945. this.enableRecheck = res.data.metadata.enable_recheck;
  946. }
  947. this.queryWatchPoints(true);
  948. },
  949. (err) => {
  950. this.loadOriginalTree();
  951. this.queryWatchPoints();
  952. this.showErrorMsg(err);
  953. },
  954. );
  955. } else {
  956. this.createWatchPointArr = [];
  957. this.createWPDialogVisible = false;
  958. }
  959. },
  960. /**
  961. * Collection change processing
  962. * @param {Object} item
  963. */
  964. collectionChange(item) {
  965. const collection = this.conditionCollections.filter((i) => {
  966. return i.id === item.collection.selectedId;
  967. })[0];
  968. if (collection.conditions && collection.conditions.length) {
  969. item.condition.options = collection.conditions;
  970. item.condition.selectedId = item.condition.options[0].id;
  971. this.conditionChange(item);
  972. } else {
  973. item.condition.options = [];
  974. item.condition.selectedId = '';
  975. item.param.options = [];
  976. item.param.name = '';
  977. item.param.type = '';
  978. item.param.value = '';
  979. this.validPram = false;
  980. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.errorType');
  981. }
  982. },
  983. /**
  984. * Condition change processing
  985. * @param {Object} item
  986. */
  987. conditionChange(item) {
  988. const condition = item.condition.options.filter((i) => {
  989. return i.id === item.condition.selectedId;
  990. })[0];
  991. if (condition.parameters && condition.parameters.length) {
  992. item.param.options = condition.parameters.filter((i) => {
  993. return i.param_type !== 'SUPPORT_PARAM';
  994. });
  995. item.compositeParams.options = condition.parameters.filter((i) => {
  996. return i.param_type === 'SUPPORT_PARAM';
  997. });
  998. item.param.name = item.param.options[0].name;
  999. this.paramChange(item);
  1000. } else {
  1001. item.param.options = [];
  1002. item.param.name = '';
  1003. item.param.type = '';
  1004. item.param.value = '';
  1005. this.validPram = true;
  1006. item.compositeParams.options = [];
  1007. item.compositeParams.selections = [];
  1008. }
  1009. },
  1010. /**
  1011. * Parameter change processing
  1012. * @param {Object} item
  1013. */
  1014. paramChange(item) {
  1015. const param = item.param.options.filter((i) => {
  1016. return i.name === item.param.name;
  1017. })[0];
  1018. if (param.required_params && param.required_params.length) {
  1019. item.compositeParams.selections = item.compositeParams.options.filter(
  1020. (i) => {
  1021. return param.required_params.includes(i.name);
  1022. },
  1023. );
  1024. item.compositeParams.selections.forEach((i) => {
  1025. i.value = i.type === 'BOOL' ? true : '';
  1026. });
  1027. } else {
  1028. item.compositeParams.selections = [];
  1029. }
  1030. item.param.type = param.type;
  1031. item.param.value = '';
  1032. this.validPram = false;
  1033. this.paramErrorMsg = this.$t('debugger.paramErrorMsg.errorType');
  1034. if (item.param.type === 'BOOL') {
  1035. item.param.value = true;
  1036. this.validPram = true;
  1037. }
  1038. },
  1039. /** Draw the tree
  1040. * @param {Object} obj Current checked obj
  1041. */
  1042. check(obj) {
  1043. const node = this.$refs.tree.getNode(obj.name);
  1044. const check = node.checked;
  1045. if (check) {
  1046. node.data.watched = this.checkboxStatus.checked;
  1047. } else {
  1048. node.data.watched = this.checkboxStatus.unchecked;
  1049. }
  1050. if (this.treeFlag && node.childNodes) {
  1051. this.dealCheckPro(node.childNodes, node.indeterminate || check);
  1052. }
  1053. if (this.curWatchPointId) {
  1054. this.$refs.tree.getCheckedKeys().forEach((val) => {
  1055. const node = this.$refs.tree.getNode(val);
  1056. if (node.data.watched === this.checkboxStatus.noCheckbox) {
  1057. node.checked = false;
  1058. }
  1059. });
  1060. this.$nextTick(() => {
  1061. if (node.indeterminate) {
  1062. node.checked = true;
  1063. node.indeterminate = false;
  1064. }
  1065. if (check) {
  1066. this.dealParentNode(node);
  1067. }
  1068. const checkedKeys = this.$refs.tree.getCheckedKeys();
  1069. const watchNodes = [];
  1070. if (this.defaultCheckedArr.length === checkedKeys.length) {
  1071. return;
  1072. } else if (this.defaultCheckedArr.length > checkedKeys.length) {
  1073. watchNodes.push(obj.name);
  1074. } else {
  1075. checkedKeys.forEach((val) => {
  1076. if (this.defaultCheckedArr.indexOf(val) === -1) {
  1077. watchNodes.push(val);
  1078. }
  1079. });
  1080. }
  1081. const params = {
  1082. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1083. watch_nodes: watchNodes,
  1084. mode: node.indeterminate || check ? 1 : 0,
  1085. graph_name: this.graphFiles.value,
  1086. rank_id: this.logicCard.value,
  1087. };
  1088. if (this.graphFiles.value === this.$t('debugger.all')) {
  1089. delete params.graph_name;
  1090. }
  1091. RequestService.updateWatchpoint(params, this.sessionId).then(
  1092. (res) => {
  1093. this.defaultCheckedArr = checkedKeys;
  1094. if (
  1095. res &&
  1096. res.data &&
  1097. res.data.metadata &&
  1098. res.data.metadata.enable_recheck !== undefined
  1099. ) {
  1100. this.enableRecheck = res.data.metadata.enable_recheck;
  1101. }
  1102. },
  1103. (err) => {
  1104. this.showErrorMsg(err);
  1105. },
  1106. );
  1107. });
  1108. }
  1109. },
  1110. dealParentNode(node) {
  1111. const parent = node.parent;
  1112. if (
  1113. parent &&
  1114. !parent.childNodes
  1115. .filter((val) => val.data.watched !== -1)
  1116. .find((val) => val.checked === false)
  1117. ) {
  1118. parent.checked = true;
  1119. parent.indeterminate = false;
  1120. this.dealParentNode(parent);
  1121. }
  1122. },
  1123. searchCheck(obj) {
  1124. const node = this.$refs.searchTree.getNode(obj.name);
  1125. const check = node.checked;
  1126. if (check) {
  1127. node.data.watched = this.checkboxStatus.checked;
  1128. } else {
  1129. node.data.watched = this.checkboxStatus.unchecked;
  1130. }
  1131. if (node.childNodes) {
  1132. this.dealCheckPro(node.childNodes, node.indeterminate || check);
  1133. }
  1134. this.$nextTick(() => {
  1135. if (node.indeterminate) {
  1136. node.checked = true;
  1137. node.indeterminate = false;
  1138. }
  1139. if (check) {
  1140. this.dealParentNode(node);
  1141. }
  1142. const checkedKeys = this.$refs.searchTree.getCheckedKeys();
  1143. const watchNodes = [];
  1144. if (this.searchCheckedArr.length === checkedKeys.length) {
  1145. return;
  1146. } else if (this.searchCheckedArr.length > checkedKeys.length) {
  1147. watchNodes.push(obj.name);
  1148. } else {
  1149. checkedKeys.forEach((val) => {
  1150. if (this.searchCheckedArr.indexOf(val) === -1) {
  1151. watchNodes.push(val);
  1152. }
  1153. });
  1154. }
  1155. const params = {
  1156. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1157. watch_nodes: watchNodes,
  1158. mode: check ? 1 : 0,
  1159. graph_name: this.graphFiles.value,
  1160. rank_id: this.logicCard.value,
  1161. search_pattern: {name: this.searchedWord},
  1162. };
  1163. if (this.graphFiles.value === this.$t('debugger.all')) {
  1164. delete params.graph_name;
  1165. }
  1166. if (this.nodeTypes.value !== 'all') {
  1167. params.search_pattern.node_category = this.nodeTypes.value;
  1168. }
  1169. RequestService.updateWatchpoint(params, this.sessionId).then(
  1170. (res) => {
  1171. this.searchCheckedArr = checkedKeys;
  1172. if (
  1173. res &&
  1174. res.data &&
  1175. res.data.metadata &&
  1176. res.data.metadata.enable_recheck !== undefined
  1177. ) {
  1178. this.enableRecheck = res.data.metadata.enable_recheck;
  1179. }
  1180. },
  1181. (err) => {
  1182. this.showErrorMsg(err);
  1183. },
  1184. );
  1185. });
  1186. },
  1187. /** Deal tree data
  1188. * @param {Object} childNodes tree node
  1189. * @param { Boolean } check check status
  1190. */
  1191. dealCheckPro(childNodes, check) {
  1192. childNodes.forEach((val) => {
  1193. val.indeterminate = false;
  1194. if (val.data.watched !== -1) {
  1195. val.checked = check;
  1196. if (check) {
  1197. val.data.watched = this.checkboxStatus.checked;
  1198. } else {
  1199. val.data.watched = this.checkboxStatus.unchecked;
  1200. }
  1201. } else {
  1202. val.checked = false;
  1203. }
  1204. if (val.childNodes) {
  1205. this.dealCheckPro(val.childNodes, check);
  1206. }
  1207. });
  1208. },
  1209. /**
  1210. * Collapse node
  1211. * @param {Object} _
  1212. * @param {Object} node node data
  1213. */
  1214. nodeCollapse(_, node) {
  1215. node.loaded = false;
  1216. node.childNodes = [];
  1217. if (this.treeFlag) {
  1218. this.dealDoubleClick(node.data.name);
  1219. }
  1220. },
  1221. /**
  1222. * Function to be executed after the search value changes
  1223. */
  1224. filterChange() {
  1225. if (this.searchWord === '' && this.nodeTypes.value === 'all') {
  1226. this.treeFlag = true;
  1227. this.$nextTick(() => {
  1228. setTimeout(() => {
  1229. const dom = document.querySelector(
  1230. '.el-tree-node.is-current.is-focusable',
  1231. );
  1232. if (dom) {
  1233. dom.scrollIntoView();
  1234. }
  1235. }, 800);
  1236. });
  1237. }
  1238. },
  1239. /**
  1240. * Filter tree data by node name
  1241. */
  1242. filter() {
  1243. this.treeFlag = this.searchWord === '' && this.nodeTypes.value === 'all';
  1244. if (this.searchWord || this.nodeTypes.value !== 'all') {
  1245. this.searchedWord = this.searchWord;
  1246. const params = {
  1247. name: this.searchWord,
  1248. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1249. graph_name: this.graphFiles.value,
  1250. rank_id: this.logicCard.value,
  1251. };
  1252. if (this.graphFiles.value === this.$t('debugger.all')) {
  1253. delete params.graph_name;
  1254. }
  1255. if (this.nodeTypes.value !== 'all') {
  1256. params.node_category = this.nodeTypes.value;
  1257. }
  1258. const loadingInstance = this.$loading(this.loadingOption);
  1259. RequestService.search(params, this.sessionId).then(
  1260. (res) => {
  1261. loadingInstance.close();
  1262. if (res.data && res.data.nodes) {
  1263. this.searchTreeData = res.data.nodes;
  1264. this.searchHalfCheckedArr = [];
  1265. this.searchCheckedArr = [];
  1266. this.dealSearchResult(this.searchTreeData);
  1267. this.searchNode.childNodes = [];
  1268. const data = res.data.nodes.map((val) => {
  1269. return {
  1270. label: val.name.split('/').pop(),
  1271. ...val,
  1272. showCheckbox: val.watched !== -1,
  1273. };
  1274. });
  1275. const currentData = JSON.parse(JSON.stringify(data));
  1276. currentData.forEach((val) => {
  1277. val.nodes = [];
  1278. });
  1279. this.searchResolve(currentData);
  1280. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  1281. this.searchNode.childNodes.forEach((val) => {
  1282. if (val.data.watched === this.checkboxStatus.indeterminate) {
  1283. val.indeterminate = true;
  1284. }
  1285. if (val.data.watched === this.checkboxStatus.checked) {
  1286. val.checked = true;
  1287. }
  1288. if (val.data.watched === this.checkboxStatus.unchecked) {
  1289. val.checked = false;
  1290. }
  1291. });
  1292. data.forEach((val, key) => {
  1293. if (val.nodes && val.nodes.length) {
  1294. val.nodes.forEach((value) => {
  1295. value.parentName = val.name;
  1296. });
  1297. this.dealSearchTreeData(val.nodes);
  1298. }
  1299. });
  1300. this.searchHalfCheckedArr.forEach((val) => {
  1301. this.$refs.searchTree.getNode(val).indeterminate = true;
  1302. });
  1303. }
  1304. },
  1305. (err) => {
  1306. loadingInstance.close();
  1307. this.showErrorMsg(err);
  1308. },
  1309. );
  1310. }
  1311. },
  1312. dealSearchTreeData(children) {
  1313. children.forEach((val) => {
  1314. const node = this.$refs.searchTree.getNode(val.parentName);
  1315. val.label = val.name.split('/').pop();
  1316. val.leaf =
  1317. val.type === 'name_scope' || val.type === 'aggregation_scope'
  1318. ? false
  1319. : true;
  1320. val.showCheckbox = val.watched !== -1;
  1321. this.$refs.searchTree.append(val, node);
  1322. node.expanded = true;
  1323. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  1324. node.childNodes.forEach((value) => {
  1325. if (value.data.watched === this.checkboxStatus.indeterminate) {
  1326. value.indeterminate = true;
  1327. }
  1328. if (value.data.watched === this.checkboxStatus.checked) {
  1329. value.checked = true;
  1330. }
  1331. if (value.data.watched === this.checkboxStatus.unchecked) {
  1332. value.checked = false;
  1333. }
  1334. });
  1335. if (val.nodes && val.nodes.length) {
  1336. val.nodes.forEach((value) => {
  1337. value.parentName = val.name;
  1338. });
  1339. this.dealSearchTreeData(val.nodes);
  1340. }
  1341. });
  1342. },
  1343. /**
  1344. * Deal search data
  1345. * @param {Array} arr search tree data
  1346. */
  1347. dealSearchResult(arr) {
  1348. arr.forEach((val) => {
  1349. if (val.nodes) {
  1350. this.dealSearchResult(val.nodes);
  1351. }
  1352. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  1353. if (val.watched === this.checkboxStatus.checked) {
  1354. this.searchCheckedArr.push(val.name);
  1355. }
  1356. val.label = val.name.split('/').pop();
  1357. });
  1358. },
  1359. retrieveAll() {
  1360. this.loadingInstance = this.$loading(this.loadingOption);
  1361. const params = {
  1362. mode: 'all',
  1363. };
  1364. RequestService.retrieve(params, this.sessionId).then(
  1365. (res) => {
  1366. this.initFail = false;
  1367. this.dialogVisible = false;
  1368. if (res.data) {
  1369. if (res.data.graph && res.data.graph.nodes) {
  1370. this.origialTree = res.data.graph.nodes.map((val) => {
  1371. return {
  1372. label: val.name.split('/').pop(),
  1373. leaf:
  1374. val.type === 'name_scope' ||
  1375. val.type === 'aggregation_scope'
  1376. ? false
  1377. : true,
  1378. ...val,
  1379. };
  1380. });
  1381. this.resolve(this.origialTree);
  1382. this.dealGraphData(
  1383. JSON.parse(JSON.stringify(res.data.graph.nodes)),
  1384. );
  1385. }
  1386. if (res.data.devices && res.data.devices.length) {
  1387. this.devices = res.data.devices;
  1388. this.logicCard.value = this.devices[0].rank_id;
  1389. this.graphFiles.options = JSON.parse(
  1390. JSON.stringify(this.devices[0].graph_names),
  1391. );
  1392. if (this.graphFiles.options.length > 1) {
  1393. this.graphFiles.options.unshift(this.$t('debugger.all'));
  1394. }
  1395. this.graphFiles.value = this.graphFiles.options[0];
  1396. this.logicCard.options = this.devices.map((val) => val.rank_id);
  1397. }
  1398. if (res.data.watch_points) {
  1399. this.watchPointArr = res.data.watch_points.map((val) => {
  1400. return {
  1401. id: val.id,
  1402. condition: val.watch_condition.id,
  1403. params: val.watch_condition.params || [],
  1404. selected: false,
  1405. };
  1406. });
  1407. }
  1408. if (res.data.metadata) {
  1409. if (res.data.metadata.debugger_version) {
  1410. this.debuggerVersion = res.data.metadata.debugger_version;
  1411. }
  1412. this.metadata = res.data.metadata;
  1413. if (
  1414. res &&
  1415. res.data &&
  1416. res.data.metadata &&
  1417. res.data.metadata.enable_recheck !== undefined
  1418. ) {
  1419. this.enableRecheck = res.data.metadata.enable_recheck;
  1420. }
  1421. if (this.metadata.backend) {
  1422. this.version = this.metadata.backend;
  1423. }
  1424. if (
  1425. !res.data.metadata.recommendation_confirmed &&
  1426. this.metadata.state === this.state.waiting
  1427. ) {
  1428. this.recommendWatchPointDialog = true;
  1429. }
  1430. this.nodeName = this.metadata.node_name;
  1431. this.currentNodeName = this.nodeName;
  1432. if (
  1433. this.metadata.state === this.state.pending ||
  1434. this.metadata.state === this.state.mismatch
  1435. ) {
  1436. this.loadingInstance.close();
  1437. }
  1438. if (this.pollInit) {
  1439. this.pollData();
  1440. this.pollInit = false;
  1441. }
  1442. if (this.devices && this.devices.length) {
  1443. this.metadata.ip = this.devices[0].server_ip;
  1444. this.metadata.device_name = this.devices[0].device_id;
  1445. }
  1446. }
  1447. }
  1448. },
  1449. (err) => {
  1450. this.initFail = true;
  1451. this.dialogVisible = true;
  1452. this.loadingInstance.close();
  1453. },
  1454. );
  1455. },
  1456. /**
  1457. * Draw the tree
  1458. * @param {Object} node tree root node
  1459. * @param {Function} resolve callback function ,return next node data
  1460. */
  1461. loadNode(node, resolve) {
  1462. if (node.level === 0) {
  1463. node.childNodes = [];
  1464. if (!this.node && !this.resolve) {
  1465. this.node = node;
  1466. this.resolve = resolve;
  1467. }
  1468. resolve([]);
  1469. } else if (node.level >= 1) {
  1470. this.loadingInstance = this.$loading(this.loadingOption);
  1471. this.isIntoView = false;
  1472. const curHalfCheckedKeys = this.$refs.tree.getHalfCheckedKeys();
  1473. const params = {
  1474. mode: 'node',
  1475. params: {
  1476. node_type: node.data.type,
  1477. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1478. name: node.data.name,
  1479. graph_name: this.graphFiles.value,
  1480. rank_id: this.logicCard.value,
  1481. },
  1482. };
  1483. if (this.graphFiles.value === this.$t('debugger.all')) {
  1484. delete params.params.graph_name;
  1485. }
  1486. RequestService.retrieve(params, this.sessionId).then(
  1487. (res) => {
  1488. if (res.data && res.data.metadata) {
  1489. this.dealMetadata(res.data.metadata);
  1490. }
  1491. if (res.data && res.data.graph) {
  1492. const graph = res.data.graph;
  1493. this.curNodeData = graph.nodes.map((val) => {
  1494. return {
  1495. label: val.name.split('/').pop(),
  1496. leaf:
  1497. val.type === 'name_scope' ||
  1498. val.type === 'aggregation_scope'
  1499. ? false
  1500. : true,
  1501. ...val,
  1502. showCheckbox: val.watched !== -1,
  1503. };
  1504. });
  1505. if (this.curNodeData.length > this.nodesCountLimit) {
  1506. this.$message.error(this.$t('graph.tooManyNodes'));
  1507. this.loadingInstance.close();
  1508. node.loading = false;
  1509. return;
  1510. }
  1511. resolve(this.curNodeData);
  1512. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  1513. this.defaultCheckedArr = this.defaultCheckedArr.concat(
  1514. this.curNodeData
  1515. .filter((val) => {
  1516. return val.watched === this.checkboxStatus.checked;
  1517. })
  1518. .map((val) => val.name),
  1519. );
  1520. const halfSelectArr = this.curNodeData
  1521. .filter((val) => {
  1522. return val.watched === this.checkboxStatus.indeterminate;
  1523. })
  1524. .map((val) => val.name);
  1525. node.childNodes.forEach((val) => {
  1526. if (halfSelectArr.indexOf(val.data.name) !== -1) {
  1527. val.indeterminate = true;
  1528. node.indeterminate = true;
  1529. }
  1530. if (val.data.watched === this.checkboxStatus.checked) {
  1531. val.checked = true;
  1532. } else if (val.data.watched === this.checkboxStatus.unchecked) {
  1533. val.checked = false;
  1534. }
  1535. });
  1536. [
  1537. ...new Set(
  1538. curHalfCheckedKeys.concat(
  1539. this.$refs.tree.getHalfCheckedKeys(),
  1540. ),
  1541. ),
  1542. ].forEach((val) => {
  1543. this.$refs.tree.getNode(val).indeterminate = true;
  1544. });
  1545. this.selectedNode.name = node.data.name;
  1546. if (!this.allGraphData[node.data.name].isUnfold) {
  1547. this.dealGraphData(
  1548. JSON.parse(JSON.stringify(graph.nodes)),
  1549. node.data.name,
  1550. );
  1551. } else {
  1552. this.selectNode(true);
  1553. }
  1554. } else {
  1555. this.selectedNode.name = node.data.name;
  1556. this.selectNode(true);
  1557. resolve([]);
  1558. }
  1559. },
  1560. (err) => {
  1561. this.showErrorMsg(err);
  1562. resolve([]);
  1563. },
  1564. );
  1565. }
  1566. },
  1567. /**
  1568. * Draw the tree
  1569. * @param {Object} node tree root node
  1570. * @param {Function} resolve callback function ,return next node data
  1571. */
  1572. loadSearchNode(node, resolve) {
  1573. if (node.level === 0) {
  1574. node.childNodes = [];
  1575. if (!this.searchNode && !this.searchResolve) {
  1576. this.searchNode = node;
  1577. this.searchResolve = resolve;
  1578. }
  1579. } else if (node.level >= 1) {
  1580. const curHalfCheckedKeys = this.$refs.searchTree.getHalfCheckedKeys();
  1581. if (node.childNodes && node.childNodes.length) {
  1582. node.expanded = true;
  1583. node.loaded = true;
  1584. node.loading = false;
  1585. return;
  1586. }
  1587. const params = {
  1588. mode: 'node',
  1589. params: {
  1590. node_type: node.data.type,
  1591. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1592. name: node.data.name,
  1593. graph_name: this.graphFiles.value,
  1594. rank_id: this.logicCard.value,
  1595. },
  1596. };
  1597. if (this.graphFiles.value === this.$t('debugger.all')) {
  1598. delete params.params.graph_name;
  1599. }
  1600. RequestService.retrieve(params, this.sessionId).then((res) => {
  1601. if (res.data && res.data.metadata) {
  1602. this.dealMetadata(res.data.metadata);
  1603. }
  1604. if (res.data && res.data.graph && res.data.graph.nodes) {
  1605. this.curNodeData = res.data.graph.nodes.map((val) => {
  1606. return {
  1607. label: val.name.split('/').pop(),
  1608. leaf:
  1609. val.type === 'name_scope' || val.type === 'aggregation_scope'
  1610. ? false
  1611. : true,
  1612. ...val,
  1613. showCheckbox: val.watched !== -1,
  1614. };
  1615. });
  1616. resolve(this.curNodeData);
  1617. this.searchCheckedArr = this.searchCheckedArr.concat(
  1618. this.curNodeData
  1619. .filter((val) => {
  1620. return val.watched === this.checkboxStatus.checked;
  1621. })
  1622. .map((val) => val.name),
  1623. );
  1624. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  1625. const halfSelectArr = this.curNodeData
  1626. .filter((val) => {
  1627. return val.watched === this.checkboxStatus.indeterminate;
  1628. })
  1629. .map((val) => val.name);
  1630. node.childNodes.forEach((val) => {
  1631. if (val.data.watched === this.checkboxStatus.checked) {
  1632. val.checked = true;
  1633. }
  1634. if (halfSelectArr.indexOf(val.data.name) !== -1) {
  1635. val.indeterminate = true;
  1636. node.indeterminate = true;
  1637. }
  1638. });
  1639. [
  1640. ...new Set(
  1641. curHalfCheckedKeys.concat(
  1642. this.$refs.searchTree.getHalfCheckedKeys(),
  1643. ),
  1644. ),
  1645. ].forEach((val) => {
  1646. this.$refs.searchTree.getNode(val).indeterminate = true;
  1647. });
  1648. }
  1649. });
  1650. }
  1651. },
  1652. initRecommendWatchPoints(value) {
  1653. this.recommendWatchPointDialog = false;
  1654. const params = {
  1655. requestBody: {
  1656. set_recommended: value,
  1657. },
  1658. };
  1659. RequestService.setRecommendWatchPoints(params, this.sessionId).then(
  1660. (res) => {
  1661. if (res && res.data) {
  1662. if (value) {
  1663. this.queryWatchPoints(false);
  1664. }
  1665. }
  1666. },
  1667. );
  1668. },
  1669. /**
  1670. * Show data of current selected watchpoint
  1671. * @param {Number} key watchpoint id
  1672. */
  1673. selectWatchPoint(key) {
  1674. this.curLeafNodeName = null;
  1675. this.curHalfCheckedKeys = [];
  1676. this.watchPointArr.forEach((val, index) => {
  1677. if (index === key) {
  1678. if (val.id) {
  1679. val.selected = true;
  1680. this.curWatchPointId = val.id;
  1681. this.queryGraphByWatchpoint(val.id);
  1682. if (this.searchWord !== '' || this.nodeTypes.value !== 'all') {
  1683. this.filter();
  1684. }
  1685. } else {
  1686. this.loadOriginalTree();
  1687. }
  1688. } else {
  1689. if (val.selected) {
  1690. val.selected = false;
  1691. }
  1692. }
  1693. });
  1694. },
  1695. /**
  1696. * Query WatchPoints
  1697. * @param {Boolean} focusLast
  1698. */
  1699. queryWatchPoints(focusLast) {
  1700. const params = {
  1701. mode: 'watchpoint',
  1702. graph_name: this.graphFiles.value,
  1703. rank_id: this.logicCard.value,
  1704. };
  1705. if (this.graphFiles.value === this.$t('debugger.all')) {
  1706. delete params.graph_name;
  1707. }
  1708. RequestService.retrieve(params, this.sessionId).then(
  1709. (res) => {
  1710. if (res.data.watch_points) {
  1711. this.watchPointArr = res.data.watch_points.map((val) => {
  1712. return {
  1713. id: val.id,
  1714. condition: val.watch_condition.id,
  1715. params: val.watch_condition.params || [],
  1716. selected: false,
  1717. };
  1718. });
  1719. if (focusLast) {
  1720. this.selectWatchPoint(this.watchPointArr.length - 1);
  1721. this.$nextTick(() => {
  1722. const newWatchPointDom = document.querySelector(
  1723. '#watch-point-list>li:last-child',
  1724. );
  1725. if (newWatchPointDom) {
  1726. newWatchPointDom.scrollIntoView();
  1727. }
  1728. });
  1729. }
  1730. }
  1731. },
  1732. (err) => {
  1733. this.showErrorMsg(err);
  1734. },
  1735. );
  1736. },
  1737. /**
  1738. * Tree linkage with graph Expand of current node
  1739. * @param {Object} nodes Data of children of current node
  1740. * @param {Object} name The name of the current node
  1741. */
  1742. nodeExpandLinkage(nodes, name) {
  1743. if (nodes.length > this.nodesCountLimit) {
  1744. return;
  1745. }
  1746. const curNodeData = nodes.map((val) => {
  1747. return {
  1748. label: val.name.split('/').pop(),
  1749. ...val,
  1750. showCheckbox: val.watched !== -1,
  1751. };
  1752. });
  1753. const node = this.$refs.tree.getNode(name);
  1754. curNodeData.forEach((val) => {
  1755. this.$refs.tree.append(val, name);
  1756. });
  1757. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  1758. node.childNodes.forEach((val) => {
  1759. if (
  1760. node.checked &&
  1761. !node.childNodes.find((val) => val.data.watched !== 2) &&
  1762. val.data.watched !== -1
  1763. ) {
  1764. val.checked = true;
  1765. }
  1766. if (val.data.watched === this.checkboxStatus.checked) {
  1767. val.checked = true;
  1768. }
  1769. if (val.data.watched === this.checkboxStatus.indeterminate) {
  1770. val.indeterminate = true;
  1771. }
  1772. if (
  1773. val.data.type !== 'name_scope' &&
  1774. val.data.type !== 'aggregation_scope'
  1775. ) {
  1776. val.isLeaf = true;
  1777. }
  1778. });
  1779. node.expanded = true;
  1780. node.loading = false;
  1781. this.$refs.tree.setCurrentKey(name);
  1782. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  1783. this.$nextTick(() => {
  1784. if (
  1785. node.indeterminate &&
  1786. !node.childNodes
  1787. .filter((val) => val.data.watched !== -1)
  1788. .find((val) => val.checked === false)
  1789. ) {
  1790. node.indeterminate = false;
  1791. node.checked = true;
  1792. this.dealParentNode(node);
  1793. }
  1794. setTimeout(() => {
  1795. const dom = document.querySelector(
  1796. '.el-tree-node.is-current.is-focusable',
  1797. );
  1798. if (dom) {
  1799. dom.scrollIntoView();
  1800. }
  1801. }, 800);
  1802. });
  1803. },
  1804. /**
  1805. * @param {Boolean} type true: search watchpointhits false:query watchpointhits
  1806. */
  1807. searchWatchpointHits(type) {
  1808. if (this.radio1 === 'hit') {
  1809. const params = {};
  1810. const condition = {
  1811. rank_id: this.logicCard.value,
  1812. };
  1813. if (type) {
  1814. if (this.selectedNode.name) {
  1815. if (this.graphFiles.value === this.$t('debugger.all')) {
  1816. const arr = this.selectedNode.name.split('/');
  1817. condition.node_name = arr[1]
  1818. ? this.selectedNode.name.replace(`${arr[0]}/`, '')
  1819. : arr[0];
  1820. condition.graph_name = arr[0];
  1821. } else {
  1822. condition.node_name = this.selectedNode.name;
  1823. condition.graph_name = this.graphFiles.value;
  1824. }
  1825. } else {
  1826. condition.offset = this.pagination.currentPage - 1;
  1827. }
  1828. } else {
  1829. condition.offset = this.pagination.currentPage - 1;
  1830. }
  1831. condition.limit = this.pagination.pageSize;
  1832. params.group_condition = condition;
  1833. RequestService.searchWatchpointHits(params, this.sessionId).then(
  1834. (res) => {
  1835. if (res.data.metadata) {
  1836. this.dealMetadata(res.data.metadata);
  1837. }
  1838. this.hitsOutdated = res.data.outdated;
  1839. if (res.data && res.data.watch_point_hits) {
  1840. this.watchPointHits = [];
  1841. this.pagination.total = res.data.total;
  1842. this.pagination.currentPage = res.data.offset + 1;
  1843. this.dealWatchpointHits(res.data.watch_point_hits);
  1844. } else {
  1845. if (condition.node_name) {
  1846. if (this.watchPointHits.length > 0) {
  1847. this.watchPointHits.forEach((val) => {
  1848. val.selected = false;
  1849. });
  1850. } else {
  1851. this.searchWatchpointHits(false);
  1852. }
  1853. } else {
  1854. this.pagination.currentPage = 1;
  1855. this.watchPointHits = [];
  1856. this.pagination.total = 0;
  1857. }
  1858. }
  1859. },
  1860. (err) => {
  1861. this.showErrorMsg(err);
  1862. },
  1863. );
  1864. } else {
  1865. this.$nextTick(() => {
  1866. setTimeout(() => {
  1867. const dom = document.querySelector(
  1868. '.el-tree-node.is-current.is-focusable',
  1869. );
  1870. if (dom) {
  1871. dom.scrollIntoView();
  1872. }
  1873. }, 200);
  1874. });
  1875. }
  1876. },
  1877. dealWatchpointHits(data) {
  1878. if (data && data.length) {
  1879. data.forEach((hit) => {
  1880. const obj = {
  1881. name: hit.node_name,
  1882. lists: [],
  1883. selected: false,
  1884. id: hit.node_name,
  1885. graph_name: hit.graph_name,
  1886. rank_id: this.logicCard.value,
  1887. };
  1888. if (hit.tensors && hit.tensors.length) {
  1889. hit.tensors.forEach((i) => {
  1890. const tensorName = `slot: ${i.slot}, `;
  1891. if (i.watch_points && i.watch_points.length) {
  1892. i.watch_points.forEach((j, key) => {
  1893. let item = `${tensorName}${this.$t('debugger.watchPoint')} ${
  1894. j.id
  1895. }, `;
  1896. let params = [];
  1897. if (j.watch_condition) {
  1898. item += ` ${this.transCondition(j.watch_condition.id)}`;
  1899. this.formateWatchpointParams(
  1900. j.watch_condition.params || [],
  1901. );
  1902. params = JSON.parse(
  1903. JSON.stringify(j.watch_condition.params),
  1904. );
  1905. }
  1906. obj.lists.push({
  1907. name: item,
  1908. params,
  1909. id: `${key}${hit.node_name}`,
  1910. tip:
  1911. j.error_list && j.error_list.length
  1912. ? j.error_list
  1913. .map((i) => {
  1914. return this.$t('debugger.checkTips')[i];
  1915. })
  1916. .join('') +
  1917. this.$t('debugger.checkTips').cannotCheck
  1918. : '',
  1919. });
  1920. });
  1921. }
  1922. });
  1923. }
  1924. this.watchPointHits.push(obj);
  1925. });
  1926. this.focusWatchpointHit();
  1927. } else {
  1928. this.pagination.currentPage = 1;
  1929. this.watchPointHits = [];
  1930. this.pagination.total = 0;
  1931. }
  1932. },
  1933. focusWatchpointHit() {
  1934. if (this.selectedNode.name) {
  1935. let selectedNodeName = this.selectedNode.name;
  1936. if (this.graphFiles.value === this.$t('debugger.all')) {
  1937. selectedNodeName = selectedNodeName.replace(
  1938. `${selectedNodeName.split('/')[0]}/`,
  1939. '',
  1940. );
  1941. }
  1942. this.expandKeys = [];
  1943. let focused = false;
  1944. this.watchPointHits.forEach((val) => {
  1945. if (val.name === selectedNodeName) {
  1946. val.selected = true;
  1947. focused = true;
  1948. this.expandKeys.push(val.id);
  1949. } else {
  1950. val.selected = false;
  1951. }
  1952. });
  1953. this.$nextTick(() => {
  1954. setTimeout(() => {
  1955. const dom = document.querySelector('.hit-item.selected');
  1956. if (dom) {
  1957. dom.scrollIntoView();
  1958. }
  1959. }, 200);
  1960. });
  1961. return focused;
  1962. }
  1963. },
  1964. /**
  1965. * Update tensor value
  1966. * @param {number} key The index of the node of the watchPointHits currently clicked
  1967. */
  1968. updateTensorValue(key) {
  1969. this.loadingInstance = this.$loading(this.loadingOption);
  1970. const currentHit = this.watchPointHits[key];
  1971. const name = currentHit.name;
  1972. const temName = this.nodeName;
  1973. this.nodeName = name;
  1974. this.isHitIntoView = false;
  1975. const params = {
  1976. mode: 'node',
  1977. params: {
  1978. name,
  1979. single_node: true,
  1980. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  1981. graph_name: currentHit.graph_name,
  1982. rank_id: this.logicCard.value,
  1983. },
  1984. };
  1985. if (this.graphFiles.value === this.$t('debugger.all')) {
  1986. delete params.params.graph_name;
  1987. params.params.name = `${currentHit.graph_name}/${name}`;
  1988. }
  1989. this.watchPointHits.forEach((val, index) => {
  1990. if (key === index) {
  1991. val.selected = true;
  1992. } else {
  1993. val.selected = false;
  1994. }
  1995. });
  1996. this.watchPointHits = JSON.parse(JSON.stringify(this.watchPointHits));
  1997. RequestService.retrieve(params, this.sessionId).then(
  1998. (res) => {
  1999. if (res.data.metadata) {
  2000. this.dealMetadata(res.data.metadata);
  2001. }
  2002. this.retrieveTensorHistory(
  2003. {name: this.nodeName},
  2004. currentHit.graph_name,
  2005. );
  2006. if (res.data && res.data.graph) {
  2007. const graph = res.data.graph;
  2008. if (
  2009. this.graphFiles.value !== currentHit.graph_name &&
  2010. this.graphFiles.value !== this.$t('debugger.all')
  2011. ) {
  2012. this.graphFiles.value = currentHit.graph_name;
  2013. this.resetAllData(graph, params.params.name);
  2014. } else {
  2015. this.querySingleNode(
  2016. JSON.parse(JSON.stringify(graph)),
  2017. params.params.name,
  2018. true,
  2019. );
  2020. }
  2021. if (graph.children) {
  2022. this.dealTreeData(graph.children, name);
  2023. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  2024. }
  2025. }
  2026. },
  2027. (err) => {
  2028. this.showErrorMsg(err);
  2029. this.nodeName = temName;
  2030. },
  2031. );
  2032. },
  2033. /**
  2034. * Query the graph data
  2035. * @param {String} nodeName The name of the node that needs to be query
  2036. * @param {Boolean} isQueryTensor The name of the node that needs to be query
  2037. * @param {String} graphName Graph file name
  2038. * @param {Boolean} needLoading Whether to display loading
  2039. */
  2040. queryAllTreeData(nodeName, isQueryTensor, graphName, needLoading) {
  2041. if (needLoading) {
  2042. this.loadingInstance = this.$loading(this.loadingOption);
  2043. }
  2044. let name = nodeName ? nodeName.split(':')[0] : '';
  2045. const params = {
  2046. mode: 'node',
  2047. params: {
  2048. name,
  2049. single_node: true,
  2050. watch_point_id: this.curWatchPointId ? this.curWatchPointId : 0,
  2051. },
  2052. };
  2053. if (
  2054. this.graphFiles.value === this.$t('debugger.all') &&
  2055. graphName &&
  2056. name
  2057. ) {
  2058. if (name !== graphName) {
  2059. name = `${graphName}/${name}`;
  2060. params.params.name = name;
  2061. }
  2062. } else {
  2063. params.params.graph_name = graphName;
  2064. }
  2065. RequestService.retrieve(params, this.sessionId).then(
  2066. (res) => {
  2067. if (res.data && res.data.metadata) {
  2068. this.dealMetadata(res.data.metadata);
  2069. }
  2070. if (res.data && res.data.graph) {
  2071. const graph = res.data.graph;
  2072. if (graph.nodes && !this.isCurrentGraph) {
  2073. this.resetAllData(graph, name);
  2074. this.isCurrentGraph = true;
  2075. } else {
  2076. this.querySingleNode(
  2077. JSON.parse(JSON.stringify(graph)),
  2078. name,
  2079. true,
  2080. );
  2081. }
  2082. if (graph.children) {
  2083. this.dealTreeData(graph.children, name);
  2084. this.defaultCheckedArr = this.$refs.tree.getCheckedKeys();
  2085. }
  2086. }
  2087. },
  2088. (err) => {
  2089. this.showErrorMsg(err);
  2090. },
  2091. );
  2092. },
  2093. /**
  2094. * Draw the tree
  2095. * @param {Object} children child node
  2096. * @param {String} name The name of the node that needs to be highlighted
  2097. */
  2098. dealTreeData(children, name) {
  2099. if (children.nodes) {
  2100. if (
  2101. (children.nodes.length > this.nodesCountLimit &&
  2102. this.$refs.tree.getNode(children.scope_name).data.type ===
  2103. 'name_scope') ||
  2104. this.allGraphData[children.scope_name].maxChainNum > this.maxChainNum
  2105. ) {
  2106. return;
  2107. }
  2108. const data = children.nodes.map((val) => {
  2109. return {
  2110. label: val.name.split('/').pop(),
  2111. ...val,
  2112. showCheckbox: val.watched !== -1,
  2113. };
  2114. });
  2115. data.forEach((val) => {
  2116. const node = this.$refs.tree.getNode(children.scope_name);
  2117. if (node.childNodes) {
  2118. if (
  2119. node.childNodes
  2120. .map((value) => value.data.name)
  2121. .indexOf(val.name) === -1
  2122. ) {
  2123. this.$refs.tree.append(val, node);
  2124. }
  2125. } else {
  2126. this.$refs.tree.append(val, node);
  2127. }
  2128. });
  2129. const node = this.$refs.tree.getNode(children.scope_name);
  2130. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  2131. node.childNodes.forEach((val) => {
  2132. if (val.data.watched === this.checkboxStatus.checked) {
  2133. val.checked = true;
  2134. }
  2135. if (val.data.watched === this.checkboxStatus.indeterminate) {
  2136. val.indeterminate = true;
  2137. }
  2138. if (
  2139. val.data.type !== 'name_scope' &&
  2140. val.data.type !== 'aggregation_scope'
  2141. ) {
  2142. val.isLeaf = true;
  2143. }
  2144. });
  2145. node.expanded = true;
  2146. node.loading = false;
  2147. } else {
  2148. this.$refs.tree.setCurrentKey(name);
  2149. this.$nextTick(() => {
  2150. setTimeout(() => {
  2151. const dom = document.querySelector(
  2152. '.el-tree-node.is-current.is-focusable',
  2153. );
  2154. if (dom) {
  2155. dom.scrollIntoView();
  2156. }
  2157. }, 800);
  2158. });
  2159. }
  2160. if (children.children && Object.keys(children.children).length) {
  2161. this.dealTreeData(children.children, name);
  2162. }
  2163. },
  2164. resetAllData(graph, name) {
  2165. this.node.childNodes = [];
  2166. this.origialTree = graph.nodes.map((val) => {
  2167. return {
  2168. label: val.name.split('/').pop(),
  2169. leaf:
  2170. val.type === 'name_scope' || val.type === 'aggregation_scope'
  2171. ? false
  2172. : true,
  2173. ...val,
  2174. showCheckbox: val.watched !== -1,
  2175. };
  2176. });
  2177. this.resolve(this.origialTree);
  2178. // watched 0:unchecked 1:indeterminate 2:checked -1:no checkbox
  2179. this.node.childNodes.forEach((val) => {
  2180. if (val.data.watched === this.checkboxStatus.checked) {
  2181. val.checked = true;
  2182. }
  2183. if (val.data.watched === this.checkboxStatus.indeterminate) {
  2184. val.indeterminate = true;
  2185. }
  2186. });
  2187. this.firstFloorNodes = [];
  2188. this.allGraphData = {};
  2189. d3.select('#graph svg').remove();
  2190. this.packageDataToObject(
  2191. '',
  2192. true,
  2193. JSON.parse(JSON.stringify(graph.nodes)),
  2194. );
  2195. if (name) {
  2196. this.querySingleNode(JSON.parse(JSON.stringify(graph)), name, true);
  2197. } else {
  2198. this.resetGraph();
  2199. }
  2200. },
  2201. },
  2202. };
  2203. </script>