Skip to content

[Native] Migrate timing logging to printf#12153

Open
simonrozsival wants to merge 5 commits into
dev/simonrozsival/nativeaot-printf-loggingfrom
dev/simonrozsival/nativeaot-timing-printf-logging
Open

[Native] Migrate timing logging to printf#12153
simonrozsival wants to merge 5 commits into
dev/simonrozsival/nativeaot-printf-loggingfrom
dev/simonrozsival/nativeaot-timing-printf-logging

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Jul 17, 2026

Copy link
Copy Markdown
Member

Summary

Continue the printf-style logging migration introduced by #12140 in the shared native timing infrastructure.

The timing headers are used by MonoVM, CoreCLR, and NativeAOT. All three runtimes now use the same printf-style path for variable timing diagnostics rather than maintaining MonoVM-only std::format branches.

Base/dependency: #12140 must merge first. This PR targets dev/simonrozsival/nativeaot-printf-logging so its diff contains only the timing migration.

Part of #12139.

Scope

Only two shared timing headers change:

  • src/native/common/include/runtime-base/timing.hh
  • src/native/common/include/runtime-base/timing-internal.hh

These files do not overlap #12141, #12142, #12145, #12148, #12150, or #12155.

Changes

Managed timing records

  • replace the owning std::format result in Timing::do_log() with log_writef() for every runtime;
  • preserve the exact message; elapsed: seconds:milliseconds::nanoseconds field order;
  • pass duration values as explicitly converted unsigned long long values matching %llu.

Fast timing diagnostics

Migrate variable diagnostics to log_warnf() for every runtime:

  • timing event buffer reallocation sizes;
  • CLOCK_MONOTONIC_RAW errors;
  • unknown event-kind values;
  • invalid event-index source method names.

Constant warning messages continue using the existing non-formatting string_view overload.

Behavior preserved

  • timing enablement and category gating are unchanged;
  • timing sequence acquisition/release is unchanged;
  • elapsed duration units, values, and output order are unchanged;
  • event-buffer growth, clock error handling, unknown-event fallback, and index validation are unchanged;
  • no timing data structures, locks, vectors, strings, or event lifecycle code change.

Runtime behavior

Runtime Result
NativeAOT Uses #12140 printf helpers for variable timing diagnostics
CoreCLR Uses #12140 printf helpers for variable timing diagnostics
MonoVM Uses the matching MonoVM printf helper implementation from #12140

Measured impact

Representative Android arm64 Release objects compiled before the MonoVM path was unified:

Runtime/object Before After Difference
CoreCLR internal-pinvokes-clr.cc.o 145,472 B 17,080 B -128,392 B (-88.26%)
NativeAOT host.cc.o 176,104 B 175,960 B -144 B

CoreCLR's representative object drops from 58 formatting symbols to zero. NativeAOT's representative object still contains formatting symbols from other included functionality, but the timing call sites migrated here no longer instantiate them.

Non-goals

  • no new timing tests or logging test framework;
  • no change to timing data ownership or synchronization;
  • no changes to the logging helper implementation introduced by [Native] Add printf-style native logging #12140;
  • no attempt to migrate unrelated timing output/file-generation code outside these shared timing headers.

Validation

  • git diff --check;
  • NDK Clang C++23 syntax compilation of all 36 Android arm64 Release NativeAOT source variants;
  • NDK Clang C++23 syntax compilation of all 38 Android arm64 Release CoreCLR source variants;
  • NDK Clang C++23 syntax compilation of all 31 Android arm64 Release MonoVM source variants;
  • representative before/after object compilation, size comparison, and symbol inspection;
  • focused review of chrono values, integer format widths, source-location output, and category semantics;
  • latest head: 21ff66b26.

Use #12140 printf helpers for shared timing diagnostics while preserving MonoVM std::format behavior.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Migrates shared native timing logging for CoreCLR/NativeAOT to the printf-style helpers introduced in #12140, while keeping MonoVM’s existing std::format-based timing output behind XA_HOST_MONOVM.

Changes:

  • Switch Timing::do_log() (managed timing records) to log_writef() for CoreCLR/NativeAOT while preserving MonoVM’s std::format path.
  • Migrate several FastTiming diagnostics (buffer growth, clock failures, unknown kinds, invalid indices) to log_warnf() for CoreCLR/NativeAOT, preserving MonoVM’s existing logging path.
Show a summary per file
File Description
src/native/common/include/runtime-base/timing.hh Use log_writef() for CoreCLR/NativeAOT managed timing record formatting; keep MonoVM on std::format.
src/native/common/include/runtime-base/timing-internal.hh Use log_warnf() for CoreCLR/NativeAOT FastTiming diagnostics under compile-time guards; keep MonoVM behavior unchanged.

Copilot's findings

  • Files reviewed: 2/2 changed files
  • Comments generated: 1

Comment thread src/native/common/include/runtime-base/timing-internal.hh Outdated
@simonrozsival simonrozsival added the drop-libcpp Work to remove the libc++ dependency from Android NativeAOT label Jul 17, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
@simonrozsival simonrozsival changed the title [CoreCLR/NativeAOT] Migrate timing logging to printf [Native] Migrate timing logging to printf Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

drop-libcpp Work to remove the libc++ dependency from Android NativeAOT

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants