Commit e608acf4 authored by Nikolaos Papaspyrou's avatar Nikolaos Papaspyrou Committed by V8 LUCI CQ

heap: Migrate young GC cycle UMA metrics

Report young generation GC statistics to the Recorder API.
These will be used by Blink to populate UMA histograms.
Existing UMA reporting in V8 remains as is for now and will be removed
in a followup.

With this CL, minor mark-compaction statistics are reported as part
of V8.GC.Cycle.*.Young. Also V8.GCScavengeReason is migrated to
V8.GC.Cycle.Reason.Young.

This CL goes together with:
https://chromium-review.googlesource.com/c/chromium/src/+/3320388

Bug: chromium:1154636
Change-Id: Ia1030c80d4bc75ac6e176ed60f838929ddb9b20f
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3320430Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: 's avatarOmer Katz <omerkatz@chromium.org>
Commit-Queue: Nikolaos Papaspyrou <nikolaos@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78416}
parent bd18ee7d
......@@ -606,6 +606,10 @@ V8_INLINE void PerformCastCheck(T* data) {
// how static casts work with std::shared_ptr.
class BackingStoreBase {};
// The maximum value in enum GarbageCollectionReason, defined in heap.h.
// This is needed for histograms sampling garbage collection reasons.
constexpr int kGarbageCollectionReasonMaxValue = 25;
} // namespace internal
} // namespace v8
......
......@@ -73,6 +73,7 @@ struct GarbageCollectionFullMainThreadBatchedIncrementalSweep {
};
struct GarbageCollectionYoungCycle {
int reason = -1;
int64_t total_wall_clock_duration_in_us = -1;
int64_t main_thread_wall_clock_duration_in_us = -1;
double collection_rate_in_percent;
......
......@@ -1452,16 +1452,26 @@ void GCTracer::ReportYoungCycleToRecorder() {
DCHECK_NOT_NULL(recorder);
if (!recorder->HasEmbedderRecorder()) return;
v8::metrics::GarbageCollectionYoungCycle event;
// Reason:
event.reason = static_cast<int>(current_.gc_reason);
// Total:
const double total_wall_clock_duration_in_us =
(current_.scopes[Scope::SCAVENGER] +
current_.scopes[Scope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL]) *
current_.scopes[Scope::MINOR_MARK_COMPACTOR] +
current_.scopes[Scope::SCAVENGER_BACKGROUND_SCAVENGE_PARALLEL] +
current_.scopes[Scope::MINOR_MC_BACKGROUND_EVACUATE_COPY] +
current_.scopes[Scope::MINOR_MC_BACKGROUND_MARKING] +
current_.scopes[Scope::MINOR_MC_BACKGROUND_EVACUATE_UPDATE_POINTERS]) *
base::Time::kMicrosecondsPerMillisecond;
// TODO(chromium:1154636): Consider adding BACKGROUND_YOUNG_ARRAY_BUFFER_SWEEP
// (both for the case of the scavenger and the minor mark-compactor), and
// BACKGROUND_UNMAPPER (for the case of the minor mark-compactor).
event.total_wall_clock_duration_in_us =
static_cast<int64_t>(total_wall_clock_duration_in_us);
// MainThread:
const double main_thread_wall_clock_duration_in_us =
current_.scopes[Scope::SCAVENGER] *
(current_.scopes[Scope::SCAVENGER] +
current_.scopes[Scope::MINOR_MARK_COMPACTOR]) *
base::Time::kMicrosecondsPerMillisecond;
event.main_thread_wall_clock_duration_in_us =
static_cast<int64_t>(main_thread_wall_clock_duration_in_us);
......
......@@ -135,7 +135,10 @@ enum class AllocationOrigin {
kNumberOfAllocationOrigins = kLastAllocationOrigin + 1
};
enum class GarbageCollectionReason {
// These values are persisted to logs. Entries should not be renumbered and
// numeric values should never be reused. If you add new items here, update
// src/tools/metrics/histograms/enums.xml in chromium.
enum class GarbageCollectionReason : int {
kUnknown = 0,
kAllocationFailure = 1,
kAllocationLimit = 2,
......@@ -162,11 +165,14 @@ enum class GarbageCollectionReason {
kGlobalAllocationLimit = 23,
kMeasureMemory = 24,
kBackgroundAllocationFailure = 25,
// If you add new items here, then update the incremental_marking_reason,
// mark_compact_reason, and scavenge_reason counters in counters.h.
// Also update src/tools/metrics/histograms/enums.xml in chromium.
kLastReason = kBackgroundAllocationFailure,
};
static_assert(kGarbageCollectionReasonMaxValue ==
static_cast<int>(GarbageCollectionReason::kLastReason),
"The value of kGarbageCollectionReasonMaxValue is inconsistent.");
enum class YoungGenerationHandling {
kRegularScavenge = 0,
kFastPromotionDuringScavenge = 1,
......
......@@ -5,6 +5,8 @@
#ifndef V8_LOGGING_COUNTERS_DEFINITIONS_H_
#define V8_LOGGING_COUNTERS_DEFINITIONS_H_
#include "include/v8-internal.h"
namespace v8 {
namespace internal {
......@@ -16,9 +18,11 @@ namespace internal {
HR(code_cache_reject_reason, V8.CodeCacheRejectReason, 1, 6, 6) \
HR(errors_thrown_per_context, V8.ErrorsThrownPerContext, 0, 200, 20) \
HR(debug_feature_usage, V8.DebugFeatureUsage, 1, 7, 7) \
HR(incremental_marking_reason, V8.GCIncrementalMarkingReason, 0, 25, 26) \
HR(incremental_marking_reason, V8.GCIncrementalMarkingReason, 0, \
kGarbageCollectionReasonMaxValue, kGarbageCollectionReasonMaxValue + 1) \
HR(incremental_marking_sum, V8.GCIncrementalMarkingSum, 0, 10000, 101) \
HR(mark_compact_reason, V8.GCMarkCompactReason, 0, 25, 26) \
HR(mark_compact_reason, V8.GCMarkCompactReason, 0, \
kGarbageCollectionReasonMaxValue, kGarbageCollectionReasonMaxValue + 1) \
HR(gc_finalize_clear, V8.GCFinalizeMC.Clear, 0, 10000, 101) \
HR(gc_finalize_epilogue, V8.GCFinalizeMC.Epilogue, 0, 10000, 101) \
HR(gc_finalize_evacuate, V8.GCFinalizeMC.Evacuate, 0, 10000, 101) \
......@@ -33,7 +37,8 @@ namespace internal {
/* Range and bucket matches BlinkGC.MainThreadMarkingThroughput. */ \
HR(gc_main_thread_marking_throughput, V8.GCMainThreadMarkingThroughput, 0, \
100000, 50) \
HR(scavenge_reason, V8.GCScavengeReason, 0, 25, 26) \
HR(scavenge_reason, V8.GCScavengeReason, 0, \
kGarbageCollectionReasonMaxValue, kGarbageCollectionReasonMaxValue + 1) \
HR(young_generation_handling, V8.GCYoungGenerationHandling, 0, 2, 3) \
/* Asm/Wasm. */ \
HR(wasm_functions_per_asm_module, V8.WasmFunctionsPerModule.asm, 1, 1000000, \
......
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