mirror of
https://github.com/varun-r-mallya/sysprof.git
synced 2025-12-31 20:36:25 +00:00
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:
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user