#

API Docs for: v2.11.1
Show: Inherited Protected Private Deprecated

# Ember.Instrumentation Class

Defined in: `packages/ember-metal/lib/instrumentation.js:4`
Module: ember

The purpose of the Ember Instrumentation module is to provide efficient, general-purpose instrumentation for Ember.

Subscribe to a listener by using `Ember.subscribe`:

    Ember.subscribe("render", {
      before(name, timestamp, payload) {

      },

      after(name, timestamp, payload) {

      }
    });

If you return a value from the `before` callback, that same value will be passed as a fourth parameter to the `after` callback.

Instrument a block of code by using `Ember.instrument`:

    Ember.instrument("render.handlebars", payload, function() {
      // rendering logic
    }, binding);

Event names passed to `Ember.instrument` are namespaced by periods, from more general to more specific. Subscribers can listen for events by whatever level of granularity they are interested in.

In the above example, the event is `render.handlebars`, and the subscriber listened for all events beginning with `render`. It would receive callbacks for events named `render`, `render.handlebars`, `render.container`, or even `render.handlebars.layout`.

- Index
- Methods

## Item Index

### Methods

- instrument
- reset
- subscribe
- unsubscribe

## Methods

### `instrument`

(

- `[name]`
- `_payload`
- `callback`
- `binding`

)
private

Defined in `packages/ember-metal/lib/instrumentation.js:78`

Notifies event's subscribers, calls `before` and `after` hooks.

#### Parameters:

- `[name]` String optional

  Namespaced event name.

- `_payload` Object
- `callback` Function

  Function that you're instrumenting.

- `binding` Object

  Context that instrument function is called with.

### `reset`

() private

Defined in `packages/ember-metal/lib/instrumentation.js:244`

Resets `Ember.Instrumentation` by flushing list of subscribers.

### `subscribe`

(

- `[pattern]`
- `[object]`

)
Subscriber private

Defined in `packages/ember-metal/lib/instrumentation.js:181`

Subscribes to a particular event or instrumented block of code.

#### Parameters:

- `[pattern]` String optional

  Namespaced event name.

- `[object]` Object optional

  Before and After hooks.

#### Returns:

Subscriber:

### `unsubscribe`

(

- `[subscriber]`

)
private

Defined in `packages/ember-metal/lib/instrumentation.js:222`

Unsubscribes from a particular event or instrumented block of code.

#### Parameters:

- `[subscriber]` Object optional