v8/test/mjsunit/runtime-callstats-helpers.js
Marja Hölttä 7cd040a164 [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}
2020-10-21 08:43:09 +00:00

22 lines
786 B
JavaScript

// 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;
}