diff options
author | Emmanuele Bassi <ebassi@gnome.org> | 2018-01-10 15:28:52 +0000 |
---|---|---|
committer | P. F. Chimento <philip.chimento@gmail.com> | 2018-01-10 10:28:35 -0800 |
commit | cbb1543ae7df1378538232034ab5922ec9f9fd1d (patch) | |
tree | c444b533784f42ab3d3ef1773ac57884108afc15 | |
parent | 9033fd6874b0031703ce9c704eba1dc0234fc298 (diff) |
Add JS convenience wrapper for ProfileProbe.start()
The C API has a convenience macro to initialise the location of the
probe in the source file. We should use an override for the start()
method in order to let GJS fill out the same data for us.
-rw-r--r-- | overrides/Endless.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/overrides/Endless.js b/overrides/Endless.js index 67d1efb..805d7bb 100644 --- a/overrides/Endless.js +++ b/overrides/Endless.js @@ -48,4 +48,20 @@ function _init() { } } }; + + // Override Endless.ProfileProbe.start() to populate it with the location + // in the JS file, like the EOS_PROFILE_PROBE pre-processor macro does for + // C files + Endless.ProfileProbe._start_real = Endless.ProfileProbe.start; + Endless.ProfileProbe.start = function(name) { + let exc = new Error(); + let splits = exc.stack.split('\n')[1].split(':'); + let [line] = splits.slice(-2); + let loc = splits.slice(0, -2).join(':'); + let [func, file] = loc.split('@'); + if (func === '') { + func = '<main>'; + } + return Endless.ProfileProbe._start_real(file, line, func, name); + }; } |