From a3a11f635fe09b3d7311902467202a6037e41744 Mon Sep 17 00:00:00 2001 From: Shu-yu Guo Date: Mon, 11 May 2015 14:16:44 -0700 Subject: [PATCH] Bug 1154115 - Fix nsIProfiler xpcshell tests to use the new profiler JSON format. (r=me) --- tools/profiler/tests/head_profiler.js | 23 +++++++++++++++++++++++ tools/profiler/tests/test_asm.js | 7 ++++--- tools/profiler/tests/test_enterjit_osr.js | 9 +++++---- 3 files changed, 32 insertions(+), 7 deletions(-) diff --git a/tools/profiler/tests/head_profiler.js b/tools/profiler/tests/head_profiler.js index 852df06d9f9..a3821f51f4f 100644 --- a/tools/profiler/tests/head_profiler.js +++ b/tools/profiler/tests/head_profiler.js @@ -6,3 +6,26 @@ const Cc = Components.classes; const Ci = Components.interfaces; const Cu = Components.utils; +function getInflatedStackLocations(thread, sample) { + let stackTable = thread.stackTable; + let frameTable = thread.frameTable; + let stringTable = thread.stringTable; + let SAMPLE_STACK_SLOT = thread.samples.schema.stack; + let STACK_PREFIX_SLOT = stackTable.schema.prefix; + let STACK_FRAME_SLOT = stackTable.schema.frame; + let FRAME_LOCATION_SLOT = frameTable.schema.location; + + // Build the stack from the raw data and accumulate the locations in + // an array. + let stackIndex = sample[SAMPLE_STACK_SLOT]; + let locations = []; + while (stackIndex !== null) { + let stackEntry = stackTable.data[stackIndex]; + let frame = frameTable.data[stackEntry[STACK_FRAME_SLOT]]; + locations.push(stringTable[frame[FRAME_LOCATION_SLOT]]); + stackIndex = stackEntry[STACK_PREFIX_SLOT]; + } + + // The profiler tree is inverted, so reverse the array. + return locations.reverse(); +} diff --git a/tools/profiler/tests/test_asm.js b/tools/profiler/tests/test_asm.js index 3fdd59f10df..4d273a5598f 100644 --- a/tools/profiler/tests/test_asm.js +++ b/tools/profiler/tests/test_asm.js @@ -28,17 +28,18 @@ function run_test() { let then = Date.now(); do {} while (Date.now() - then < delayMS); - var profile = p.getProfileData().threads[0].samples; + var thread0 = p.getProfileData().threads[0]; if (delayMS > 30000) return; delayMS *= 2; - if (profile.length == 0) + if (thread0.samples.data.length == 0) continue; - stack = String(profile[profile.length - 1].frames.map(f => f.location)); + var lastSample = thread0.samples.data[thread0.samples.data.length - 1]; + stack = String(getInflatedStackLocations(thread0, lastSample)); if (stack.indexOf("trampoline") !== -1) return; } diff --git a/tools/profiler/tests/test_enterjit_osr.js b/tools/profiler/tests/test_enterjit_osr.js index 886f66008c7..a4bca590f89 100644 --- a/tools/profiler/tests/test_enterjit_osr.js +++ b/tools/profiler/tests/test_enterjit_osr.js @@ -30,8 +30,8 @@ function run_test() { while (--n); // OSR happens here // Spin in the hope of getting a sample. } while (Date.now() - then < delayMS); - let pr = p.getProfileData().threads[0].samples; - if (pr.length > 0 || delayMS > 30000) + let pr = p.getProfileData().threads[0]; + if (pr.samples.data.length > 0 || delayMS > 30000) return pr; delayMS *= 2; } @@ -39,8 +39,9 @@ function run_test() { var profile = arbitrary_name(); - do_check_neq(profile.length, 0); - let stack = profile[profile.length - 1].frames.map(f => f.location); + do_check_neq(profile.samples.data.length, 0); + var lastSample = profile.samples.data[profile.samples.data.length - 1]; + var stack = getInflatedStackLocations(profile, lastSample); do_print(stack); // All we can really check here is ensure that there is exactly