3

stacktrace.js is a micro-library for getting stack traces in all web browsers.

It offers functions instrumentation:

var p = new printStackTrace.implementation();
p.instrumentFunction(this, 'baz', logStackTrace);
function logStackTrace(stack) {
    console.log(stack.join(' -> '));
}
function foo() {
    var a = 1;
    bar();
}
function bar() {
    baz();
}
foo(); //Will log a stacktrace when 'baz()' is called containing 'foo()'!

p.deinstrumentFunction(this, 'baz'); //Remove function instrumentation

What's the best way to "instrument all or almost all functions" in a safe way? Basically I want (say ... in "debug mode") to "auto-catch and log" all stack traces from all functions that are feasible to instrument. What's a good snippet to do this? Which functions should I avoid instrumenting?

Eric Wendelin
  • 39,122
  • 8
  • 59
  • 87
ripper234
  • 202,011
  • 255
  • 600
  • 878
  • Bad idea. In any real application, you have way too many functions to get useful debugging information by making them *all* report stack traces. – Bergi Jun 18 '15 at 21:58
  • Please define "feasible". – Bergi Jun 18 '15 at 21:58
  • Note that stacktracing all functions is redundant since by definition a stack trace prints all the functions called that leads to the traced function. So if function a calls b and b calls c and you stacktrace everything you'll print out "calling a, calling a, calling b, calling a, calling b, calling c" which is hard to read. What you want instead is to console log functions. – slebetman Nov 23 '15 at 06:26

0 Answers0