diff --git a/src/libsysprof/meson.build b/src/libsysprof/meson.build index 6b81a9f9..ebe85eb9 100644 --- a/src/libsysprof/meson.build +++ b/src/libsysprof/meson.build @@ -50,6 +50,7 @@ libsysprof_public_sources = [ 'sysprof-proxied-instrument.c', 'sysprof-recording.c', 'sysprof-sampler.c', + 'sysprof-scheduler-details.c', 'sysprof-spawnable.c', 'sysprof-subprocess-output.c', 'sysprof-symbol.c', @@ -114,6 +115,7 @@ libsysprof_public_headers = [ 'sysprof-proxied-instrument.h', 'sysprof-recording.h', 'sysprof-sampler.h', + 'sysprof-scheduler-details.h', 'sysprof-spawnable.h', 'sysprof-subprocess-output.h', 'sysprof-symbol.h', diff --git a/src/libsysprof/sysprof-scheduler-details.c b/src/libsysprof/sysprof-scheduler-details.c new file mode 100644 index 00000000..5c0f4427 --- /dev/null +++ b/src/libsysprof/sysprof-scheduler-details.c @@ -0,0 +1,397 @@ +/* sysprof-scheduler-details.c + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#include "config.h" + +#include "sysprof-instrument-private.h" +#include "sysprof-perf-event-stream-private.h" +#include "sysprof-scheduler-details.h" +#include "sysprof-recording-private.h" + +#include "line-reader-private.h" + +struct _SysprofSchedulerDetails +{ + SysprofInstrument parent_instance; + + SysprofRecording *recording; + DexFuture *cancellable; + GPtrArray *streams; + gint64 *last_switch_times; + + gint64 started_at; + gint64 ended_at; + + gint64 sched_switch_id; + gint64 prev_comm_offset; + gint64 prev_pid_offset; + gint64 prev_state_offset; +}; + +struct _SysprofSchedulerDetailsClass +{ + SysprofInstrumentClass parent_class; +}; + +G_DEFINE_FINAL_TYPE (SysprofSchedulerDetails, sysprof_scheduler_details, SYSPROF_TYPE_INSTRUMENT) + +static void +sysprof_scheduler_details_event_cb (const SysprofPerfEvent *event, + guint cpu, + gpointer user_data) +{ + SysprofSchedulerDetails *self = user_data; + const guint8 *raw; + gint64 begin, end; + glong prev_state; + char prev_comm[16]; + char name[8]; + GPid prev_pid; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + + if (event->header.type != PERF_RECORD_SAMPLE) + return; + + begin = self->last_switch_times[cpu]; + end = event->tracepoint.time; + + if (begin == 0) + goto finish; + + if (self->started_at == 0 || end < self->started_at) + return; + + if (self->ended_at != 0 && begin > self->ended_at) + return; + + raw = event->tracepoint.raw; + + memcpy (&prev_pid, raw + self->prev_pid_offset, sizeof prev_pid); + memcpy (&prev_state, raw + self->prev_state_offset, sizeof prev_state); + memcpy (&prev_comm[0], raw + self->prev_comm_offset, sizeof prev_comm); + + prev_comm[sizeof prev_comm-1] = 0; + + g_snprintf (name, sizeof name, "CPU %u", cpu); + + sysprof_capture_writer_add_mark (self->recording->writer, + begin, + cpu, + event->tracepoint.pid, + end - begin, + "Scheduler", + name, + prev_comm); + +finish: + self->last_switch_times[cpu] = end; +} + +static void +sysprof_scheduler_details_parse_field (SysprofSchedulerDetails *self, + char **parts) +{ + G_GNUC_UNUSED gboolean _signed = FALSE; + gint64 offset = -1; + gint64 size = 0; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + g_assert (parts != NULL); + + for (guint i = 1; parts[i]; i++) + { + if (g_str_has_prefix (parts[i], "offset:")) + offset = g_ascii_strtoll (parts[i] + strlen ("offset:"), NULL, 10); + else if (g_str_has_prefix (parts[i], "size:")) + size = g_ascii_strtoll (parts[i] + strlen ("size:"), NULL, 10); + else if (g_str_has_prefix (parts[i], "signed:")) + _signed = parts[i][strlen ("signed:")] == '1'; + } + + if (offset == -1) + return; + + if (g_str_equal (parts[0], "field:char prev_comm[16];")) + { + if (size == 16) + self->prev_comm_offset = offset; + } + else if (g_str_equal (parts[0], "field:pid_t prev_pid;")) + { + if (size == 4) + self->prev_pid_offset = offset; + } + else if (g_str_equal (parts[0], "field:long prev_state;")) + { + if (size == sizeof (glong)) + self->prev_state_offset = offset; + } +} + +static gboolean +sysprof_scheduler_details_parse_format (SysprofSchedulerDetails *self, + char *format) +{ + LineReader reader; + char *line; + gsize line_len; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + g_assert (format != NULL); + + line_reader_init (&reader, format, -1); + + while ((line = line_reader_next (&reader, &line_len))) + { + line[line_len] = 0; + + if (g_str_has_prefix (line, "ID: ")) + { + if (!(self->sched_switch_id = g_ascii_strtoll (line + strlen ("ID: "), NULL, 10))) + return FALSE; + } + + if (g_str_has_prefix (line, "\t")) + { + g_auto(GStrv) parts = g_strsplit (g_strstrip (line), "\t", 0); + + sysprof_scheduler_details_parse_field (self, parts); + } + } + + return self->sched_switch_id > 0 && + self->prev_comm_offset > 0 && + self->prev_state_offset > 0 && + self->prev_pid_offset > 0; +} + +static DexFuture * +sysprof_scheduler_details_prepare_fiber (gpointer user_data) +{ + SysprofSchedulerDetails *self = user_data; + g_autoptr(GDBusConnection) bus = NULL; + g_autoptr(GPtrArray) futures = NULL; + g_autoptr(GVariant) format_reply = NULL; + g_autoptr(GError) error = NULL; + g_autofree char *format = NULL; + int n_cpu; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + g_assert (SYSPROF_IS_RECORDING (self->recording)); + + if (!(bus = dex_await_object (dex_bus_get (G_BUS_TYPE_SYSTEM), &error))) + goto handle_error; + + if (!(format_reply = dex_await_variant (dex_dbus_connection_call (bus, + "org.gnome.Sysprof3", + "/org/gnome/Sysprof3", + "org.gnome.Sysprof3.Service", + "GetProcFile", + g_variant_new ("(^ay)", "/sys/kernel/debug/tracing/events/sched/sched_switch/format"), + G_VARIANT_TYPE ("(ay)"), + G_DBUS_CALL_FLAGS_ALLOW_INTERACTIVE_AUTHORIZATION, + G_MAXINT), + &error))) + goto handle_error; + + g_variant_get (format_reply, "(^ay)", &format); + + if (!sysprof_scheduler_details_parse_format (self, format)) + { + error = g_error_new_literal (G_IO_ERROR, + G_IO_ERROR_INVALID_DATA, + "Could not parse data in tracepoint format"); + goto handle_error; + } + + futures = g_ptr_array_new_with_free_func (dex_unref); + n_cpu = g_get_num_processors (); + + self->last_switch_times = g_new0 (gint64, n_cpu); + + for (int cpu = 0; cpu < n_cpu; cpu++) + { + struct perf_event_attr attr = {0}; + + attr.type = PERF_TYPE_TRACEPOINT; + attr.type = PERF_TYPE_TRACEPOINT; + attr.sample_type = PERF_SAMPLE_RAW | + PERF_SAMPLE_IP | + PERF_SAMPLE_TID | + PERF_SAMPLE_IDENTIFIER | + PERF_SAMPLE_TIME; + attr.config = self->sched_switch_id; + attr.sample_period = 1; + +#ifdef HAVE_PERF_CLOCKID + attr.clockid = sysprof_clock; + attr.use_clockid = 1; +#endif + + attr.size = sizeof attr; + + g_ptr_array_add (futures, + sysprof_perf_event_stream_new (bus, + &attr, + cpu, + -1, + 0, + sysprof_scheduler_details_event_cb, + self, + NULL)); + } + + /* Create perf stream per-cpu to get sched:sched_switch */ + if (!dex_await (dex_future_allv ((DexFuture **)futures->pdata, futures->len), &error)) + goto handle_error; + + for (int i = 0; i < futures->len; i++) + { + DexFuture *future = g_ptr_array_index (futures, i); + g_autoptr(SysprofPerfEventStream) stream = dex_await_object (dex_ref (future), NULL); + + g_assert (stream != NULL); + g_assert (SYSPROF_IS_PERF_EVENT_STREAM (stream)); + + /* We'll start processing these once start_time is set + * for recording. That way we don't miss anything when + * racing to record. + */ + if (sysprof_perf_event_stream_enable (stream, NULL)) + g_ptr_array_add (self->streams, g_object_ref (stream)); + } + + return dex_future_new_for_boolean (TRUE); + +handle_error: + g_assert (error != NULL); + + _sysprof_recording_diagnostic (self->recording, + "Scheduler", + "Failed to register scheduler tracepoints: %s", + error->message); + + return dex_future_new_for_error (g_steal_pointer (&error)); +} + +static DexFuture * +sysprof_scheduler_details_prepare (SysprofInstrument *instrument, + SysprofRecording *recording) +{ + SysprofSchedulerDetails *self = (SysprofSchedulerDetails *)instrument; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + g_assert (SYSPROF_IS_RECORDING (recording)); + + g_set_object (&self->recording, recording); + + return dex_scheduler_spawn (NULL, 0, + sysprof_scheduler_details_prepare_fiber, + g_object_ref (self), + g_object_unref); +} + +static DexFuture * +sysprof_scheduler_details_record_fiber (gpointer user_data) +{ + SysprofSchedulerDetails *self = user_data; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + g_assert (SYSPROF_IS_RECORDING (self->recording)); + g_assert (DEX_IS_FUTURE (self->cancellable)); + + self->started_at = SYSPROF_CAPTURE_CURRENT_TIME; + dex_await (dex_ref (self->cancellable), NULL); + self->ended_at = SYSPROF_CAPTURE_CURRENT_TIME; + + return dex_future_new_for_boolean (TRUE); +} + +static DexFuture * +sysprof_scheduler_details_record (SysprofInstrument *instrument, + SysprofRecording *recording, + GCancellable *cancellable) +{ + SysprofSchedulerDetails *self = (SysprofSchedulerDetails *)instrument; + + g_assert (SYSPROF_IS_SCHEDULER_DETAILS (self)); + g_assert (SYSPROF_IS_RECORDING (recording)); + g_assert (recording == self->recording); + g_assert (self->cancellable == NULL); + + self->cancellable = dex_cancellable_new_from_cancellable (cancellable); + + return dex_scheduler_spawn (NULL, 0, + sysprof_scheduler_details_record_fiber, + g_object_ref (self), + g_object_unref); +} + +static void +sysprof_scheduler_details_dispose (GObject *object) +{ + SysprofSchedulerDetails *self = (SysprofSchedulerDetails *)object; + + if (self->streams != NULL) + { + for (guint i = 0; i < self->streams->len; i++) + { + SysprofPerfEventStream *stream = g_ptr_array_index (self->streams, i); + sysprof_perf_event_stream_disable (stream, NULL); + } + + g_clear_pointer (&self->streams, g_ptr_array_unref); + } + + g_clear_object (&self->recording); + g_clear_pointer (&self->last_switch_times, g_free); + dex_clear (&self->cancellable); + + G_OBJECT_CLASS (sysprof_scheduler_details_parent_class)->dispose (object); +} + +static void +sysprof_scheduler_details_class_init (SysprofSchedulerDetailsClass *klass) +{ + GObjectClass *object_class = G_OBJECT_CLASS (klass); + SysprofInstrumentClass *instrument_class = SYSPROF_INSTRUMENT_CLASS (klass); + + object_class->dispose = sysprof_scheduler_details_dispose; + + instrument_class->prepare = sysprof_scheduler_details_prepare; + instrument_class->record = sysprof_scheduler_details_record; +} + +static void +sysprof_scheduler_details_init (SysprofSchedulerDetails *self) +{ + self->sched_switch_id = -1; + self->prev_comm_offset = -1; + self->prev_pid_offset = -1; + self->prev_state_offset = -1; + self->streams = g_ptr_array_new_with_free_func (g_object_unref); +} + +SysprofInstrument * +sysprof_scheduler_details_new (void) +{ + return g_object_new (SYSPROF_TYPE_SCHEDULER_DETAILS, NULL); +} diff --git a/src/libsysprof/sysprof-scheduler-details.h b/src/libsysprof/sysprof-scheduler-details.h new file mode 100644 index 00000000..9e4e54d7 --- /dev/null +++ b/src/libsysprof/sysprof-scheduler-details.h @@ -0,0 +1,42 @@ +/* sysprof-scheduler-details.h + * + * Copyright 2023 Christian Hergert + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * SPDX-License-Identifier: GPL-3.0-or-later + */ + +#pragma once + +#include "sysprof-instrument.h" + +G_BEGIN_DECLS + +#define SYSPROF_TYPE_SCHEDULER_DETAILS (sysprof_scheduler_details_get_type()) +#define SYSPROF_IS_SCHEDULER_DETAILS(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, SYSPROF_TYPE_SCHEDULER_DETAILS) +#define SYSPROF_SCHEDULER_DETAILS(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, SYSPROF_TYPE_SCHEDULER_DETAILS, SysprofSchedulerDetails) +#define SYSPROF_SCHEDULER_DETAILS_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, SYSPROF_TYPE_SCHEDULER_DETAILS, SysprofSchedulerDetailsClass) + +typedef struct _SysprofSchedulerDetails SysprofSchedulerDetails; +typedef struct _SysprofSchedulerDetailsClass SysprofSchedulerDetailsClass; + +SYSPROF_AVAILABLE_IN_ALL +GType sysprof_scheduler_details_get_type (void) G_GNUC_CONST; +SYSPROF_AVAILABLE_IN_ALL +SysprofInstrument *sysprof_scheduler_details_new (void); + +G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofSchedulerDetails, g_object_unref) + +G_END_DECLS diff --git a/src/libsysprof/sysprof.h b/src/libsysprof/sysprof.h index cc5c73ce..529386c8 100644 --- a/src/libsysprof/sysprof.h +++ b/src/libsysprof/sysprof.h @@ -76,6 +76,7 @@ G_BEGIN_DECLS # include "sysprof-proxied-instrument.h" # include "sysprof-recording.h" # include "sysprof-sampler.h" +# include "sysprof-scheduler-details.h" # include "sysprof-spawnable.h" # include "sysprof-subprocess-output.h" # include "sysprof-symbol.h" diff --git a/src/libsysprof/tests/test-profiler.c b/src/libsysprof/tests/test-profiler.c index 5fd67381..5df0a8b5 100644 --- a/src/libsysprof/tests/test-profiler.c +++ b/src/libsysprof/tests/test-profiler.c @@ -203,6 +203,8 @@ main (int argc, if (memprof) sysprof_profiler_add_instrument (profiler, sysprof_malloc_tracing_new ()); + sysprof_profiler_add_instrument (profiler, sysprof_scheduler_details_new ()); + if (tracer) sysprof_profiler_add_instrument (profiler, sysprof_tracer_new ()); else diff --git a/src/sysprof-agent/sysprof-agent.c b/src/sysprof-agent/sysprof-agent.c index 67561b97..7a43fce2 100644 --- a/src/sysprof-agent/sysprof-agent.c +++ b/src/sysprof-agent/sysprof-agent.c @@ -68,6 +68,7 @@ static gboolean no_throttle; static gboolean decode; static gboolean do_system_bus; static gboolean do_session_bus; +static gboolean scheduler_details; static const GOptionEntry options[] = { { "read-fd", 0, 0, G_OPTION_ARG_INT, &read_fd, "The read side of the FD to use for D-Bus" }, { "write-fd", 0, 0, G_OPTION_ARG_INT, &write_fd, "The write side of the FD to use for D-Bus" }, @@ -90,6 +91,7 @@ static const GOptionEntry options[] = { { "no-throttle", 0, 0, G_OPTION_ARG_NONE, &no_throttle, "Disable CPU throttling [Deprecated for --power-profile]" }, { "tracefd", 0, 0, G_OPTION_ARG_NONE, &aid_tracefd, "Provide TRACEFD to subprocess" }, { "power-profile", 0, 0, G_OPTION_ARG_STRING, &power_profile, "Use POWER_PROFILE for duration of recording", "power-saver|balanced|performance" }, + { "scheduler", 0, 0, G_OPTION_ARG_NONE, &scheduler_details, "Track when processes are scheduled per CPU" }, { "session-bus", 0, 0, G_OPTION_ARG_NONE, &do_session_bus, "Profile the D-Bus session bus" }, { "system-bus", 0, 0, G_OPTION_ARG_NONE, &do_system_bus, "Profile the D-Bus system bus" }, { NULL } @@ -529,6 +531,9 @@ main (int argc, if (do_system_bus) sysprof_profiler_add_instrument (profiler, sysprof_dbus_monitor_new (G_BUS_TYPE_SYSTEM)); + if (scheduler_details) + sysprof_profiler_add_instrument (profiler, sysprof_scheduler_details_new ()); + if (decode) sysprof_profiler_add_instrument (profiler, sysprof_symbols_bundle_new ()); diff --git a/src/sysprof-cli/sysprof-cli.c b/src/sysprof-cli/sysprof-cli.c index 282418fa..c990fc66 100644 --- a/src/sysprof-cli/sysprof-cli.c +++ b/src/sysprof-cli/sysprof-cli.c @@ -295,6 +295,7 @@ main (int argc, gboolean memprof = FALSE; gboolean merge = FALSE; gboolean speedtrack = FALSE; + gboolean scheduler_details = FALSE; gboolean system_bus = FALSE; gboolean session_bus = FALSE; int pid = -1; @@ -315,6 +316,7 @@ main (int argc, { "no-memory", 0, 0, G_OPTION_ARG_NONE, &no_memory, N_("Disable recording of memory statistics") }, { "no-network", 0, 0, G_OPTION_ARG_NONE, &no_network, N_("Disable recording of network statistics") }, { "use-trace-fd", 0, 0, G_OPTION_ARG_NONE, &use_trace_fd, N_("Set SYSPROF_TRACE_FD environment for subprocess") }, + { "scheduler", 0, 0, G_OPTION_ARG_NONE, &scheduler_details, N_("Track when processes are scheduled") }, { "session-bus", 0, 0, G_OPTION_ARG_NONE, &session_bus, N_("Profile the D-Bus session bus") }, { "system-bus", 0, 0, G_OPTION_ARG_NONE, &system_bus, N_("Profile the D-Bus system bus") }, { "gjs", 0, 0, G_OPTION_ARG_NONE, &gjs, N_("Set GJS_TRACE_FD environment to trace GJS processes") }, @@ -553,6 +555,9 @@ Examples:\n\ if (system_bus) sysprof_profiler_add_instrument (profiler, sysprof_dbus_monitor_new (G_BUS_TYPE_SYSTEM)); + if (scheduler_details) + sysprof_profiler_add_instrument (profiler, sysprof_scheduler_details_new ()); + sysprof_profiler_add_instrument (profiler, g_object_new (SYSPROF_TYPE_SUBPROCESS_OUTPUT, "stdout-path", "eglinfo", diff --git a/src/sysprof/sysprof-greeter.ui b/src/sysprof/sysprof-greeter.ui index 3e2741b0..43abf5d9 100644 --- a/src/sysprof/sysprof-greeter.ui +++ b/src/sysprof/sysprof-greeter.ui @@ -111,6 +111,34 @@ + + + + + include_scheduler_details + Record Scheduler Details + Track when processes are scheduled per CPU + + + center + + + + + + + + Sysprof must launch your application to record JavaScript stacks using GJS. + 0 + 8 + + + + + Tracing diff --git a/src/sysprof/sysprof-memory-section.ui b/src/sysprof/sysprof-memory-section.ui index 8dec6d44..1a48e84c 100644 --- a/src/sysprof/sysprof-memory-section.ui +++ b/src/sysprof/sysprof-memory-section.ui @@ -116,6 +116,7 @@ + false @@ -171,6 +172,7 @@ + false diff --git a/src/sysprof/sysprof-recording-template.c b/src/sysprof/sysprof-recording-template.c index 240ff720..16c97aa0 100644 --- a/src/sysprof/sysprof-recording-template.c +++ b/src/sysprof/sysprof-recording-template.c @@ -45,6 +45,7 @@ struct _SysprofRecordingTemplate guint memory_usage : 1; guint native_stacks : 1; guint network_usage : 1; + guint scheduler_details : 1; guint session_bus : 1; guint system_bus : 1; guint system_log : 1; @@ -70,6 +71,7 @@ enum { PROP_NATIVE_STACKS, PROP_NETWORK_USAGE, PROP_POWER_PROFILE, + PROP_SCHEDULER_DETAILS, PROP_SESSION_BUS, PROP_SYSTEM_BUS, PROP_SYSTEM_LOG, @@ -175,6 +177,10 @@ sysprof_recording_template_get_property (GObject *object, g_value_set_string (value, self->power_profile); break; + case PROP_SCHEDULER_DETAILS: + g_value_set_boolean (value, self->scheduler_details); + break; + case PROP_SESSION_BUS: g_value_set_boolean (value, self->session_bus); break; @@ -275,6 +281,10 @@ sysprof_recording_template_set_property (GObject *object, g_set_str (&self->power_profile, g_value_get_string (value)); break; + case PROP_SCHEDULER_DETAILS: + self->scheduler_details = g_value_get_boolean (value); + break; + case PROP_SESSION_BUS: self->session_bus = g_value_get_boolean (value); break; @@ -391,6 +401,11 @@ sysprof_recording_template_class_init (SysprofRecordingTemplateClass *klass) NULL, (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + properties[PROP_SCHEDULER_DETAILS] = + g_param_spec_boolean ("scheduler-details", NULL, NULL, + FALSE, + (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); + properties[PROP_SESSION_BUS] = g_param_spec_boolean ("session-bus", NULL, NULL, FALSE, @@ -420,6 +435,7 @@ sysprof_recording_template_init (SysprofRecordingTemplate *self) self->memory_usage = TRUE; self->native_stacks = TRUE; self->network_usage = TRUE; + self->scheduler_details = FALSE; self->system_log = TRUE; self->command_line = g_strdup (""); } @@ -595,6 +611,9 @@ sysprof_recording_template_apply (SysprofRecordingTemplate *self, if (self->network_usage) sysprof_profiler_add_instrument (profiler, sysprof_network_usage_new ()); + if (self->scheduler_details) + sysprof_profiler_add_instrument (profiler, sysprof_scheduler_details_new ()); + if (self->session_bus) sysprof_profiler_add_instrument (profiler, sysprof_dbus_monitor_new (G_BUS_TYPE_SESSION)); diff --git a/src/sysprof/sysprof-samples-section.ui b/src/sysprof/sysprof-samples-section.ui index 7b7980be..7f9e100e 100644 --- a/src/sysprof/sysprof-samples-section.ui +++ b/src/sysprof/sysprof-samples-section.ui @@ -121,6 +121,7 @@ + false SysprofSamplesSection diff --git a/src/sysprof/sysprof-time-filter-model.c b/src/sysprof/sysprof-time-filter-model.c index c931041e..4a216563 100644 --- a/src/sysprof/sysprof-time-filter-model.c +++ b/src/sysprof/sysprof-time-filter-model.c @@ -30,16 +30,20 @@ struct _SysprofTimeFilterModel GtkExpression *expression; GtkSliceListModel *slice; SysprofTimeSpan time_span; + guint inclusive : 1; }; enum { PROP_0, PROP_EXPRESSION, + PROP_INCLUSIVE, PROP_MODEL, PROP_TIME_SPAN, N_PROPS }; +static void sysprof_time_filter_model_update (SysprofTimeFilterModel *self); + static GType sysprof_time_filter_model_get_item_type (GListModel *model) { @@ -108,6 +112,10 @@ sysprof_time_filter_model_get_property (GObject *object, gtk_value_set_expression (value, sysprof_time_filter_model_get_expression (self)); break; + case PROP_INCLUSIVE: + g_value_set_boolean (value, self->inclusive); + break; + case PROP_MODEL: g_value_set_object (value, sysprof_time_filter_model_get_model (self)); break; @@ -135,6 +143,11 @@ sysprof_time_filter_model_set_property (GObject *object, sysprof_time_filter_model_set_expression (self, gtk_value_get_expression (value)); break; + case PROP_INCLUSIVE: + self->inclusive = g_value_get_boolean (value); + sysprof_time_filter_model_update (self); + break; + case PROP_MODEL: sysprof_time_filter_model_set_model (self, g_value_get_object (value)); break; @@ -161,6 +174,17 @@ sysprof_time_filter_model_class_init (SysprofTimeFilterModelClass *klass) gtk_param_spec_expression ("expression", NULL, NULL, (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + /** + * SysprofTimeFilterModel:inclusive: + * + * If we're inclusive of items that are off the edge of the + * boundaries. + */ + properties[PROP_INCLUSIVE] = + g_param_spec_boolean ("inclusive", NULL, NULL, + TRUE, + (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); + properties[PROP_MODEL] = g_param_spec_object ("model", NULL, NULL, G_TYPE_LIST_MODEL, @@ -178,6 +202,7 @@ static void sysprof_time_filter_model_init (SysprofTimeFilterModel *self) { self->expression = gtk_property_expression_new (SYSPROF_TYPE_DOCUMENT_FRAME, NULL, "time"); + self->inclusive = TRUE; self->time_span.begin_nsec = G_MININT64; self->time_span.end_nsec = G_MAXINT64; @@ -368,6 +393,19 @@ sysprof_time_filter_model_update (SysprofTimeFilterModel *self) calculate_bounds (self, model, &self->time_span, &offset, &size); + /* We want to extend our selection to adjacent values so that we + * are more likely to include enough data to overlap the boundaries + * when drawing graphs. + * + * This can sort of muck up callgraphs, so it's disabled in those. + */ + if (self->inclusive) + { + if (offset > 0) + offset--; + size++; + } + gtk_slice_list_model_set_offset (self->slice, offset); gtk_slice_list_model_set_size (self->slice, size); }