Commit 9c8a8c6d authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm] Add counter for the number of cache events

With dynamic tiering, caching is triggered multiple times as there is
no single event anymore that triggers when the module should be cached.

This CL adds a counter for the number of times caching is triggered.
This counter can indicate whether our current caching heuristics are
good or should get adjusted.

R=thibaudm@chromium.org

Bug: v8:12281
Change-Id: I8ed9ed73a556d11df643c31ec6d20760a257e0d4
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3295578Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78045}
parent b0c6dd86
......@@ -104,7 +104,10 @@ namespace internal {
/* The maximum of 100M backtracks takes roughly 2 seconds on my machine. */ \
HR(regexp_backtracks, V8.RegExpBacktracks, 1, 100000000, 50) \
/* See the CagedMemoryAllocationOutcome enum in backing-store.cc */ \
HR(caged_memory_allocation_outcome, V8.CagedMemoryAllocationOutcome, 0, 2, 3)
HR(caged_memory_allocation_outcome, V8.CagedMemoryAllocationOutcome, 0, 2, \
3) \
/* number of times a cache event is triggered for a wasm module */ \
HR(wasm_cache_count, V8.WasmCacheCount, 0, 100, 101)
#define NESTED_TIMED_HISTOGRAM_LIST(HT) \
/* Timer histograms, not thread safe: HT(name, caption, max, unit) */ \
......
......@@ -321,7 +321,13 @@ class CompilationChunkFinishedCallback : public CompilationEventCallback {
std::weak_ptr<NativeModule> native_module,
AsyncStreamingDecoder::ModuleCompiledCallback callback)
: native_module_(std::move(native_module)),
callback_(std::move(callback)) {}
callback_(std::move(callback)) {
// As a baseline we also count the modules that could be cached but
// never reach the threshold.
if (std::shared_ptr<NativeModule> module = native_module_.lock()) {
module->counters()->wasm_cache_count()->AddSample(0);
}
}
void call(CompilationEvent event) override {
if (event != CompilationEvent::kFinishedCompilationChunk &&
......@@ -331,6 +337,7 @@ class CompilationChunkFinishedCallback : public CompilationEventCallback {
// If the native module is still alive, get back a shared ptr and call the
// callback.
if (std::shared_ptr<NativeModule> native_module = native_module_.lock()) {
native_module->counters()->wasm_cache_count()->AddSample(++cache_count_);
callback_(native_module);
}
}
......@@ -342,6 +349,7 @@ class CompilationChunkFinishedCallback : public CompilationEventCallback {
private:
const std::weak_ptr<NativeModule> native_module_;
const AsyncStreamingDecoder::ModuleCompiledCallback callback_;
int cache_count_ = 0;
};
} // namespace
......
......@@ -563,6 +563,8 @@ class WasmCodeAllocator {
// Hold the {NativeModule}'s {allocation_mutex_} when calling this method.
size_t GetNumCodeSpaces() const;
Counters* counters() const { return async_counters_.get(); }
private:
// Sentinel value to be used for {AllocateForCodeInRegion} for specifying no
// restriction on the region to allocate in.
......@@ -841,6 +843,8 @@ class V8_EXPORT_PRIVATE NativeModule final {
uint32_t* tiering_budget_array() { return tiering_budgets_.get(); }
Counters* counters() const { return code_allocator_.counters(); }
private:
friend class WasmCode;
friend class WasmCodeAllocator;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment