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.
This commit is contained in:
David Cormier 2013-12-16 11:09:17 -05:00
parent f85b7110da
commit c88576fad2
2 changed files with 32 additions and 0 deletions

View file

@ -152,6 +152,7 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
<div class="brand">
<img alt="brand" src="img/favicon.png" title="Connected to {{ host }}:{{ port}}">
</div>
<button ng-show="debugMode" ng-click="countWatchers()">Count Watchers</button>
<div class="title" ng-bind-html="activeBuffer().title | linky:'_blank'"></div>
<div class="actions pull-right vertical-line-left">
<div class="dropdown pull-left">
@ -220,6 +221,16 @@ $ openssl req -nodes -newkey rsa:2048 -keyout relay.pem -x509 -days 365 -out rel
</div>
</form>
</li>
<li class="">
<form class="form-inline" role="form">
<div class="checkbox">
<label>
<input type="checkbox" ng-model="debugMode">
Debug Mode
</label>
</div>
</form>
</li>
</ul>
</div>
<a ng-click="disconnect()">

View file

@ -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);