Skip to content

Commit

Permalink
ui improve, cli improve, final rearranging
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmarkclements committed Mar 14, 2018
1 parent e48d252 commit fbbae44
Show file tree
Hide file tree
Showing 20 changed files with 260 additions and 219 deletions.
45 changes: 33 additions & 12 deletions changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,44 @@
* add `--kernel-tracing` option
* removed `--svg` flag
* removed `--gen` flag
* removed `--timestamp-profiles`
* removed `--theme`
* removed `--include`
* removed `--exclude | -x`
* removed `--tiers | -t`
* removed `--langs | -l`
* renamed `--trace-info` to `--kernel-tracing-debug`
* removed `--log-output`
* removed `--stacks-only`
* removed `-d | --delay`
* removed `--timestamp-profiles` flag
* removed `--theme` flag
* removed `--include` flag
* removed `--exclude | -x` flag
* removed `--tiers | -t` flag
* removed `--langs | -l` flag
* renamed `--trace-info` to `--kernel-tracing-debug` flag
* removed `--log-output` flag
* removed `--stacks-only` flag
* removed `-d | --delay` flag
* renamed `--json-stacks` to `--tree-debug` flag
* profile folders renamed to `{outputDir}/{name}.0x`
* ui: removed langs button
* ui: removed theme button
* ui: style changes (adopted tachyons css)
* ui: style changes, minor redesign
* altered mapFrames API (frames is now an array of objects, not strings)
* ui: rename/reoganize type labels
* ui: rename/reorganize type labels
* ui: tier coloring improvements
* ui: search improvements
* categorization improvements
* API: removed `log` option
* API: added `kernelTracing` option
* API: removed `svg` option
* API: removed `gen` option
* API: removed `timestamp-profiles` option
* API: removed `theme` option
* API: removed `include` option
* API: removed `exclude` option
* API: removed `tiers` option
* API: removed `langs` option
* API: renamed `traceInfo` to `kernelTracingDebug` option
* API: removed `logOutput` option
* API: removed `stacksOnly` option
* API: removed `delay` option
* API: renamed `jsonStacks` to `treeDebug` option
* enhanced status console output (can be overridden in API)
* added merging capability (v8 prof only)
* added capturing inline data along side v8 prof ("pre-inlined" functions)


# v3.4.1
Expand Down
58 changes: 32 additions & 26 deletions cmd.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env node

const fs = require('fs')
const minimist = require('minimist')
const { join } = require('path')
const minimist = require('minimist')
const semver = require('semver')
const zeroEks = require('./')
const { version } = require('./package.json')
const debug = require('debug')('0x')
const sll = require('single-line-log')
const launch = require('opn')
const hasUnicode = require('has-unicode')()
const zeroEks = semver.lt(process.version, '8.5.0') === true ? () => {} : require('./')
const { version } = require('./package.json')

const defaultBanner = `
0x ${version}
Expand All @@ -18,20 +20,20 @@ const defaultBanner = `

if (module.parent === null) {
cmd(process.argv.slice(2)).catch((err) => {
console.error('0x: ', err.message)
console.error(hasUnicode ? `🔥 ${err.message}` : err.message)
debug(err)
process.exit(err.code || 1)
})
} else module.exports = cmd

function cmd (argv, banner = defaultBanner) {
async function cmd (argv, banner = defaultBanner) {
var args = minimist(argv, {
stopEarly: true,
'--': true,
number: ['phase'],
boolean: [
'open', 'version', 'help', 'quiet',
'silent', 'jsonStacks', 'kernelTracingDebug',
'silent', 'treeDebug', 'kernelTracingDebug',
'kernelTracing', 'collectOnly'
],
alias: {
Expand All @@ -44,23 +46,26 @@ function cmd (argv, banner = defaultBanner) {
F: 'outputHtml',
version: 'v',
help: 'h',
jsonStacks: 'json-stacks',
loggingOutput: 'logging-output',
visualizeOnly: 'visualize-only',
collectOnly: 'collect-only',
kernelTracing: 'kernel-tracing',
kernelTracingDebug: 'kernel-tracing-debug',
treeDebug: 'tree-debug'
},
default: {
phase: 2
}
})

if (semver.lt(process.version, '8.5.0') === true) {
console.error('0x v4 supports Node 8.5.0 and above, current Node version is ' + process.version)
console.error('On Linux, macOS or Solaris the --kernel-tracing flag\nmay be able to generate a flamegraph with the current Node version')
console.error('See 0x --help for more info')
process.exit(1)
throw Error(
'Node version unsupported. Current Node version is ' + process.version + '\n' +
'Support extends from Node 8.5.0 and above\n\n' +
'On Linux, macOS or Solaris kernel tracing mode may be used\n' +
'to generate a flamegraph with the current Node version\n' +
'See help for more info\n'
)
}

if (args.help || argv.length === 0) {
Expand All @@ -69,13 +74,23 @@ function cmd (argv, banner = defaultBanner) {
}

if (args.version) return console.log('0x ' + version)
const status = createStatus(args)
args.workingDir = process.cwd()
args.log = createLogger(args)
args.status = createStatus(args)
args.status = status
const { pathToNodeBinary, subprocessArgv } = parseSubprocessCommand(args)
args.argv = subprocessArgv

return zeroEks(args, pathToNodeBinary)
if (args.visualizeOnly) status(`Creating flamegraph from ${args.visualizeOnly}`)

const assetPath = await zeroEks(args, pathToNodeBinary)

if (args.collectOnly) status(`Stats collected in folder file://${assetPath}\n`)
else {
status('Flamegraph generated in\n' + assetPath + '\n')
if (args.open) launch(assetPath, {wait: false})
}

return assetPath
}

function parseSubprocessCommand (args) {
Expand All @@ -95,18 +110,9 @@ function parseSubprocessCommand (args) {
return { pathToNodeBinary, subprocessArgv }
}

function createLogger ({silent, quiet}) {
const logStream = process.stderr
return function log (msg, force) {
if (silent) return
if (!force && quiet) return
logStream.write(msg)
}
}

function createStatus ({silent, quiet}) {
const statusStream = process.stderr
return quiet || silent
? () => {}
: sll(statusStream)
if (quiet || silent) return () => {}
const status = sll(statusStream)
return hasUnicode ? (s) => status(`🔥 ${s}`) : status
}
Loading

0 comments on commit fbbae44

Please sign in to comment.