Skip to content

trace_region on Android and Windows#58

Open
ryantrem wants to merge 7 commits intomicrosoft:masterfrom
ryantrem:trace-region-more-platforms
Open

trace_region on Android and Windows#58
ryantrem wants to merge 7 commits intomicrosoft:masterfrom
ryantrem:trace-region-more-platforms

Conversation

@ryantrem
Copy link
Copy Markdown
Member

@ryantrem ryantrem commented Mar 31, 2026

This pull request implements platform-specific trace_region classes for Android and Windows, providing cross-platform tracing support for performance analysis. Each implementation uses the native tracing APIs on its platform (Android NDK ATrace, Apple os_signpost, Windows ETW TraceLogging) and ensures that trace regions can be correlated across threads and viewed in their respective profiling tools. The changes also improve move semantics, logging, and runtime feature detection.

Platform-specific tracing implementations:

  • Android (Source/Android/arcana/tracing/trace_region.h):
    • Implements trace_region using the NDK ATrace async API, supporting cross-thread trace regions and runtime detection of async tracing support for devices below API 29. Logging to logcat is enabled at the log trace level. [1] [2]
image
  • Apple (Source/Apple/arcana/tracing/trace_region.h):

    • Implements trace_region using os_signpost, with detailed instructions for capturing and viewing traces in Instruments. Supports cross-thread correlation using unique os_signpost_id_t.
  • Windows (Source/Windows/arcana/tracing/trace_region.h):

    • Implements trace_region using ETW TraceLogging, emitting activity start/stop pairs with unique GUIDs for cross-thread correlation. Provides instructions for capturing and analyzing traces with WPA or PerfView. Debug logging is sent to OutputDebugStringA.
image

Improvements to trace_region API and semantics:

  • Adds move constructor and move assignment operator to trace_region, ensuring safe transfer of region ownership without emitting duplicate end events. [1] [2]
  • Stores region name as std::string to ensure correct lifetime and matching for begin/end events across threads. [1] [2]

Runtime and logging enhancements:

  • Enables or disables tracing and logging at runtime via static methods, with logging output directed to platform-appropriate sinks (logcat, OutputDebugStringA). [1] [2]
  • On Android, resolves async trace functions at runtime using dlsym for compatibility with older devices.

These changes provide robust, cross-platform tracing primitives that integrate with each platform's native profiling tools, improving the ability to analyze and debug performance issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant