Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Time(ms) implemented in call stack⏳⏳ #6

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 41 additions & 36 deletions src/modules/main/logFileProcessor/logFileProcessor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { LightningElement } from 'lwc';
import { eventsRegexMain } from 'parser/utilVariables';
import { eventsRegexMain, timeStampRegex } from 'parser/utilVariables';

import { publish } from 'services/pubsub';
// import { publish, MessageContext } from 'lightning/messageService';
Expand Down Expand Up @@ -81,10 +81,6 @@ export default class LogFileProcessor extends LightningElement {
nofMethodUnits: 0
};
fileDataPartial = [];
// treeNodes = [];
level = 1;
posinset = 1;
maxsize = 100;
// @wire(MessageContext)
// messageContext;
get acceptedFormats() {
Expand Down Expand Up @@ -137,25 +133,33 @@ export default class LogFileProcessor extends LightningElement {
'=>',
line
);
this.createCodeUnit(line, value, idx);
this.createCodeUnit(line, value, idx + 1);
break;
}
}
} else if (lineEvent === 'CODE_UNIT_FINISHED') {
//process codeunit finish logic
this.exitCodeUnit(idx);
try {
this.exitCodeUnit(idx + 1, line);
} catch (err) {
console.error(e);
}
} else if (lineEvent === 'METHOD_ENTRY') {
const RegexMap = eventsRegexMain.get(lineEvent);
for (let [key, value] of RegexMap) {
if (key.test(line)) {
// console.log(value, "=>", key.test(line), "=>", line);
this.createMethodUnit(line, value, idx);
this.createMethodUnit(line, value, idx + 1);
break;
}
}
} else if (lineEvent === 'METHOD_EXIT') {
//process methodunit finish logic
this.exitMethodUnit(idx);
try {
this.exitMethodUnit(idx + 1, line);
} catch (e) {
console.error(e);
}
} else {
this.addLinetoCUorMU(line, lineEvent, idx);
}
Expand Down Expand Up @@ -282,7 +286,7 @@ export default class LogFileProcessor extends LightningElement {
if (enteredCondition) {
this.isCurUnitCU = true;
cu.Id = this.codeUnitsCount++;

cu.startTime = this.extractTimeStamp(line);
this.addCUtoResult(cu);
this.codeUnitsStack.push(cu);
}
Expand All @@ -292,9 +296,15 @@ export default class LogFileProcessor extends LightningElement {
* get the current CU and update the lineDuration
* Update the currentCUIndex and isCurUnitCU
*/
exitCodeUnit(idx) {
exitCodeUnit(idx, line) {
let CodeUnit = this.currentCU();
if (CodeUnit === null) {
throw new Error(
'Oops!! Some code units are not picked by the parser'
);
}
CodeUnit.unitDuration += ' - ' + idx;
CodeUnit.endTime = this.extractTimeStamp(line);
this.codeUnitsStack.pop();
}

Expand Down Expand Up @@ -335,11 +345,18 @@ export default class LogFileProcessor extends LightningElement {
this.addMUtoResult(methodUnit);
this.methodUnitsStack.push(methodUnit);
}
methodUnit.startTime = this.extractTimeStamp(line);
}

exitMethodUnit(index) {
exitMethodUnit(index, line) {
let methodUnit = this.currentMU();
if (methodUnit === null) {
throw new Error(
'Oops!! Some method units are not picked by the parser'
);
}
methodUnit.unitDuration += ' - ' + index;
methodUnit.endTime = this.extractTimeStamp(line);
this.methodUnitsStack.pop();
}

Expand Down Expand Up @@ -376,7 +393,7 @@ export default class LogFileProcessor extends LightningElement {

addCUtoResult(codeUnit) {
if (this.codeUnitsStack.length !== 0) {
console.log('Entered length condition');
// console.log('Entered length condition');
let CUTop = this.currentCU();
console.log(CUTop.childUnitsandLines);
if (
Expand All @@ -385,17 +402,12 @@ export default class LogFileProcessor extends LightningElement {
) {
CUTop.childUnitsandLines = [];
CUTop.childUnitsandLines.push(codeUnit);
this.level++;
this.posinset = 1;
// this.treeNodes.push(this.createNode(codeUnit));
} else {
CUTop.childUnitsandLines.push(codeUnit);
// this.treeNodes.push(this.createNode(codeUnit));
}
} else {
console.log('Entered direct push condition');
// console.log('Entered direct push condition');
this.result.push(codeUnit);
// this.treeNodes.push(this.createNode(codeUnit));
}
}

Expand All @@ -404,23 +416,6 @@ export default class LogFileProcessor extends LightningElement {
this.addMUtoResult(lineDetails);
}

createNode(codeUnit) {
let Node = {
id: codeUnit.Id,
name: codeUnit.cuName,
type: codeUnit.cuType,
hasError: codeUnit.hasError,
hasChild: false,
isExpanded: false,
isSelected: false,
level: this.level,
posinset: this.posinset,
maxsize: this.maxsize
};
this.posinset++;
return Node;
}

addToFileDataPartial(line, event, lineNumber) {
const temp = {
line: line,
Expand All @@ -443,4 +438,14 @@ export default class LogFileProcessor extends LightningElement {
};
publish('logChannel', payload);
}

extractTimeStamp(line) {
const durRaw = line.substring(0, line.indexOf('|'));
const match = durRaw.match(timeStampRegex);
if (match !== null && match.length === 4) {
const timeStamp = parseInt(match[3], 10);
return timeStamp;
}
return null;
}
}
1 change: 1 addition & 0 deletions src/modules/main/logViewer/logViewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ th {
}

.line-text {
line-height: normal;
color: #16315a;
fill: #16315a;
font-weight: 400;
Expand Down
18 changes: 17 additions & 1 deletion src/modules/parser/callTree/callTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function parseResultToTree(result) {
// posMap.forEach((value, key) => {
// console.log(`Level: ${key}, Position: ${value}`);
// });
// console.log('units', units);
console.log('units', units);
return units;
}

Expand Down Expand Up @@ -127,18 +127,26 @@ function parseDebugLogUnits(obj, units = [], level = 1, parentId) {
if (obj.cuType) {
// Extract code unit information
let duration = 0;
let timeInMS = 0;
let uniqueId = null;
try {
({ duration, uniqueId } = calculateDuration(obj.unitDuration));
} catch (e) {
uniqueId = Math.random().toString(36).substring(2, 6);
console.error(e);
}
if (obj.startTime && obj.endTime && obj.startTime !== obj.endTime) {
let temp = (obj.endTime - obj.startTime) / 1000000;
timeInMS = temp.toFixed(3);
} else {
timeInMS = 'N/A';
}
const unit = {
id: uniqueId,
parentId: parentId,
type: obj.cuType,
name: obj.cuName,
timeInMS: timeInMS,
level: level,
unitDuration: obj.unitDuration,
unitLength: duration,
Expand All @@ -153,6 +161,13 @@ function parseDebugLogUnits(obj, units = [], level = 1, parentId) {
// Extract code unit information
let duration = 0;
let uniqueId = null;
let timeInMS = 0;
if (obj.startTime && obj.endTime && obj.startTime !== obj.endTime) {
let temp = (obj.endTime - obj.startTime) / 1000000;
timeInMS = temp.toFixed(3);
} else {
timeInMS = 'N/A';
}
try {
({ duration, uniqueId } = calculateDuration(obj.unitDuration));
} catch (e) {
Expand All @@ -163,6 +178,7 @@ function parseDebugLogUnits(obj, units = [], level = 1, parentId) {
id: uniqueId,
parentId: parentId,
name: obj.methodTitle,
timeInMS: timeInMS,
type: obj.type,
level: level,
unitDuration: obj.unitDuration,
Expand Down
4 changes: 4 additions & 0 deletions src/modules/parser/utilVariables/utilVariables.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,7 @@ eventsRegexMain.set(
]
])
);

export let timeStampRegex = new RegExp(
'(\\d{2}:\\d{2}:\\d{2})\\.(\\d+)\\s\\((\\d+)\\)'
);
43 changes: 43 additions & 0 deletions src/modules/ui/utilityPanel/utilityPanel.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,38 @@ <h2 id="panel-heading-01">Call Stack</h2>
</span>
</div>
</th>
<th
aria-sort="none"
class="slds-has-button-menu slds-is-resizable slds-is-sortable"
scope="col"
>
<div class="slds-th__action slds-text-link_reset">
<div
class="slds-grid slds-grid_vertical-align-center slds-has-flexi-truncate"
>
<span
class="slds-truncate"
title="Total Time (ms)"
>Total Time (ms)</span
>
</div>
</div>
<div class="slds-resizable">
<input
type="range"
aria-label="Line duration column width"
class="slds-resizable__input slds-assistive-text"
max="1000"
min="20"
tabindex="-1"
/>
<span class="slds-resizable__handle">
<span
class="slds-resizable__divider"
></span>
</span>
</div>
</th>
</tr>
</thead>
<tbody>
Expand Down Expand Up @@ -201,6 +233,17 @@ <h2 id="panel-heading-01">Call Stack</h2>
>
</div>
</td>
<td
data-label="Total Time (ms)"
role="gridcell"
>
<div
class="slds-truncate"
title={node.timeInMS}
>
{node.timeInMS} ms
</div>
</td>
</tr></template
></template
>
Expand Down