How can I get the wrapping function name of my code? I want to implement a runtime-tracking feature in many functions of my project and don't want to replace the function name in every function by myself.
function my_function_name() {
let t0 = performance.now();
....
DEBUG_TRACK_RUNTIME(performance.now() - t0)
}
function DEBUG_TRACK_RUNTIME(runtime) {
console.log("PROCESS RUNTIME: " + this.caller, Math.round(runtime, 0) + " ms")
}
Is there a way to get the function name "my_function_name()" as a string?
QUESTION ANSWERED. This solution worked great for me. Thanks
function abcd() {
let t0 = performance.now();
...
DEBUG_TRACK_RUNTIME(arguments.callee.name, performance.now() - t0)
}
function DEBUG_TRACK_RUNTIME(title, runtime) {
console.log("PROCESS RUNTIME: " + title + "()", Math.round(runtime, 0) + " ms")
}