libsysprof: fallback to software perf counters

If we fail to enable hardware perf counters, fallback to software perf
counters. This fixes Sysprof to work on Fedora Asahi.
This commit is contained in:
Christian Hergert
2023-10-23 22:27:04 +00:00
parent 98634cdaa6
commit d852115de1

View File

@ -256,6 +256,7 @@ sysprof_sampler_prepare_fiber (gpointer user_data)
struct perf_event_attr attr = {0};
gboolean with_mmap2 = TRUE;
guint n_cpu;
gboolean use_software = FALSE;
g_assert (prepare != NULL);
g_assert (SYSPROF_IS_RECORDING (prepare->recording));
@ -314,9 +315,18 @@ try_again:
attr.size = sizeof attr;
attr.type = PERF_TYPE_HARDWARE;
attr.config = PERF_COUNT_HW_CPU_CYCLES;
attr.sample_period = 1200000;
if (use_software)
{
attr.type = PERF_TYPE_SOFTWARE;
attr.config = PERF_COUNT_SW_CPU_CLOCK;
attr.sample_period = 1000000;
}
else
{
attr.type = PERF_TYPE_HARDWARE;
attr.config = PERF_COUNT_HW_CPU_CYCLES;
attr.sample_period = 1200000;
}
if (!(connection = dex_await_object (dex_bus_get (G_BUS_TYPE_SYSTEM), &error)))
return dex_future_new_for_error (g_steal_pointer (&error));
@ -367,6 +377,14 @@ try_again:
goto try_again;
}
if (use_software == FALSE)
{
with_mmap2 = TRUE;
use_software = TRUE;
g_ptr_array_remove_range (futures, 0, futures->len);
goto try_again;
}
return dex_future_new_for_error (g_steal_pointer (&error));
}
}