diff --git a/js/src/vm/SavedStacks.cpp b/js/src/vm/SavedStacks.cpp index 4316ad506d83..2cb7b9c07a43 100644 --- a/js/src/vm/SavedStacks.cpp +++ b/js/src/vm/SavedStacks.cpp @@ -27,6 +27,7 @@ #include "js/Vector.h" #include "vm/Debugger.h" #include "vm/SavedFrame.h" +#include "vm/SPSProfiler.h" #include "vm/StringBuffer.h" #include "vm/Time.h" #include "vm/WrapperObject.h" @@ -1010,6 +1011,7 @@ SavedStacks::saveCurrentStack(JSContext* cx, MutableHandleSavedFrame frame, unsi return true; } + AutoSPSEntry psuedoFrame(cx->runtime(), "js::SavedStacks::saveCurrentStack"); FrameIter iter(cx, FrameIter::ALL_CONTEXTS, FrameIter::GO_THROUGH_SAVED); return insertFrames(cx, iter, frame, maxFrameCount); } diff --git a/tools/profiler/tests/test_saved_stacks.js b/tools/profiler/tests/test_saved_stacks.js new file mode 100644 index 000000000000..c8852768cfd8 --- /dev/null +++ b/tools/profiler/tests/test_saved_stacks.js @@ -0,0 +1,69 @@ +// Test that we get `js::SavedStacks::saveCurrentStack` frames. + +function run_test() { + let p = Cc["@mozilla.org/tools/profiler;1"]; + // Just skip the test if the profiler component isn't present. + if (!p) + return; + p = p.getService(Ci.nsIProfiler); + if (!p) + return; + + const { saveStack } = Cu.getJSTestingFunctions(); + + const ms = 5; + p.StartProfiler(100, ms, ["js"], 1); + + let then = Date.now(); + while (Date.now() - then < 30000) { + function a() { + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + saveStack(); + } + + a(); + a(); + a(); + a(); + a(); + + function b() { + a(); + } + + b(); + b(); + b(); + b(); + b(); + } + + var profile = p.getProfileData().threads[0]; + + do_check_neq(profile.samples.data.length, 0); + + let found = false; + for (let sample of profile.samples.data) { + const stack = getInflatedStackLocations(profile, sample); + for (let frame of stack) { + if (frame.indexOf("js::SavedStacks::saveCurrentStack") >= 0) { + found = true; + break; + } + } + } + do_check_true(found); + + p.StopProfiler(); +} diff --git a/tools/profiler/tests/xpcshell.ini b/tools/profiler/tests/xpcshell.ini index 00d0ab020206..cb77571523b9 100644 --- a/tools/profiler/tests/xpcshell.ini +++ b/tools/profiler/tests/xpcshell.ini @@ -16,3 +16,4 @@ skip-if = !debug [test_enterjit_osr_enabling.js] skip-if = !debug [test_asm.js] +[test_saved_stacks.js]