pretty-trace
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "pretty-trace", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "Stacktrace prettyfier with theme support.", | ||
@@ -9,2 +9,5 @@ "main": "pretty-trace.js", | ||
}, | ||
"bin": { | ||
"pretty-trace": "bin/pretty-trace" | ||
}, | ||
"repository": { | ||
@@ -16,3 +19,4 @@ "type": "git", | ||
"dependencies": { | ||
"ansicolors": "~0.2.1" | ||
"ansicolors": "~0.2.1", | ||
"split2": "~0.2.1" | ||
}, | ||
@@ -19,0 +23,0 @@ "devDependencies": { |
'use strict'; | ||
var colors = require('ansicolors'); | ||
// #10 0x1234a23b in node::Parser::on_headers_complete(http_parser*) at node_http_parser.cc:241 | ||
var lldbRegex = /^#(:?\d+)\W+(:?0x(?:(?:\d|[abcdefABCDEF]){0,2})+)\W+in\W+(:?.+?)(?:\W+at\W+(:?.+)){0,1}$/m | ||
// #9 0x00001226b65fe54b in LazyCompile:~watchIndex /Users/thlorenz/dev/talks/memory-profiling/example/app.js:32 () | ||
// #10 0x1234a23b in node::Parser::on_headers_complete(http_parser*) at node_http_parser.cc:241 | ||
var lldbRegex = /^#(:?\d+\W+)(:?0x(?:(?:\d|[abcdefABCDEF]){0,2})+)\W+in\W+(:?.+?)(?:\W+at\W+(:?.+)){0,1}(?:(:?(?:[/\\][^/\\]+?)+\:\d+)\W+\(\)){0,1}$/m | ||
// Captures include white space to maintain indentation | ||
// 67.0ms 97.1%,0, , node::TimerWrap::OnTimeout(uv_timer_s*) | ||
// 67.0ms 97.1%,0, , 0x38852ff1decf | ||
var instrumentsCsvRegex = /^(:?[0-9.]+)(:?ms|s)(:?\W+[0-9.]+%),\d+,\W+,(:?\W+0x(?:(?:\d|[abcdefABCDEF]){2})+){0,1}(:?.+?){0,1}$/m; | ||
// 89dd46 v8::internal::UseIterator::UseIterator(v8::internal::LInstruction*) (/usr/local/bin/node) | ||
var perfScriptRegex = /^(:?\W+(?:(?:\d|[abcdefABCDEF]){2})+){0,1}\W+(:?.+?){1}(:?\([^()]+\)){0,1}$/m | ||
exports.line = | ||
@@ -12,3 +21,3 @@ | ||
* | ||
* @name prettifyTrace::line | ||
* @name prettyTrace::line | ||
* @function | ||
@@ -29,3 +38,11 @@ * @param {string} line the line to be prettified | ||
if (lldbRegex.test(line)) { | ||
return line.replace(lldbRegex, function (match, number, address, symbol, location) { | ||
return line.replace(lldbRegex, function (match, number, address, symbol, location, jitLocation) { | ||
var fc; | ||
location = location || jitLocation; | ||
if (location) { | ||
// complete file path to make it clickable in the terminal and browser | ||
fc = location.slice(0, 1) | ||
location = fc != '/' && fc != '~' ? '/' + location : location; | ||
} | ||
return theme.number('#' + number) + ' ' | ||
@@ -37,2 +54,18 @@ + theme.address(address) | ||
} | ||
if (instrumentsCsvRegex.test(line)) { | ||
return line.replace(instrumentsCsvRegex, function (match, time, timeUnit, percent, address, symbol) { | ||
return theme.number(time) + ' ' | ||
+ timeUnit | ||
+ theme.location(percent) + ' ' | ||
+ (address ? theme.address(address) : '') | ||
+ (symbol ? theme.symbol(symbol) : '') | ||
}) | ||
} | ||
if (perfScriptRegex.test(line)) { | ||
return line.replace(perfScriptRegex, function (match, address, symbol, process) { | ||
return theme.address(address) + ' ' | ||
+ theme.symbol(symbol) + ' ' | ||
+ theme.location(process); | ||
}) | ||
} | ||
return theme.raw(line); | ||
@@ -46,6 +79,6 @@ } | ||
* | ||
* @name prettifyTrace::lines | ||
* @name prettyTrace::lines | ||
* @function | ||
* @param {Array.<string>} lines lines to be prettified | ||
* @param {Object} theme theme that specifies how to prettify a trace @see prettifyTrace::line | ||
* @param {Object} theme theme that specifies how to prettify a trace @see prettyTrace::line | ||
* @return {Array.<string>} the prettified lines | ||
@@ -68,6 +101,6 @@ */ | ||
* | ||
* @name prettifyTrace::terminalTheme | ||
* @name prettyTrace::terminalTheme | ||
*/ | ||
exports.terminalTheme = { | ||
raw : colors.brightBlue | ||
raw : colors.white | ||
, number : colors.blue | ||
@@ -79,4 +112,7 @@ , address : colors.brightBlack | ||
function spanClass(clazz) { | ||
function spanClass(clazz, link) { | ||
return function span(x) { | ||
if (link) { | ||
x = '<a href="file://' + x.split(':')[0] +'">' + x + '</a>'; | ||
} | ||
return '<span class="' + clazz + '">' + x + '</span>'; | ||
@@ -89,3 +125,3 @@ } | ||
* | ||
* @name prettifyTrace::htmlTheme | ||
* @name prettyTrace::htmlTheme | ||
*/ | ||
@@ -97,3 +133,24 @@ exports.htmlTheme = { | ||
, symbol : spanClass('trace-symbol') | ||
, location : spanClass('trace-location') | ||
, location : spanClass('trace-location', true) | ||
} | ||
/** | ||
* Regex used to match debug traces created by tools like lldb. | ||
* | ||
* @name prettyTrace::debugTraceRegex | ||
*/ | ||
exports.debugTraceRegex = lldbRegex; | ||
/** | ||
* Regex used to match callgraphs generated with Mac Instruments and exported as csv. | ||
* | ||
* @name prettyTrace::instrumentsCsvRegex | ||
*/ | ||
exports.instrumentsCsvRegex = instrumentsCsvRegex; | ||
/** | ||
* Regex used to match callgraphs generated running Linux `perf script`. | ||
* | ||
* @name prettyTrace::perfScriptRegex | ||
*/ | ||
exports.perfScriptRegex = perfScriptRegex ; |
@@ -18,2 +18,8 @@ # pretty-trace [![build status](https://secure.travis-ci.org/thlorenz/pretty-trace.png)](http://travis-ci.org/thlorenz/pretty-trace) | ||
## CLI | ||
``` | ||
cat ./test/fixtures/lldb-trace.txt | pretty-trace | ||
``` | ||
## Installation | ||
@@ -38,6 +44,24 @@ | ||
<dt> | ||
<h4 class="name" id="prettifyTrace::htmlTheme"><span class="type-signature"></span>prettifyTrace::htmlTheme<span class="type-signature"></span></h4> | ||
<h4 class="name" id="prettyTrace::debugTraceRegex"><span class="type-signature"></span>prettyTrace::debugTraceRegex<span class="type-signature"></span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>Regex used to match debug traces created by tools like lldb.</p> | ||
</div> | ||
<dl class="details"> | ||
<dt class="tag-source">Source:</dt> | ||
<dd class="tag-source"><ul class="dummy"> | ||
<li> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js">pretty-trace.js</a> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L129">lineno 129</a> | ||
</li> | ||
</ul></dd> | ||
</dl> | ||
</dd> | ||
<dt> | ||
<h4 class="name" id="prettyTrace::htmlTheme"><span class="type-signature"></span>prettyTrace::htmlTheme<span class="type-signature"></span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>A theme that surrounds the given trace using with spans classed <code>trace-*</code> in order to allow styling with CSS.</p> | ||
@@ -51,3 +75,3 @@ </div> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L80">lineno 80</a> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L116">lineno 116</a> | ||
</li> | ||
@@ -58,6 +82,42 @@ </ul></dd> | ||
<dt> | ||
<h4 class="name" id="prettifyTrace::terminalTheme"><span class="type-signature"></span>prettifyTrace::terminalTheme<span class="type-signature"></span></h4> | ||
<h4 class="name" id="prettyTrace::instrumentsCsvRegex"><span class="type-signature"></span>prettyTrace::instrumentsCsvRegex<span class="type-signature"></span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>Regex used to match callgraphs generated with Mac Instruments and exported as csv.</p> | ||
</div> | ||
<dl class="details"> | ||
<dt class="tag-source">Source:</dt> | ||
<dd class="tag-source"><ul class="dummy"> | ||
<li> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js">pretty-trace.js</a> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L136">lineno 136</a> | ||
</li> | ||
</ul></dd> | ||
</dl> | ||
</dd> | ||
<dt> | ||
<h4 class="name" id="prettyTrace::perfScriptRegex"><span class="type-signature"></span>prettyTrace::perfScriptRegex<span class="type-signature"></span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>Regex used to match callgraphs generated running Linux <code>perf script</code>.</p> | ||
</div> | ||
<dl class="details"> | ||
<dt class="tag-source">Source:</dt> | ||
<dd class="tag-source"><ul class="dummy"> | ||
<li> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js">pretty-trace.js</a> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L143">lineno 143</a> | ||
</li> | ||
</ul></dd> | ||
</dl> | ||
</dd> | ||
<dt> | ||
<h4 class="name" id="prettyTrace::terminalTheme"><span class="type-signature"></span>prettyTrace::terminalTheme<span class="type-signature"></span></h4> | ||
</dt> | ||
<dd> | ||
<div class="description"> | ||
<p>A theme that colorizes the given trace using ANSI color codes.</p> | ||
@@ -71,3 +131,3 @@ </div> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L61">lineno 61</a> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L94">lineno 94</a> | ||
</li> | ||
@@ -80,3 +140,3 @@ </ul></dd> | ||
<dt> | ||
<h4 class="name" id="prettifyTrace::line"><span class="type-signature"></span>prettifyTrace::line<span class="signature">(line, theme)</span><span class="type-signature"> → {string}</span></h4> | ||
<h4 class="name" id="prettyTrace::line"><span class="type-signature"></span>prettyTrace::line<span class="signature">(line, theme)</span><span class="type-signature"> → {string}</span></h4> | ||
</dt> | ||
@@ -167,3 +227,3 @@ <dd> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L9">lineno 9</a> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L18">lineno 18</a> | ||
</li> | ||
@@ -186,3 +246,3 @@ </ul></dd> | ||
<dt> | ||
<h4 class="name" id="prettifyTrace::lines"><span class="type-signature"></span>prettifyTrace::lines<span class="signature">(lines, theme)</span><span class="type-signature"> → {Array.<string>}</span></h4> | ||
<h4 class="name" id="prettyTrace::lines"><span class="type-signature"></span>prettyTrace::lines<span class="signature">(lines, theme)</span><span class="type-signature"> → {Array.<string>}</span></h4> | ||
</dt> | ||
@@ -215,3 +275,3 @@ <dd> | ||
</td> | ||
<td class="description last"><p>theme that specifies how to prettify a trace @see prettifyTrace::line</p></td> | ||
<td class="description last"><p>theme that specifies how to prettify a trace @see prettyTrace::line</p></td> | ||
</tr> | ||
@@ -226,3 +286,3 @@ </tbody> | ||
<span>, </span> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L40">lineno 40</a> | ||
<a href="https://github.com/thlorenz/pretty-trace/blob/master/pretty-trace.js#L73">lineno 73</a> | ||
</li> | ||
@@ -229,0 +289,0 @@ </ul></dd> |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20067
8
223
306
2
+ Addedsplit2@~0.2.1
+ Addedcore-util-is@1.0.3(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedisarray@0.0.1(transitive)
+ Addedreadable-stream@1.0.34(transitive)
+ Addedsplit2@0.2.1(transitive)
+ Addedstring_decoder@0.10.31(transitive)
+ Addedthrough2@0.6.5(transitive)
+ Addedxtend@4.0.2(transitive)