Add js-profiling-mode enum Document Policy with eager/lazy V8 profiler initialization [chromium/src : main]

0 views
Skip to first unread message

Michal Mocny (Gerrit)

unread,
Feb 19, 2026, 10:10:27 AM (3 days ago) Feb 19
to Thomas BERTET, Chromium Metrics Reviews, chromium...@chromium.org, Luna Lu, asvitkine...@chromium.org, blink-re...@chromium.org, blink-...@chromium.org, core-timi...@chromium.org, iclella...@chromium.org, ipc-securi...@chromium.org, jmedle...@chromium.org, kinuko...@chromium.org, speed-metrics...@chromium.org
Attention needed from Thomas BERTET

Michal Mocny added 11 comments

Patchset-level comments
File-level comment, Patchset 2 (Latest):
Michal Mocny . resolved

This is not my area of code expertise (doc policy not js profiling) but here is an initial review.

I haven't really analyzed the tests, but I think this is a solid start and we can expand the test cases a bit later, as needed.

You may be able/want to address some of my superficial comments, but don't hesitate to start to ask experts to start review for feedback / guidance on direction.

Commit Message
Line 13, Patchset 2 (Latest):This is the first enum-type Document Policy feature in Chromium.
Michal Mocny . resolved

Fancy!

File third_party/blink/common/permissions_policy/document_policy.cc
Line 40, Patchset 2 (Latest):const char* EnumValueToToken(int32_t value) {
Michal Mocny . unresolved

Style on returning char* based strings...

Line 58, Patchset 2 (Latest): const char* token = EnumValueToToken(value.IntValue());
Michal Mocny . unresolved

So *any* enum will map to this specific enum values?

This feels fine as a local prototype, but I think you need some machinery to handle mapping the right enum type to the right enum strings. As a bad alternative, find a way to break this loudly when the next enum type is introduced so the next person has to deal with it...

File third_party/blink/renderer/core/permissions_policy/document_policy_features.json5
Line 108, Patchset 2 (Latest): default_value: "0",
Michal Mocny . unresolved

The `default_value` of `0` corresponds to `JSProfilingMode::kNone`. However, there isn't a corresponding token in `TokenToEnumValue` (line 29 in `document_policy_parser.cc`) or `EnumValueToToken` (line 40 in `document_policy.cc`) to represent `kNone`.

This means that while `kNone` is the default, it cannot be explicitly set via a Document Policy header. Only `eager` and `lazy` can be specified.

Is this intentional? If so, it might be worth adding a comment to clarify that `kNone` is an implicit default and cannot be set explicitly via the policy header, to avoid confusion if someone tries to write `js-profiling-mode='none'`.

File third_party/blink/renderer/core/permissions_policy/document_policy_parser.cc
Line 29, Patchset 2 (Latest):std::optional<int32_t> TokenToEnumValue(const std::string& token) {
Michal Mocny . unresolved

Hmm, we go from enum string to enum value back to enum string later... Ideally these to_string and from_string would be defined together, indeally in `profiler_group.h`?

(Also this implementation has the same issue as the other one in that its generic for all enums but specific to this particular enum.)

---

WDYT about adding a second enum directly to `third_party/blink/public/mojom/permissions_policy/document_policy_feature.mojom`?

And then use `document_policy_features.json5`?

...that might need some build file pre-processing changes to support enum *values*, but I think this feels like the correct approach.

(I'm totally new to this area, but this is what I found with a bit of digging.)

File third_party/blink/renderer/core/timing/profiler_group.h
Line 89, Patchset 2 (Latest): void InitV8Profiler(v8::CpuProfilingLoggingMode logging_mode);
Michal Mocny . unresolved

Similarly here, can we just have one variant?

Line 76, Patchset 2 (Latest): void OnProfilingContextAddedLazy(ExecutionContext* context);
Michal Mocny . unresolved

Nit: Just add a mode arg to the method above, with a default of eager?

File third_party/blink/renderer/core/timing/profiler_group.cc
Line 80, Patchset 2 (Latest): int32_t enum_val = mode_value.IntValue();
if (enum_val == static_cast<int32_t>(JSProfilingMode::kEager) ||
enum_val == static_cast<int32_t>(JSProfilingMode::kLazy)) {
return static_cast<JSProfilingMode>(enum_val);
}
Michal Mocny . unresolved

Nit: style, but let's iterate on the design of the enum first

Line 104, Patchset 2 (Latest): return true;
Michal Mocny . unresolved

If `GetProfilingMode()` returns `kNone`, it means that `IsFeatureEnabled(kJSProfiling)` has already returned `false`. Therefore, the `IsFeatureEnabled` check on line 102 will also be `false`, making this `return true;` unreachable.

Additionally, my understanding is that `IsFeatureEnabled` do some logging/reporting and the GetProfilingMode would skip its check if the new profiling mode was supplied without the general profiling policy.

---

If kJSProfiling is still required alongside kJSProfilingMode, I think you could swap the order of feature detection and if kJSProfiling is disabled always return kNone, otherwise return provided policy or default to eager.

If kJSProfiling is optional... maybe the current implementation is fine, but perhaps add a comment here?

Line 177, Patchset 2 (Latest): context_observers_.insert(observer);
Michal Mocny . unresolved

THis will require expert review, but, it surpises me that you can init via `InitV8Profiler(v8::kLazyLogging);` but that we choose not to do so.

So you can have tri-state:

  • Un-init
  • Init w/ Lazy
  • Init w/ Eager

This document policy adds 2 modes and picks (1) and (3).

(But it also creates a `ProfilingContextObserver` eagerly, which afaik isn't needed until you start to profile? Not sure.)

Open in Gerrit

Related details

Attention is currently required from:
  • Thomas BERTET
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: If3e61ee55318b46bf2b07a16d113a5a388f7bf67
Gerrit-Change-Number: 7575656
Gerrit-PatchSet: 2
Gerrit-Owner: Thomas BERTET <thomas...@gmail.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Luna Lu <loon...@chromium.org>
Gerrit-CC: Michal Mocny <mmo...@chromium.org>
Gerrit-Attention: Thomas BERTET <thomas...@gmail.com>
Gerrit-Comment-Date: Thu, 19 Feb 2026 15:10:20 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages