[runtime callstats] Helpers for using runtime callstats in mjsunit tests

Change-Id: I1b350c797093454b0b64dca81ed1d28c35d3ada1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2488685
Commit-Queue: Marja Hölttä <marja@chromium.org>
Reviewed-by: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#70674}
This commit is contained in:
Marja Hölttä 2020-10-21 10:04:15 +02:00 committed by Commit Bot
parent 1e0b92aea9
commit 7cd040a164

View File

@ -0,0 +1,21 @@
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
// Add --allow-natives-syntax --runtime-call-stats to your test file in order to
// use this function. You can suppress the extra printout by calling
// %GetAndResetRuntimeCallStats() at the end of the test.
function getRuntimeFunctionCallCount(function_name) {
const stats = %GetAndResetRuntimeCallStats();
const lines = stats.split("\n");
for (let i = 3; i < lines.length - 3; ++i) {
const line = lines[i];
const m = line.match(/(?<name>\S+)\s+\S+\s+\S+\s+(?<count>\S+)/);
if (function_name == m.groups.name) {
return m.groups.count;
}
}
return 0;
}