Commit 1f6fc830 authored by Clemens Hammacher's avatar Clemens Hammacher Committed by Commit Bot

[wasm] Sample code size after baseline finished

Our UMA data shows a lot of small modules, and I have the suspicion we
are loosing some numbers about the bigger ones. Thus sample the module
code size after baseline compilation finished. At that point the
majority of the code was generated.
Sampling after top-tier finished is not that easy since we do not spawn
a foreground task at that point.

R=mstarzinger@chromium.org

Bug: v8:8217
Change-Id: Icaa4a2efb201d24cbc8d2e1b8da516ae26574f01
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1508675
Commit-Queue: Clemens Hammacher <clemensh@chromium.org>
Reviewed-by: 's avatarMichael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60158}
parent 333fd4d0
......@@ -1259,7 +1259,11 @@ class RuntimeCallTimerScope {
HR(wasm_memory_allocation_result, V8.WasmMemoryAllocationResult, 0, 3, 4) \
HR(wasm_address_space_usage_mb, V8.WasmAddressSpaceUsageMiB, 0, 1 << 20, \
128) \
HR(wasm_module_code_size_mb, V8.WasmModuleCodeSizeMiB, 0, 1024, 64)
/* code size of live modules, collected on GC */ \
HR(wasm_module_code_size_mb, V8.WasmModuleCodeSizeMiB, 0, 1024, 32) \
/* code size of modules after baseline compilation */ \
HR(wasm_module_code_size_mb_after_baseline, \
V8.WasmModuleCodeSizeBaselineMiB, 0, 1024, 32)
#define HISTOGRAM_TIMER_LIST(HT) \
/* Garbage collection timers. */ \
......
......@@ -984,8 +984,8 @@ class AsyncCompileJob::CompilationStateCallback {
break;
case CompilationEvent::kFinishedTopTierCompilation:
DCHECK_EQ(CompilationEvent::kFinishedBaselineCompilation, last_event_);
// This callback should not react to top tier finished callbacks, since
// the job might already be gone then.
// At this point, the job will already be gone, thus do not access it
// here.
break;
case CompilationEvent::kFailedCompilation: {
DCHECK(!last_event_.has_value());
......@@ -1252,6 +1252,10 @@ class AsyncCompileJob::CompileFinished : public CompileStep {
private:
void RunInForeground(AsyncCompileJob* job) override {
TRACE_COMPILE("(3b) Compilation finished\n");
// Sample the generated code size when baseline compilation finished.
job->native_module_->SampleCodeSize(job->isolate_->counters(),
NativeModule::kAfterBaseline);
// Then finalize and publish the generated module.
job->FinishCompile();
}
};
......
......@@ -453,6 +453,8 @@ WasmCode* NativeModule::AddOwnedCode(
}
memcpy(reinterpret_cast<void*>(code->instruction_start()),
instructions.start(), instructions.size());
generated_code_size_.fetch_add(instructions.size(),
std::memory_order_relaxed);
return code;
}
......@@ -1165,6 +1167,24 @@ bool NativeModule::SetExecutable(bool executable) {
return true;
}
void NativeModule::SampleCodeSize(
Counters* counters, NativeModule::CodeSamplingTime sampling_time) const {
size_t code_size = sampling_time == kSampling
? committed_code_space()
: generated_code_size_.load(std::memory_order_relaxed);
int code_size_mb = static_cast<int>(code_size / MB);
Histogram* histogram = nullptr;
switch (sampling_time) {
case kAfterBaseline:
histogram = counters->wasm_module_code_size_mb_after_baseline();
break;
case kSampling:
histogram = counters->wasm_module_code_size_mb();
break;
}
histogram->AddSample(code_size_mb);
}
void WasmCodeManager::FreeNativeModule(NativeModule* native_module) {
base::MutexGuard lock(&native_modules_mutex_);
TRACE_HEAP("Freeing NativeModule %p\n", native_module);
......
......@@ -360,6 +360,10 @@ class V8_EXPORT_PRIVATE NativeModule final {
const char* GetRuntimeStubName(Address runtime_stub_entry) const;
// Sample the current code size of this modules to the given counters.
enum CodeSamplingTime : int8_t { kAfterBaseline, kSampling };
void SampleCodeSize(Counters*, CodeSamplingTime) const;
private:
friend class WasmCode;
friend class WasmCodeManager;
......@@ -484,6 +488,7 @@ class V8_EXPORT_PRIVATE NativeModule final {
WasmEngine* const engine_;
std::atomic<size_t> committed_code_space_{0};
std::atomic<size_t> generated_code_size_{0};
int modification_scope_depth_ = 0;
bool can_request_more_memory_;
UseTrapHandler use_trap_handler_ = kNoTrapHandler;
......
......@@ -438,14 +438,12 @@ void WasmEngine::AddIsolate(Isolate* isolate) {
auto callback = [](v8::Isolate* v8_isolate, v8::GCType type,
v8::GCCallbackFlags flags, void* data) {
Isolate* isolate = reinterpret_cast<Isolate*>(v8_isolate);
Counters* counters = isolate->counters();
WasmEngine* engine = isolate->wasm_engine();
base::MutexGuard lock(&engine->mutex_);
DCHECK_EQ(1, engine->isolates_.count(isolate));
for (NativeModule* native_module :
engine->isolates_[isolate]->native_modules) {
int code_size =
static_cast<int>(native_module->committed_code_space() / MB);
isolate->counters()->wasm_module_code_size_mb()->AddSample(code_size);
for (auto* native_module : engine->isolates_[isolate]->native_modules) {
native_module->SampleCodeSize(counters, NativeModule::kSampling);
}
};
isolate->heap()->AddGCEpilogueCallback(callback, v8::kGCTypeMarkSweepCompact,
......
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