UNPKG

rn-blockmonitor

Version:

block monitor

197 lines (179 loc) 5.24 kB
import HMS from "house-middleware-sdk"; class Node { constructor(val) { this.value = val; this.next = null; } } export class BMLinkList { constructor(node) { this.head = null; this.length = 0; this.maxStackSize = 50; this.showLocalConsoleLogByTimeInterval = 50; } push=(value) => { const node = new Node(value); if (this.head == null) { this.head = node; } else { let current = this.head; while (current.next != null) { current = current.next; } current.next = node; } this.length++; if (this.length >= this.maxStackSize) { this.head = this.head.next; this.length--; } } insertAfter=(value, item) => { const node = new Node(value); const current = this.find(item); if (current == null) { return; } node.next = current.next; current.next = node; this.length++; } remove=(value) => { const current = this.find(value); if (!current) { return; } const previous = this.findPrevious(value); if (!previous) { this.head = current.next; } else { previous.next = current.next; } this.length--; } removeAt=(pos) => { if (pos > -1 && pos < this.length) { let current = this.head; let index = 0; if (pos === 0) { this.head = current.next; } else { while (index < pos) { var previous = current; current = current.next; index++; } previous.next = current.next; } this.length--; } else { return null; } } find=(value) => { let currentNode = this.head; if (currentNode == null) { return null; } if (currentNode.value === value) { return currentNode; } while (currentNode.next) { currentNode = currentNode.next; if (currentNode.value === value) { return currentNode; } } return null; } findPrevious=(value) => { let current = this.head; if (current == null) { return null; } if (current.value === value) { return null; } while (current.next) { if (current.next.value === value) { return current; } current = current.next; } return null; } indexof=(value) => { let current = this.head; let index = 0; if (current == null) { return null; } while (current) { if (current.value === value) { return index; } index++; current = current.next; } return -1; } size=() => this.length setMaxStackSize=(len) => { if (len > 0) this.maxStackSize = len; } setShowLocalConsoleLogByTimeInterval=(time) => { if (time > 0) this.showLocalConsoleLogByTimeInterval = time; } clear=() => { this.head = null; this.length = 0; } alignIndex=index => (Array(3).join('0') + index).slice(-3) getUploadData=(busyTime, lastInterval, now, thresholdInterval) => { const dicArr = []; let current = this.head; let index = 0; while (current != null) { const curDic = current.value; const curTimeStamp = curDic.timeStamp; if (lastInterval <= curTimeStamp && curTimeStamp <= now) { const packDic = {}; packDic.stackIndex = this.alignIndex(index); packDic.timeStamp = curTimeStamp; packDic.stackName = curDic.stackName; dicArr.push(packDic); } current = current.next; index++; } if (dicArr.length) { dicArr.reverse(); console.log('BlockMonitor', '↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓'); console.log('BlockMonitor', `Captured Block: ${busyTime}ms,InsertTime:${lastInterval},ExpectedExecutionTime:${lastInterval + (thresholdInterval / 2)},ExecutionTime:${now},stackNum:${this.length},stackDetailBelow:`); let preTime = 0; const jsonArr = []; dicArr.map((curDic, i) => { jsonArr.push(curDic); const curTime = curDic.timeStamp; let intervalBetweenStack = 0; if (preTime === 0) { preTime = curTime; } else { intervalBetweenStack = preTime - curTime; preTime = curTime; } console.log('BlockMonitor', `${JSON.stringify(curDic)}`); if (intervalBetweenStack >= this.showLocalConsoleLogByTimeInterval) { console.log('BlockMonitor', `************timeout Index:${this.alignIndex(curDic.stackIndex)}-${this.alignIndex(parseInt(curDic.stackIndex) + 1)}****time-consuming:${intervalBetweenStack}*************`); } }); console.log('BlockMonitor', '↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑'); const upData = jsonArr; return upData; } return null; } }