jkuester:template-monitor

v1.0.0Published 4 years ago

This package has not had recent updates. Please investigate it's current state before committing to using it in your project.

JavaScript Style Guide Project Status: Active – The project has reached a stable, usable state and is being actively developed. GitHub file size in bytes GitHub

Meteor Template Monitor

Monitoring for Blaze templates. Tracks the following Template internals:

  • Template.prototype.onCreated
  • Template.prototype.onRendered
  • Template.prototype.onDestroyed
  • Template.prototype.helpers
  • Template.prototype.events
  • Template.prototype.constructView
  • Template.registerHelper

Currently measures

  • Call count per Template and per function
  • Duration of call and average duration of the last 100 calls

Installation and usage

Use

$ meteor add jkuester:template-monitor

to install the package.

Covering Templates from other packages

The package hooks immediately into Template as soon as it's added. Therefore you have to place the package in your .meteor/packages at a position, where all following packages are intended to be monitored.

This is due to the fact, that many packages still use api.addFiles in order to register Templates immediately at build / startup time. If they are added before the this one they simply wont't be monitored.

If you only want to monitor your project's Templates you place the package as the last entry in .meteor/packages.

Configuration

This package monitors all the aforementioned Template internals by default. If you want to shut anyone off you can add the following entry to your Meteor.settings.public:

1{
2  "templateMonitor": {
3    "onCreated": Boolean,
4    "onRendered": Boolean,
5    "onDestroyed": Boolean,
6    "helpers": Boolean,
7    "events": Boolean,
8    "constructView": Boolean,
9    "registerHelper": Boolean
10  }
11}

Omitting an entry or setting it to true have basically the same effect, only an explicit false will skip monitoring the respective internals.

Accessing the stats

You can manually access the stats at any point using Template.monitor(), which will return an Object with a snapshot of all current stats.

You can either call it from your code or even type it in the Browser's JavaScript console.

Note for Firefox users: Firefox prevents timing attacks by rounding values of performance.now which may result in less distinctive stats. If you need detailed insights to timing you may check for a browser, that does not use this rounding or disable it in Firefox.

License

MIT, see LICENSE