-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add several more metrics and info
- Loading branch information
1 parent
ee888e0
commit def94bb
Showing
6 changed files
with
173 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Ntp } from '../../ntp'; | ||
const meteorInstall = require('meteor/modules').meteorInstall; | ||
const oldFetch = meteorInstall.fetch; | ||
|
||
export function wrapDynamicImport () { | ||
meteorInstall.fetch = function (ids) { | ||
const promise = oldFetch(ids); | ||
Kadira.webVitals.numberOfImports += 1; | ||
const now = Ntp._now(); | ||
return promise.then((...args) => { | ||
Kadira.webVitals.importTime.push(Ntp._now() - now); | ||
return Promise.resolve(...args); | ||
}); | ||
}; | ||
} | ||
export function unwrapDynamicImport () { | ||
meteorInstall.fetch = oldFetch; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { Ntp } from '../../ntp'; | ||
|
||
let tracking = true; | ||
export function wrapLogin () { | ||
if (Package['accounts-base']) { | ||
Package['accounts-base'].Accounts.onLogin(() => { | ||
if (!tracking) { | ||
return; | ||
} | ||
Kadira.webVitals.loggedIn = Ntp._now() - Kadira.webVitals.startTime; | ||
}); | ||
} | ||
} | ||
export function unWrapLogin () { | ||
tracking = false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Ntp } from '../../ntp'; | ||
const oldCall = Meteor.call; | ||
|
||
export function wrapMethodCall () { | ||
Meteor.call = function (name, /* .. [arguments] .. callback */) { | ||
// if it's a function, the last argument is the result callback, | ||
// not a parameter to the remote method. | ||
const args = [...arguments].slice(1); | ||
let callback; | ||
if (args.length && typeof args[args.length - 1] === 'function') { | ||
callback = args.pop(); | ||
} | ||
const now = Ntp._now(); | ||
|
||
const newCallback = (...params) => { | ||
Kadira.webVitals.methods.push(Ntp._now() - now); | ||
callback?.(...params); | ||
}; | ||
return this.apply(name, args, newCallback); | ||
}.bind(Meteor.connection); | ||
} | ||
export function unwrapMethodCall () { | ||
Meteor.call = oldCall; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Ntp } from '../../ntp'; | ||
const oldSubscribe = Meteor.subscribe; | ||
|
||
export function wrapSubscription () { | ||
Meteor.subscribe = function (/* name, .. [arguments] .. (callback|callbacks) */) { | ||
const params = [...arguments].slice(1); | ||
let callbacks = Object.create(null); | ||
const now = Ntp._now(); | ||
|
||
if (params.length) { | ||
const lastParam = params[params.length - 1]; | ||
if (typeof lastParam === 'function') { | ||
callbacks.onReady = params.pop(); | ||
} else if (lastParam && [ | ||
lastParam.onReady, | ||
// XXX COMPAT WITH 1.0.3.1 onError used to exist, but now we use | ||
// onStop with an error callback instead. | ||
lastParam.onError, | ||
lastParam.onStop | ||
].some(f => typeof f === 'function')) { | ||
callbacks = params.pop(); | ||
} | ||
} | ||
const oldReady = callbacks.onReady; | ||
const onReady = () => { | ||
const diff = Ntp._now() - now; | ||
if (diff > 0) { | ||
Kadira.webVitals.subs.push(diff); | ||
} | ||
oldReady?.(); | ||
}; | ||
callbacks.onReady = onReady; | ||
return oldSubscribe(arguments[0],...params, callbacks); | ||
}.bind(Meteor.connection); | ||
} | ||
export function unwrapSubscription () { | ||
Meteor.subscribe = oldSubscribe; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters