|
@@ -6,14 +6,41 @@ app.controller('ResultsCtrl', function ($scope) {
|
|
$scope.phantomasMetadata = window._phantomas_metadata.metrics;
|
|
$scope.phantomasMetadata = window._phantomas_metadata.metrics;
|
|
|
|
|
|
$scope.view = 'summary';
|
|
$scope.view = 'summary';
|
|
- $scope.slowRequestsOn = false;
|
|
|
|
- $scope.slowRequestsLimit = 5;
|
|
|
|
|
|
|
|
- if ($scope.phantomasResults.offenders && $scope.phantomasResults.offenders.javascriptExecutionTree) {
|
|
|
|
-
|
|
|
|
|
|
+ if ($scope.phantomasResults.metrics && $scope.phantomasResults.offenders && $scope.phantomasResults.offenders.javascriptExecutionTree) {
|
|
|
|
+
|
|
// Get the execution tree from the offenders
|
|
// Get the execution tree from the offenders
|
|
$scope.javascript = JSON.parse($scope.phantomasResults.offenders.javascriptExecutionTree);
|
|
$scope.javascript = JSON.parse($scope.phantomasResults.offenders.javascriptExecutionTree);
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ initSummaryView();
|
|
|
|
+ initExecutionView();
|
|
|
|
+ initMetricsView();
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $scope.setView = function(viewName) {
|
|
|
|
+ $scope.view = viewName;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ $scope.onNodeDetailsClick = function(node) {
|
|
|
|
+ var isOpen = node.data.showDetails;
|
|
|
|
+ if (!isOpen) {
|
|
|
|
+ // Close all other nodes
|
|
|
|
+ $scope.javascript.children.forEach(function(currentNode) {
|
|
|
|
+ currentNode.data.showDetails = false;
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ // Parse the backtrace
|
|
|
|
+ if (!node.data.parsedBacktrace) {
|
|
|
|
+ node.data.parsedBacktrace = parseBacktrace(node.data.backtrace);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ node.data.showDetails = !isOpen;
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ function initSummaryView() {
|
|
|
|
+
|
|
// Read the main elements of the tree and sum the total time
|
|
// Read the main elements of the tree and sum the total time
|
|
$scope.totalJSTime = 0;
|
|
$scope.totalJSTime = 0;
|
|
treeRunner($scope.javascript, function(node) {
|
|
treeRunner($scope.javascript, function(node) {
|
|
@@ -26,10 +53,71 @@ app.controller('ResultsCtrl', function ($scope) {
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
});
|
|
});
|
|
|
|
+
|
|
|
|
+ $scope.notations = {
|
|
|
|
+ domComplexity: 'A',
|
|
|
|
+ domManipulations: 'A',
|
|
|
|
+ duplicatedDomQueries: 'A'
|
|
|
|
+ };
|
|
|
|
+
|
|
|
|
+ var domComplexityScore = $scope.phantomasResults.metrics.DOMelementsCount;
|
|
|
|
+ if (domComplexityScore > 500) {
|
|
|
|
+ $scope.notations.domComplexity = 'B';
|
|
|
|
+ }
|
|
|
|
+ if (domComplexityScore > 1000) {
|
|
|
|
+ $scope.notations.domComplexity = 'C';
|
|
|
|
+ }
|
|
|
|
+ if (domComplexityScore > 1500) {
|
|
|
|
+ $scope.notations.domComplexity = 'D';
|
|
|
|
+ }
|
|
|
|
+ if (domComplexityScore > 2000) {
|
|
|
|
+ $scope.notations.domComplexity = 'E';
|
|
|
|
+ }
|
|
|
|
+ if (domComplexityScore > 3000) {
|
|
|
|
+ $scope.notations.domComplexity = 'F';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var domManipulationsScore = $scope.phantomasResults.metrics.DOMinserts + $scope.phantomasResults.metrics.DOMqueries * 0.5 + $scope.totalJSTime;
|
|
|
|
+ if (domManipulationsScore > 50) {
|
|
|
|
+ $scope.notations.domManipulations = 'B';
|
|
|
|
+ }
|
|
|
|
+ if (domManipulationsScore > 100) {
|
|
|
|
+ $scope.notations.domManipulations = 'C';
|
|
|
|
+ }
|
|
|
|
+ if (domManipulationsScore > 200) {
|
|
|
|
+ $scope.notations.domManipulations = 'D';
|
|
|
|
+ }
|
|
|
|
+ if (domManipulationsScore > 500) {
|
|
|
|
+ $scope.notations.domManipulations = 'E';
|
|
|
|
+ }
|
|
|
|
+ if (domManipulationsScore > 1000) {
|
|
|
|
+ $scope.notations.domManipulations = 'F';
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var duplicatedDomQueries = $scope.phantomasResults.metrics.DOMqueriesDuplicated;
|
|
|
|
+ if (duplicatedDomQueries > 5) {
|
|
|
|
+ $scope.notations.duplicatedDomQueries = 'B';
|
|
|
|
+ }
|
|
|
|
+ if (duplicatedDomQueries > 10) {
|
|
|
|
+ $scope.notations.duplicatedDomQueries = 'C';
|
|
|
|
+ }
|
|
|
|
+ if (duplicatedDomQueries > 20) {
|
|
|
|
+ $scope.notations.duplicatedDomQueries = 'D';
|
|
|
|
+ }
|
|
|
|
+ if (duplicatedDomQueries > 50) {
|
|
|
|
+ $scope.notations.duplicatedDomQueries = 'E';
|
|
|
|
+ }
|
|
|
|
+ if (duplicatedDomQueries > 100) {
|
|
|
|
+ $scope.notations.duplicatedDomQueries = 'F';
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
- if ($scope.phantomasResults.metrics && $scope.phantomasResults.offenders) {
|
|
|
|
|
|
+ function initExecutionView() {
|
|
|
|
+ $scope.slowRequestsOn = false;
|
|
|
|
+ $scope.slowRequestsLimit = 5;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ function initMetricsView() {
|
|
// Get the Phantomas modules from metadata
|
|
// Get the Phantomas modules from metadata
|
|
$scope.metricsModule = {};
|
|
$scope.metricsModule = {};
|
|
for (var metricName in $scope.phantomasMetadata) {
|
|
for (var metricName in $scope.phantomasMetadata) {
|
|
@@ -39,30 +127,8 @@ app.controller('ResultsCtrl', function ($scope) {
|
|
}
|
|
}
|
|
$scope.metricsModule[metric.module][metricName] = metric;
|
|
$scope.metricsModule[metric.module][metricName] = metric;
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- $scope.setView = function(viewName) {
|
|
|
|
- $scope.view = viewName;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
- $scope.onNodeDetailsClick = function(node) {
|
|
|
|
- var isOpen = node.data.showDetails;
|
|
|
|
- if (!isOpen) {
|
|
|
|
- // Close all other nodes
|
|
|
|
- $scope.javascript.children.forEach(function(currentNode) {
|
|
|
|
- currentNode.data.showDetails = false;
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- // Parse the backtrace
|
|
|
|
- if (!node.data.parsedBacktrace) {
|
|
|
|
- node.data.parsedBacktrace = parseBacktrace(node.data.backtrace);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- }
|
|
|
|
- node.data.showDetails = !isOpen;
|
|
|
|
- };
|
|
|
|
-
|
|
|
|
function parseBacktrace(str) {
|
|
function parseBacktrace(str) {
|
|
if (!str) {
|
|
if (!str) {
|
|
return null;
|
|
return null;
|