Skip to content

Commit

Permalink
Merge pull request #5 from charangirijala/development
Browse files Browse the repository at this point in the history
Call Stack functionality implemented πŸ†πŸ†
  • Loading branch information
charangirijala authored Dec 25, 2024
2 parents be90385 + 612bd46 commit 059594b
Show file tree
Hide file tree
Showing 8 changed files with 21,484 additions and 20,993 deletions.
41,952 changes: 20,976 additions & 20,976 deletions package-lock.json

Large diffs are not rendered by default.

21 changes: 12 additions & 9 deletions src/modules/main/logFileProcessor/logFileProcessor.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { LightningElement } from 'lwc';
import { eventsRegexMain } from 'parser/utilVariables';

import { publish } from 'services/pubsub';
// import { publish, MessageContext } from 'lightning/messageService';

Expand Down Expand Up @@ -80,7 +81,7 @@ export default class LogFileProcessor extends LightningElement {
nofMethodUnits: 0
};
fileDataPartial = [];
treeNodes = [];
// treeNodes = [];
level = 1;
posinset = 1;
maxsize = 100;
Expand Down Expand Up @@ -171,15 +172,15 @@ export default class LogFileProcessor extends LightningElement {

//publish fileData to MessageChannel
this.publishFileMetadata();

// parseResultToTree(this.result);
console.log('Total stdExps: ', this.stdExpCount);
console.log('Total exeAnonys: ', this.execAnonyCount);
console.log('Total CodeUnits Count: ', this.codeUnitsCount);
console.log('Total MethodUnits Count: ', this.methodUnitsCount);
console.log('Final Result after processing res: ', this.result);
console.log('codeUnitsStack count: ', this.codeUnitsStack.length);
console.log('methodUnitsStack count: ', this.methodUnitsStack.length);
console.log('treeNodes: ', this.treeNodes);
// console.log('treeNodes: ', this.treeNodes);
}

/*
Expand All @@ -198,6 +199,7 @@ export default class LogFileProcessor extends LightningElement {
const splitArr1 = neededLine.split('/');
cu.cuName = splitArr1[splitArr1.length - 2];
cu.cuType = 'Class';

cu.methodRunning = splitArr1[splitArr1.length - 1];
cu.isTrigger = false;
} else if (type === 'Class-Method') {
Expand Down Expand Up @@ -305,7 +307,8 @@ export default class LogFileProcessor extends LightningElement {
methodUnit.unitDuration = index;
if (type === 'Method-Generic') {
this.isCurUnitCU = false;
methodUnit.Id = this.methodUnitsCount++;
this.methodUnitsCount++;
// methodUnit.Id = this.methodUnitsCount++;
methodUnit.type = 'Method';
const splitArr = line.split('|');
methodUnit.methodTitle = splitArr[splitArr.length - 1];
Expand All @@ -325,7 +328,7 @@ export default class LogFileProcessor extends LightningElement {
this.methodUnitsStack.push(methodUnit);
} else if (type === 'Method-System') {
this.isCurUnitCU = false;
methodUnit.Id = this.methodUnitsCount++;
// methodUnit.Id = this.methodUnitsCount++;
methodUnit.methodTitle = 'System Method';
methodUnit.type = 'System Method';
methodUnit.methodName = line.substring(line.lastIndexOf('|') + 1);
Expand Down Expand Up @@ -384,21 +387,20 @@ export default class LogFileProcessor extends LightningElement {
CUTop.childUnitsandLines.push(codeUnit);
this.level++;
this.posinset = 1;
this.treeNodes.push(this.createNode(codeUnit));
// this.treeNodes.push(this.createNode(codeUnit));
} else {
CUTop.childUnitsandLines.push(codeUnit);
this.treeNodes.push(this.createNode(codeUnit));
// this.treeNodes.push(this.createNode(codeUnit));
}
} else {
console.log('Entered direct push condition');
this.result.push(codeUnit);
this.treeNodes.push(this.createNode(codeUnit));
// this.treeNodes.push(this.createNode(codeUnit));
}
}

addLinetoCUorMU(line, event, idx) {
let lineDetails = { line: line, event: event, lineNumber: idx };

this.addMUtoResult(lineDetails);
}

Expand Down Expand Up @@ -436,6 +438,7 @@ export default class LogFileProcessor extends LightningElement {
const payload = {
fileMetadata: this.fileMetadata,
fileData: this.fileDataPartial,
result: this.result,
eventsPicklistValues: Array.from(this.eventsPicklistValues)
};
publish('logChannel', payload);
Expand Down
13 changes: 8 additions & 5 deletions src/modules/main/logViewer/logViewer.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ <h1>
<span>Log Viewer</span
><span
class="slds-page-header__title slds-truncate"
title="New Accounts Report"
title={fileMetadata.fileName}
>{fileMetadata.fileName}</span
>
</h1>
Expand Down Expand Up @@ -850,10 +850,13 @@ <h1>
</li>
</ul>
<!-- utility panel -->
<ui-utility-panel
panel-toggle={callStackToggle}
onclosepanel={closeCallStack}
></ui-utility-panel>
<template lwc:if={callStackToggle}>
<ui-utility-panel
panel-toggle={callStackToggle}
onclosepanel={closeCallStack}
data={result}
></ui-utility-panel>
</template>
</footer>
</div>
</template>
5 changes: 5 additions & 0 deletions src/modules/main/logViewer/logViewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default class logViewer extends LightningElement {
goToPlaceholder = 'Go to line';
goTohasLabel = false;
reRenderVal = false;
result = [];
isLoading = false;
isSearching = false;
callStackToggle = false;
Expand Down Expand Up @@ -130,6 +131,10 @@ export default class logViewer extends LightningElement {
}
if (data.fileMetadata)
this.fileMetadata = data.fileMetadata;
if (data.result) {
// console.log('Result: ', data.result);
this.result = data.result;
}
if (data.eventsPicklistValues) {
if (Array.isArray(data.eventsPicklistValues)) {
this.filterPickListMaster =
Expand Down
197 changes: 197 additions & 0 deletions src/modules/parser/callTree/callTree.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
/** RESULT Schema
* {
"type": "array",
"items": {
"type": "object",
"required": [],
"properties": {
"unitDuration": {
"type": "string"
},
"cuType": {
"type": "string"
},
"isTrigger": {
"type": "string"
},
"cuName": {
"type": "string"
},
"Id": {
"type": "string"
},
"childUnitsandLines": {
"type": "array",
"items": {
"type": "object",
"required": [],
"properties": {
"line": {
"type": "string"
},
"event": {
"type": "string"
},
"lineNumber": {
"type": "number"
}
}
}
}
}
}
} **/

export function parseResultToTree(result) {
// Usage example:
const units = parseDebugLogUnits(result, [], 1, null);
let posMap = new Map();
if (units.length > 0) {
units.forEach((unit) => {
if (posMap.has(unit.level)) {
let pos = posMap.get(unit.level);
unit.posinset = pos;
posMap.set(unit.level, pos + 1);
} else {
unit.posinset = 1;
posMap.set(unit.level, 2);
}

if (unit.hasChild) {
unit.isExpanded = false;
}
});
}
setMaxPos(units, posMap);
// posMap.forEach((value, key) => {
// console.log(`Level: ${key}, Position: ${value}`);
// });
// console.log('units', units);
return units;
}

const setMaxPos = (units, posMap) => {
units.forEach((unit) => {
let maxPos = posMap.get(unit.level) - 1;
unit.maxsize = maxPos;
});
};

const hasChildUnits = (value) => {
return (
Array.isArray(value) &&
value.some(
(item) =>
item.cuType || (item.type && item.type !== 'System Method')
)
);
};

function calculateDuration(timeRangeStr) {
// Remove any extra whitespace and split by hyphen
const [startTimeStr, endTimeStr] = timeRangeStr
.split('-')
.map((str) => str.trim());

// Convert string timestamps to numbers
const startTime = parseInt(startTimeStr, 10);
const endTime = parseInt(endTimeStr, 10);

if (isNaN(startTime) || isNaN(endTime)) {
throw new Error(
'Invalid unitDuration format uniqueId and duration not generated'
);
}

const duration = endTime - startTime;
const uniqueId = `${startTime}${Math.random().toString(36).substring(2, 6)}${endTime}`;

return {
duration,
uniqueId
};
}

function parseDebugLogUnits(obj, units = [], level = 1, parentId) {
// Base case - if obj is null or not an object
if (
!obj ||
typeof obj !== 'object' ||
obj.type === 'System Method' ||
obj.line
) {
return units;
}
let currId = parentId;
// Check if current object has 'event' and 'line' properties
if (obj.cuType) {
// Extract code unit information
let duration = 0;
let uniqueId = null;
try {
({ duration, uniqueId } = calculateDuration(obj.unitDuration));
} catch (e) {
uniqueId = Math.random().toString(36).substring(2, 6);
console.error(e);
}
const unit = {
id: uniqueId,
parentId: parentId,
type: obj.cuType,
name: obj.cuName,
level: level,
unitDuration: obj.unitDuration,
unitLength: duration,
hasChild: Object.values(obj).some(hasChildUnits)
};
currId = uniqueId;
units.push(unit);
}

if (obj.type && obj.type !== 'System Method') {
// Extract method unit information and exclude System Methods
// Extract code unit information
let duration = 0;
let uniqueId = null;
try {
({ duration, uniqueId } = calculateDuration(obj.unitDuration));
} catch (e) {
uniqueId = Math.random().toString(36).substring(2, 6);
console.error(e);
}
const unit = {
id: uniqueId,
parentId: parentId,
name: obj.methodTitle,
type: obj.type,
level: level,
unitDuration: obj.unitDuration,
unitLength: duration,
hasChild: Object.values(obj).some(hasChildUnits)
};
currId = uniqueId;
units.push(unit);
}

//Recursively process arrays
if (Array.isArray(obj)) {
obj.forEach((item) => parseDebugLogUnits(item, units, level, currId));
}
// Recursively process object properties
else {
Object.values(obj).forEach((value) => {
if (Array.isArray(value)) {
value.forEach((element) => {
if (
element.cuType ||
(element.type && element.type !== 'System Method')
) {
parseDebugLogUnits(element, units, level + 1, currId);
}
});
}
});
}

return units;
}
37 changes: 36 additions & 1 deletion src/modules/ui/utilityPanel/utilityPanel.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
:host {
line-height: normal;
}
.utility-panel {
width: 30rem;
width: auto;
left: 0.75rem;
right: 0.75rem;
bottom: 2.5rem;
}

.line-length {
font-size: 0.75rem;
color: #747474;
display: none;
}

tr:hover span {
display: inline;
}

th,
td {
padding-top: 0.1rem;
padding-bottom: 0.1rem;
}

.slds-th__action {
padding-top: 0.1rem;
padding-bottom: 0.1rem;
height: 1.5rem;
}

th {
color: #16315a;
}
.slds-utility-panel__body {
overflow: auto;
}
Loading

0 comments on commit 059594b

Please sign in to comment.