6161#include " embedded-assemblies.hh"
6262#include " monodroid-glue.hh"
6363#include " monodroid-glue-internal.hh"
64+ #include " monodroid-profiling.hh"
6465#include " globals.hh"
6566#include " xamarin-app.hh"
6667#include " timing.hh"
67- // #include "xa-internal-api-impl.hh"
6868#include " build-info.hh"
6969#include " monovm-properties.hh"
7070#include " startup-aware-lock.hh"
7171#include " timing-internal.hh"
7272#include " search.hh"
7373#include " runtime-util.hh"
7474
75- // #include "xamarin_getifaddrs.h"
76-
7775#include " cpp-util.hh"
7876#include " strings.hh"
7977
@@ -547,7 +545,7 @@ MonodroidRuntime::mono_runtime_init ([[maybe_unused]] JNIEnv *env, [[maybe_unuse
547545{
548546#if defined(PERFETTO_ENABLED)
549547 log_info (LOG_DEFAULT, " Trace event for mono_runtime_init" );
550- TRACE_EVENT (
548+ TRACE_EVENT_BEGIN (
551549 PerfettoConstants::MonoRuntimeCategory.data (),
552550 " mono_runtime_init" ,
553551 PerfettoSupport::get_name_annotated_thread_track<PerfettoTrackId::MonodroidRuntime> ()
@@ -667,12 +665,6 @@ MonodroidRuntime::mono_runtime_init ([[maybe_unused]] JNIEnv *env, [[maybe_unuse
667665 Util::set_world_accessable (jit_log_path.get ());
668666 }
669667
670- profiler_handle = mono_profiler_create (nullptr );
671- mono_profiler_set_thread_started_callback (profiler_handle, thread_start);
672- mono_profiler_set_thread_stopped_callback (profiler_handle, thread_end);
673- #if defined (PERFETTO_ENABLED)
674- perfetto_hook_mono_events ();
675- #endif
676668 if (log_methods) [[unlikely]]{
677669 jit_time.mark_start ();
678670 mono_profiler_set_jit_begin_callback (profiler_handle, jit_begin);
@@ -729,6 +721,13 @@ MonodroidRuntime::mono_runtime_init ([[maybe_unused]] JNIEnv *env, [[maybe_unuse
729721 xamarin_app_init (env, get_function_pointer_at_startup);
730722 }
731723#endif // def RELEASE && def ANDROID && def NET
724+
725+ #if defined(PERFETTO_ENABLED)
726+ TRACE_EVENT_END (
727+ PerfettoConstants::MonoRuntimeCategory.data (),
728+ PerfettoSupport::get_name_annotated_thread_track<PerfettoTrackId::MonodroidRuntime> ()
729+ );
730+ #endif
732731}
733732
734733void
@@ -1584,41 +1583,77 @@ MonodroidRuntime::install_logging_handlers ()
15841583void
15851584MonodroidRuntime::perfetto_init () noexcept
15861585{
1587- log_warn (LOG_TIMING, " INIT perfetto" );
15881586 perfetto::TracingInitArgs args;
15891587 args.backends = perfetto::kSystemBackend ;
15901588
15911589 perfetto::Tracing::Initialize (args);
15921590 perfetto::TrackEvent::Register ();
15931591}
1592+ #endif // def PERFETTO_ENABLED
15941593
15951594void
1596- MonodroidRuntime::perfetto_hook_mono_events () noexcept
1595+ MonodroidRuntime::timing_init_extended () noexcept
15971596{
1598- if (profiler_handle == nullptr ) {
1599- return ;
1600- }
1601-
1602- log_warn (LOG_TIMING, " HOOK perfetto" );
16031597 mono_profiler_set_assembly_loading_callback (profiler_handle, prof_assembly_loading);
16041598 mono_profiler_set_assembly_loaded_callback (profiler_handle, prof_assembly_loaded);
1605- mono_profiler_set_image_loading_callback (profiler_handle, prof_image_loading);
1606- mono_profiler_set_image_loaded_callback (profiler_handle, prof_image_loaded);
16071599
16081600 mono_profiler_set_class_loading_callback (profiler_handle, prof_class_loading);
16091601 mono_profiler_set_class_loaded_callback (profiler_handle, prof_class_loaded);
1610- // mono_profiler_set_vtable_loading_callback (profiler_handle, prof_vtable_loading);
1611- // mono_profiler_set_vtable_loaded_callback (profiler_handle, prof_vtable_loaded);
1612- mono_profiler_set_monitor_contention_callback (profiler_handle, prof_monitor_contention);
1613- mono_profiler_set_monitor_acquired_callback (profiler_handle, prof_monitor_acquired);
16141602
16151603 mono_profiler_set_method_begin_invoke_callback (profiler_handle, prof_method_begin_invoke);
16161604 mono_profiler_set_method_end_invoke_callback (profiler_handle, prof_method_end_invoke);
1617- mono_profiler_set_method_enter_callback (profiler_handle, prof_method_enter);
1618- mono_profiler_set_method_leave_callback (profiler_handle, prof_method_leave);
1605+ }
1606+
1607+ void
1608+ MonodroidRuntime::timing_init_verbose () noexcept
1609+ {
1610+ mono_profiler_set_jit_begin_callback (profiler_handle, jit_begin);
1611+ mono_profiler_set_jit_done_callback (profiler_handle, jit_done);
1612+ mono_profiler_set_jit_failed_callback (profiler_handle, jit_failed);
16191613
1614+ mono_profiler_set_monitor_contention_callback (profiler_handle, prof_monitor_contention);
1615+ mono_profiler_set_monitor_acquired_callback (profiler_handle, prof_monitor_acquired);
16201616}
1617+
1618+ void
1619+ MonodroidRuntime::timing_init_extreme () noexcept
1620+ {
1621+ mono_profiler_set_vtable_loading_callback (profiler_handle, prof_vtable_loading);
1622+ mono_profiler_set_vtable_loaded_callback (profiler_handle, prof_vtable_loaded);
1623+
1624+ mono_profiler_set_image_loading_callback (profiler_handle, prof_image_loading);
1625+ mono_profiler_set_image_loaded_callback (profiler_handle, prof_image_loaded);
1626+ }
1627+
1628+ [[gnu::flatten]] void
1629+ MonodroidRuntime::timing_init () noexcept
1630+ {
1631+ #if !defined(PERFETTO_ENABLED)
1632+ if (!FastTiming::enabled () || FastTiming::mode () == ProfilingMode::Bare) {
1633+ return ;
1634+ }
1635+ #endif
1636+ switch (FastTiming::mode ()) {
1637+ case ProfilingMode::Extreme:
1638+ timing_init_extreme ();
1639+ [[fallthrough]];
1640+
1641+ case ProfilingMode::Verbose:
1642+ timing_init_verbose ();
1643+ [[fallthrough]];
1644+
1645+ #if defined(PERFETTO_ENABLED)
1646+ case ProfilingMode::Bare:
16211647#endif
1648+ case ProfilingMode::Extended:
1649+ timing_init_extended ();
1650+ break ;
1651+
1652+ default :
1653+ // ignored
1654+ break ;
1655+ }
1656+ }
16221657
16231658inline void
16241659MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass klass, jstring lang, jobjectArray runtimeApksJava,
@@ -1627,7 +1662,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16271662 jboolean haveSplitApks)
16281663{
16291664#if defined(PERFETTO_ENABLED)
1630- TRACE_EVENT (
1665+ TRACE_EVENT_BEGIN (
16311666 PerfettoConstants::MonoRuntimeCategory.data (),
16321667 " initInternal" ,
16331668 PerfettoSupport::get_name_annotated_thread_track<PerfettoTrackId::MonodroidRuntime> ()
@@ -1644,6 +1679,11 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
16441679 // If fast logging is disabled, log messages immediately
16451680 FastTiming::initialize ((Logger::log_timing_categories () & LogTimingCategories::FastBare) != LogTimingCategories::FastBare);
16461681
1682+ profiler_handle = mono_profiler_create (nullptr );
1683+ mono_profiler_set_thread_started_callback (profiler_handle, thread_start);
1684+ mono_profiler_set_thread_stopped_callback (profiler_handle, thread_end);
1685+ timing_init ();
1686+
16471687 size_t total_time_index;
16481688 if (FastTiming::enabled ()) [[unlikely]] {
16491689 timing = new Timing ();
@@ -1759,13 +1799,7 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
17591799 }
17601800
17611801 mono_runtime_init (env, runtime_args);
1762- #if defined(PERFETTO_ENABLED)
1763- TRACE_EVENT (
1764- PerfettoConstants::MonoRuntimeCategory.data (),
1765- " initInternal_2" ,
1766- PerfettoSupport::get_name_annotated_thread_track<PerfettoTrackId::MonodroidRuntime> ()
1767- );
1768- #endif
1802+
17691803 if (FastTiming::enabled ()) [[unlikely]] {
17701804 internal_timing->end_event (mono_runtime_init_index);
17711805 }
@@ -1807,6 +1841,10 @@ MonodroidRuntime::Java_mono_android_Runtime_initInternal (JNIEnv *env, jclass kl
18071841 startup_in_progress = false ;
18081842
18091843#if defined(PERFETTO_ENABLED)
1844+ TRACE_EVENT_END (
1845+ PerfettoConstants::MonoRuntimeCategory.data (),
1846+ PerfettoSupport::get_name_annotated_thread_track<PerfettoTrackId::MonodroidRuntime> ()
1847+ );
18101848 perfetto::TrackEvent::Flush ();
18111849#endif
18121850}
0 commit comments