Perf traces in the CLI.
This commit is contained in:
parent
29ce3bd05e
commit
cea4157402
@ -30,6 +30,7 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"babel-runtime": "^5",
|
||||
"blocked": "^1.1.0",
|
||||
"bluebird": "^2.9.21",
|
||||
"debug": "^2.1.3",
|
||||
"event-to-promise": "^0.3.2",
|
||||
|
@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env node
|
||||
|
||||
import blocked from 'blocked'
|
||||
import Bluebird, {coroutine} from 'bluebird'
|
||||
import eventToPromise from 'event-to-promise'
|
||||
import execPromise from 'exec-promise'
|
||||
@ -9,17 +10,27 @@ import {start as createRepl} from 'repl'
|
||||
|
||||
import {createClient} from './'
|
||||
|
||||
// ===================================================================
|
||||
|
||||
Bluebird.longStackTraces()
|
||||
|
||||
import createDebug from 'debug'
|
||||
const debug = createDebug('xen-api:cli')
|
||||
|
||||
import sourceMapSupport from 'source-map-support'
|
||||
sourceMapSupport.install()
|
||||
|
||||
// ===================================================================
|
||||
|
||||
const usage = `Usage: xen-api <url> <user>`
|
||||
|
||||
const main = coroutine(function * (args) {
|
||||
const opts = minimist(args, {
|
||||
boolean: ['help'],
|
||||
boolean: ['help', 'verbose'],
|
||||
|
||||
alias: {
|
||||
help: 'h'
|
||||
help: 'h',
|
||||
verbose: 'v'
|
||||
}
|
||||
})
|
||||
|
||||
@ -27,6 +38,13 @@ const main = coroutine(function * (args) {
|
||||
return usage
|
||||
}
|
||||
|
||||
if (opts.verbose) {
|
||||
// Does not work perfectly.
|
||||
//
|
||||
// https://github.com/visionmedia/debug/pull/156
|
||||
createDebug.enable('xen-api,xen-api:*')
|
||||
}
|
||||
|
||||
const [url, user] = opts._
|
||||
if (!url || !user) {
|
||||
throw new Error('missing arguments')
|
||||
@ -37,6 +55,13 @@ const main = coroutine(function * (args) {
|
||||
pw(resolve)
|
||||
})
|
||||
|
||||
{
|
||||
const debug = createDebug('xen-api:perf')
|
||||
blocked(ms => {
|
||||
debug('blocked for %sms', ms | 0)
|
||||
})
|
||||
}
|
||||
|
||||
const xapi = createClient({url, auth: {user, password}})
|
||||
yield xapi.connect()
|
||||
|
||||
|
@ -107,10 +107,16 @@ const noop = () => {}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
const notConnectedPromise = Bluebird.reject(new Error('not connected'))
|
||||
let getNotConnectedPromise = function () {
|
||||
const promise = Bluebird.reject(new Error('not connected'))
|
||||
|
||||
// Does nothing but avoid a Bluebird message error.
|
||||
notConnectedPromise.catch(noop)
|
||||
// Does nothing but avoid a Bluebird message error.
|
||||
promise.catch(noop)
|
||||
|
||||
getNotConnectedPromise = () => promise
|
||||
|
||||
return promise
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
@ -155,7 +161,7 @@ export class Xapi extends EventEmitter {
|
||||
this._url = parseUrl(opts.url)
|
||||
this._auth = opts.auth
|
||||
|
||||
this._sessionId = notConnectedPromise
|
||||
this._sessionId = getNotConnectedPromise()
|
||||
|
||||
this._init()
|
||||
|
||||
@ -237,7 +243,7 @@ export class Xapi extends EventEmitter {
|
||||
})
|
||||
}
|
||||
|
||||
this._sessionId = notConnectedPromise
|
||||
this._sessionId = getNotConnectedPromise()
|
||||
|
||||
return Bluebird.resolve().then(() => {
|
||||
debug('%s: disconnected', this._humanId)
|
||||
@ -316,7 +322,7 @@ export class Xapi extends EventEmitter {
|
||||
// Try to login again.
|
||||
debug('%s: the session has been reinitialized', this._humanId)
|
||||
|
||||
this._sessionId = notConnectedPromise
|
||||
this._sessionId = getNotConnectedPromise()
|
||||
|
||||
return this._sessionCall(method, args)
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user