From c88576fad2d138c122cd8a9480e47b538496465a Mon Sep 17 00:00:00 2001 From: David Cormier Date: Mon, 16 Dec 2013 11:09:17 -0500 Subject: [PATCH] Add button to count watcher and debug mode Performance issues are mainly caused by spurious angularjs watchers. This debug mode provides a button to display the number of registered watchers in the console. --- index.html | 11 +++++++++++ js/websockets.js | 21 +++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/index.html b/index.html index 8ea5f45..399677d 100644 --- a/index.html +++ b/index.html @@ -152,6 +152,7 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
brand
+
+
  • +
    +
    + +
    +
    +
  • diff --git a/js/websockets.js b/js/websockets.js index 824dc1a..7c0c625 100644 --- a/js/websockets.js +++ b/js/websockets.js @@ -437,6 +437,27 @@ weechat.controller('WeechatCtrl', ['$rootScope', '$scope', '$store', '$timeout', }); } + + $rootScope.countWatchers = function () { + var root = $(document.getElementsByTagName('body')); + var watchers = []; + + var f = function (element) { + if (element.data().hasOwnProperty('$scope')) { + angular.forEach(element.data().$scope.$$watchers, function (watcher) { + watchers.push(watcher); + }); + } + + angular.forEach(element.children(), function (childElement) { + f($(childElement)); + }); + }; + + f(root); + console.log(watchers.length); + }; + if(window.webkitNotifications != undefined) { if (window.webkitNotifications.checkPermission() == 0) { // 0 is PERMISSION_ALLOWED $log.info('Notification permission status:', window.webkitNotifications.checkPermission() == 0);