From ae571f3f6e3332e3353b9a833eb1097ebe5d427e Mon Sep 17 00:00:00 2001 From: Christian Hergert Date: Wed, 12 Jul 2023 10:00:11 -0700 Subject: [PATCH] libsysprof-ui: remove legacy libsysprof-ui library This is libsysprof-gtk now, but that too will be absorbed by sysprof app directly rather than having a UI library. --- .../css/SysprofDisplay-shared.css | 86 - .../css/SysprofEnvironEditor-shared.css | 13 - .../css/SysprofProfilerAssistant-shared.css | 7 - src/libsysprof-ui/egg-handle-private.h | 35 - src/libsysprof-ui/egg-handle.c | 145 -- src/libsysprof-ui/egg-paned-private.h | 48 - src/libsysprof-ui/egg-paned.c | 593 ------- src/libsysprof-ui/egg-resizer-private.h | 40 - src/libsysprof-ui/egg-resizer.c | 495 ------ src/libsysprof-ui/libsysprof-ui.gresource.xml | 30 - src/libsysprof-ui/meson.build | 136 -- src/libsysprof-ui/pointcache.c | 116 -- src/libsysprof-ui/pointcache.h | 52 - src/libsysprof-ui/rectangles.c | 248 --- src/libsysprof-ui/rectangles.h | 48 - src/libsysprof-ui/sysprof-aid-icon.c | 211 --- src/libsysprof-ui/sysprof-aid-icon.h | 39 - src/libsysprof-ui/sysprof-aid-icon.ui | 41 - src/libsysprof-ui/sysprof-aid.c | 353 ---- src/libsysprof-ui/sysprof-aid.h | 76 - src/libsysprof-ui/sysprof-battery-aid.c | 242 --- src/libsysprof-ui/sysprof-battery-aid.h | 33 - src/libsysprof-ui/sysprof-cairo.c | 71 - src/libsysprof-ui/sysprof-callgraph-aid.c | 275 --- src/libsysprof-ui/sysprof-callgraph-aid.h | 33 - src/libsysprof-ui/sysprof-callgraph-page.c | 1299 -------------- src/libsysprof-ui/sysprof-callgraph-page.h | 51 - src/libsysprof-ui/sysprof-callgraph-page.ui | 212 --- .../sysprof-cell-renderer-duration.c | 455 ----- .../sysprof-cell-renderer-duration.h | 41 - .../sysprof-cell-renderer-percent.c | 139 -- .../sysprof-cell-renderer-percent.h | 57 - .../sysprof-cell-renderer-progress.c | 712 -------- .../sysprof-cell-renderer-progress.h | 53 - src/libsysprof-ui/sysprof-check.c | 106 -- src/libsysprof-ui/sysprof-check.h | 37 - src/libsysprof-ui/sysprof-color-cycle.c | 157 -- src/libsysprof-ui/sysprof-color-cycle.h | 41 - src/libsysprof-ui/sysprof-counters-aid.c | 284 --- src/libsysprof-ui/sysprof-counters-aid.h | 33 - src/libsysprof-ui/sysprof-cpu-aid.c | 357 ---- src/libsysprof-ui/sysprof-cpu-aid.h | 33 - src/libsysprof-ui/sysprof-depth-visualizer.c | 453 ----- src/libsysprof-ui/sysprof-depth-visualizer.h | 40 - src/libsysprof-ui/sysprof-details-page.c | 325 ---- src/libsysprof-ui/sysprof-details-page.h | 57 - src/libsysprof-ui/sysprof-details-page.ui | 361 ---- src/libsysprof-ui/sysprof-diskstat-aid.c | 269 --- src/libsysprof-ui/sysprof-diskstat-aid.h | 33 - src/libsysprof-ui/sysprof-display-private.h | 29 - src/libsysprof-ui/sysprof-display.c | 1340 -------------- src/libsysprof-ui/sysprof-display.h | 96 - src/libsysprof-ui/sysprof-display.ui | 71 - src/libsysprof-ui/sysprof-duplex-visualizer.c | 633 ------- src/libsysprof-ui/sysprof-duplex-visualizer.h | 45 - .../sysprof-environ-editor-row.c | 277 --- .../sysprof-environ-editor-row.h | 38 - .../sysprof-environ-editor-row.ui | 40 - src/libsysprof-ui/sysprof-environ-editor.c | 343 ---- src/libsysprof-ui/sysprof-environ-editor.h | 38 - src/libsysprof-ui/sysprof-environ-variable.c | 185 -- src/libsysprof-ui/sysprof-environ-variable.h | 40 - src/libsysprof-ui/sysprof-environ.c | 379 ---- src/libsysprof-ui/sysprof-environ.h | 52 - src/libsysprof-ui/sysprof-failed-state-view.c | 62 - src/libsysprof-ui/sysprof-failed-state-view.h | 41 - .../sysprof-failed-state-view.ui | 47 - src/libsysprof-ui/sysprof-line-visualizer.c | 909 ---------- src/libsysprof-ui/sysprof-line-visualizer.h | 57 - src/libsysprof-ui/sysprof-log-model.c | 422 ----- src/libsysprof-ui/sysprof-log-model.h | 49 - src/libsysprof-ui/sysprof-logs-aid.c | 237 --- src/libsysprof-ui/sysprof-logs-aid.h | 33 - src/libsysprof-ui/sysprof-logs-page.c | 116 -- src/libsysprof-ui/sysprof-logs-page.h | 31 - src/libsysprof-ui/sysprof-logs-page.ui | 73 - src/libsysprof-ui/sysprof-mark-detail.c | 208 --- src/libsysprof-ui/sysprof-mark-detail.h | 37 - src/libsysprof-ui/sysprof-mark-visualizer.c | 276 --- src/libsysprof-ui/sysprof-mark-visualizer.h | 47 - src/libsysprof-ui/sysprof-marks-aid.c | 490 ------ src/libsysprof-ui/sysprof-marks-aid.h | 33 - src/libsysprof-ui/sysprof-marks-model.c | 592 ------- src/libsysprof-ui/sysprof-marks-model.h | 65 - src/libsysprof-ui/sysprof-marks-page.c | 610 ------- src/libsysprof-ui/sysprof-marks-page.h | 44 - src/libsysprof-ui/sysprof-marks-page.ui | 259 --- src/libsysprof-ui/sysprof-memory-aid.c | 70 - src/libsysprof-ui/sysprof-memory-aid.h | 33 - src/libsysprof-ui/sysprof-memprof-aid.c | 226 --- src/libsysprof-ui/sysprof-memprof-aid.h | 33 - src/libsysprof-ui/sysprof-memprof-page.c | 1552 ----------------- src/libsysprof-ui/sysprof-memprof-page.h | 51 - src/libsysprof-ui/sysprof-memprof-page.ui | 330 ---- .../sysprof-memprof-visualizer.c | 613 ------- .../sysprof-memprof-visualizer.h | 33 - src/libsysprof-ui/sysprof-model-filter.c | 497 ------ src/libsysprof-ui/sysprof-model-filter.h | 60 - src/libsysprof-ui/sysprof-netdev-aid.c | 266 --- src/libsysprof-ui/sysprof-netdev-aid.h | 33 - src/libsysprof-ui/sysprof-notebook.c | 561 ------ src/libsysprof-ui/sysprof-notebook.h | 85 - src/libsysprof-ui/sysprof-page.c | 256 --- src/libsysprof-ui/sysprof-page.h | 88 - src/libsysprof-ui/sysprof-process-model-row.c | 258 --- src/libsysprof-ui/sysprof-process-model-row.h | 54 - .../sysprof-process-model-row.ui | 52 - src/libsysprof-ui/sysprof-procs-visualizer.c | 296 ---- src/libsysprof-ui/sysprof-procs-visualizer.h | 33 - .../sysprof-profiler-assistant.c | 493 ------ .../sysprof-profiler-assistant.h | 37 - .../sysprof-profiler-assistant.ui | 279 --- src/libsysprof-ui/sysprof-proxy-aid.c | 209 --- src/libsysprof-ui/sysprof-proxy-aid.h | 46 - src/libsysprof-ui/sysprof-rapl-aid.c | 253 --- src/libsysprof-ui/sysprof-rapl-aid.h | 33 - .../sysprof-recording-state-view.c | 202 --- .../sysprof-recording-state-view.h | 41 - .../sysprof-recording-state-view.ui | 83 - src/libsysprof-ui/sysprof-scrollmap.c | 333 ---- src/libsysprof-ui/sysprof-scrollmap.h | 40 - src/libsysprof-ui/sysprof-tab.c | 158 -- src/libsysprof-ui/sysprof-tab.h | 35 - src/libsysprof-ui/sysprof-tab.ui | 36 - src/libsysprof-ui/sysprof-theme-manager.c | 269 --- src/libsysprof-ui/sysprof-theme-manager.h | 47 - src/libsysprof-ui/sysprof-time-label.c | 117 -- src/libsysprof-ui/sysprof-time-label.h | 34 - src/libsysprof-ui/sysprof-time-visualizer.c | 543 ------ src/libsysprof-ui/sysprof-time-visualizer.h | 54 - src/libsysprof-ui/sysprof-ui-private.h | 48 - src/libsysprof-ui/sysprof-ui.h | 41 - .../sysprof-visualizer-group-header.c | 241 --- .../sysprof-visualizer-group-header.h | 31 - .../sysprof-visualizer-group-private.h | 45 - src/libsysprof-ui/sysprof-visualizer-group.c | 471 ----- src/libsysprof-ui/sysprof-visualizer-group.h | 76 - src/libsysprof-ui/sysprof-visualizer-ticks.c | 324 ---- src/libsysprof-ui/sysprof-visualizer-ticks.h | 35 - src/libsysprof-ui/sysprof-visualizer.c | 289 --- src/libsysprof-ui/sysprof-visualizer.h | 88 - src/libsysprof-ui/sysprof-visualizers-frame.c | 721 -------- src/libsysprof-ui/sysprof-visualizers-frame.h | 52 - .../sysprof-visualizers-frame.ui | 242 --- src/libsysprof-ui/sysprof-zoom-manager.c | 661 ------- src/libsysprof-ui/sysprof-zoom-manager.h | 59 - src/meson.build | 1 - src/tests/meson.build | 33 - 148 files changed, 29695 deletions(-) delete mode 100644 src/libsysprof-ui/css/SysprofDisplay-shared.css delete mode 100644 src/libsysprof-ui/css/SysprofEnvironEditor-shared.css delete mode 100644 src/libsysprof-ui/css/SysprofProfilerAssistant-shared.css delete mode 100644 src/libsysprof-ui/egg-handle-private.h delete mode 100644 src/libsysprof-ui/egg-handle.c delete mode 100644 src/libsysprof-ui/egg-paned-private.h delete mode 100644 src/libsysprof-ui/egg-paned.c delete mode 100644 src/libsysprof-ui/egg-resizer-private.h delete mode 100644 src/libsysprof-ui/egg-resizer.c delete mode 100644 src/libsysprof-ui/libsysprof-ui.gresource.xml delete mode 100644 src/libsysprof-ui/meson.build delete mode 100644 src/libsysprof-ui/pointcache.c delete mode 100644 src/libsysprof-ui/pointcache.h delete mode 100644 src/libsysprof-ui/rectangles.c delete mode 100644 src/libsysprof-ui/rectangles.h delete mode 100644 src/libsysprof-ui/sysprof-aid-icon.c delete mode 100644 src/libsysprof-ui/sysprof-aid-icon.h delete mode 100644 src/libsysprof-ui/sysprof-aid-icon.ui delete mode 100644 src/libsysprof-ui/sysprof-aid.c delete mode 100644 src/libsysprof-ui/sysprof-aid.h delete mode 100644 src/libsysprof-ui/sysprof-battery-aid.c delete mode 100644 src/libsysprof-ui/sysprof-battery-aid.h delete mode 100644 src/libsysprof-ui/sysprof-cairo.c delete mode 100644 src/libsysprof-ui/sysprof-callgraph-aid.c delete mode 100644 src/libsysprof-ui/sysprof-callgraph-aid.h delete mode 100644 src/libsysprof-ui/sysprof-callgraph-page.c delete mode 100644 src/libsysprof-ui/sysprof-callgraph-page.h delete mode 100644 src/libsysprof-ui/sysprof-callgraph-page.ui delete mode 100644 src/libsysprof-ui/sysprof-cell-renderer-duration.c delete mode 100644 src/libsysprof-ui/sysprof-cell-renderer-duration.h delete mode 100644 src/libsysprof-ui/sysprof-cell-renderer-percent.c delete mode 100644 src/libsysprof-ui/sysprof-cell-renderer-percent.h delete mode 100644 src/libsysprof-ui/sysprof-cell-renderer-progress.c delete mode 100644 src/libsysprof-ui/sysprof-cell-renderer-progress.h delete mode 100644 src/libsysprof-ui/sysprof-check.c delete mode 100644 src/libsysprof-ui/sysprof-check.h delete mode 100644 src/libsysprof-ui/sysprof-color-cycle.c delete mode 100644 src/libsysprof-ui/sysprof-color-cycle.h delete mode 100644 src/libsysprof-ui/sysprof-counters-aid.c delete mode 100644 src/libsysprof-ui/sysprof-counters-aid.h delete mode 100644 src/libsysprof-ui/sysprof-cpu-aid.c delete mode 100644 src/libsysprof-ui/sysprof-cpu-aid.h delete mode 100644 src/libsysprof-ui/sysprof-depth-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-depth-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-details-page.c delete mode 100644 src/libsysprof-ui/sysprof-details-page.h delete mode 100644 src/libsysprof-ui/sysprof-details-page.ui delete mode 100644 src/libsysprof-ui/sysprof-diskstat-aid.c delete mode 100644 src/libsysprof-ui/sysprof-diskstat-aid.h delete mode 100644 src/libsysprof-ui/sysprof-display-private.h delete mode 100644 src/libsysprof-ui/sysprof-display.c delete mode 100644 src/libsysprof-ui/sysprof-display.h delete mode 100644 src/libsysprof-ui/sysprof-display.ui delete mode 100644 src/libsysprof-ui/sysprof-duplex-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-duplex-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-environ-editor-row.c delete mode 100644 src/libsysprof-ui/sysprof-environ-editor-row.h delete mode 100644 src/libsysprof-ui/sysprof-environ-editor-row.ui delete mode 100644 src/libsysprof-ui/sysprof-environ-editor.c delete mode 100644 src/libsysprof-ui/sysprof-environ-editor.h delete mode 100644 src/libsysprof-ui/sysprof-environ-variable.c delete mode 100644 src/libsysprof-ui/sysprof-environ-variable.h delete mode 100644 src/libsysprof-ui/sysprof-environ.c delete mode 100644 src/libsysprof-ui/sysprof-environ.h delete mode 100644 src/libsysprof-ui/sysprof-failed-state-view.c delete mode 100644 src/libsysprof-ui/sysprof-failed-state-view.h delete mode 100644 src/libsysprof-ui/sysprof-failed-state-view.ui delete mode 100644 src/libsysprof-ui/sysprof-line-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-line-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-log-model.c delete mode 100644 src/libsysprof-ui/sysprof-log-model.h delete mode 100644 src/libsysprof-ui/sysprof-logs-aid.c delete mode 100644 src/libsysprof-ui/sysprof-logs-aid.h delete mode 100644 src/libsysprof-ui/sysprof-logs-page.c delete mode 100644 src/libsysprof-ui/sysprof-logs-page.h delete mode 100644 src/libsysprof-ui/sysprof-logs-page.ui delete mode 100644 src/libsysprof-ui/sysprof-mark-detail.c delete mode 100644 src/libsysprof-ui/sysprof-mark-detail.h delete mode 100644 src/libsysprof-ui/sysprof-mark-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-mark-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-marks-aid.c delete mode 100644 src/libsysprof-ui/sysprof-marks-aid.h delete mode 100644 src/libsysprof-ui/sysprof-marks-model.c delete mode 100644 src/libsysprof-ui/sysprof-marks-model.h delete mode 100644 src/libsysprof-ui/sysprof-marks-page.c delete mode 100644 src/libsysprof-ui/sysprof-marks-page.h delete mode 100644 src/libsysprof-ui/sysprof-marks-page.ui delete mode 100644 src/libsysprof-ui/sysprof-memory-aid.c delete mode 100644 src/libsysprof-ui/sysprof-memory-aid.h delete mode 100644 src/libsysprof-ui/sysprof-memprof-aid.c delete mode 100644 src/libsysprof-ui/sysprof-memprof-aid.h delete mode 100644 src/libsysprof-ui/sysprof-memprof-page.c delete mode 100644 src/libsysprof-ui/sysprof-memprof-page.h delete mode 100644 src/libsysprof-ui/sysprof-memprof-page.ui delete mode 100644 src/libsysprof-ui/sysprof-memprof-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-memprof-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-model-filter.c delete mode 100644 src/libsysprof-ui/sysprof-model-filter.h delete mode 100644 src/libsysprof-ui/sysprof-netdev-aid.c delete mode 100644 src/libsysprof-ui/sysprof-netdev-aid.h delete mode 100644 src/libsysprof-ui/sysprof-notebook.c delete mode 100644 src/libsysprof-ui/sysprof-notebook.h delete mode 100644 src/libsysprof-ui/sysprof-page.c delete mode 100644 src/libsysprof-ui/sysprof-page.h delete mode 100644 src/libsysprof-ui/sysprof-process-model-row.c delete mode 100644 src/libsysprof-ui/sysprof-process-model-row.h delete mode 100644 src/libsysprof-ui/sysprof-process-model-row.ui delete mode 100644 src/libsysprof-ui/sysprof-procs-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-procs-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-profiler-assistant.c delete mode 100644 src/libsysprof-ui/sysprof-profiler-assistant.h delete mode 100644 src/libsysprof-ui/sysprof-profiler-assistant.ui delete mode 100644 src/libsysprof-ui/sysprof-proxy-aid.c delete mode 100644 src/libsysprof-ui/sysprof-proxy-aid.h delete mode 100644 src/libsysprof-ui/sysprof-rapl-aid.c delete mode 100644 src/libsysprof-ui/sysprof-rapl-aid.h delete mode 100644 src/libsysprof-ui/sysprof-recording-state-view.c delete mode 100644 src/libsysprof-ui/sysprof-recording-state-view.h delete mode 100644 src/libsysprof-ui/sysprof-recording-state-view.ui delete mode 100644 src/libsysprof-ui/sysprof-scrollmap.c delete mode 100644 src/libsysprof-ui/sysprof-scrollmap.h delete mode 100644 src/libsysprof-ui/sysprof-tab.c delete mode 100644 src/libsysprof-ui/sysprof-tab.h delete mode 100644 src/libsysprof-ui/sysprof-tab.ui delete mode 100644 src/libsysprof-ui/sysprof-theme-manager.c delete mode 100644 src/libsysprof-ui/sysprof-theme-manager.h delete mode 100644 src/libsysprof-ui/sysprof-time-label.c delete mode 100644 src/libsysprof-ui/sysprof-time-label.h delete mode 100644 src/libsysprof-ui/sysprof-time-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-time-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-ui-private.h delete mode 100644 src/libsysprof-ui/sysprof-ui.h delete mode 100644 src/libsysprof-ui/sysprof-visualizer-group-header.c delete mode 100644 src/libsysprof-ui/sysprof-visualizer-group-header.h delete mode 100644 src/libsysprof-ui/sysprof-visualizer-group-private.h delete mode 100644 src/libsysprof-ui/sysprof-visualizer-group.c delete mode 100644 src/libsysprof-ui/sysprof-visualizer-group.h delete mode 100644 src/libsysprof-ui/sysprof-visualizer-ticks.c delete mode 100644 src/libsysprof-ui/sysprof-visualizer-ticks.h delete mode 100644 src/libsysprof-ui/sysprof-visualizer.c delete mode 100644 src/libsysprof-ui/sysprof-visualizer.h delete mode 100644 src/libsysprof-ui/sysprof-visualizers-frame.c delete mode 100644 src/libsysprof-ui/sysprof-visualizers-frame.h delete mode 100644 src/libsysprof-ui/sysprof-visualizers-frame.ui delete mode 100644 src/libsysprof-ui/sysprof-zoom-manager.c delete mode 100644 src/libsysprof-ui/sysprof-zoom-manager.h diff --git a/src/libsysprof-ui/css/SysprofDisplay-shared.css b/src/libsysprof-ui/css/SysprofDisplay-shared.css deleted file mode 100644 index a4ca6d57..00000000 --- a/src/libsysprof-ui/css/SysprofDisplay-shared.css +++ /dev/null @@ -1,86 +0,0 @@ -SysprofVisualizer { - background: @content_view_bg; - } -SysprofVisualizer:not(:last-child) { - border-bottom: 1px solid alpha(@borders, 0.3); - } - -SysprofVisualizerGroup { - border-bottom: 1px solid @borders; - } -SysprofVisualizerGroup:last-child { - box-shadow: 0 20px 15px 15px alpha(@borders, 0.3); - } - -SysprofVisualizersFrame box.horizontal.inline-toolbar { - padding: 0; - margin: 0; - border: none; - border-radius: 0; - border-width: 0; - } - -SysprofVisualizersFrame viewport.visualizers { - border-right: 1px solid @borders; - box-shadow: 1px 1px 3px alpha(@borders, 0.5); - } - -SysprofVisualizersFrame scrollbar.horizontal { - color: mix(@theme_fg_color, @theme_selected_bg_color, 0.5); - background: transparent; - } - -SysprofVisualizersFrame scrollbar.horizontal range trough { - background: transparent; - } - -SysprofVisualizersFrame scrollbar.horizontal range trough slider { - margin-left: 1px; - margin-right: 1px; - padding: 6px; - min-height: 14px; - background: alpha(@content_view_bg, 0.2); - border-radius: 3px; - border: 2px solid @theme_selected_bg_color; - box-shadow: inset 0 10px 5px alpha(@content_view_bg,.3), - inset 0 -15px 5px alpha(@content_view_bg,.1), - 0px 2px 4px @borders; - } - -SysprofVisualizerTicks { - color: mix(@theme_fg_color, @borders, 0.5); - background-color: @content_view_bg; - } - -SysprofVisualizersFrame list { - background-color: @theme_bg_color; - } - -SysprofVisualizersFrame list.visualizer-groups row { - padding: 0; - border-bottom: 1px solid @borders; - } -SysprofVisualizersFrame list.visualizer-groups row:not(:selected) { - background-color: @theme_bg_color; - } -SysprofVisualizersFrame list.visualizer-groups row:last-child { - box-shadow: 0 20px 15px 15px alpha(@borders, 0.3); - } - -SysprofVisualizersFrame .left-column .small-button.flat { - border-color: transparent; - min-height: 8px; - min-width: 8px; - } -SysprofVisualizersFrame .left-column .small-button.flat:checked, -SysprofVisualizersFrame .left-column .small-button.flat:hover { - border-color: @borders; - } - -SysprofVisualizersFrame .selection { - border-radius: 3px; - background-color: alpha(@theme_selected_bg_color, 0.35); - box-shadow: inset 0 10px 5px alpha(@content_view_bg,.3), - inset 0 -15px 5px alpha(@content_view_bg,.1), - inset 0 0 1px 1px @theme_selected_bg_color; - } diff --git a/src/libsysprof-ui/css/SysprofEnvironEditor-shared.css b/src/libsysprof-ui/css/SysprofEnvironEditor-shared.css deleted file mode 100644 index e202b29b..00000000 --- a/src/libsysprof-ui/css/SysprofEnvironEditor-shared.css +++ /dev/null @@ -1,13 +0,0 @@ -list.environ-editor row button.flat:last-child { - min-height: 16px; - min-width: 16px; - padding: 0; - margin: 3px; -} -list.environ-editor row button.flat:not(:hover) { - border-color: transparent; -} -list.environ-editor row button.flat image { - padding: 3px; - margin: 0; -} diff --git a/src/libsysprof-ui/css/SysprofProfilerAssistant-shared.css b/src/libsysprof-ui/css/SysprofProfilerAssistant-shared.css deleted file mode 100644 index f0acc7e4..00000000 --- a/src/libsysprof-ui/css/SysprofProfilerAssistant-shared.css +++ /dev/null @@ -1,7 +0,0 @@ -sysprofaidicon image.right.top { - border-radius: 9999px; - background-color: @theme_selected_bg_color; - color: @theme_selected_fg_color; - padding: 2px; - margin: 0px; -} diff --git a/src/libsysprof-ui/egg-handle-private.h b/src/libsysprof-ui/egg-handle-private.h deleted file mode 100644 index 9c004aa0..00000000 --- a/src/libsysprof-ui/egg-handle-private.h +++ /dev/null @@ -1,35 +0,0 @@ -/* egg-handle.h - * - * Copyright 2021 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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: LGPL-3.0-or-later - */ - -#pragma once - -#include - -G_BEGIN_DECLS - -#define EGG_TYPE_HANDLE (egg_handle_get_type()) - -G_DECLARE_FINAL_TYPE (EggHandle, egg_handle, EGG, HANDLE, GtkWidget) - -GtkWidget *egg_handle_new (GtkPositionType position); -void egg_handle_set_position (EggHandle *self, - GtkPositionType position); - -G_END_DECLS diff --git a/src/libsysprof-ui/egg-handle.c b/src/libsysprof-ui/egg-handle.c deleted file mode 100644 index 5872abb3..00000000 --- a/src/libsysprof-ui/egg-handle.c +++ /dev/null @@ -1,145 +0,0 @@ -/* egg-handle.c - * - * Copyright 2021 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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: LGPL-3.0-or-later - */ - -#include "config.h" - -#include "egg-handle-private.h" - -#define EXTRA_SIZE 8 - -struct _EggHandle -{ - GtkWidget parent_instance; - GtkWidget *separator; - GtkPositionType position : 3; -}; - -G_DEFINE_TYPE (EggHandle, egg_handle, GTK_TYPE_WIDGET) - -static gboolean -egg_handle_contains (GtkWidget *widget, - double x, - double y) -{ - EggHandle *self = (EggHandle *)widget; - graphene_rect_t area; - - g_assert (EGG_IS_HANDLE (self)); - - if (!gtk_widget_compute_bounds (GTK_WIDGET (self->separator), - GTK_WIDGET (self), - &area)) - return FALSE; - - switch (self->position) - { - case GTK_POS_LEFT: - area.origin.x -= EXTRA_SIZE; - area.size.width = EXTRA_SIZE; - break; - - case GTK_POS_RIGHT: - area.size.width = EXTRA_SIZE; - break; - - case GTK_POS_TOP: - area.origin.y -= EXTRA_SIZE; - area.size.height = EXTRA_SIZE; - break; - - case GTK_POS_BOTTOM: - area.size.height = EXTRA_SIZE; - break; - - default: - g_assert_not_reached (); - break; - } - - return graphene_rect_contains_point (&area, &GRAPHENE_POINT_INIT (x, y)); -} - -static void -egg_handle_dispose (GObject *object) -{ - EggHandle *self = (EggHandle *)object; - - g_clear_pointer (&self->separator, gtk_widget_unparent); - - G_OBJECT_CLASS (egg_handle_parent_class)->dispose (object); -} - -static void -egg_handle_class_init (EggHandleClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = egg_handle_dispose; - - widget_class->contains = egg_handle_contains; - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); -} - -static void -egg_handle_init (EggHandle *self) -{ - self->separator = gtk_separator_new (GTK_ORIENTATION_HORIZONTAL); - gtk_widget_set_parent (GTK_WIDGET (self->separator), GTK_WIDGET (self)); -} - -void -egg_handle_set_position (EggHandle *self, - GtkPositionType position) -{ - g_return_if_fail (EGG_IS_HANDLE (self)); - - self->position = position; - - switch (position) - { - case GTK_POS_LEFT: - case GTK_POS_RIGHT: - gtk_widget_set_cursor_from_name (GTK_WIDGET (self), "col-resize"); - gtk_orientable_set_orientation (GTK_ORIENTABLE (self->separator), GTK_ORIENTATION_VERTICAL); - break; - - case GTK_POS_TOP: - case GTK_POS_BOTTOM: - gtk_widget_set_cursor_from_name (GTK_WIDGET (self), "row-resize"); - gtk_orientable_set_orientation (GTK_ORIENTABLE (self->separator), GTK_ORIENTATION_HORIZONTAL); - break; - - default: - g_assert_not_reached (); - } -} - -GtkWidget * -egg_handle_new (GtkPositionType position) -{ - EggHandle *self; - - self = g_object_new (EGG_TYPE_HANDLE, NULL); - egg_handle_set_position (self, position); - - return GTK_WIDGET (self); -} diff --git a/src/libsysprof-ui/egg-paned-private.h b/src/libsysprof-ui/egg-paned-private.h deleted file mode 100644 index b673c1a4..00000000 --- a/src/libsysprof-ui/egg-paned-private.h +++ /dev/null @@ -1,48 +0,0 @@ -/* egg-paned.h - * - * Copyright 2021 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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: LGPL-3.0-or-later - */ - -#pragma once - -#include - -G_BEGIN_DECLS - -#define EGG_TYPE_PANED (egg_paned_get_type()) - -G_DECLARE_FINAL_TYPE (EggPaned, egg_paned, EGG, PANED, GtkWidget) - -GtkWidget *egg_paned_new (void); -void egg_paned_append (EggPaned *self, - GtkWidget *child); -void egg_paned_prepend (EggPaned *self, - GtkWidget *child); -void egg_paned_insert (EggPaned *self, - int position, - GtkWidget *child); -void egg_paned_insert_after (EggPaned *self, - GtkWidget *child, - GtkWidget *sibling); -void egg_paned_remove (EggPaned *self, - GtkWidget *child); -guint egg_paned_get_n_children (EggPaned *self); -GtkWidget *egg_paned_get_nth_child (EggPaned *self, - guint nth); - -G_END_DECLS diff --git a/src/libsysprof-ui/egg-paned.c b/src/libsysprof-ui/egg-paned.c deleted file mode 100644 index 25b0d82c..00000000 --- a/src/libsysprof-ui/egg-paned.c +++ /dev/null @@ -1,593 +0,0 @@ -/* egg-paned.c - * - * Copyright 2021 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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: LGPL-3.0-or-later - */ - -#include "config.h" - -#include - -#include "egg-paned-private.h" -#include "egg-resizer-private.h" - -struct _EggPaned -{ - GtkWidget parent_instance; - GtkOrientation orientation; -}; - -static void buildable_iface_init (GtkBuildableIface *iface); - -G_DEFINE_TYPE_WITH_CODE (EggPaned, egg_paned, GTK_TYPE_WIDGET, - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init) - G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)) - -enum { - PROP_0, - N_PROPS, - - PROP_ORIENTATION, -}; - -static void -update_orientation (GtkWidget *widget, - GtkOrientation orientation) -{ - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - gtk_widget_remove_css_class (widget, "vertical"); - gtk_widget_add_css_class (widget, "horizontal"); - } - else - { - gtk_widget_remove_css_class (widget, "horizontal"); - gtk_widget_add_css_class (widget, "vertical"); - } - - gtk_accessible_update_property (GTK_ACCESSIBLE (widget), - GTK_ACCESSIBLE_PROPERTY_ORIENTATION, orientation, - -1); -} - -/** - * egg_paned_new: - * - * Create a new #EggPaned. - * - * Returns: (transfer full): a newly created #EggPaned - */ -GtkWidget * -egg_paned_new (void) -{ - return g_object_new (EGG_TYPE_PANED, NULL); -} - -static void -egg_paned_set_orientation (EggPaned *self, - GtkOrientation orientation) -{ - GtkPositionType pos; - - g_assert (EGG_IS_PANED (self)); - g_assert (orientation == GTK_ORIENTATION_HORIZONTAL || - orientation == GTK_ORIENTATION_VERTICAL); - - if (self->orientation == orientation) - return; - - self->orientation = orientation; - - if (self->orientation == GTK_ORIENTATION_HORIZONTAL) - pos = GTK_POS_LEFT; - else - pos = GTK_POS_TOP; - - for (GtkWidget *child = gtk_widget_get_last_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_prev_sibling (child)) - { - g_assert (EGG_IS_RESIZER (child)); - - egg_resizer_set_position (EGG_RESIZER (child), pos); - } - - update_orientation (GTK_WIDGET (self), self->orientation); - gtk_widget_queue_resize (GTK_WIDGET (self)); - g_object_notify (G_OBJECT (self), "orientation"); -} - -static void -egg_paned_measure (GtkWidget *widget, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) -{ - EggPaned *self = (EggPaned *)widget; - - g_assert (EGG_IS_PANED (self)); - - *minimum = 0; - *natural = 0; - *minimum_baseline = -1; - *natural_baseline = -1; - - for (GtkWidget *child = gtk_widget_get_first_child (widget); - child != NULL; - child = gtk_widget_get_next_sibling (child)) - { - int child_min, child_nat; - - gtk_widget_measure (child, orientation, for_size, &child_min, &child_nat, NULL, NULL); - - if (orientation == self->orientation) - { - *minimum += child_min; - *natural += child_nat; - } - else - { - *minimum = MAX (*minimum, child_min); - *natural = MAX (*natural, child_nat); - } - } -} - -typedef struct -{ - GtkWidget *widget; - GtkRequisition min_request; - GtkRequisition nat_request; - GtkAllocation alloc; -} ChildAllocation; - -static void -egg_paned_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - EggPaned *self = (EggPaned *)widget; - ChildAllocation *allocs; - ChildAllocation *last_alloc = NULL; - GtkOrientation orientation; - guint n_children = 0; - guint n_expand = 0; - guint i; - int extra_width = width; - int extra_height = height; - int expand_width; - int expand_height; - int x, y; - - g_assert (EGG_IS_PANED (self)); - - GTK_WIDGET_CLASS (egg_paned_parent_class)->size_allocate (widget, width, height, baseline); - - n_children = egg_paned_get_n_children (self); - - if (n_children == 1) - { - GtkWidget *child = gtk_widget_get_first_child (widget); - GtkAllocation alloc = { 0, 0, width, height }; - - if (gtk_widget_get_visible (child)) - { - gtk_widget_size_allocate (child, &alloc, -1); - return; - } - } - - orientation = gtk_orientable_get_orientation (GTK_ORIENTABLE (self)); - allocs = g_newa (ChildAllocation, n_children); - memset (allocs, 0, sizeof *allocs * n_children); - - /* Give min size to each of the children */ - i = 0; - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_next_sibling (child), i++) - { - ChildAllocation *child_alloc = &allocs[i]; - - if (!gtk_widget_get_visible (child)) - continue; - - gtk_widget_measure (child, GTK_ORIENTATION_HORIZONTAL, height, - &child_alloc->min_request.width, - &child_alloc->nat_request.width, - NULL, NULL); - gtk_widget_measure (child, GTK_ORIENTATION_VERTICAL, width, - &child_alloc->min_request.height, - &child_alloc->nat_request.height, - NULL, NULL); - - child_alloc->alloc.width = child_alloc->min_request.width; - child_alloc->alloc.height = child_alloc->min_request.height; - - n_expand += gtk_widget_compute_expand (child, orientation); - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - extra_width -= child_alloc->alloc.width; - child_alloc->alloc.height = height; - } - else - { - extra_height -= child_alloc->alloc.height; - child_alloc->alloc.width = width; - } - } - - /* Now try to distribute extra space for natural size */ - i = 0; - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_next_sibling (child), i++) - { - ChildAllocation *child_alloc = &allocs[i]; - - if (!gtk_widget_get_visible (child)) - continue; - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - int taken = MIN (extra_width, child_alloc->nat_request.width - child_alloc->alloc.width); - - if (taken > 0) - { - child_alloc->alloc.width += taken; - extra_width -= taken; - } - } - else - { - int taken = MIN (extra_height, child_alloc->nat_request.height - child_alloc->alloc.height); - - if (taken > 0) - { - child_alloc->alloc.height += taken; - extra_height -= taken; - } - } - - last_alloc = child_alloc; - } - - /* Now give extra space for those that expand */ - expand_width = n_expand ? extra_width / n_expand : 0; - expand_height = n_expand ? extra_height / n_expand : 0; - i = n_children; - for (GtkWidget *child = gtk_widget_get_last_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_prev_sibling (child), i--) - { - ChildAllocation *child_alloc = &allocs[i-1]; - - if (!gtk_widget_get_visible (child)) - continue; - - if (!gtk_widget_compute_expand (child, orientation)) - continue; - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - { - child_alloc->alloc.width += expand_width; - extra_width -= expand_width; - } - else - { - child_alloc->alloc.height += expand_height; - extra_height -= expand_height; - } - } - - /* Give any leftover to the last visible child */ - if (last_alloc) - { - if (orientation == GTK_ORIENTATION_HORIZONTAL) - last_alloc->alloc.width += extra_width; - else - last_alloc->alloc.height += extra_height; - } - - i = 0; - x = 0; - y = 0; - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_next_sibling (child), i++) - { - ChildAllocation *child_alloc = &allocs[i]; - - child_alloc->alloc.x = x; - child_alloc->alloc.y = y; - - if (orientation == GTK_ORIENTATION_HORIZONTAL) - x += child_alloc->alloc.width; - else - y += child_alloc->alloc.height; - - gtk_widget_size_allocate (child, &child_alloc->alloc, -1); - } -} - -static void -egg_paned_dispose (GObject *object) -{ - EggPaned *self = (EggPaned *)object; - GtkWidget *child; - - child = gtk_widget_get_first_child (GTK_WIDGET (self)); - while (child) - { - GtkWidget *next = gtk_widget_get_next_sibling (child); - gtk_widget_unparent (child); - child = next; - } - - G_OBJECT_CLASS (egg_paned_parent_class)->dispose (object); -} - -static void -egg_paned_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EggPaned *self = EGG_PANED (object); - - switch (prop_id) - { - case PROP_ORIENTATION: - g_value_set_enum (value, self->orientation); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -egg_paned_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EggPaned *self = EGG_PANED (object); - - switch (prop_id) - { - case PROP_ORIENTATION: - egg_paned_set_orientation (self, g_value_get_enum (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -egg_paned_class_init (EggPanedClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = egg_paned_dispose; - object_class->get_property = egg_paned_get_property; - object_class->set_property = egg_paned_set_property; - - widget_class->measure = egg_paned_measure; - widget_class->size_allocate = egg_paned_size_allocate; - - g_object_class_override_property (object_class, PROP_ORIENTATION, "orientation"); - - gtk_widget_class_set_css_name (widget_class, "eggpaned"); -} - -static void -egg_paned_init (EggPaned *self) -{ - self->orientation = GTK_ORIENTATION_HORIZONTAL; - - update_orientation (GTK_WIDGET (self), self->orientation); -} - -static void -egg_paned_update_handles (EggPaned *self) -{ - GtkWidget *child; - - g_assert (EGG_IS_PANED (self)); - - for (child = gtk_widget_get_first_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_next_sibling (child)) - { - GtkWidget *handle; - - g_assert (EGG_IS_RESIZER (child)); - - if ((handle = egg_resizer_get_handle (EGG_RESIZER (child)))) - gtk_widget_show (handle); - } - - if ((child = gtk_widget_get_last_child (GTK_WIDGET (self)))) - { - GtkWidget *handle = egg_resizer_get_handle (EGG_RESIZER (child)); - gtk_widget_hide (handle); - } -} - -void -egg_paned_remove (EggPaned *self, - GtkWidget *child) -{ - GtkWidget *resizer; - - g_return_if_fail (EGG_IS_PANED (self)); - g_return_if_fail (GTK_IS_WIDGET (child)); - - resizer = gtk_widget_get_ancestor (child, EGG_TYPE_RESIZER); - g_return_if_fail (resizer != NULL && - gtk_widget_get_parent (resizer) == GTK_WIDGET (self)); - gtk_widget_unparent (resizer); - egg_paned_update_handles (self); - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - -void -egg_paned_insert (EggPaned *self, - int position, - GtkWidget *child) -{ - GtkPositionType pos; - GtkWidget *resizer; - - g_return_if_fail (EGG_IS_PANED (self)); - g_return_if_fail (GTK_IS_WIDGET (child)); - g_return_if_fail (gtk_widget_get_parent (child) == NULL); - - if (self->orientation == GTK_ORIENTATION_HORIZONTAL) - pos = GTK_POS_LEFT; - else - pos = GTK_POS_TOP; - - resizer = egg_resizer_new (pos); - egg_resizer_set_child (EGG_RESIZER (resizer), child); - - if (position < 0) - gtk_widget_insert_before (GTK_WIDGET (resizer), GTK_WIDGET (self), NULL); - else if (position == 0) - gtk_widget_insert_after (GTK_WIDGET (resizer), GTK_WIDGET (self), NULL); - else - { - GtkWidget *sibling = gtk_widget_get_first_child (GTK_WIDGET (self)); - - for (int i = position; i > 0 && sibling != NULL; i--) - sibling = gtk_widget_get_next_sibling (sibling); - - gtk_widget_insert_before (GTK_WIDGET (resizer), GTK_WIDGET (self), sibling); - } - - egg_paned_update_handles (self); - - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - -void -egg_paned_append (EggPaned *self, - GtkWidget *child) -{ - egg_paned_insert (self, -1, child); -} - -void -egg_paned_prepend (EggPaned *self, - GtkWidget *child) -{ - egg_paned_insert (self, 0, child); -} - -void -egg_paned_insert_after (EggPaned *self, - GtkWidget *child, - GtkWidget *sibling) -{ - int position = 0; - - g_return_if_fail (EGG_IS_PANED (self)); - g_return_if_fail (GTK_IS_WIDGET (child)); - g_return_if_fail (!sibling || GTK_IS_WIDGET (sibling)); - - if (sibling == NULL) - { - egg_paned_prepend (self, child); - return; - } - - /* TODO: We should reverse insert() to call this */ - - for (GtkWidget *ancestor = gtk_widget_get_first_child (GTK_WIDGET (self)); - ancestor != NULL; - ancestor = gtk_widget_get_next_sibling (ancestor)) - { - position++; - - if (sibling == ancestor || gtk_widget_is_ancestor (sibling, ancestor)) - break; - } - - egg_paned_insert (self, position, child); -} - -guint -egg_paned_get_n_children (EggPaned *self) -{ - guint count = 0; - - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_next_sibling (child)) - count++; - - return count; -} - -GtkWidget * -egg_paned_get_nth_child (EggPaned *self, - guint nth) -{ - g_return_val_if_fail (EGG_IS_PANED (self), NULL); - - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self)); - child != NULL; - child = gtk_widget_get_next_sibling (child)) - { - g_assert (EGG_IS_RESIZER (child)); - - if (nth == 0) - return egg_resizer_get_child (EGG_RESIZER (child)); - - nth--; - } - - return NULL; -} - -static void -egg_paned_add_child (GtkBuildable *buildable, - GtkBuilder *builder, - GObject *child, - const char *type) -{ - if (GTK_IS_WIDGET (child)) - egg_paned_append (EGG_PANED (buildable), GTK_WIDGET (child)); - else - g_warning ("Cannot add child of type %s to %s", - G_OBJECT_TYPE_NAME (child), - G_OBJECT_TYPE_NAME (buildable)); -} - -static void -buildable_iface_init (GtkBuildableIface *iface) -{ - iface->add_child = egg_paned_add_child; -} diff --git a/src/libsysprof-ui/egg-resizer-private.h b/src/libsysprof-ui/egg-resizer-private.h deleted file mode 100644 index 58db56c3..00000000 --- a/src/libsysprof-ui/egg-resizer-private.h +++ /dev/null @@ -1,40 +0,0 @@ -/* egg-resizer.h - * - * Copyright 2021 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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: LGPL-3.0-or-later - */ - -#pragma once - -#include - -G_BEGIN_DECLS - -#define EGG_TYPE_RESIZER (egg_resizer_get_type()) - -G_DECLARE_FINAL_TYPE (EggResizer, egg_resizer, EGG, RESIZER, GtkWidget) - -GtkWidget *egg_resizer_new (GtkPositionType position); -GtkPositionType egg_resizer_get_position (EggResizer *self); -void egg_resizer_set_position (EggResizer *self, - GtkPositionType position); -GtkWidget *egg_resizer_get_child (EggResizer *self); -void egg_resizer_set_child (EggResizer *self, - GtkWidget *child); -GtkWidget *egg_resizer_get_handle (EggResizer *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/egg-resizer.c b/src/libsysprof-ui/egg-resizer.c deleted file mode 100644 index c2b427bc..00000000 --- a/src/libsysprof-ui/egg-resizer.c +++ /dev/null @@ -1,495 +0,0 @@ -/* egg-resizer.c - * - * Copyright 2021 Christian Hergert - * - * This file is free software; you can redistribute it and/or modify it under - * the terms of the GNU Lesser General Public License as published by the Free - * Software Foundation; either version 3 of the License, or (at your option) - * any later version. - * - * This file 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 Lesser 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: LGPL-3.0-or-later - */ - -#include "config.h" - -#include "egg-handle-private.h" -#include "egg-resizer-private.h" - -#define HANDLE_SIZE 8 - -struct _EggResizer -{ - GtkWidget parent_instance; - - EggHandle *handle; - GtkWidget *child; - - double drag_orig_size; - double drag_position; - - GtkPositionType position : 3; -}; - -G_DEFINE_TYPE (EggResizer, egg_resizer, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_CHILD, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static void -egg_resizer_drag_begin_cb (EggResizer *self, - double start_x, - double start_y, - GtkGestureDrag *drag) -{ - GtkAllocation child_alloc; - GtkAllocation handle_alloc; - - g_assert (EGG_IS_RESIZER (self)); - g_assert (GTK_IS_GESTURE_DRAG (drag)); - - if (self->child == NULL) - return; - - switch (self->position) - { - case GTK_POS_LEFT: - if (start_x > gtk_widget_get_width (GTK_WIDGET (self)) - HANDLE_SIZE) - goto start_drag; - break; - - case GTK_POS_RIGHT: - if (start_x <= HANDLE_SIZE) - goto start_drag; - break; - - case GTK_POS_TOP: - if (start_y > gtk_widget_get_height (GTK_WIDGET (self)) - HANDLE_SIZE) - goto start_drag; - break; - - case GTK_POS_BOTTOM: - if (start_y <= HANDLE_SIZE) - goto start_drag; - break; - - default: - g_assert_not_reached (); - break; - } - - gtk_gesture_set_state (GTK_GESTURE (drag), - GTK_EVENT_SEQUENCE_DENIED); - - return; - -start_drag: - - gtk_widget_get_allocation (self->child, &child_alloc); - gtk_widget_get_allocation (GTK_WIDGET (self->handle), &handle_alloc); - - if (self->position == GTK_POS_LEFT || - self->position == GTK_POS_RIGHT) - { - self->drag_orig_size = child_alloc.width + handle_alloc.width; - gtk_widget_set_hexpand (self->child, FALSE); - } - else - { - self->drag_orig_size = child_alloc.height + handle_alloc.height; - gtk_widget_set_vexpand (self->child, FALSE); - } - - self->drag_position = self->drag_orig_size; - - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - -static void -egg_resizer_drag_update_cb (EggResizer *self, - double offset_x, - double offset_y, - GtkGestureDrag *drag) -{ - g_assert (EGG_IS_RESIZER (self)); - g_assert (GTK_IS_GESTURE_DRAG (drag)); - - if (self->position == GTK_POS_LEFT) - self->drag_position = self->drag_orig_size + offset_x; - else if (self->position == GTK_POS_RIGHT) - self->drag_position = gtk_widget_get_width (GTK_WIDGET (self)) - offset_x; - else if (self->position == GTK_POS_TOP) - self->drag_position = self->drag_orig_size + offset_y; - else if (self->position == GTK_POS_BOTTOM) - self->drag_position = gtk_widget_get_height (GTK_WIDGET (self)) - offset_y; - - gtk_widget_queue_resize (GTK_WIDGET (self)); -} - -static void -egg_resizer_drag_end_cb (EggResizer *self, - double offset_x, - double offset_y, - GtkGestureDrag *drag) -{ - g_assert (EGG_IS_RESIZER (self)); - g_assert (GTK_IS_GESTURE_DRAG (drag)); -} - -GtkWidget * -egg_resizer_new (GtkPositionType position) -{ - EggResizer *self; - - self = g_object_new (EGG_TYPE_RESIZER, NULL); - self->position = position; - self->handle = EGG_HANDLE (egg_handle_new (position)); - gtk_widget_set_parent (GTK_WIDGET (self->handle), GTK_WIDGET (self)); - - return GTK_WIDGET (self); -} - -static void -egg_resizer_measure (GtkWidget *widget, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) -{ - EggResizer *self = (EggResizer *)widget; - - g_assert (EGG_IS_RESIZER (self)); - - *minimum = 0; - *natural = 0; - *minimum_baseline = -1; - *natural_baseline = -1; - - if (self->child != NULL) - gtk_widget_measure (self->child, - orientation, - for_size, - minimum, natural, - NULL, NULL); - - if ((orientation == GTK_ORIENTATION_HORIZONTAL && - (self->position == GTK_POS_LEFT || - self->position == GTK_POS_RIGHT)) || - (orientation == GTK_ORIENTATION_VERTICAL && - (self->position == GTK_POS_TOP || - self->position == GTK_POS_BOTTOM))) - { - int handle_min, handle_nat; - - if (self->drag_position != 0) - { - if (self->drag_position > *minimum) - *natural = self->drag_position; - else if (self->drag_position < *minimum) - *natural = *minimum; - } - - if (gtk_widget_get_visible (GTK_WIDGET (self->handle))) - { - gtk_widget_measure (GTK_WIDGET (self->handle), - orientation, for_size, - &handle_min, &handle_nat, - NULL, NULL); - - *minimum += handle_min; - *natural += handle_nat; - } - } -} - -static void -egg_resizer_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - EggResizer *self = (EggResizer *)widget; - GtkOrientation orientation; - GtkAllocation child_alloc; - GtkAllocation handle_alloc; - int handle_min = 0, handle_nat = 0; - - g_assert (EGG_IS_RESIZER (self)); - - if (self->position == GTK_POS_LEFT || - self->position == GTK_POS_RIGHT) - orientation = GTK_ORIENTATION_HORIZONTAL; - else - orientation = GTK_ORIENTATION_VERTICAL; - - if (gtk_widget_get_visible (GTK_WIDGET (self->handle))) - gtk_widget_measure (GTK_WIDGET (self->handle), - orientation, - -1, - &handle_min, &handle_nat, - NULL, NULL); - - switch (self->position) - { - case GTK_POS_LEFT: - handle_alloc.x = width - handle_min; - handle_alloc.width = handle_min; - handle_alloc.y = 0; - handle_alloc.height = height; - child_alloc.x = 0; - child_alloc.y = 0; - child_alloc.width = width - handle_min; - child_alloc.height = height; - break; - - case GTK_POS_RIGHT: - handle_alloc.x = 0; - handle_alloc.width = handle_min; - handle_alloc.y = 0; - handle_alloc.height = height; - child_alloc.x = handle_min; - child_alloc.y = 0; - child_alloc.width = width - handle_min; - child_alloc.height = height; - break; - - case GTK_POS_TOP: - handle_alloc.x = 0; - handle_alloc.width = width; - handle_alloc.y = height - handle_min; - handle_alloc.height = handle_min; - child_alloc.x = 0; - child_alloc.y = 0; - child_alloc.width = width; - child_alloc.height = height - handle_min; - break; - - case GTK_POS_BOTTOM: - handle_alloc.x = 0; - handle_alloc.width = width; - handle_alloc.y = 0; - handle_alloc.height = handle_min; - child_alloc.x = 0; - child_alloc.y = handle_min; - child_alloc.width = width; - child_alloc.height = height - handle_min; - break; - - default: - g_assert_not_reached (); - } - - if (gtk_widget_get_mapped (GTK_WIDGET (self->handle))) - gtk_widget_size_allocate (GTK_WIDGET (self->handle), &handle_alloc, -1); - - if (self->child != NULL && - gtk_widget_get_mapped (self->child)) - gtk_widget_size_allocate (self->child, &child_alloc, -1); -} - -static void -egg_resizer_compute_expand (GtkWidget *widget, - gboolean *hexpand, - gboolean *vexpand) -{ - EggResizer *self = EGG_RESIZER (widget); - - if (self->child != NULL) - { - *hexpand = gtk_widget_compute_expand (self->child, GTK_ORIENTATION_HORIZONTAL); - *vexpand = gtk_widget_compute_expand (self->child, GTK_ORIENTATION_VERTICAL); - } - else - { - *hexpand = FALSE; - *vexpand = FALSE; - } -} - -static void -egg_resizer_dispose (GObject *object) -{ - EggResizer *self = (EggResizer *)object; - - if (self->handle) - gtk_widget_unparent (GTK_WIDGET (self->handle)); - self->handle = NULL; - - if (self->child) - gtk_widget_unparent (self->child); - self->child = NULL; - - G_OBJECT_CLASS (egg_resizer_parent_class)->dispose (object); -} - -static void -egg_resizer_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - EggResizer *self = EGG_RESIZER (object); - - switch (prop_id) - { - case PROP_CHILD: - g_value_set_object (value, egg_resizer_get_child (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -egg_resizer_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - EggResizer *self = EGG_RESIZER (object); - - switch (prop_id) - { - case PROP_CHILD: - egg_resizer_set_child (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -egg_resizer_class_init (EggResizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = egg_resizer_dispose; - object_class->get_property = egg_resizer_get_property; - object_class->set_property = egg_resizer_set_property; - - widget_class->compute_expand = egg_resizer_compute_expand; - widget_class->measure = egg_resizer_measure; - widget_class->size_allocate = egg_resizer_size_allocate; - - properties [PROP_CHILD] = - g_param_spec_object ("child", - "Child", - "Child", - GTK_TYPE_WIDGET, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_css_name (widget_class, "eggresizer"); -} - -static void -egg_resizer_init (EggResizer *self) -{ - GtkGesture *gesture; - - gesture = gtk_gesture_drag_new (); - gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (gesture), GTK_PHASE_CAPTURE); - g_signal_connect_object (gesture, - "drag-begin", - G_CALLBACK (egg_resizer_drag_begin_cb), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (gesture, - "drag-update", - G_CALLBACK (egg_resizer_drag_update_cb), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (gesture, - "drag-end", - G_CALLBACK (egg_resizer_drag_end_cb), - self, - G_CONNECT_SWAPPED); - gtk_widget_add_controller (GTK_WIDGET (self), GTK_EVENT_CONTROLLER (gesture)); -} - -/** - * egg_resizer_get_child: - * @self: a #EggResizer - * - * Gets the child widget of the resizer. - * - * Returns: (transfer none) (nullable): A #GtkWidget or %NULL - */ -GtkWidget * -egg_resizer_get_child (EggResizer *self) -{ - g_return_val_if_fail (EGG_IS_RESIZER (self), NULL); - - return self->child; -} - -void -egg_resizer_set_child (EggResizer *self, - GtkWidget *child) -{ - g_return_if_fail (EGG_IS_RESIZER (self)); - g_return_if_fail (!child || GTK_IS_WIDGET (child)); - - if (child == self->child) - return; - - g_clear_pointer (&self->child, gtk_widget_unparent); - - self->child = child; - - if (self->child != NULL) - gtk_widget_insert_before (self->child, - GTK_WIDGET (self), - GTK_WIDGET (self->handle)); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CHILD]); -} - -GtkPositionType -egg_resizer_get_position (EggResizer *self) -{ - g_return_val_if_fail (EGG_IS_RESIZER (self), 0); - - return self->position; -} - -void -egg_resizer_set_position (EggResizer *self, - GtkPositionType position) -{ - g_return_if_fail (EGG_IS_RESIZER (self)); - - if (position != self->position) - { - self->position = position; - - egg_handle_set_position (self->handle, position); - gtk_widget_queue_resize (GTK_WIDGET (self)); - } -} - -GtkWidget * -egg_resizer_get_handle (EggResizer *self) -{ - g_return_val_if_fail (EGG_IS_RESIZER (self), NULL); - - return GTK_WIDGET (self->handle); -} diff --git a/src/libsysprof-ui/libsysprof-ui.gresource.xml b/src/libsysprof-ui/libsysprof-ui.gresource.xml deleted file mode 100644 index e5aa0593..00000000 --- a/src/libsysprof-ui/libsysprof-ui.gresource.xml +++ /dev/null @@ -1,30 +0,0 @@ - - - - css/SysprofEnvironEditor-shared.css - css/SysprofDisplay-shared.css - css/SysprofProfilerAssistant-shared.css - - - ../../data/icons/org.gnome.Sysprof.svg - ../../data/icons/symbolic/apps/org.gnome.Sysprof-symbolic.svg - ../../data/icons/symbolic/apps/org.gnome.Sysprof-symbolic.svg - - - - sysprof-aid-icon.ui - sysprof-callgraph-page.ui - sysprof-details-page.ui - sysprof-display.ui - sysprof-environ-editor-row.ui - sysprof-failed-state-view.ui - sysprof-logs-page.ui - sysprof-marks-page.ui - sysprof-memprof-page.ui - sysprof-process-model-row.ui - sysprof-profiler-assistant.ui - sysprof-recording-state-view.ui - sysprof-tab.ui - sysprof-visualizers-frame.ui - - diff --git a/src/libsysprof-ui/meson.build b/src/libsysprof-ui/meson.build deleted file mode 100644 index 0017eedb..00000000 --- a/src/libsysprof-ui/meson.build +++ /dev/null @@ -1,136 +0,0 @@ -libsysprof_ui_public_sources = [ - 'sysprof-check.c', - 'sysprof-display.c', - 'sysprof-model-filter.c', - 'sysprof-notebook.c', - 'sysprof-page.c', - 'sysprof-process-model-row.c', - 'sysprof-visualizer.c', - 'sysprof-visualizer-group.c', - 'sysprof-zoom-manager.c', -] - -libsysprof_ui_private_sources = [ - 'egg-handle.c', - 'egg-paned.c', - 'egg-resizer.c', - - 'pointcache.c', - 'rectangles.c', - 'sysprof-aid.c', - 'sysprof-aid-icon.c', - 'sysprof-battery-aid.c', - 'sysprof-cairo.c', - 'sysprof-callgraph-aid.c', - 'sysprof-callgraph-page.c', - 'sysprof-cell-renderer-duration.c', - 'sysprof-cell-renderer-percent.c', - 'sysprof-cell-renderer-progress.c', - 'sysprof-color-cycle.c', - 'sysprof-counters-aid.c', - 'sysprof-cpu-aid.c', - 'sysprof-depth-visualizer.c', - 'sysprof-details-page.c', - 'sysprof-diskstat-aid.c', - 'sysprof-display.c', - 'sysprof-duplex-visualizer.c', - 'sysprof-environ.c', - 'sysprof-environ-editor.c', - 'sysprof-environ-editor-row.c', - 'sysprof-environ-variable.c', - 'sysprof-failed-state-view.c', - 'sysprof-line-visualizer.c', - 'sysprof-log-model.c', - 'sysprof-logs-aid.c', - 'sysprof-logs-page.c', - 'sysprof-mark-detail.c', - 'sysprof-marks-aid.c', - 'sysprof-marks-model.c', - 'sysprof-marks-page.c', - 'sysprof-mark-visualizer.c', - 'sysprof-memory-aid.c', - 'sysprof-memprof-aid.c', - 'sysprof-memprof-page.c', - 'sysprof-memprof-visualizer.c', - 'sysprof-netdev-aid.c', - 'sysprof-procs-visualizer.c', - 'sysprof-profiler-assistant.c', - 'sysprof-proxy-aid.c', - 'sysprof-rapl-aid.c', - 'sysprof-recording-state-view.c', - 'sysprof-scrollmap.c', - 'sysprof-tab.c', - 'sysprof-theme-manager.c', - 'sysprof-time-label.c', - 'sysprof-time-visualizer.c', - 'sysprof-visualizer-group-header.c', - 'sysprof-visualizers-frame.c', - 'sysprof-visualizer-ticks.c', - '../stackstash.c', -] - -libsysprof_ui_public_headers = [ - 'sysprof-check.h', - 'sysprof-display.h', - 'sysprof-model-filter.h', - 'sysprof-notebook.h', - 'sysprof-page.h', - 'sysprof-process-model-row.h', - 'sysprof-visualizer.h', - 'sysprof-visualizer-group.h', - 'sysprof-zoom-manager.h', - 'sysprof-ui.h', -] - -libsysprof_ui_resources = gnome.compile_resources( - 'libsysprof-ui-resources', - 'libsysprof-ui.gresource.xml', - c_name: 'lisysprof_ui', -) - -# Subset of dependencies used in generating the pkg-config file -libsysprof_ui_pkg_deps = [ - dependency('gio-2.0', version: glib_req_version), - dependency('gtk4', version: gtk_req_version), - dependency('libadwaita-1'), -] - -libsysprof_ui_deps = libsysprof_ui_pkg_deps + [ - libsysprof_dep, -] - -# Meson's pkgconfig module wants to see a library here, not an internal -# dependency object -libsysprof_ui_pkg_deps += libsysprof - -libsysprof_ui = shared_library( - 'sysprof-ui-@0@'.format(libsysprof_ui_api_version), - libsysprof_ui_public_sources + libsysprof_ui_private_sources + libsysprof_ui_resources, - - dependencies: libsysprof_ui_deps + [librax_dep], - install_dir: get_option('libdir'), - install: true, - c_args: [ '-DSYSPROF_UI_COMPILATION' ], - gnu_symbol_visibility: 'hidden', -) - -libsysprof_ui_dep = declare_dependency( - link_with: libsysprof_ui, - dependencies: libsysprof_ui_deps, - include_directories: include_directories('.'), -) -meson.override_dependency('sysprof-ui-@0@'.format(libsysprof_api_version), libsysprof_ui_dep) - -pkgconfig.generate( - libsysprof_ui, - subdirs: [ sysprof_ui_header_subdir ], - description: 'The UI library for GTK applications embedding sysprof', - install_dir: join_paths(get_option('libdir'), 'pkgconfig'), - requires: [ 'gio-2.0', 'gtk4' ], - libraries_private: libsysprof_ui_pkg_deps, - variables: [ - 'datadir=' + datadir_for_pc_file, - ], -) - -install_headers(libsysprof_ui_public_headers, subdir: sysprof_ui_header_subdir) diff --git a/src/libsysprof-ui/pointcache.c b/src/libsysprof-ui/pointcache.c deleted file mode 100644 index c16304ff..00000000 --- a/src/libsysprof-ui/pointcache.c +++ /dev/null @@ -1,116 +0,0 @@ -/* pointcache.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "pointcache" - -#include "pointcache.h" - -struct _PointCache -{ - volatile gint ref_count; - GHashTable *sets; -}; - -static void -point_cache_finalize (PointCache *self) -{ - g_clear_pointer (&self->sets, g_hash_table_unref); - g_slice_free (PointCache, self); -} - -PointCache * -point_cache_ref (PointCache *self) -{ - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (self->ref_count > 0, NULL); - - g_atomic_int_inc (&self->ref_count); - - return self; -} - -void -point_cache_unref (PointCache *self) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (self->ref_count > 0); - - if (g_atomic_int_dec_and_test (&self->ref_count)) - point_cache_finalize (self); -} - -PointCache * -point_cache_new (void) -{ - PointCache *self; - - self = g_slice_new0 (PointCache); - self->ref_count = 1; - self->sets = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify)g_array_unref); - - return self; -} - -void -point_cache_add_set (PointCache *self, - guint set_id) -{ - g_hash_table_insert (self->sets, - GUINT_TO_POINTER (set_id), - g_array_new (FALSE, FALSE, sizeof (Point))); -} - -gboolean -point_cache_contains_set (PointCache *self, - guint set_id) -{ - return g_hash_table_contains (self->sets, GUINT_TO_POINTER (set_id)); -} - -void -point_cache_add_point_to_set (PointCache *self, - guint set_id, - gdouble x, - gdouble y) -{ - GArray *ar; - Point point = { x, y }; - - ar = g_hash_table_lookup (self->sets, GUINT_TO_POINTER (set_id)); - g_array_append_val (ar, point); -} - -const Point * -point_cache_get_points (PointCache *self, - guint set_id, - guint *n_points) -{ - GArray *ar; - - *n_points = 0; - - if ((ar = g_hash_table_lookup (self->sets, GUINT_TO_POINTER (set_id)))) - { - *n_points = ar->len; - return &g_array_index (ar, const Point, 0); - } - - return NULL; -} diff --git a/src/libsysprof-ui/pointcache.h b/src/libsysprof-ui/pointcache.h deleted file mode 100644 index 3aed8179..00000000 --- a/src/libsysprof-ui/pointcache.h +++ /dev/null @@ -1,52 +0,0 @@ -/* pointcache.h - * - * Copyright 2016-2019 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 - -G_BEGIN_DECLS - -typedef struct _PointCache PointCache; - -typedef struct -{ - gdouble x; - gdouble y; -} Point; - -PointCache *point_cache_new (void); -PointCache *point_cache_ref (PointCache *self); -void point_cache_unref (PointCache *self); -void point_cache_add_set (PointCache *self, - guint set_id); -gboolean point_cache_contains_set (PointCache *self, - guint set_id); -void point_cache_add_point_to_set (PointCache *self, - guint set_id, - gdouble x, - gdouble y); -const Point *point_cache_get_points (PointCache *self, - guint set_id, - guint *n_points); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC (PointCache, point_cache_unref) - -G_END_DECLS diff --git a/src/libsysprof-ui/rectangles.c b/src/libsysprof-ui/rectangles.c deleted file mode 100644 index 9db41038..00000000 --- a/src/libsysprof-ui/rectangles.c +++ /dev/null @@ -1,248 +0,0 @@ -/* rectangles.c - * - * Copyright 2018-2019 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 "rectangles.h" -#include "sysprof-color-cycle.h" -#include "sysprof-visualizer.h" - -typedef struct -{ - const gchar *name; - const gchar *message; - gint64 begin; - gint64 end; - GdkRectangle area; -} Rectangle; - -struct _Rectangles -{ - GStringChunk *strings; - GArray *rectangles; - GHashTable *y_indexes; - GHashTable *colors; - SysprofColorCycle *cycle; - gint64 begin_time; - gint64 end_time; - guint sorted : 1; -}; - -Rectangles * -rectangles_new (gint64 begin_time, - gint64 end_time) -{ - Rectangles *self; - - self = g_slice_new0 (Rectangles); - self->strings = g_string_chunk_new (4096); - self->rectangles = g_array_new (FALSE, FALSE, sizeof (Rectangle)); - self->y_indexes = g_hash_table_new (g_str_hash, g_str_equal); - self->colors = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free); - self->cycle = sysprof_color_cycle_new (); - self->begin_time = begin_time; - self->end_time = end_time; - self->sorted = FALSE; - - return self; -} - -void -rectangles_add (Rectangles *self, - gint64 begin_time, - gint64 end_time, - const gchar *name, - const gchar *message) -{ - Rectangle rect = {0}; - - g_assert (self != NULL); - - if (message != NULL) - rect.message = g_string_chunk_insert_const (self->strings, message); - - if (name != NULL) - rect.name = g_string_chunk_insert_const (self->strings, name); - - rect.begin = begin_time; - rect.end = end_time; - - if (rect.end == rect.begin) - rect.area.width = 1; - - g_array_append_val (self->rectangles, rect); - - self->sorted = FALSE; -} - -void -rectangles_free (Rectangles *self) -{ - g_string_chunk_free (self->strings); - g_array_unref (self->rectangles); - g_hash_table_unref (self->colors); - g_hash_table_unref (self->y_indexes); - sysprof_color_cycle_unref (self->cycle); - g_slice_free (Rectangles, self); -} - -static gint -sort_rectangles (gconstpointer a, - gconstpointer b) -{ - const Rectangle *r1 = a; - const Rectangle *r2 = b; - gint64 r = r1->begin - r2->begin; - if (r == 0) - r = r1->end - r2->end; - if (r > 0) return 1; - else if (r < 0) return -1; - else return 0; -} - -static void -rectangles_sort (Rectangles *self) -{ - guint sequence = 0; - - g_assert (self != NULL); - - if (self->sorted) - return; - - g_array_sort (self->rectangles, sort_rectangles); - - g_hash_table_remove_all (self->y_indexes); - - for (guint i = 0; i < self->rectangles->len; i++) - { - const Rectangle *rect = &g_array_index (self->rectangles, Rectangle, i); - - if (!g_hash_table_contains (self->y_indexes, rect->name)) - { - GdkRGBA rgba; - - sysprof_color_cycle_next (self->cycle, &rgba); - g_hash_table_insert (self->y_indexes, (gchar *)rect->name, GUINT_TO_POINTER (++sequence)); - g_hash_table_insert (self->colors, (gchar *)rect->name, g_memdup2 (&rgba, sizeof rgba)); - } - } - - self->sorted = TRUE; -} - -void -rectangles_draw (Rectangles *self, - GtkWidget *row, - cairo_t *cr) -{ - GtkAllocation alloc; - gdouble range; - guint ns; - - g_assert (self != NULL); - g_assert (SYSPROF_IS_VISUALIZER (row)); - g_assert (cr != NULL); - - if (!self->sorted) - rectangles_sort (self); - - gtk_widget_get_allocation (row, &alloc); - ns = g_hash_table_size (self->y_indexes); - if (ns == 0 || alloc.height == 0) - return; - - range = self->end_time - self->begin_time; - - for (guint i = 0; i < self->rectangles->len; i++) - { - Rectangle *rect = &g_array_index (self->rectangles, Rectangle, i); - guint y_index = GPOINTER_TO_UINT (g_hash_table_lookup (self->y_indexes, rect->name)); - SysprofVisualizerRelativePoint in_points[2]; - SysprofVisualizerAbsolutePoint out_points[2]; - GdkRectangle r; - GdkRGBA *rgba; - - g_assert (y_index > 0); - g_assert (y_index <= ns); - - in_points[0].x = (rect->begin - self->begin_time) / range; - in_points[0].y = (y_index - 1) / (gdouble)ns; - in_points[1].x = (rect->end - self->begin_time) / range; - in_points[1].y = 0; - - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (row), - in_points, G_N_ELEMENTS (in_points), - out_points, G_N_ELEMENTS (out_points)); - - r.height = alloc.height / (gdouble)ns; - r.x = out_points[0].x; - r.y = out_points[0].y - r.height; - - if (rect->end <= rect->begin) - r.width = 1; - else - r.width = MAX (1, out_points[1].x - out_points[0].x); - - rect->area = r; - - rgba = g_hash_table_lookup (self->colors, rect->name); - - gdk_cairo_rectangle (cr, &r); - gdk_cairo_set_source_rgba (cr, rgba); - cairo_fill (cr); - } -} - -void -rectangles_set_end_time (Rectangles *self, - gint64 end_time) -{ - /* We might not know the real end time until we've exhausted the stream */ - self->end_time = end_time; -} - -gboolean -rectangles_query_tooltip (Rectangles *self, - GtkTooltip *tooltip, - const gchar *group, - gint x, - gint y) -{ - g_assert (self != NULL); - g_assert (GTK_IS_TOOLTIP (tooltip)); - - /* TODO: Sort, binary search, etc. */ - - for (guint i = 0; i < self->rectangles->len; i++) - { - const Rectangle *r = &g_array_index (self->rectangles, Rectangle, i); - - if (r->area.x <= x && - r->area.y <= y && - r->area.x + r->area.width >= x && - r->area.y + r->area.height >= y) - { - g_autofree gchar *text = g_strdup_printf ("%s:%s: %s", group, r->name, r->message); - gtk_tooltip_set_text (tooltip, text); - return TRUE; - } - } - - return FALSE; -} diff --git a/src/libsysprof-ui/rectangles.h b/src/libsysprof-ui/rectangles.h deleted file mode 100644 index f71c3a43..00000000 --- a/src/libsysprof-ui/rectangles.h +++ /dev/null @@ -1,48 +0,0 @@ -/* rectangles.h - * - * Copyright 2018-2019 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 - -G_BEGIN_DECLS - -typedef struct _Rectangles Rectangles; - -Rectangles *rectangles_new (gint64 begin_time, - gint64 end_time); -void rectangles_free (Rectangles *self); -void rectangles_draw (Rectangles *self, - GtkWidget *widget, - cairo_t *cr); -void rectangles_add (Rectangles *self, - gint64 begin_time, - gint64 end_time, - const gchar *name, - const gchar *message); -void rectangles_set_end_time (Rectangles *self, - gint64 end_time); -gboolean rectangles_query_tooltip (Rectangles *self, - GtkTooltip *tooltip, - const gchar *group, - gint x, - gint y); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-aid-icon.c b/src/libsysprof-ui/sysprof-aid-icon.c deleted file mode 100644 index eba2b4ff..00000000 --- a/src/libsysprof-ui/sysprof-aid-icon.c +++ /dev/null @@ -1,211 +0,0 @@ -/* sysprof-aid-icon.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-aid-icon" - -#include "config.h" - -#include "sysprof-aid-icon.h" - -struct _SysprofAidIcon -{ - GtkFlowBoxChild parent_instance; - - SysprofAid *aid; - - /* Template Objects */ - GtkLabel *label; - GtkImage *image; - GtkImage *check; -}; - -G_DEFINE_TYPE (SysprofAidIcon, sysprof_aid_icon, GTK_TYPE_FLOW_BOX_CHILD) - -enum { - PROP_0, - PROP_AID, - PROP_SELECTED, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -/** - * sysprof_aid_icon_new: - * - * Create a new #SysprofAidIcon. - * - * Returns: (transfer full): a newly created #SysprofAidIcon - */ -GtkWidget * -sysprof_aid_icon_new (SysprofAid *aid) -{ - g_return_val_if_fail (SYSPROF_IS_AID (aid), NULL); - - return g_object_new (SYSPROF_TYPE_AID_ICON, - "aid", aid, - NULL); -} - -gboolean -sysprof_aid_icon_is_selected (SysprofAidIcon *self) -{ - g_return_val_if_fail (SYSPROF_IS_AID_ICON (self), FALSE); - - return gtk_widget_get_visible (GTK_WIDGET (self->check)); -} - -/** - * sysprof_aid_icon_get_aid: - * - * Get the aid that is represented by the icon. - * - * Returns: (transfer none): a #SysprofAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_aid_icon_get_aid (SysprofAidIcon *self) -{ - g_return_val_if_fail (SYSPROF_IS_AID_ICON (self), NULL); - - return self->aid; -} - -static void -sysprof_aid_icon_set_aid (SysprofAidIcon *self, - SysprofAid *aid) -{ - g_return_if_fail (SYSPROF_IS_AID_ICON (self)); - g_return_if_fail (SYSPROF_IS_AID (aid)); - - if (g_set_object (&self->aid, aid)) - { - GIcon *icon = sysprof_aid_get_icon (aid); - const gchar *title = sysprof_aid_get_display_name (aid); - - g_object_set (self->image, "gicon", icon, NULL); - gtk_label_set_label (self->label, title); - } -} - -static void -sysprof_aid_icon_finalize (GObject *object) -{ - SysprofAidIcon *self = (SysprofAidIcon *)object; - - g_clear_object (&self->aid); - - G_OBJECT_CLASS (sysprof_aid_icon_parent_class)->finalize (object); -} - -static void -sysprof_aid_icon_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofAidIcon *self = SYSPROF_AID_ICON (object); - - switch (prop_id) - { - case PROP_AID: - g_value_set_object (value, sysprof_aid_icon_get_aid (self)); - break; - - case PROP_SELECTED: - g_value_set_boolean (value, gtk_widget_get_visible (GTK_WIDGET (self->check))); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_aid_icon_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofAidIcon *self = SYSPROF_AID_ICON (object); - - switch (prop_id) - { - case PROP_AID: - sysprof_aid_icon_set_aid (self, g_value_get_object (value)); - break; - - case PROP_SELECTED: - gtk_widget_set_visible (GTK_WIDGET (self->check), g_value_get_boolean (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_aid_icon_class_init (SysprofAidIconClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->finalize = sysprof_aid_icon_finalize; - object_class->get_property = sysprof_aid_icon_get_property; - object_class->set_property = sysprof_aid_icon_set_property; - - properties [PROP_AID] = - g_param_spec_object ("aid", - "Aid", - "The aid for the icon", - SYSPROF_TYPE_AID, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_SELECTED] = - g_param_spec_boolean ("selected", - "Selected", - "If the item is selected", - FALSE, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_css_name (widget_class, "sysprofaidicon"); - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-aid-icon.ui"); - gtk_widget_class_bind_template_child (widget_class, SysprofAidIcon, check); - gtk_widget_class_bind_template_child (widget_class, SysprofAidIcon, image); - gtk_widget_class_bind_template_child (widget_class, SysprofAidIcon, label); -} - -static void -sysprof_aid_icon_init (SysprofAidIcon *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); -} - -void -sysprof_aid_icon_toggle (SysprofAidIcon *self) -{ - g_return_if_fail (SYSPROF_IS_AID_ICON (self)); - - gtk_widget_set_visible (GTK_WIDGET (self->check), - !gtk_widget_get_visible (GTK_WIDGET (self->check))); -} diff --git a/src/libsysprof-ui/sysprof-aid-icon.h b/src/libsysprof-ui/sysprof-aid-icon.h deleted file mode 100644 index 20f53f68..00000000 --- a/src/libsysprof-ui/sysprof-aid-icon.h +++ /dev/null @@ -1,39 +0,0 @@ -/* sysprof-aid-icon.h - * - * Copyright 2019 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 -#include - -#include "sysprof-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_AID_ICON (sysprof_aid_icon_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofAidIcon, sysprof_aid_icon, SYSPROF, AID_ICON, GtkFlowBoxChild) - -GtkWidget *sysprof_aid_icon_new (SysprofAid *aid); -SysprofAid *sysprof_aid_icon_get_aid (SysprofAidIcon *self); -void sysprof_aid_icon_toggle (SysprofAidIcon *self); -gboolean sysprof_aid_icon_is_selected (SysprofAidIcon *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-aid-icon.ui b/src/libsysprof-ui/sysprof-aid-icon.ui deleted file mode 100644 index 491cb405..00000000 --- a/src/libsysprof-ui/sysprof-aid-icon.ui +++ /dev/null @@ -1,41 +0,0 @@ - - - - - diff --git a/src/libsysprof-ui/sysprof-aid.c b/src/libsysprof-ui/sysprof-aid.c deleted file mode 100644 index 1bf3a489..00000000 --- a/src/libsysprof-ui/sysprof-aid.c +++ /dev/null @@ -1,353 +0,0 @@ -/* sysprof-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-aid" - -#include "config.h" - -#include - -#include "sysprof-aid.h" - -typedef struct -{ - GPtrArray *sources; - gchar *display_name; - GIcon *icon; -} SysprofAidPrivate; - -static void buildable_iface_init (GtkBuildableIface *iface); - -G_DEFINE_TYPE_WITH_CODE (SysprofAid, sysprof_aid, G_TYPE_OBJECT, - G_ADD_PRIVATE (SysprofAid) - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init)) - -enum { - PROP_0, - PROP_DISPLAY_NAME, - PROP_ICON, - PROP_ICON_NAME, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_aid_real_present_async (SysprofAid *self, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_task_report_new_error (self, callback, user_data, - sysprof_aid_real_present_async, - G_IO_ERROR, - G_IO_ERROR_NOT_SUPPORTED, - "Not supported"); -} - -static gboolean -sysprof_aid_real_present_finish (SysprofAid *self, - GAsyncResult *result, - GError **error) -{ - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_aid_finalize (GObject *object) -{ - SysprofAid *self = (SysprofAid *)object; - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_clear_pointer (&priv->sources, g_ptr_array_unref); - g_clear_pointer (&priv->display_name, g_free); - g_clear_object (&priv->icon); - - G_OBJECT_CLASS (sysprof_aid_parent_class)->finalize (object); -} - -static void -sysprof_aid_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofAid *self = SYSPROF_AID (object); - - switch (prop_id) - { - case PROP_DISPLAY_NAME: - g_value_set_string (value, sysprof_aid_get_display_name (self)); - break; - - case PROP_ICON: - g_value_set_object (value, sysprof_aid_get_icon (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_aid_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofAid *self = SYSPROF_AID (object); - - switch (prop_id) - { - case PROP_DISPLAY_NAME: - sysprof_aid_set_display_name (self, g_value_get_string (value)); - break; - - case PROP_ICON: - sysprof_aid_set_icon (self, g_value_get_object (value)); - break; - - case PROP_ICON_NAME: - sysprof_aid_set_icon_name (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_aid_class_init (SysprofAidClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_aid_finalize; - object_class->get_property = sysprof_aid_get_property; - object_class->set_property = sysprof_aid_set_property; - - klass->present_async = sysprof_aid_real_present_async; - klass->present_finish = sysprof_aid_real_present_finish; - - properties [PROP_DISPLAY_NAME] = - g_param_spec_string ("display-name", - "Display Name", - "Display Name", - NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_ICON_NAME] = - g_param_spec_string ("icon-name", - "Icon Name", - "Icon Name", - NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_ICON] = - g_param_spec_object ("icon", - "Icon", - "The icon to display", - G_TYPE_ICON, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_aid_init (SysprofAid *self G_GNUC_UNUSED) -{ -} - -/** - * sysprof_aid_get_display_name: - * @self: a #SysprofAid - * - * Gets the display name as it should be shown to the user. - * - * Returns: a string containing the display name - * - * Since: 3.34 - */ -const gchar * -sysprof_aid_get_display_name (SysprofAid *self) -{ - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_AID (self), NULL); - - return priv->display_name; -} - -/** - * sysprof_aid_get_icon: - * - * Gets the icon for the aid. - * - * Returns: (transfer none) (nullable): a #GIcon or %NULL - * - * Since: 3.34 - */ -GIcon * -sysprof_aid_get_icon (SysprofAid *self) -{ - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_AID (self), NULL); - - return priv->icon; -} - -void -sysprof_aid_set_icon (SysprofAid *self, - GIcon *icon) -{ - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_AID (self)); - - if (g_set_object (&priv->icon, icon)) - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ICON]); -} - -void -sysprof_aid_set_icon_name (SysprofAid *self, - const gchar *icon_name) -{ - g_autoptr(GIcon) icon = NULL; - - g_return_if_fail (SYSPROF_IS_AID (self)); - - if (icon_name != NULL) - icon = g_themed_icon_new (icon_name); - - sysprof_aid_set_icon (self, icon); -} - -void -sysprof_aid_set_display_name (SysprofAid *self, - const gchar *display_name) -{ - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_AID (self)); - - if (g_strcmp0 (display_name, priv->display_name) != 0) - { - g_free (priv->display_name); - priv->display_name = g_strdup (display_name); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_DISPLAY_NAME]); - } -} - -void -sysprof_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_AID (self)); - g_return_if_fail (SYSPROF_IS_PROFILER (profiler)); - - if (priv->sources != NULL) - { - for (guint i = 0; i < priv->sources->len; i++) - { - SysprofSource *source = g_ptr_array_index (priv->sources, i); - - sysprof_profiler_add_source (profiler, source); - } - - if (priv->sources->len > 0) - g_ptr_array_remove_range (priv->sources, 0, priv->sources->len); - } - - if (SYSPROF_AID_GET_CLASS (self)->prepare) - SYSPROF_AID_GET_CLASS (self)->prepare (self, profiler); -} - -static void -sysprof_aid_add_child (GtkBuildable *buildable, - GtkBuilder *builder, - GObject *object, - const gchar *type G_GNUC_UNUSED) -{ - SysprofAid *self = (SysprofAid *)buildable; - SysprofAidPrivate *priv = sysprof_aid_get_instance_private (self); - - g_assert (SYSPROF_IS_AID (self)); - g_assert (GTK_IS_BUILDER (builder)); - g_assert (G_IS_OBJECT (object)); - - if (SYSPROF_IS_SOURCE (object)) - { - if (priv->sources == NULL) - priv->sources = g_ptr_array_new_with_free_func (g_object_unref); - g_ptr_array_add (priv->sources, g_object_ref (object)); - return; - } - - g_warning ("Unsupported child type of %s: %s", - G_OBJECT_TYPE_NAME (self), - G_OBJECT_TYPE_NAME (object)); -} - -static void -buildable_iface_init (GtkBuildableIface *iface) -{ - iface->add_child = sysprof_aid_add_child; -} - -SysprofAid * -sysprof_aid_new (const gchar *display_name, - const gchar *icon_name) -{ - return g_object_new (SYSPROF_TYPE_AID, - "display-aid", display_name, - "icon-name", icon_name, - NULL); -} - -void -sysprof_aid_present_async (SysprofAid *self, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_return_if_fail (SYSPROF_IS_AID (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (SYSPROF_IS_DISPLAY (display)); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - SYSPROF_AID_GET_CLASS (self)->present_async (self, reader, display, cancellable, callback, user_data); -} - -gboolean -sysprof_aid_present_finish (SysprofAid *self, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_AID (self), FALSE); - g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); - - return SYSPROF_AID_GET_CLASS (self)->present_finish (self, result, error); -} diff --git a/src/libsysprof-ui/sysprof-aid.h b/src/libsysprof-ui/sysprof-aid.h deleted file mode 100644 index 70a16667..00000000 --- a/src/libsysprof-ui/sysprof-aid.h +++ /dev/null @@ -1,76 +0,0 @@ -/* sysprof-aid.h - * - * Copyright 2019 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 -#include - -#include "sysprof-display.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_AID (sysprof_aid_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofAid, sysprof_aid, SYSPROF, AID, GObject) - -struct _SysprofAidClass -{ - GObjectClass parent_class; - - void (*prepare) (SysprofAid *self, - SysprofProfiler *profiler); - void (*present_async) (SysprofAid *self, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - gboolean (*present_finish) (SysprofAid *self, - GAsyncResult *result, - GError **error); - - /*< private >*/ - gpointer _reserved[16]; -}; - -SysprofAid *sysprof_aid_new (const gchar *display_name, - const gchar *icon_name); -const gchar *sysprof_aid_get_display_name (SysprofAid *self); -void sysprof_aid_set_display_name (SysprofAid *self, - const gchar *display_name); -GIcon *sysprof_aid_get_icon (SysprofAid *self); -void sysprof_aid_set_icon (SysprofAid *self, - GIcon *icon); -void sysprof_aid_set_icon_name (SysprofAid *self, - const gchar *icon_name); -void sysprof_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler); -void sysprof_aid_present_async (SysprofAid *self, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean sysprof_aid_present_finish (SysprofAid *self, - GAsyncResult *result, - GError **error); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-battery-aid.c b/src/libsysprof-ui/sysprof-battery-aid.c deleted file mode 100644 index 9351200f..00000000 --- a/src/libsysprof-ui/sysprof-battery-aid.c +++ /dev/null @@ -1,242 +0,0 @@ -/* sysprof-battery-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-battery-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-battery-aid.h" -#include "sysprof-line-visualizer.h" - -struct _SysprofBatteryAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; -} Present; - -G_DEFINE_TYPE (SysprofBatteryAid, sysprof_battery_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -/** - * sysprof_battery_aid_new: - * - * Create a new #SysprofBatteryAid. - * - * Returns: (transfer full): a newly created #SysprofBatteryAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_battery_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_BATTERY_AID, NULL); -} - -static void -sysprof_battery_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ -#ifdef __linux__ - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_BATTERY_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_battery_source_new (); - sysprof_profiler_add_source (profiler, source); -#endif -} - -static bool -collect_battery_counters (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - GArray *counters = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (counters != NULL); - - for (guint i = 0; i < def->n_counters; i++) - { - const SysprofCaptureCounter *counter = &def->counters[i]; - - if (g_strcmp0 (counter->category, "Battery Charge") == 0) - g_array_append_vals (counters, counter, 1); - } - - return TRUE; -} - -static void -sysprof_battery_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *present = task_data; - g_autoptr(GArray) counters = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_BATTERY_AID (source_object)); - g_assert (present != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); - sysprof_capture_cursor_foreach (present->cursor, collect_battery_counters, counters); - g_task_return_pointer (task, - g_steal_pointer (&counters), - (GDestroyNotify) g_array_unref); -} - -static void -sysprof_battery_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_CTRDEF }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_BATTERY_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (1, types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_battery_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_battery_aid_present_worker); -} - -static gboolean -sysprof_battery_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) counters = NULL; - Present *present; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_TASK (result)); - - present = g_task_get_task_data (G_TASK (result)); - - if ((counters = g_task_propagate_pointer (G_TASK (result), error))) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - SysprofVisualizerGroup *group; - guint found = 0; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "title", _("Battery Charge"), - "visible", TRUE, - NULL); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *ctr = &g_array_index (counters, SysprofCaptureCounter, i); - - if (g_strcmp0 (ctr->category, "Battery Charge") == 0) - { - g_autofree gchar *title = NULL; - gboolean is_combined = g_str_equal (ctr->name, "Combined"); - GtkWidget *row; - GdkRGBA rgba; - - if (is_combined) - title = g_strdup (_("Battery Charge (All)")); - else - title = g_strdup_printf ("Battery Charge (%s)", ctr->name); - - row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", title, - "height-request", 35, - "visible", is_combined, - NULL); - sysprof_color_cycle_next (cycle, &rgba); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - sysprof_visualizer_group_insert (group, - SYSPROF_VISUALIZER (row), - is_combined ? 0 : -1, - !is_combined); - - found++; - } - } - - if (found > 0) - sysprof_display_add_group (present->display, group); - else - g_object_unref (g_object_ref_sink (group)); - } - - return counters != NULL; -} - -static void -sysprof_battery_aid_class_init (SysprofBatteryAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_battery_aid_prepare; - aid_class->present_async = sysprof_battery_aid_present_async; - aid_class->present_finish = sysprof_battery_aid_present_finish; -} - -static void -sysprof_battery_aid_init (SysprofBatteryAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Battery")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "battery-low-charging-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-battery-aid.h b/src/libsysprof-ui/sysprof-battery-aid.h deleted file mode 100644 index 563793f1..00000000 --- a/src/libsysprof-ui/sysprof-battery-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-battery-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_BATTERY_AID (sysprof_battery_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofBatteryAid, sysprof_battery_aid, SYSPROF, BATTERY_AID, SysprofAid) - -SysprofAid *sysprof_battery_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-cairo.c b/src/libsysprof-ui/sysprof-cairo.c deleted file mode 100644 index 3d8f82a6..00000000 --- a/src/libsysprof-ui/sysprof-cairo.c +++ /dev/null @@ -1,71 +0,0 @@ -/* sysprof-cairo.c - * - * Copyright 2019 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-ui-private.h" - -void -_sysprof_rounded_rectangle (cairo_t *cr, - const GdkRectangle *rect, - gint x_radius, - gint y_radius) -{ - gint x; - gint y; - gint width; - gint height; - gint x1, x2; - gint y1, y2; - gint xr1, xr2; - gint yr1, yr2; - - g_return_if_fail (cr); - g_return_if_fail (rect); - - x = rect->x; - y = rect->y; - width = rect->width; - height = rect->height; - - x1 = x; - x2 = x1 + width; - y1 = y; - y2 = y1 + height; - - x_radius = MIN (x_radius, width / 2.0); - y_radius = MIN (y_radius, width / 2.0); - - xr1 = x_radius; - xr2 = x_radius / 2.0; - yr1 = y_radius; - yr2 = y_radius / 2.0; - - cairo_move_to (cr, x1 + xr1, y1); - cairo_line_to (cr, x2 - xr1, y1); - cairo_curve_to (cr, x2 - xr2, y1, x2, y1 + yr2, x2, y1 + yr1); - cairo_line_to (cr, x2, y2 - yr1); - cairo_curve_to (cr, x2, y2 - yr2, x2 - xr2, y2, x2 - xr1, y2); - cairo_line_to (cr, x1 + xr1, y2); - cairo_curve_to (cr, x1 + xr2, y2, x1, y2 - yr2, x1, y2 - yr1); - cairo_line_to (cr, x1, y1 + yr1); - cairo_curve_to (cr, x1, y1 + yr2, x1 + xr2, y1, x1 + xr1, y1); - cairo_close_path (cr); -} diff --git a/src/libsysprof-ui/sysprof-callgraph-aid.c b/src/libsysprof-ui/sysprof-callgraph-aid.c deleted file mode 100644 index f12be766..00000000 --- a/src/libsysprof-ui/sysprof-callgraph-aid.c +++ /dev/null @@ -1,275 +0,0 @@ -/* sysprof-callgraph-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-callgraph-aid" - -#include "config.h" - -#include - -#include "sysprof-callgraph-aid.h" -#include "sysprof-callgraph-page.h" -#include "sysprof-depth-visualizer.h" - -struct _SysprofCallgraphAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; - guint has_samples : 1; -} Present; - -G_DEFINE_TYPE (SysprofCallgraphAid, sysprof_callgraph_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -static void -on_group_activated_cb (SysprofVisualizerGroup *group, - SysprofPage *page) -{ - SysprofDisplay *display; - - g_assert (SYSPROF_IS_VISUALIZER_GROUP (group)); - g_assert (SYSPROF_IS_PAGE (page)); - - display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (page), SYSPROF_TYPE_DISPLAY)); - sysprof_display_set_visible_page (display, page); -} - -/** - * sysprof_callgraph_aid_new: - * - * Create a new #SysprofCallgraphAid. - * - * Returns: (transfer full): a newly created #SysprofCallgraphAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_callgraph_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_CALLGRAPH_AID, NULL); -} - -static void -sysprof_callgraph_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ - g_assert (SYSPROF_IS_CALLGRAPH_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - -#ifdef __linux__ - { - const GPid *pids; - guint n_pids; - - if ((pids = sysprof_profiler_get_pids (profiler, &n_pids))) - { - for (guint i = 0; i < n_pids; i++) - { - g_autoptr(SysprofSource) source = NULL; - - source = sysprof_perf_source_new (); - sysprof_perf_source_set_target_pid (SYSPROF_PERF_SOURCE (source), pids[i]); - sysprof_profiler_add_source (profiler, source); - } - } - else - { - g_autoptr(SysprofSource) source = NULL; - - source = sysprof_perf_source_new (); - sysprof_profiler_add_source (profiler, source); - } - } -#endif -} - -static bool -discover_samples_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - Present *p = user_data; - - g_assert (frame != NULL); - g_assert (p != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_SAMPLE) - { - p->has_samples = TRUE; - return FALSE; - } - - return TRUE; -} - -static void -sysprof_callgraph_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *p = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_CALLGRAPH_AID (source_object)); - g_assert (p != NULL); - g_assert (p->cursor != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - /* If we find a sample frame, then we should enable the callgraph - * and stack visualizers. - */ - sysprof_capture_cursor_foreach (p->cursor, discover_samples_cb, p); - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_callgraph_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_SAMPLE }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_CALLGRAPH_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (1, types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_callgraph_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_callgraph_aid_present_worker); -} - -static gboolean -sysprof_callgraph_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - Present *p; - - g_assert (SYSPROF_IS_CALLGRAPH_AID (aid)); - g_assert (G_IS_TASK (result)); - - p = g_task_get_task_data (G_TASK (result)); - - if (p->has_samples) - { - SysprofVisualizerGroup *group; - SysprofVisualizer *depth; - SysprofPage *page; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "has-page", TRUE, - "priority", -500, - "title", _("Stack Traces"), - "visible", TRUE, - NULL); - - depth = sysprof_depth_visualizer_new (SYSPROF_DEPTH_VISUALIZER_COMBINED); - g_object_set (depth, - "title", _("Stack Traces"), - "height-request", 35, - "visible", TRUE, - NULL); - sysprof_visualizer_group_insert (group, depth, 0, FALSE); - - depth = sysprof_depth_visualizer_new (SYSPROF_DEPTH_VISUALIZER_KERNEL_ONLY); - g_object_set (depth, - "title", _("Stack Traces (In Kernel)"), - "height-request", 35, - "visible", FALSE, - NULL); - sysprof_visualizer_group_insert (group, depth, 1, TRUE); - - depth = sysprof_depth_visualizer_new (SYSPROF_DEPTH_VISUALIZER_USER_ONLY); - g_object_set (depth, - "title", _("Stack Traces (In User)"), - "height-request", 35, - "visible", FALSE, - NULL); - sysprof_visualizer_group_insert (group, depth, 2, TRUE); - - sysprof_display_add_group (p->display, group); - - page = g_object_new (SYSPROF_TYPE_CALLGRAPH_PAGE, - "title", _("Callgraph"), - "vexpand", TRUE, - "visible", TRUE, - NULL); - sysprof_display_add_page (p->display, page); - sysprof_display_set_visible_page (p->display, page); - - g_signal_connect_object (group, - "group-activated", - G_CALLBACK (on_group_activated_cb), - page, - 0); - } - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_callgraph_aid_class_init (SysprofCallgraphAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_callgraph_aid_prepare; - aid_class->present_async = sysprof_callgraph_aid_present_async; - aid_class->present_finish = sysprof_callgraph_aid_present_finish; -} - -static void -sysprof_callgraph_aid_init (SysprofCallgraphAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Callgraph")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "org.gnome.Sysprof-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-callgraph-aid.h b/src/libsysprof-ui/sysprof-callgraph-aid.h deleted file mode 100644 index 3fdde80a..00000000 --- a/src/libsysprof-ui/sysprof-callgraph-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-callgraph-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_CALLGRAPH_AID (sysprof_callgraph_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofCallgraphAid, sysprof_callgraph_aid, SYSPROF, CALLGRAPH_AID, SysprofAid) - -SysprofAid *sysprof_callgraph_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-callgraph-page.c b/src/libsysprof-ui/sysprof-callgraph-page.c deleted file mode 100644 index 0cbabbb4..00000000 --- a/src/libsysprof-ui/sysprof-callgraph-page.c +++ /dev/null @@ -1,1299 +0,0 @@ -/* sysprof-callgraph-page.c - * - * Copyright 2016-2019 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 - */ - -/* Sysprof -- Sampling, systemwide CPU profiler - * Copyright 2004, Red Hat, Inc. - * Copyright 2004, 2005, 2006, Soeren Sandmann - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include - -#include "../stackstash.h" - -#include "egg-paned-private.h" - -#include "sysprof-callgraph-page.h" -#include "sysprof-cell-renderer-percent.h" - -typedef struct -{ - SysprofCallgraphProfile *profile; - - GtkTreeView *callers_view; - GtkTreeView *functions_view; - GtkTreeView *descendants_view; - GtkTreeViewColumn *descendants_name_column; - GtkStack *stack; - GtkWidget *empty_state; - GtkWidget *loading_state; - GtkWidget *callgraph; - - GQueue *history; - - guint profile_size; - guint loading; -} SysprofCallgraphPagePrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofCallgraphPage, sysprof_callgraph_page, SYSPROF_TYPE_PAGE) - -enum { - PROP_0, - PROP_PROFILE, - N_PROPS -}; - -enum { - GO_PREVIOUS, - N_SIGNALS -}; - -enum { - COLUMN_NAME, - COLUMN_SELF, - COLUMN_TOTAL, - COLUMN_POINTER, - COLUMN_HITS, -}; - -static void sysprof_callgraph_page_update_descendants (SysprofCallgraphPage *self, - StackNode *node); - -static GParamSpec *properties [N_PROPS]; -static guint signals [N_SIGNALS]; - -static guint -sysprof_callgraph_page_get_profile_size (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - StackStash *stash; - StackNode *node; - guint size = 0; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - if (priv->profile_size != 0) - return priv->profile_size; - - if (priv->profile == NULL) - return 0; - - if (NULL == (stash = sysprof_callgraph_profile_get_stash (priv->profile))) - return 0; - - for (node = stack_stash_get_root (stash); node != NULL; node = node->siblings) - size += node->total; - - priv->profile_size = size; - - return size; -} - -static void -build_functions_store (StackNode *node, - gpointer user_data) -{ - struct { - GtkListStore *store; - gdouble profile_size; - } *state = user_data; - GtkTreeIter iter; - const StackNode *n; - guint size = 0; - guint total = 0; - - g_assert (state != NULL); - g_assert (GTK_IS_LIST_STORE (state->store)); - - for (n = node; n != NULL; n = n->next) - { - size += n->size; - if (n->toplevel) - total += n->total; - } - - gtk_list_store_append (state->store, &iter); - gtk_list_store_set (state->store, &iter, - COLUMN_NAME, U64_TO_POINTER(node->data), - COLUMN_SELF, 100.0 * size / state->profile_size, - COLUMN_TOTAL, 100.0 * total / state->profile_size, - COLUMN_POINTER, node, - -1); - -} - -static void -sysprof_callgraph_page_load (SysprofCallgraphPage *self, - SysprofCallgraphProfile *profile) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkListStore *functions; - StackStash *stash; - StackNode *n; - GtkTreeIter iter; - struct { - GtkListStore *store; - gdouble profile_size; - } state = { 0 }; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (SYSPROF_IS_CALLGRAPH_PROFILE (profile)); - - /* - * TODO: This is probably the type of thing we want to do off the main - * thread. We should be able to build the tree models off thread - * and then simply apply them on the main thread. - * - * In the mean time, we should set the state of the widget to - * insensitive and give some indication of loading progress. - */ - - if (!g_set_object (&priv->profile, profile)) - return; - - if (sysprof_callgraph_profile_is_empty (profile)) - return; - - stash = sysprof_callgraph_profile_get_stash (profile); - - for (n = stack_stash_get_root (stash); n; n = n->siblings) - state.profile_size += n->total; - - functions = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_POINTER); - - state.store = functions; - stack_stash_foreach_by_address (stash, build_functions_store, &state); - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (functions), - COLUMN_TOTAL, - GTK_SORT_DESCENDING); - - gtk_tree_view_set_model (priv->functions_view, GTK_TREE_MODEL (functions)); - gtk_tree_view_set_model (priv->callers_view, NULL); - gtk_tree_view_set_model (priv->descendants_view, NULL); - - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (functions), &iter)) - { - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (priv->functions_view); - gtk_tree_selection_select_iter (selection, &iter); - } - - gtk_stack_set_visible_child (priv->stack, priv->callgraph); - - g_clear_object (&functions); -} - -void -_sysprof_callgraph_page_set_failed (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - gtk_stack_set_visible_child (priv->stack, priv->empty_state); -} - -static void -sysprof_callgraph_page_unload (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (SYSPROF_IS_CALLGRAPH_PROFILE (priv->profile)); - - g_queue_clear (priv->history); - g_clear_object (&priv->profile); - priv->profile_size = 0; - - gtk_tree_view_set_model (priv->callers_view, NULL); - gtk_tree_view_set_model (priv->functions_view, NULL); - gtk_tree_view_set_model (priv->descendants_view, NULL); - - gtk_stack_set_visible_child (priv->stack, priv->empty_state); -} - -/** - * sysprof_callgraph_page_get_profile: - * - * Returns: (transfer none): An #SysprofCallgraphProfile. - */ -SysprofCallgraphProfile * -sysprof_callgraph_page_get_profile (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (self), NULL); - - return priv->profile; -} - -void -sysprof_callgraph_page_set_profile (SysprofCallgraphPage *self, - SysprofCallgraphProfile *profile) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_return_if_fail (!profile || SYSPROF_IS_CALLGRAPH_PROFILE (profile)); - - if (profile != priv->profile) - { - if (priv->profile) - sysprof_callgraph_page_unload (self); - - if (profile) - sysprof_callgraph_page_load (self, profile); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PROFILE]); - } -} - -static void -sysprof_callgraph_page_expand_descendants (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeModel *model; - GList *all_paths = NULL; - GtkTreePath *first_path; - GtkTreeIter iter; - gdouble top_value = 0; - gint max_rows = 40; /* FIXME */ - gint n_rows; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - model = gtk_tree_view_get_model (priv->descendants_view); - first_path = gtk_tree_path_new_first (); - all_paths = g_list_prepend (all_paths, first_path); - n_rows = 1; - - gtk_tree_model_get_iter (model, &iter, first_path); - gtk_tree_model_get (model, &iter, - COLUMN_TOTAL, &top_value, - -1); - - while ((all_paths != NULL) && (n_rows < max_rows)) - { - GtkTreeIter best_iter; - GtkTreePath *best_path = NULL; - GList *list; - gdouble best_value = 0.0; - gint n_children; - gint i; - - for (list = all_paths; list != NULL; list = list->next) - { - GtkTreePath *path = list->data; - - g_assert (path != NULL); - - if (gtk_tree_model_get_iter (model, &iter, path)) - { - gdouble value; - - gtk_tree_model_get (model, &iter, - COLUMN_TOTAL, &value, - -1); - - if (value >= best_value) - { - best_value = value; - best_path = path; - best_iter = iter; - } - } - } - - n_children = gtk_tree_model_iter_n_children (model, &best_iter); - - if ((n_children > 0) && - ((best_value / top_value) > 0.04) && - ((n_children + gtk_tree_path_get_depth (best_path)) / (gdouble)max_rows) < (best_value / top_value)) - { - gtk_tree_view_expand_row (priv->descendants_view, best_path, FALSE); - n_rows += n_children; - - if (gtk_tree_path_get_depth (best_path) < 4) - { - GtkTreePath *path; - - path = gtk_tree_path_copy (best_path); - gtk_tree_path_down (path); - - for (i = 0; i < n_children; i++) - { - all_paths = g_list_prepend (all_paths, path); - - path = gtk_tree_path_copy (path); - gtk_tree_path_next (path); - } - - gtk_tree_path_free (path); - } - } - - all_paths = g_list_remove (all_paths, best_path); - - /* Always expand at least once */ - if ((all_paths == NULL) && (n_rows == 1)) - gtk_tree_view_expand_row (priv->descendants_view, best_path, FALSE); - - gtk_tree_path_free (best_path); - } - - g_list_free_full (all_paths, (GDestroyNotify)gtk_tree_path_free); -} - -typedef struct -{ - StackNode *node; - const gchar *name; - guint self; - guint total; -} Caller; - -static Caller * -caller_new (StackNode *node) -{ - Caller *c; - - c = g_slice_new (Caller); - c->name = U64_TO_POINTER (node->data); - c->self = 0; - c->total = 0; - c->node = node; - - return c; -} - -static void -caller_free (gpointer data) -{ - Caller *c = data; - g_slice_free (Caller, c); -} - -static void -sysprof_callgraph_page_function_selection_changed (SysprofCallgraphPage *self, - GtkTreeSelection *selection) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeModel *model = NULL; - GtkTreeIter iter; - GtkListStore *callers_store; - g_autoptr(GHashTable) callers = NULL; - g_autoptr(GHashTable) processed = NULL; - StackNode *callees = NULL; - StackNode *node; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (GTK_IS_TREE_SELECTION (selection)); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - { - gtk_tree_view_set_model (priv->callers_view, NULL); - gtk_tree_view_set_model (priv->descendants_view, NULL); - return; - } - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &callees, - -1); - - sysprof_callgraph_page_update_descendants (self, callees); - - callers_store = gtk_list_store_new (4, - G_TYPE_STRING, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE, - G_TYPE_POINTER); - - callers = g_hash_table_new_full (NULL, NULL, NULL, caller_free); - processed = g_hash_table_new (NULL, NULL); - - for (node = callees; node != NULL; node = node->next) - { - Caller *c; - - if (!node->parent) - continue; - - c = g_hash_table_lookup (callers, U64_TO_POINTER (node->parent->data)); - - if (c == NULL) - { - c = caller_new (node->parent); - g_hash_table_insert (callers, (gpointer)c->name, c); - } - } - - for (node = callees; node != NULL; node = node->next) - { - StackNode *top_caller = node->parent; - StackNode *top_callee = node; - StackNode *n; - Caller *c; - - if (!node->parent) - continue; - - /* - * We could have a situation where the function was called in a - * reentrant fashion, so we want to take the top-most match in the - * stack. - */ - for (n = node; n && n->parent; n = n->parent) - { - if (n->data == node->data && n->parent->data == node->parent->data) - { - top_caller = n->parent; - top_callee = n; - } - } - - c = g_hash_table_lookup (callers, U64_TO_POINTER (node->parent->data)); - - g_assert (c != NULL); - - if (!g_hash_table_lookup (processed, top_caller)) - { - c->total += top_callee->total; - g_hash_table_insert (processed, top_caller, top_caller); - } - - c->self += node->size; - } - - { - GHashTableIter hiter; - gpointer key, value; - guint size = 0; - - size = MAX (1, sysprof_callgraph_page_get_profile_size (self)); - - g_hash_table_iter_init (&hiter, callers); - - while (g_hash_table_iter_next (&hiter, &key, &value)) - { - Caller *c = value; - - gtk_list_store_append (callers_store, &iter); - gtk_list_store_set (callers_store, &iter, - COLUMN_NAME, c->name, - COLUMN_SELF, c->self * 100.0 / size, - COLUMN_TOTAL, c->total * 100.0 / size, - COLUMN_POINTER, c->node, - -1); - } - } - - gtk_tree_view_set_model (priv->callers_view, GTK_TREE_MODEL (callers_store)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (callers_store), - COLUMN_TOTAL, - GTK_SORT_DESCENDING); - - g_clear_object (&callers_store); -} - -static void -sysprof_callgraph_page_set_node (SysprofCallgraphPage *self, - StackNode *node) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeModel *model; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (node != NULL); - - if (priv->profile == NULL) - return; - - model = gtk_tree_view_get_model (priv->functions_view); - - if (gtk_tree_model_get_iter_first (model, &iter)) - { - do - { - StackNode *item = NULL; - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &item, - -1); - - if (item != NULL && item->data == node->data) - { - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (priv->functions_view); - gtk_tree_selection_select_iter (selection, &iter); - - break; - } - } - while (gtk_tree_model_iter_next (model, &iter)); - } -} - -static void -sysprof_callgraph_page_descendant_activated (SysprofCallgraphPage *self, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkTreeView *tree_view) -{ - GtkTreeModel *model; - StackNode *node = NULL; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (GTK_IS_TREE_VIEW (tree_view)); - g_assert (path != NULL); - g_assert (GTK_IS_TREE_VIEW_COLUMN (column)); - - model = gtk_tree_view_get_model (tree_view); - - if (!gtk_tree_model_get_iter (model, &iter, path)) - return; - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &node, - -1); - - if (node != NULL) - sysprof_callgraph_page_set_node (self, node); -} - -static void -sysprof_callgraph_page_caller_activated (SysprofCallgraphPage *self, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkTreeView *tree_view) -{ - GtkTreeModel *model; - StackNode *node = NULL; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (GTK_IS_TREE_VIEW (tree_view)); - g_assert (path != NULL); - g_assert (GTK_IS_TREE_VIEW_COLUMN (column)); - - model = gtk_tree_view_get_model (tree_view); - - if (!gtk_tree_model_get_iter (model, &iter, path)) - return; - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &node, - -1); - - if (node != NULL) - sysprof_callgraph_page_set_node (self, node); -} - -static void -sysprof_callgraph_page_tag_data_func (GtkTreeViewColumn *column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - SysprofCallgraphPage *self = data; - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - StackNode *node = NULL; - const gchar *str = NULL; - - if (priv->profile == NULL) - return; - - gtk_tree_model_get (model, iter, COLUMN_POINTER, &node, -1); - - if (node && node->data) - { - GQuark tag; - - tag = sysprof_callgraph_profile_get_tag (priv->profile, GSIZE_TO_POINTER (node->data)); - if (tag != 0) - str = g_quark_to_string (tag); - } - - g_object_set (cell, "text", str, NULL); -} - -static void -sysprof_callgraph_page_real_go_previous (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - StackNode *node; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - node = g_queue_pop_head (priv->history); - - if (NULL != (node = g_queue_peek_head (priv->history))) - sysprof_callgraph_page_set_node (self, node); -} - -static gboolean -descendants_view_move_cursor_cb (GtkTreeView *descendants_view, - GtkMovementStep step, - int direction, - gboolean extend, - gboolean modify, - gpointer user_data) -{ - if (step == GTK_MOVEMENT_VISUAL_POSITIONS) - { - GtkTreePath *path; - - gtk_tree_view_get_cursor (descendants_view, &path, NULL); - - if (direction == 1) - { - gtk_tree_view_expand_row (descendants_view, path, FALSE); - g_signal_stop_emission_by_name (descendants_view, "move-cursor"); - return FALSE; - } - else if (direction == -1) - { - gtk_tree_view_collapse_row (descendants_view, path); - g_signal_stop_emission_by_name (descendants_view, "move-cursor"); - return FALSE; - } - - gtk_tree_path_free (path); - } - - return TRUE; -} - -static void -copy_tree_view_selection_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - g_autofree gchar *name = NULL; - gchar sstr[16]; - gchar tstr[16]; - GString *str = data; - gdouble self; - gdouble total; - gint depth; - - g_assert (GTK_IS_TREE_MODEL (model)); - g_assert (path != NULL); - g_assert (iter != NULL); - g_assert (str != NULL); - - depth = gtk_tree_path_get_depth (path); - gtk_tree_model_get (model, iter, - COLUMN_NAME, &name, - COLUMN_SELF, &self, - COLUMN_TOTAL, &total, - -1); - - g_snprintf (sstr, sizeof sstr, "%.2lf%%", self); - g_snprintf (tstr, sizeof tstr, "%.2lf%%", total); - - g_string_append_printf (str, "[%8s] [%8s] ", sstr, tstr); - - for (gint i = 1; i < depth; i++) - g_string_append (str, " "); - g_string_append (str, name); - g_string_append_c (str, '\n'); -} - -static void -copy_tree_view_selection (GtkTreeView *tree_view) -{ - g_autoptr(GString) str = NULL; - GdkClipboard *clipboard; - - g_assert (GTK_IS_TREE_VIEW (tree_view)); - - str = g_string_new (" SELF TOTAL FUNCTION\n"); - gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (tree_view), - copy_tree_view_selection_cb, - str); - - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (tree_view)); - gdk_clipboard_set_text (clipboard, str->str); -} - -static void -sysprof_callgraph_page_copy_cb (GtkWidget *widget, - const char *action_name, - GVariant *param) -{ - SysprofCallgraphPage *self = (SysprofCallgraphPage *)widget; - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkRoot *toplevel; - GtkWidget *focus; - - g_assert (GTK_IS_WIDGET (widget)); - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - if (!(toplevel = gtk_widget_get_root (widget)) || - !GTK_IS_ROOT (toplevel) || - !(focus = gtk_root_get_focus (toplevel))) - return; - - if (focus == GTK_WIDGET (priv->descendants_view)) - copy_tree_view_selection (priv->descendants_view); - else if (focus == GTK_WIDGET (priv->callers_view)) - copy_tree_view_selection (priv->callers_view); - else if (focus == GTK_WIDGET (priv->functions_view)) - copy_tree_view_selection (priv->functions_view); -} - -static void -sysprof_callgraph_page_generate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofProfile *profile = (SysprofProfile *)object; - SysprofCallgraphPage *self; - g_autoptr(GTask) task = user_data; - g_autoptr(GError) error = NULL; - - g_assert (SYSPROF_IS_PROFILE (profile)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - self = g_task_get_source_object (task); - - if (!sysprof_profile_generate_finish (profile, result, &error)) - g_task_return_error (task, g_steal_pointer (&error)); - else - sysprof_callgraph_page_set_profile (self, SYSPROF_CALLGRAPH_PROFILE (profile)); -} - -static void -sysprof_callgraph_page_load_async (SysprofPage *page, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *filter, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofCallgraphPage *self = (SysprofCallgraphPage *)page; - g_autoptr(SysprofCaptureReader) copy = NULL; - g_autoptr(SysprofProfile) profile = NULL; - g_autoptr(GTask) task = NULL; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_SELECTION (selection)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_callgraph_page_load_async); - - copy = sysprof_capture_reader_copy (reader); - - profile = sysprof_callgraph_profile_new_with_selection (selection); - sysprof_profile_set_reader (profile, reader); - sysprof_profile_generate (profile, - cancellable, - sysprof_callgraph_page_generate_cb, - g_steal_pointer (&task)); -} - -static gboolean -sysprof_callgraph_page_load_finish (SysprofPage *page, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (page), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_callgraph_page_finalize (GObject *object) -{ - SysprofCallgraphPage *self = (SysprofCallgraphPage *)object; - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - g_clear_pointer (&priv->history, g_queue_free); - g_clear_object (&priv->profile); - - G_OBJECT_CLASS (sysprof_callgraph_page_parent_class)->finalize (object); -} - -static void -sysprof_callgraph_page_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofCallgraphPage *self = SYSPROF_CALLGRAPH_PAGE (object); - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - switch (prop_id) - { - case PROP_PROFILE: - g_value_set_object (value, priv->profile); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_callgraph_page_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofCallgraphPage *self = SYSPROF_CALLGRAPH_PAGE (object); - - switch (prop_id) - { - case PROP_PROFILE: - sysprof_callgraph_page_set_profile (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_callgraph_page_class_init (SysprofCallgraphPageClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofPageClass *page_class = SYSPROF_PAGE_CLASS (klass); - - object_class->finalize = sysprof_callgraph_page_finalize; - object_class->get_property = sysprof_callgraph_page_get_property; - object_class->set_property = sysprof_callgraph_page_set_property; - - page_class->load_async = sysprof_callgraph_page_load_async; - page_class->load_finish = sysprof_callgraph_page_load_finish; - - klass->go_previous = sysprof_callgraph_page_real_go_previous; - - properties [PROP_PROFILE] = - g_param_spec_object ("profile", - "Profile", - "The callgraph profile to view", - SYSPROF_TYPE_CALLGRAPH_PROFILE, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - signals [GO_PREVIOUS] = - g_signal_new ("go-previous", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (SysprofCallgraphPageClass, go_previous), - NULL, NULL, NULL, G_TYPE_NONE, 0); - - gtk_widget_class_set_template_from_resource (widget_class, - "/org/gnome/sysprof/ui/sysprof-callgraph-page.ui"); - - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, callers_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, functions_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, descendants_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, descendants_name_column); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, stack); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, callgraph); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, empty_state); - gtk_widget_class_bind_template_child_private (widget_class, SysprofCallgraphPage, loading_state); - - gtk_widget_class_install_action (widget_class, "page.copy", NULL, sysprof_callgraph_page_copy_cb); - - gtk_widget_class_add_binding_action (widget_class, GDK_KEY_c, GDK_CONTROL_MASK, "page.copy", NULL); - gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Left, GDK_ALT_MASK, "go-previous", NULL); - - g_type_ensure (EGG_TYPE_PANED); - g_type_ensure (SYSPROF_TYPE_CELL_RENDERER_PERCENT); -} - -static void -sysprof_callgraph_page_init (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeSelection *selection; - GtkCellRenderer *cell; - - priv->history = g_queue_new (); - - gtk_widget_init_template (GTK_WIDGET (self)); - - gtk_stack_set_visible_child (priv->stack, priv->loading_state); - - selection = gtk_tree_view_get_selection (priv->functions_view); - - g_signal_connect_object (selection, - "changed", - G_CALLBACK (sysprof_callgraph_page_function_selection_changed), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->descendants_view, - "row-activated", - G_CALLBACK (sysprof_callgraph_page_descendant_activated), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->callers_view, - "row-activated", - G_CALLBACK (sysprof_callgraph_page_caller_activated), - self, - G_CONNECT_SWAPPED); - - g_signal_connect (priv->descendants_view, - "move-cursor", - G_CALLBACK (descendants_view_move_cursor_cb), - NULL); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, - "ellipsize", PANGO_ELLIPSIZE_MIDDLE, - "xalign", 0.0f, - NULL); - gtk_tree_view_column_pack_start (priv->descendants_name_column, cell, TRUE); - gtk_tree_view_column_add_attribute (priv->descendants_name_column, cell, "text", 0); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, - "foreground", "#666666", - "scale", PANGO_SCALE_SMALL, - "xalign", 1.0f, - NULL); - gtk_tree_view_column_pack_start (priv->descendants_name_column, cell, FALSE); - gtk_tree_view_column_set_cell_data_func (priv->descendants_name_column, cell, - sysprof_callgraph_page_tag_data_func, - self, NULL); - - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (priv->descendants_view), - GTK_SELECTION_MULTIPLE); -} - -typedef struct _Descendant Descendant; - -struct _Descendant -{ - const gchar *name; - guint self; - guint cumulative; - Descendant *parent; - Descendant *siblings; - Descendant *children; -}; - -static void -build_tree_cb (StackLink *trace, - gint size, - gpointer user_data) -{ - Descendant **tree = user_data; - Descendant *parent = NULL; - StackLink *link; - - g_assert (trace != NULL); - g_assert (tree != NULL); - - /* Get last item */ - link = trace; - while (link->next) - link = link->next; - - for (; link != NULL; link = link->prev) - { - const gchar *address = U64_TO_POINTER (link->data); - Descendant *prev = NULL; - Descendant *match = NULL; - - for (match = *tree; match != NULL; match = match->siblings) - { - if (match->name == address) - { - if (prev != NULL) - { - /* Move to front */ - prev->siblings = match->siblings; - match->siblings = *tree; - *tree = match; - } - break; - } - } - - if (match == NULL) - { - /* Have we seen this object further up the tree? */ - for (match = parent; match != NULL; match = match->parent) - { - if (match->name == address) - break; - } - } - - if (match == NULL) - { - match = g_slice_new (Descendant); - match->name = address; - match->cumulative = 0; - match->self = 0; - match->children = NULL; - match->parent = parent; - match->siblings = *tree; - *tree = match; - } - - tree = &match->children; - parent = match; - } - - parent->self += size; - - for (; parent != NULL; parent = parent->parent) - parent->cumulative += size; -} - -static Descendant * -build_tree (StackNode *node) -{ - Descendant *tree = NULL; - - for (; node != NULL; node = node->next) - { - if (node->toplevel) - stack_node_foreach_trace (node, build_tree_cb, &tree); - } - - return tree; -} - -static void -append_to_tree_and_free (SysprofCallgraphPage *self, - StackStash *stash, - GtkTreeStore *store, - Descendant *item, - GtkTreeIter *parent) -{ - StackNode *node = NULL; - GtkTreeIter iter; - guint profile_size; - - g_assert (GTK_IS_TREE_STORE (store)); - g_assert (item != NULL); - - profile_size = MAX (1, sysprof_callgraph_page_get_profile_size (self)); - - gtk_tree_store_append (store, &iter, parent); - - node = stack_stash_find_node (stash, (gpointer)item->name); - - gtk_tree_store_set (store, &iter, - COLUMN_NAME, item->name, - COLUMN_SELF, item->self * 100.0 / (gdouble)profile_size, - COLUMN_TOTAL, item->cumulative * 100.0 / (gdouble)profile_size, - COLUMN_POINTER, node, - COLUMN_HITS, (guint)item->cumulative, - -1); - - if (item->siblings != NULL) - append_to_tree_and_free (self, stash, store, item->siblings, parent); - - if (item->children != NULL) - append_to_tree_and_free (self, stash, store, item->children, &iter); - - g_slice_free (Descendant, item); -} - -static void -sysprof_callgraph_page_update_descendants (SysprofCallgraphPage *self, - StackNode *node) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeStore *store; - - g_assert (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - if (g_queue_peek_head (priv->history) != node) - g_queue_push_head (priv->history, node); - - store = gtk_tree_store_new (5, - G_TYPE_STRING, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE, - G_TYPE_POINTER, - G_TYPE_UINT); - - if (priv->profile != NULL) - { - StackStash *stash; - - stash = sysprof_callgraph_profile_get_stash (priv->profile); - if (stash != NULL) - { - Descendant *tree; - - tree = build_tree (node); - if (tree != NULL) - append_to_tree_and_free (self, stash, store, tree, NULL); - } - } - - gtk_tree_view_set_model (priv->descendants_view, GTK_TREE_MODEL (store)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - COLUMN_TOTAL, GTK_SORT_DESCENDING); - sysprof_callgraph_page_expand_descendants (self); - - g_clear_object (&store); -} - -/** - * sysprof_callgraph_page_screenshot: - * @self: A #SysprofCallgraphPage. - * - * This function will generate a text representation of the descendants tree. - * This is useful if you want to include various profiling information in a - * commit message or email. - * - * The text generated will match the current row expansion in the tree view. - * - * Returns: (nullable) (transfer full): A newly allocated string that should be freed - * with g_free(). - */ -gchar * -sysprof_callgraph_page_screenshot (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeView *tree_view; - GtkTreeModel *model; - GtkTreePath *tree_path; - GString *str; - GtkTreeIter iter; - - g_return_val_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (self), NULL); - - tree_view = priv->descendants_view; - - if (NULL == (model = gtk_tree_view_get_model (tree_view))) - return NULL; - - /* - * To avoid having to precalculate the deepest visible row, we - * put the timing information at the beginning of the line. - */ - - str = g_string_new (" SELF CUMULATIVE FUNCTION\n"); - tree_path = gtk_tree_path_new_first (); - - for (;;) - { - if (gtk_tree_model_get_iter (model, &iter, tree_path)) - { - guint depth = gtk_tree_path_get_depth (tree_path); - StackNode *node; - gdouble in_self; - gdouble total; - guint i; - - gtk_tree_model_get (model, &iter, - COLUMN_SELF, &in_self, - COLUMN_TOTAL, &total, - COLUMN_POINTER, &node, - -1); - - g_string_append_printf (str, "[% 7.2lf%%] [% 7.2lf%%] ", in_self, total); - - for (i = 0; i < depth; i++) - g_string_append (str, " "); - g_string_append (str, GSIZE_TO_POINTER (node->data)); - g_string_append_c (str, '\n'); - - if (gtk_tree_view_row_expanded (tree_view, tree_path)) - gtk_tree_path_down (tree_path); - else - gtk_tree_path_next (tree_path); - - continue; - } - - if (!gtk_tree_path_up (tree_path) || !gtk_tree_path_get_depth (tree_path)) - break; - - gtk_tree_path_next (tree_path); - } - - gtk_tree_path_free (tree_path); - - return g_string_free (str, FALSE); -} - -guint -sysprof_callgraph_page_get_n_functions (SysprofCallgraphPage *self) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - GtkTreeModel *model; - guint ret = 0; - - g_return_val_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (self), 0); - - if (NULL != (model = gtk_tree_view_get_model (priv->functions_view))) - ret = gtk_tree_model_iter_n_children (model, NULL); - - return ret; -} - -void -_sysprof_callgraph_page_set_loading (SysprofCallgraphPage *self, - gboolean loading) -{ - SysprofCallgraphPagePrivate *priv = sysprof_callgraph_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_CALLGRAPH_PAGE (self)); - - if (loading) - priv->loading++; - else - priv->loading--; - - if (priv->loading) - gtk_stack_set_visible_child (priv->stack, priv->loading_state); - else - gtk_stack_set_visible_child (priv->stack, priv->callgraph); -} diff --git a/src/libsysprof-ui/sysprof-callgraph-page.h b/src/libsysprof-ui/sysprof-callgraph-page.h deleted file mode 100644 index 7624c580..00000000 --- a/src/libsysprof-ui/sysprof-callgraph-page.h +++ /dev/null @@ -1,51 +0,0 @@ -/* sysprof-callgraph-page.h - * - * Copyright 2016-2019 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 -#include - -#include "sysprof-page.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_CALLGRAPH_PAGE (sysprof_callgraph_page_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofCallgraphPage, sysprof_callgraph_page, SYSPROF, CALLGRAPH_PAGE, SysprofPage) - -struct _SysprofCallgraphPageClass -{ - SysprofPageClass parent_class; - - void (*go_previous) (SysprofCallgraphPage *self); - - /*< private >*/ - gpointer _reserved[16]; -}; - -GtkWidget *sysprof_callgraph_page_new (void); -SysprofCallgraphProfile *sysprof_callgraph_page_get_profile (SysprofCallgraphPage *self); -void sysprof_callgraph_page_set_profile (SysprofCallgraphPage *self, - SysprofCallgraphProfile *profile); -gchar *sysprof_callgraph_page_screenshot (SysprofCallgraphPage *self); -guint sysprof_callgraph_page_get_n_functions (SysprofCallgraphPage *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-callgraph-page.ui b/src/libsysprof-ui/sysprof-callgraph-page.ui deleted file mode 100644 index b0dc4f26..00000000 --- a/src/libsysprof-ui/sysprof-callgraph-page.ui +++ /dev/null @@ -1,212 +0,0 @@ - - - diff --git a/src/libsysprof-ui/sysprof-cell-renderer-duration.c b/src/libsysprof-ui/sysprof-cell-renderer-duration.c deleted file mode 100644 index 3e60166e..00000000 --- a/src/libsysprof-ui/sysprof-cell-renderer-duration.c +++ /dev/null @@ -1,455 +0,0 @@ -/* sysprof-cell-renderer-duration.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-cell-renderer-duration" - -#include "config.h" - -#include "sysprof-cell-renderer-duration.h" -#include "sysprof-ui-private.h" -#include "sysprof-zoom-manager.h" - -typedef struct -{ - gint64 capture_begin_time; - gint64 capture_end_time; - gint64 capture_duration; - gint64 begin_time; - gint64 end_time; - gchar *text; - SysprofZoomManager *zoom_manager; - GdkRGBA color; - guint color_set : 1; -} SysprofCellRendererDurationPrivate; - -enum { - PROP_0, - PROP_BEGIN_TIME, - PROP_CAPTURE_BEGIN_TIME, - PROP_CAPTURE_END_TIME, - PROP_COLOR, - PROP_END_TIME, - PROP_TEXT, - PROP_ZOOM_MANAGER, - N_PROPS -}; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofCellRendererDuration, sysprof_cell_renderer_duration, GTK_TYPE_CELL_RENDERER) - -static GParamSpec *properties [N_PROPS]; - -static inline void -rounded_rectangle (cairo_t *cr, - const GdkRectangle *rect, - int x_radius, - int y_radius) -{ - int x; - int y; - int width; - int height; - int x1, x2; - int y1, y2; - int xr1, xr2; - int yr1, yr2; - - g_assert (cr); - g_assert (rect); - - x = rect->x; - y = rect->y; - width = rect->width; - height = rect->height; - - x1 = x; - x2 = x1 + width; - y1 = y; - y2 = y1 + height; - - x_radius = MIN (x_radius, width / 2.0); - y_radius = MIN (y_radius, width / 2.0); - - xr1 = x_radius; - xr2 = x_radius / 2.0; - yr1 = y_radius; - yr2 = y_radius / 2.0; - - cairo_move_to (cr, x1 + xr1, y1); - cairo_line_to (cr, x2 - xr1, y1); - cairo_curve_to (cr, x2 - xr2, y1, x2, y1 + yr2, x2, y1 + yr1); - cairo_line_to (cr, x2, y2 - yr1); - cairo_curve_to (cr, x2, y2 - yr2, x2 - xr2, y2, x2 - xr1, y2); - cairo_line_to (cr, x1 + xr1, y2); - cairo_curve_to (cr, x1 + xr2, y2, x1, y2 - yr2, x1, y2 - yr1); - cairo_line_to (cr, x1, y1 + yr1); - cairo_curve_to (cr, x1, y1 + yr2, x1 + xr2, y1, x1 + xr1, y1); - cairo_close_path (cr); -} - -static void -sysprof_cell_renderer_duration_snapshot (GtkCellRenderer *renderer, - GtkSnapshot *snapshot, - GtkWidget *widget, - const GdkRectangle *bg_area, - const GdkRectangle *cell_area, - GtkCellRendererState state) -{ - SysprofCellRendererDuration *self = (SysprofCellRendererDuration *)renderer; - SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self); - g_autoptr(GString) str = NULL; - GtkStyleContext *style_context; - cairo_t *cr; - gdouble x1, x2; - GdkRGBA rgba; - GdkRectangle r; - gint64 duration; - - g_assert (SYSPROF_IS_CELL_RENDERER_DURATION (self)); - g_assert (snapshot != NULL); - g_assert (GTK_IS_WIDGET (widget)); - - if (priv->zoom_manager == NULL) - return; - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (cell_area->x, cell_area->y, cell_area->width, cell_area->height)); - - style_context = gtk_widget_get_style_context (widget); - - if (priv->color_set) - rgba = priv->color; - else - gtk_style_context_get_color (style_context, &rgba); - - duration = sysprof_zoom_manager_get_duration_for_width (priv->zoom_manager, bg_area->width); - - x1 = (priv->begin_time - priv->capture_begin_time) / (gdouble)duration * cell_area->width; - x2 = (priv->end_time - priv->capture_begin_time) / (gdouble)duration * cell_area->width; - - if (x2 < x1) - x2 = x1; - - r.x = cell_area->x + x1; - r.height = 12; - r.y = cell_area->y + (cell_area->height - r.height) / 2; - r.width = MAX (1.0, x2 - x1); - - if ((cell_area->height - r.height) % 2 == 1) - r.height++; - - gdk_cairo_set_source_rgba (cr, &rgba); - - if (r.width > 3) - { - rounded_rectangle (cr, &r, 2, 2); - cairo_fill (cr); - } - else if (r.width > 1) - { - gdk_cairo_rectangle (cr, &r); - cairo_fill (cr); - } - else - { - cairo_set_line_width (cr, 1); - cairo_move_to (cr, r.x + .5, r.y); - cairo_line_to (cr, r.x + .5, r.y + r.height); - cairo_stroke (cr); - } - - str = g_string_new (NULL); - - if (priv->begin_time != priv->end_time) - { - g_autofree gchar *fmt = _sysprof_format_duration (priv->end_time - priv->begin_time); - g_string_append_printf (str, "%s — ", fmt); - } - - if (priv->text != NULL) - g_string_append (str, priv->text); - - if (str->len) - { - PangoLayout *layout; - gint w, h; - - /* Add some spacing before/after */ - r.x -= 24; - r.width += 48; - - layout = gtk_widget_create_pango_layout (widget, NULL); - pango_layout_set_text (layout, str->str, str->len); - pango_layout_get_pixel_size (layout, &w, &h); - - if ((r.x + r.width + w) < (cell_area->x + cell_area->width) || - ((cell_area->x + w) > r.x)) - cairo_move_to (cr, r.x + r.width, r.y + ((r.height - h) / 2)); - else - cairo_move_to (cr, r.x - w, r.y + ((r.height - h) / 2)); - - if (priv->end_time < priv->begin_time) - { - gdk_rgba_parse (&rgba, "#f00"); - if (state & GTK_CELL_RENDERER_SELECTED) - rgba.alpha = 0.6; - } - - gdk_cairo_set_source_rgba (cr, &rgba); - pango_cairo_show_layout (cr, layout); - - g_object_unref (layout); - } - - cairo_destroy (cr); -} - -static GtkSizeRequestMode -sysprof_cell_renderer_duration_get_request_mode (GtkCellRenderer *renderer) -{ - return GTK_SIZE_REQUEST_HEIGHT_FOR_WIDTH; -} - -static void -sysprof_cell_renderer_duration_get_preferred_width (GtkCellRenderer *cell, - GtkWidget *widget, - gint *min_width, - gint *nat_width) -{ - SysprofCellRendererDuration *self = (SysprofCellRendererDuration *)cell; - SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self); - gint width = 1; - - g_assert (SYSPROF_IS_CELL_RENDERER_DURATION (self)); - g_assert (GTK_IS_WIDGET (widget)); - - GTK_CELL_RENDERER_CLASS (sysprof_cell_renderer_duration_parent_class)->get_preferred_width (cell, widget, min_width, nat_width); - - if (priv->zoom_manager && priv->capture_begin_time && priv->capture_end_time) - width = sysprof_zoom_manager_get_width_for_duration (priv->zoom_manager, - priv->capture_end_time - priv->capture_begin_time); - - if (min_width) - *min_width = width; - - if (nat_width) - *nat_width = width; -} - -static void -sysprof_cell_renderer_duration_get_preferred_height_for_width (GtkCellRenderer *cell, - GtkWidget *widget, - gint width, - gint *min_height, - gint *nat_height) -{ - PangoLayout *layout; - gint w, h; - gint ypad; - - g_assert (SYSPROF_IS_CELL_RENDERER_DURATION (cell)); - - gtk_cell_renderer_get_padding (cell, NULL, &ypad); - - layout = gtk_widget_create_pango_layout (widget, "XMZ09"); - pango_layout_get_pixel_size (layout, &w, &h); - g_clear_object (&layout); - - if (min_height) - *min_height = h + (ypad * 2); - - if (nat_height) - *nat_height = h + (ypad * 2); -} - -static void -sysprof_cell_renderer_duration_finalize (GObject *object) -{ - SysprofCellRendererDuration *self = (SysprofCellRendererDuration *)object; - SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self); - - g_clear_object (&priv->zoom_manager); - g_clear_pointer (&priv->text, g_free); - - G_OBJECT_CLASS (sysprof_cell_renderer_duration_parent_class)->finalize (object); -} - -static void -sysprof_cell_renderer_duration_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofCellRendererDuration *self = SYSPROF_CELL_RENDERER_DURATION (object); - SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self); - - switch (prop_id) - { - case PROP_BEGIN_TIME: - g_value_set_int64 (value, priv->begin_time); - break; - - case PROP_CAPTURE_BEGIN_TIME: - g_value_set_int64 (value, priv->capture_begin_time); - break; - - case PROP_CAPTURE_END_TIME: - g_value_set_int64 (value, priv->capture_end_time); - break; - - case PROP_END_TIME: - g_value_set_int64 (value, priv->end_time); - break; - - case PROP_TEXT: - g_value_set_string (value, priv->text); - break; - - case PROP_ZOOM_MANAGER: - g_value_set_object (value, priv->zoom_manager); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_cell_renderer_duration_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofCellRendererDuration *self = SYSPROF_CELL_RENDERER_DURATION (object); - SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self); - - switch (prop_id) - { - case PROP_BEGIN_TIME: - priv->begin_time = g_value_get_int64 (value); - break; - - case PROP_CAPTURE_BEGIN_TIME: - priv->capture_begin_time = g_value_get_int64 (value); - priv->capture_duration = priv->capture_end_time - priv->capture_begin_time; - break; - - case PROP_CAPTURE_END_TIME: - priv->capture_end_time = g_value_get_int64 (value); - priv->capture_duration = priv->capture_end_time - priv->capture_begin_time; - break; - - case PROP_COLOR: - if (g_value_get_boxed (value)) - priv->color = *(GdkRGBA *)g_value_get_boxed (value); - else - gdk_rgba_parse (&priv->color, "#000"); - priv->color_set = !!g_value_get_boolean (value); - break; - - case PROP_END_TIME: - priv->end_time = g_value_get_int64 (value); - break; - - case PROP_TEXT: - g_free (priv->text); - priv->text = g_value_dup_string (value); - break; - - case PROP_ZOOM_MANAGER: - g_set_object (&priv->zoom_manager, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_cell_renderer_duration_class_init (SysprofCellRendererDurationClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); - - object_class->finalize = sysprof_cell_renderer_duration_finalize; - object_class->get_property = sysprof_cell_renderer_duration_get_property; - object_class->set_property = sysprof_cell_renderer_duration_set_property; - - cell_class->get_preferred_height_for_width = sysprof_cell_renderer_duration_get_preferred_height_for_width; - cell_class->get_preferred_width = sysprof_cell_renderer_duration_get_preferred_width; - cell_class->get_request_mode = sysprof_cell_renderer_duration_get_request_mode; - cell_class->snapshot = sysprof_cell_renderer_duration_snapshot; - - /* Note we do not emit ::notify() for these properties */ - - properties [PROP_BEGIN_TIME] = - g_param_spec_int64 ("begin-time", NULL, NULL, - G_MININT64, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CAPTURE_BEGIN_TIME] = - g_param_spec_int64 ("capture-begin-time", NULL, NULL, - G_MININT64, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CAPTURE_END_TIME] = - g_param_spec_int64 ("capture-end-time", NULL, NULL, - G_MININT64, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_COLOR] = - g_param_spec_boxed ("color", NULL, NULL, - GDK_TYPE_RGBA, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_END_TIME] = - g_param_spec_int64 ("end-time", NULL, NULL, - G_MININT64, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_END_TIME] = - g_param_spec_int64 ("end-time", NULL, NULL, - G_MININT64, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_TEXT] = - g_param_spec_string ("text", NULL, NULL, - NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_ZOOM_MANAGER] = - g_param_spec_object ("zoom-manager", NULL, NULL, - SYSPROF_TYPE_ZOOM_MANAGER, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_cell_renderer_duration_init (SysprofCellRendererDuration *self) -{ - SysprofCellRendererDurationPrivate *priv = sysprof_cell_renderer_duration_get_instance_private (self); - - priv->color.alpha = 1.0; -} - -GtkCellRenderer * -sysprof_cell_renderer_duration_new (void) -{ - return g_object_new (SYSPROF_TYPE_CELL_RENDERER_DURATION, NULL); -} diff --git a/src/libsysprof-ui/sysprof-cell-renderer-duration.h b/src/libsysprof-ui/sysprof-cell-renderer-duration.h deleted file mode 100644 index 243a261c..00000000 --- a/src/libsysprof-ui/sysprof-cell-renderer-duration.h +++ /dev/null @@ -1,41 +0,0 @@ -/* sysprof-cell-renderer-duration.h - * - * Copyright 2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_CELL_RENDERER_DURATION (sysprof_cell_renderer_duration_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofCellRendererDuration, sysprof_cell_renderer_duration, SYSPROF, CELL_RENDERER_DURATION, GtkCellRenderer) - -struct _SysprofCellRendererDurationClass -{ - GtkCellRendererClass parent_class; - - /*< private >*/ - gpointer _reserved[8]; -}; - -GtkCellRenderer *sysprof_cell_renderer_duration_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-cell-renderer-percent.c b/src/libsysprof-ui/sysprof-cell-renderer-percent.c deleted file mode 100644 index e23e1fed..00000000 --- a/src/libsysprof-ui/sysprof-cell-renderer-percent.c +++ /dev/null @@ -1,139 +0,0 @@ -/* sysprof-cell-renderer-percent.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-cell-renderer-percent" - -#include "config.h" - -#include - -#include "sysprof-cell-renderer-percent.h" - -typedef struct -{ - gdouble percent; -} SysprofCellRendererPercentPrivate; - -enum { - PROP_0, - PROP_PERCENT, - N_PROPS -}; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofCellRendererPercent, sysprof_cell_renderer_percent, SYSPROF_TYPE_CELL_RENDERER_PROGRESS) - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_cell_renderer_percent_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofCellRendererPercent *self = SYSPROF_CELL_RENDERER_PERCENT (object); - - switch (prop_id) - { - case PROP_PERCENT: - g_value_set_double (value, sysprof_cell_renderer_percent_get_percent (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_cell_renderer_percent_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofCellRendererPercent *self = SYSPROF_CELL_RENDERER_PERCENT (object); - - switch (prop_id) - { - case PROP_PERCENT: - sysprof_cell_renderer_percent_set_percent (self, g_value_get_double (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_cell_renderer_percent_class_init (SysprofCellRendererPercentClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->get_property = sysprof_cell_renderer_percent_get_property; - object_class->set_property = sysprof_cell_renderer_percent_set_property; - - properties [PROP_PERCENT] = - g_param_spec_double ("percent", - "Percent", - "Percent", - 0.0, - 100.0, - 0.0, - /* Doesn't notify to avoid signal emission */ - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_cell_renderer_percent_init (SysprofCellRendererPercent *self) -{ - g_object_set (self, "text-xalign", 1.0f, NULL); -} - -gdouble -sysprof_cell_renderer_percent_get_percent (SysprofCellRendererPercent *self) -{ - SysprofCellRendererPercentPrivate *priv = sysprof_cell_renderer_percent_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_CELL_RENDERER_PERCENT (self), 0.0); - - return priv->percent; -} - -void -sysprof_cell_renderer_percent_set_percent (SysprofCellRendererPercent *self, - gdouble percent) -{ - SysprofCellRendererPercentPrivate *priv = sysprof_cell_renderer_percent_get_instance_private (self); - gchar text[8]; - - g_return_if_fail (SYSPROF_IS_CELL_RENDERER_PERCENT (self)); - g_return_if_fail (percent >= 0.0); - g_return_if_fail (percent <= 100.0); - - priv->percent = percent; - - g_snprintf (text, sizeof text, "%.2lf%%", percent); - text [sizeof text - 1] = '\0'; - - g_object_set (self, - "value", (guint)percent, - "text", text, - NULL); -} diff --git a/src/libsysprof-ui/sysprof-cell-renderer-percent.h b/src/libsysprof-ui/sysprof-cell-renderer-percent.h deleted file mode 100644 index 44a8fc04..00000000 --- a/src/libsysprof-ui/sysprof-cell-renderer-percent.h +++ /dev/null @@ -1,57 +0,0 @@ -/* sysprof-cell-renderer-percent.h - * - * Copyright 2016-2019 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-cell-renderer-progress.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_CELL_RENDERER_PERCENT (sysprof_cell_renderer_percent_get_type()) -#define SYSPROF_CELL_RENDERER_PERCENT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYSPROF_TYPE_CELL_RENDERER_PERCENT, SysprofCellRendererPercent)) -#define SYSPROF_CELL_RENDERER_PERCENT_CONST(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYSPROF_TYPE_CELL_RENDERER_PERCENT, SysprofCellRendererPercent const)) -#define SYSPROF_CELL_RENDERER_PERCENT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), SYSPROF_TYPE_CELL_RENDERER_PERCENT, SysprofCellRendererPercentClass)) -#define SYSPROF_IS_CELL_RENDERER_PERCENT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYSPROF_TYPE_CELL_RENDERER_PERCENT)) -#define SYSPROF_IS_CELL_RENDERER_PERCENT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), SYSPROF_TYPE_CELL_RENDERER_PERCENT)) -#define SYSPROF_CELL_RENDERER_PERCENT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), SYSPROF_TYPE_CELL_RENDERER_PERCENT, SysprofCellRendererPercentClass)) - -typedef struct _SysprofCellRendererPercent SysprofCellRendererPercent; -typedef struct _SysprofCellRendererPercentClass SysprofCellRendererPercentClass; - -struct _SysprofCellRendererPercent -{ - SysprofCellRendererProgress parent; -}; - -struct _SysprofCellRendererPercentClass -{ - SysprofCellRendererProgressClass parent_class; - - /*< private >*/ - gpointer _reserved[4]; -}; - -GType sysprof_cell_renderer_percent_get_type (void); -GtkCellRenderer *sysprof_cell_renderer_percent_new (void); -gdouble sysprof_cell_renderer_percent_get_percent (SysprofCellRendererPercent *self); -void sysprof_cell_renderer_percent_set_percent (SysprofCellRendererPercent *self, - gdouble percent); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-cell-renderer-progress.c b/src/libsysprof-ui/sysprof-cell-renderer-progress.c deleted file mode 100644 index a0943b64..00000000 --- a/src/libsysprof-ui/sysprof-cell-renderer-progress.c +++ /dev/null @@ -1,712 +0,0 @@ -/* gtkcellrendererprogress.c - * Copyright (C) 2002 Naba Kumar - * heavily modified by Jörgen Scheibengruber - * heavily modified by Marco Pesenti Gritti - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ -/* - * Modified by the GTK+ Team and others 1997-2007. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#include "config.h" - -#include -#include - -#include "sysprof-cell-renderer-progress.h" - - -enum -{ - PROP_0, - PROP_VALUE, - PROP_TEXT, - PROP_PULSE, - PROP_TEXT_XALIGN, - PROP_TEXT_YALIGN, - PROP_ORIENTATION, - PROP_INVERTED -}; - -struct _SysprofCellRendererProgressPrivate -{ - int value; - char *text; - char *label; - int min_h; - int min_w; - int pulse; - int offset; - float text_xalign; - float text_yalign; - GtkOrientation orientation; - gboolean inverted; -}; - -static void sysprof_cell_renderer_progress_finalize (GObject *object); -static void sysprof_cell_renderer_progress_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec); -static void sysprof_cell_renderer_progress_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec); -static void sysprof_cell_renderer_progress_set_value (SysprofCellRendererProgress *cellprogress, - int value); -static void sysprof_cell_renderer_progress_set_text (SysprofCellRendererProgress *cellprogress, - const char *text); -static void sysprof_cell_renderer_progress_set_pulse (SysprofCellRendererProgress *cellprogress, - int pulse); -static void compute_dimensions (GtkCellRenderer *cell, - GtkWidget *widget, - const char *text, - int *width, - int *height); -static void sysprof_cell_renderer_progress_snapshot (GtkCellRenderer *cell, - GtkSnapshot *snapshot, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags); - - -G_DEFINE_TYPE_WITH_CODE (SysprofCellRendererProgress, sysprof_cell_renderer_progress, GTK_TYPE_CELL_RENDERER, - G_ADD_PRIVATE (SysprofCellRendererProgress) - G_IMPLEMENT_INTERFACE (GTK_TYPE_ORIENTABLE, NULL)) - -static void -recompute_label (SysprofCellRendererProgress *cellprogress) -{ - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - char *label; - - if (priv->text) - label = g_strdup (priv->text); - else if (priv->pulse < 0) - label = g_strdup_printf (C_("progress bar label", "%d %%"), priv->value); - else - label = NULL; - - g_free (priv->label); - priv->label = label; -} - -static void -sysprof_cell_renderer_progress_set_value (SysprofCellRendererProgress *cellprogress, - int value) -{ - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - - if (priv->value != value) - { - priv->value = value; - recompute_label (cellprogress); - g_object_notify (G_OBJECT (cellprogress), "value"); - } -} - -static void -sysprof_cell_renderer_progress_set_text (SysprofCellRendererProgress *cellprogress, - const char *text) -{ - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - char *new_text; - - new_text = g_strdup (text); - g_free (priv->text); - priv->text = new_text; - recompute_label (cellprogress); - g_object_notify (G_OBJECT (cellprogress), "text"); -} - -static void -sysprof_cell_renderer_progress_set_pulse (SysprofCellRendererProgress *cellprogress, - int pulse) -{ - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - - if (pulse != priv->pulse) - { - if (pulse <= 0) - priv->offset = 0; - else - priv->offset = pulse; - g_object_notify (G_OBJECT (cellprogress), "pulse"); - } - - priv->pulse = pulse; - recompute_label (cellprogress); -} - -static void -sysprof_cell_renderer_progress_finalize (GObject *object) -{ - SysprofCellRendererProgress *cellprogress = SYSPROF_CELL_RENDERER_PROGRESS (object); - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - - g_free (priv->text); - g_free (priv->label); - - G_OBJECT_CLASS (sysprof_cell_renderer_progress_parent_class)->finalize (object); -} - -static void -sysprof_cell_renderer_progress_get_property (GObject *object, - guint param_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofCellRendererProgress *cellprogress = SYSPROF_CELL_RENDERER_PROGRESS (object); - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - - switch (param_id) - { - case PROP_VALUE: - g_value_set_int (value, priv->value); - break; - case PROP_TEXT: - g_value_set_string (value, priv->text); - break; - case PROP_PULSE: - g_value_set_int (value, priv->pulse); - break; - case PROP_TEXT_XALIGN: - g_value_set_float (value, priv->text_xalign); - break; - case PROP_TEXT_YALIGN: - g_value_set_float (value, priv->text_yalign); - break; - case PROP_ORIENTATION: - g_value_set_enum (value, priv->orientation); - break; - case PROP_INVERTED: - g_value_set_boolean (value, priv->inverted); - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - } -} - -static void -sysprof_cell_renderer_progress_set_property (GObject *object, - guint param_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofCellRendererProgress *cellprogress = SYSPROF_CELL_RENDERER_PROGRESS (object); - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - - switch (param_id) - { - case PROP_VALUE: - sysprof_cell_renderer_progress_set_value (cellprogress, - g_value_get_int (value)); - break; - case PROP_TEXT: - sysprof_cell_renderer_progress_set_text (cellprogress, - g_value_get_string (value)); - break; - case PROP_PULSE: - sysprof_cell_renderer_progress_set_pulse (cellprogress, - g_value_get_int (value)); - break; - case PROP_TEXT_XALIGN: - priv->text_xalign = g_value_get_float (value); - break; - case PROP_TEXT_YALIGN: - priv->text_yalign = g_value_get_float (value); - break; - case PROP_ORIENTATION: - if (priv->orientation != g_value_get_enum (value)) - { - priv->orientation = g_value_get_enum (value); - g_object_notify_by_pspec (object, pspec); - } - break; - case PROP_INVERTED: - if (priv->inverted != g_value_get_boolean (value)) - { - priv->inverted = g_value_get_boolean (value); - g_object_notify_by_pspec (object, pspec); - } - break; - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec); - } -} - -static void -compute_dimensions (GtkCellRenderer *cell, - GtkWidget *widget, - const char *text, - int *width, - int *height) -{ - PangoRectangle logical_rect; - PangoLayout *layout; - int xpad, ypad; - - layout = gtk_widget_create_pango_layout (widget, text); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - - if (width) - *width = logical_rect.width + xpad * 2; - - if (height) - *height = logical_rect.height + ypad * 2; - - g_object_unref (layout); -} - -static void -sysprof_cell_renderer_progress_get_preferred_width (GtkCellRenderer *cell, - GtkWidget *widget, - int *minimum, - int *natural) -{ - SysprofCellRendererProgress *self = SYSPROF_CELL_RENDERER_PROGRESS (cell); - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (self); - int w, h; - int size; - - if (priv->min_w < 0) - { - char *text = g_strdup_printf (C_("progress bar label", "%d %%"), 100); - compute_dimensions (cell, widget, text, - &priv->min_w, - &priv->min_h); - g_free (text); - } - - compute_dimensions (cell, widget, priv->label, &w, &h); - - size = MAX (priv->min_w, w); - - if (minimum != NULL) - *minimum = size; - if (natural != NULL) - *natural = size; -} - -static void -sysprof_cell_renderer_progress_get_preferred_height (GtkCellRenderer *cell, - GtkWidget *widget, - int *minimum, - int *natural) -{ - SysprofCellRendererProgress *self = SYSPROF_CELL_RENDERER_PROGRESS (cell); - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (self); - int w, h; - int size; - - if (priv->min_w < 0) - { - char *text = g_strdup_printf (C_("progress bar label", "%d %%"), 100); - compute_dimensions (cell, widget, text, - &priv->min_w, - &priv->min_h); - g_free (text); - } - - compute_dimensions (cell, widget, priv->label, &w, &h); - - size = MIN (priv->min_h, h); - - if (minimum != NULL) - *minimum = size; - if (natural != NULL) - *natural = size; -} - -static inline int -get_bar_size (int pulse, - int value, - int full_size) -{ - int bar_size; - - if (pulse < 0) - bar_size = full_size * MAX (0, value) / 100; - else if (pulse == 0) - bar_size = 0; - else if (pulse == G_MAXINT) - bar_size = full_size; - else - bar_size = MAX (2, full_size / 5); - - return bar_size; -} - -static inline int -get_bar_position (int start, - int full_size, - int bar_size, - int pulse, - int offset, - gboolean is_rtl) -{ - int position; - - if (pulse < 0 || pulse == 0 || pulse == G_MAXINT) - { - position = is_rtl ? (start + full_size - bar_size) : start; - } - else - { - position = (is_rtl ? offset + 12 : offset) % 24; - if (position > 12) - position = 24 - position; - position = start + full_size * position / 15; - } - - return position; -} - -static void -sysprof_cell_renderer_progress_snapshot (GtkCellRenderer *cell, - GtkSnapshot *snapshot, - GtkWidget *widget, - const GdkRectangle *background_area, - const GdkRectangle *cell_area, - GtkCellRendererState flags) -{ - SysprofCellRendererProgress *cellprogress = SYSPROF_CELL_RENDERER_PROGRESS (cell); - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - GtkStyleContext *context; - GtkBorder padding; - PangoLayout *layout; - PangoRectangle logical_rect; - int x, y, w, h, x_pos, y_pos, bar_position, bar_size, start, full_size; - int xpad, ypad; - GdkRectangle clip; - gboolean is_rtl; - - context = gtk_widget_get_style_context (widget); - is_rtl = gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL; - - gtk_cell_renderer_get_padding (cell, &xpad, &ypad); - x = cell_area->x + xpad; - y = cell_area->y + ypad; - w = cell_area->width - xpad * 2; - h = cell_area->height - ypad * 2; - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "trough"); - - gtk_snapshot_render_background (snapshot, context, x, y, w, h); - gtk_snapshot_render_frame (snapshot, context, x, y, w, h); - - gtk_style_context_get_padding (context, &padding); - - x += padding.left; - y += padding.top; - w -= padding.left + padding.right; - h -= padding.top + padding.bottom; - - gtk_style_context_restore (context); - - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - clip.y = y; - clip.height = h; - - start = x; - full_size = w; - - bar_size = get_bar_size (priv->pulse, priv->value, full_size); - - if (!priv->inverted) - bar_position = get_bar_position (start, full_size, bar_size, - priv->pulse, priv->offset, is_rtl); - else - bar_position = get_bar_position (start, full_size, bar_size, - priv->pulse, priv->offset, !is_rtl); - - clip.width = bar_size; - clip.x = bar_position; - } - else - { - clip.x = x; - clip.width = w; - - start = y; - full_size = h; - - bar_size = get_bar_size (priv->pulse, priv->value, full_size); - - if (priv->inverted) - bar_position = get_bar_position (start, full_size, bar_size, - priv->pulse, priv->offset, TRUE); - else - bar_position = get_bar_position (start, full_size, bar_size, - priv->pulse, priv->offset, FALSE); - - clip.height = bar_size; - clip.y = bar_position; - } - - if (bar_size > 0) - { - gtk_style_context_save (context); - gtk_style_context_add_class (context, "progressbar"); - - gtk_snapshot_render_background (snapshot, context, clip.x, clip.y, clip.width, clip.height); - gtk_snapshot_render_frame (snapshot, context, clip.x, clip.y, clip.width, clip.height); - - gtk_style_context_restore (context); - } - - if (priv->label) - { - float text_xalign; - - layout = gtk_widget_create_pango_layout (widget, priv->label); - pango_layout_get_pixel_extents (layout, NULL, &logical_rect); - - if (gtk_widget_get_direction (widget) != GTK_TEXT_DIR_LTR) - text_xalign = 1.0 - priv->text_xalign; - else - text_xalign = priv->text_xalign; - - x_pos = x + padding.left + text_xalign * - (w - padding.left - padding.right - logical_rect.width); - - y_pos = y + padding.top + priv->text_yalign * - (h - padding.top - padding.bottom - logical_rect.height); - - gtk_snapshot_push_clip (snapshot, - &GRAPHENE_RECT_INIT( - clip.x, clip.y, - clip.width, clip.height - )); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "progressbar"); - - gtk_snapshot_render_layout (snapshot, context, - x_pos, y_pos, - layout); - - gtk_style_context_restore (context); - gtk_snapshot_pop (snapshot); - - gtk_style_context_save (context); - gtk_style_context_add_class (context, "trough"); - - if (bar_position > start) - { - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - clip.x = x; - clip.width = bar_position - x; - } - else - { - clip.y = y; - clip.height = bar_position - y; - } - - gtk_snapshot_push_clip (snapshot, - &GRAPHENE_RECT_INIT( - clip.x, clip.y, - clip.width, clip.height - )); - - gtk_snapshot_render_layout (snapshot, context, - x_pos, y_pos, - layout); - - gtk_snapshot_pop (snapshot); - } - - if (bar_position + bar_size < start + full_size) - { - if (priv->orientation == GTK_ORIENTATION_HORIZONTAL) - { - clip.x = bar_position + bar_size; - clip.width = x + w - (bar_position + bar_size); - } - else - { - clip.y = bar_position + bar_size; - clip.height = y + h - (bar_position + bar_size); - } - - gtk_snapshot_push_clip (snapshot, - &GRAPHENE_RECT_INIT( - clip.x, clip.y, - clip.width, clip.height - )); - - gtk_snapshot_render_layout (snapshot, context, - x_pos, y_pos, - layout); - - gtk_snapshot_pop (snapshot); - } - - gtk_style_context_restore (context); - g_object_unref (layout); - } -} - -static void -sysprof_cell_renderer_progress_class_init (SysprofCellRendererProgressClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkCellRendererClass *cell_class = GTK_CELL_RENDERER_CLASS (klass); - - object_class->finalize = sysprof_cell_renderer_progress_finalize; - object_class->get_property = sysprof_cell_renderer_progress_get_property; - object_class->set_property = sysprof_cell_renderer_progress_set_property; - - cell_class->get_preferred_width = sysprof_cell_renderer_progress_get_preferred_width; - cell_class->get_preferred_height = sysprof_cell_renderer_progress_get_preferred_height; - cell_class->snapshot = sysprof_cell_renderer_progress_snapshot; - - /** - * SysprofCellRendererProgress:value: - * - * The "value" property determines the percentage to which the - * progress bar will be "filled in". - **/ - g_object_class_install_property (object_class, - PROP_VALUE, - g_param_spec_int ("value", - "Value", - "Value of the progress bar", - 0, 100, 0, - G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * SysprofCellRendererProgress:text: - * - * The "text" property determines the label which will be drawn - * over the progress bar. Setting this property to %NULL causes the default - * label to be displayed. Setting this property to an empty string causes - * no label to be displayed. - **/ - g_object_class_install_property (object_class, - PROP_TEXT, - g_param_spec_string ("text", - "Text", - "Text on the progress bar", - NULL, - G_PARAM_READWRITE)); - - /** - * SysprofCellRendererProgress:pulse: - * - * Setting this to a non-negative value causes the cell renderer to - * enter "activity mode", where a block bounces back and forth to - * indicate that some progress is made, without specifying exactly how - * much. - * - * Each increment of the property causes the block to move by a little - * bit. - * - * To indicate that the activity has not started yet, set the property - * to zero. To indicate completion, set the property to %G_MAXINT. - */ - g_object_class_install_property (object_class, - PROP_PULSE, - g_param_spec_int ("pulse", - "Pulse", - "Set this to positive values to indicate that some progress is made, but you don’t know how much.", - -1, G_MAXINT, -1, - G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); - - /** - * SysprofCellRendererProgress:text-xalign: - * - * The "text-xalign" property controls the horizontal alignment of the - * text in the progress bar. Valid values range from 0 (left) to 1 - * (right). Reserved for RTL layouts. - */ - g_object_class_install_property (object_class, - PROP_TEXT_XALIGN, - g_param_spec_float ("text-xalign", - "Text x alignment", - "The horizontal text alignment, from 0 (left) to 1 (right). Reversed for RTL layouts.", - 0.0, 1.0, 0.5, - G_PARAM_READWRITE)); - - /** - * SysprofCellRendererProgress:text-yalign: - * - * The "text-yalign" property controls the vertical alignment of the - * text in the progress bar. Valid values range from 0 (top) to 1 - * (bottom). - */ - g_object_class_install_property (object_class, - PROP_TEXT_YALIGN, - g_param_spec_float ("text-yalign", - "Text y alignment", - "The vertical text alignment, from 0 (top) to 1 (bottom).", - 0.0, 1.0, 0.5, - G_PARAM_READWRITE)); - - g_object_class_override_property (object_class, - PROP_ORIENTATION, - "orientation"); - - g_object_class_install_property (object_class, - PROP_INVERTED, - g_param_spec_boolean ("inverted", - "Inverted", - "Invert the direction in which the progress bar grows", - FALSE, - G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY)); -} - -static void -sysprof_cell_renderer_progress_init (SysprofCellRendererProgress *cellprogress) -{ - SysprofCellRendererProgressPrivate *priv = sysprof_cell_renderer_progress_get_instance_private (cellprogress); - - priv->value = 0; - priv->text = NULL; - priv->label = NULL; - priv->min_w = -1; - priv->min_h = -1; - priv->pulse = -1; - priv->offset = 0; - - priv->text_xalign = 0.5; - priv->text_yalign = 0.5; - - priv->orientation = GTK_ORIENTATION_HORIZONTAL, - priv->inverted = FALSE; -} - -/** - * sysprof_cell_renderer_progress_new: - * - * Creates a new `SysprofCellRendererProgress`. - * - * Returns: the new cell renderer - **/ -GtkCellRenderer* -sysprof_cell_renderer_progress_new (void) -{ - return g_object_new (SYSPROF_TYPE_CELL_RENDERER_PROGRESS, NULL); -} diff --git a/src/libsysprof-ui/sysprof-cell-renderer-progress.h b/src/libsysprof-ui/sysprof-cell-renderer-progress.h deleted file mode 100644 index 7a006072..00000000 --- a/src/libsysprof-ui/sysprof-cell-renderer-progress.h +++ /dev/null @@ -1,53 +0,0 @@ -/* gtkcellrendererprogress.h - * Copyright (C) 2002 Naba Kumar - * modified by Jörgen Scheibengruber - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Library General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later version. - * - * This library 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 - * Library General Public License for more details. - * - * You should have received a copy of the GNU Library General Public - * License along with this library. If not, see . - */ - -/* - * Modified by the GTK+ Team and others 1997-2004. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#pragma once - -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_CELL_RENDERER_PROGRESS (sysprof_cell_renderer_progress_get_type ()) -#define SYSPROF_CELL_RENDERER_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), SYSPROF_TYPE_CELL_RENDERER_PROGRESS, SysprofCellRendererProgress)) -#define SYSPROF_IS_CELL_RENDERER_PROGRESS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), SYSPROF_TYPE_CELL_RENDERER_PROGRESS)) - -typedef struct _SysprofCellRendererProgress SysprofCellRendererProgress; -typedef struct _SysprofCellRendererProgressClass SysprofCellRendererProgressClass; -typedef struct _SysprofCellRendererProgressPrivate SysprofCellRendererProgressPrivate; - -struct _SysprofCellRendererProgress -{ - GtkCellRenderer parent_instance; -}; - -struct _SysprofCellRendererProgressClass -{ - GtkCellRendererClass parent_class; -}; - -GType sysprof_cell_renderer_progress_get_type (void) G_GNUC_CONST; -GtkCellRenderer *sysprof_cell_renderer_progress_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-check.c b/src/libsysprof-ui/sysprof-check.c deleted file mode 100644 index d7025790..00000000 --- a/src/libsysprof-ui/sysprof-check.c +++ /dev/null @@ -1,106 +0,0 @@ -/* sysprof-check.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-check" - -#include "config.h" - -#include "sysprof-check.h" - -static void -sysprof_check_supported_ping_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - GDBusConnection *bus = (GDBusConnection *)object; - g_autoptr(GVariant) reply = NULL; - g_autoptr(GError) error = NULL; - g_autoptr(GTask) task = user_data; - - g_assert (G_IS_DBUS_CONNECTION (bus)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - if (!(reply = g_dbus_connection_call_finish (bus, result, &error))) - g_task_return_error (task, g_steal_pointer (&error)); - else - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_check_supported_bus_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - g_autoptr(GDBusConnection) bus = NULL; - g_autoptr(GError) error = NULL; - g_autoptr(GTask) task = user_data; - - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - if (!(bus = g_bus_get_finish (result, &error))) - g_task_return_error (task, g_steal_pointer (&error)); - else - g_dbus_connection_call (bus, - "org.gnome.Sysprof3", - "/org/gnome/Sysprof3", - "org.freedesktop.DBus.Peer", - "Ping", - g_variant_new ("()"), - NULL, - G_DBUS_CALL_FLAGS_NONE, - -1, - g_task_get_cancellable (task), - sysprof_check_supported_ping_cb, - g_object_ref (task)); -} - -void -sysprof_check_supported_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_autoptr(GTask) task = NULL; - - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (NULL, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_check_supported_async); - - /* Get access to the System D-Bus and check to see if we can ping the - * service that is found at org.gnome.Sysprof3. - */ - - g_bus_get (G_BUS_TYPE_SYSTEM, - cancellable, - sysprof_check_supported_bus_cb, - g_steal_pointer (&task)); - -} - -gboolean -sysprof_check_supported_finish (GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - return g_task_propagate_boolean (G_TASK (result), error); -} diff --git a/src/libsysprof-ui/sysprof-check.h b/src/libsysprof-ui/sysprof-check.h deleted file mode 100644 index bb8f4e7c..00000000 --- a/src/libsysprof-ui/sysprof-check.h +++ /dev/null @@ -1,37 +0,0 @@ -/* sysprof-check.h - * - * Copyright 2019 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 - -#include "sysprof-version-macros.h" - -G_BEGIN_DECLS - -SYSPROF_AVAILABLE_IN_ALL -void sysprof_check_supported_async (GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_check_supported_finish (GAsyncResult *result, - GError **error); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-color-cycle.c b/src/libsysprof-ui/sysprof-color-cycle.c deleted file mode 100644 index 582878e9..00000000 --- a/src/libsysprof-ui/sysprof-color-cycle.c +++ /dev/null @@ -1,157 +0,0 @@ -/* sysprof-color-cycle.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-color-cycle" - -#include "config.h" - -#include "sysprof-color-cycle.h" - -G_DEFINE_BOXED_TYPE (SysprofColorCycle, sysprof_color_cycle, sysprof_color_cycle_ref, sysprof_color_cycle_unref) - -static const gchar *default_colors[] = { - - "#1a5fb4", /* Blue 5 */ - "#26a269", /* Green 5 */ - "#e5a50a", /* Yellow 5 */ - "#c64600", /* Orange 5 */ - "#a51d2d", /* Red 5 */ - "#613583", /* Purple 5 */ - "#63452c", /* Brown 5 */ - - "#1c71d8", /* Blue 4 */ - "#2ec27e", /* Green 4 */ - "#f5c211", /* Yellow 4 */ - "#e66100", /* Orange 4 */ - "#c01c28", /* Red 4 */ - "#813d9c", /* Purple 4 */ - "#865e3c", /* Brown 4 */ - - "#3584e4", /* Blue 3 */ - "#33d17a", /* Green 3 */ - "#f6d32d", /* Yellow 3 */ - "#ff7800", /* Orange 3 */ - "#e01b24", /* Red 3 */ - "#9141ac", /* Purple 3 */ - "#986a44", /* Brown 3 */ - - "#62a0ea", /* Blue 2 */ - "#57e389", /* Green 2 */ - "#f8e45c", /* Yellow 2 */ - "#ffa348", /* Orange 2 */ - "#ed333b", /* Red 2 */ - "#c061cb", /* Purple 2 */ - "#b5835a", /* Brown 2 */ - - "#99c1f1", /* Blue 1 */ - "#8ff0a4", /* Green 1 */ - "#f9f06b", /* Yellow 1 */ - "#ffbe6f", /* Orange 1 */ - "#f66151", /* Red 1 */ - "#dc8add", /* Purple 1 */ - "#cdab8f", /* Brown 1 */ - - NULL -}; - -struct _SysprofColorCycle -{ - volatile gint ref_count; - GdkRGBA *colors; - gsize n_colors; - guint position; -}; - -static void -sysprof_color_cycle_destroy (SysprofColorCycle *self) -{ - g_free (self->colors); - g_slice_free (SysprofColorCycle, self); -} - -SysprofColorCycle * -sysprof_color_cycle_new (void) -{ - SysprofColorCycle *self; - - self = g_slice_new0 (SysprofColorCycle); - self->ref_count = 1; - self->n_colors = g_strv_length ((gchar **)default_colors); - self->colors = g_new0 (GdkRGBA, self->n_colors); - - for (guint i = 0; default_colors[i]; i++) - { - if G_UNLIKELY (!gdk_rgba_parse (&self->colors[i], default_colors[i])) - g_warning ("Failed to parse color %s into an RGBA", default_colors[i]); - } - - return self; -} - -SysprofColorCycle * -sysprof_color_cycle_ref (SysprofColorCycle *self) -{ - g_return_val_if_fail (self != NULL, NULL); - g_return_val_if_fail (self->ref_count > 0, NULL); - g_atomic_int_inc (&self->ref_count); - return self; -} - -void -sysprof_color_cycle_unref (SysprofColorCycle *self) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (self->ref_count > 0); - if (g_atomic_int_dec_and_test (&self->ref_count)) - sysprof_color_cycle_destroy (self); -} - -void -sysprof_color_cycle_next (SysprofColorCycle *self, - GdkRGBA *rgba) -{ - g_return_if_fail (self != NULL); - g_return_if_fail (self->position < self->n_colors); - - *rgba = self->colors[self->position]; - - /* - * TODO: Adjust color HSV/etc - * - * We could simply adjust the brightness/etc after we dispatch - * a color so that we get darker as we go. - */ - - self->position = (self->position + 1) % self->n_colors; -} - -void -sysprof_color_cycle_reset (SysprofColorCycle *self) -{ - g_return_if_fail (self != NULL); - - for (guint i = 0; default_colors[i]; i++) - { - if G_UNLIKELY (!gdk_rgba_parse (&self->colors[i], default_colors[i])) - g_warning ("Failed to parse color %s into an RGBA", default_colors[i]); - } - - self->position = 0; -} diff --git a/src/libsysprof-ui/sysprof-color-cycle.h b/src/libsysprof-ui/sysprof-color-cycle.h deleted file mode 100644 index 650acb78..00000000 --- a/src/libsysprof-ui/sysprof-color-cycle.h +++ /dev/null @@ -1,41 +0,0 @@ -/* sysprof-color-cycle.h - * - * Copyright 2016-2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_COLOR_CYCLE (sysprof_color_cycle_get_type()) - -typedef struct _SysprofColorCycle SysprofColorCycle; - -GType sysprof_color_cycle_get_type (void); -SysprofColorCycle *sysprof_color_cycle_ref (SysprofColorCycle *self); -void sysprof_color_cycle_unref (SysprofColorCycle *self); -SysprofColorCycle *sysprof_color_cycle_new (void); -void sysprof_color_cycle_reset (SysprofColorCycle *self); -void sysprof_color_cycle_next (SysprofColorCycle *self, - GdkRGBA *rgba); - -G_DEFINE_AUTOPTR_CLEANUP_FUNC (SysprofColorCycle, sysprof_color_cycle_unref) - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-counters-aid.c b/src/libsysprof-ui/sysprof-counters-aid.c deleted file mode 100644 index 42bd04f0..00000000 --- a/src/libsysprof-ui/sysprof-counters-aid.c +++ /dev/null @@ -1,284 +0,0 @@ -/* sysprof-counters-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-counters-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-counters-aid.h" -#include "sysprof-line-visualizer.h" -#include "sysprof-marks-page.h" -#include "sysprof-time-visualizer.h" - -struct _SysprofCountersAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; -} Present; - -G_DEFINE_TYPE (SysprofCountersAid, sysprof_counters_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -static void -on_group_activated_cb (SysprofVisualizerGroup *group, - SysprofPage *page) -{ - SysprofDisplay *display; - - g_assert (SYSPROF_IS_VISUALIZER_GROUP (group)); - g_assert (SYSPROF_IS_PAGE (page)); - - display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (page), SYSPROF_TYPE_DISPLAY)); - sysprof_display_set_visible_page (display, page); -} - -/** - * sysprof_counters_aid_new: - * - * Create a new #SysprofCountersAid. - * - * Returns: (transfer full): a newly created #SysprofCountersAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_counters_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_COUNTERS_AID, NULL); -} - -static void -sysprof_counters_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ -} - -static gchar * -build_title (const SysprofCaptureCounter *ctr) -{ - GString *str; - - str = g_string_new (NULL); - - if (ctr->category[0] != 0) - { - if (str->len) - g_string_append_c (str, ' '); - g_string_append (str, ctr->category); - } - - if (ctr->name[0] != 0) - { - if (str->len) - g_string_append (str, " — "); - g_string_append (str, ctr->name); - } - - if (ctr->description[0] != 0) - { - if (str->len) - g_string_append_printf (str, " (%s)", ctr->description); - else - g_string_append (str, ctr->description); - } - - if (str->len == 0) - /* this is untranslated on purpose */ - g_string_append_printf (str, "Counter %d", ctr->id); - - return g_string_free (str, FALSE); -} - -static bool -collect_counters (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - GArray *counters = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (counters != NULL); - - if (def->n_counters > 0) - g_array_append_vals (counters, def->counters, def->n_counters); - - return TRUE; -} - -static void -sysprof_counters_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *present = task_data; - g_autoptr(GArray) counters = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_COUNTERS_AID (source_object)); - g_assert (present != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); - sysprof_capture_cursor_foreach (present->cursor, collect_counters, counters); - g_task_return_pointer (task, - g_steal_pointer (&counters), - (GDestroyNotify) g_array_unref); -} - -static void -sysprof_counters_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_CTRDEF }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_COUNTERS_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (1, types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_counters_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_counters_aid_present_worker); -} - -static gboolean -sysprof_counters_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) counters = NULL; - Present *present; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_TASK (result)); - - present = g_task_get_task_data (G_TASK (result)); - - if ((counters = g_task_propagate_pointer (G_TASK (result), error)) && counters->len > 0) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - SysprofVisualizerGroup *group; - SysprofVisualizer *combined; - GtkWidget *page; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "has-page", TRUE, - "title", _("Counters"), - "visible", TRUE, - NULL); - - combined = g_object_new (SYSPROF_TYPE_TIME_VISUALIZER, - "title", _("Counters"), - "height-request", 35, - "visible", TRUE, - NULL); - sysprof_visualizer_group_insert (group, combined, -1, TRUE); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *ctr = &g_array_index (counters, SysprofCaptureCounter, i); - g_autofree gchar *title = build_title (ctr); - GtkWidget *row; - GdkRGBA rgba; - - row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", title, - "height-request", 35, - "visible", FALSE, - NULL); - sysprof_color_cycle_next (cycle, &rgba); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - rgba.alpha = .5; - sysprof_line_visualizer_set_fill (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - sysprof_time_visualizer_add_counter (SYSPROF_TIME_VISUALIZER (combined), ctr->id, &rgba); - sysprof_visualizer_group_insert (group, SYSPROF_VISUALIZER (row), -1, TRUE); - } - - sysprof_display_add_group (present->display, group); - - page = sysprof_marks_page_new (sysprof_display_get_zoom_manager (present->display), - SYSPROF_MARKS_MODEL_COUNTERS); - gtk_widget_show (page); - - g_signal_connect_object (group, - "group-activated", - G_CALLBACK (on_group_activated_cb), - page, - 0); - sysprof_display_add_page (present->display, SYSPROF_PAGE (page)); - } - - return counters != NULL; -} - -static void -sysprof_counters_aid_class_init (SysprofCountersAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_counters_aid_prepare; - aid_class->present_async = sysprof_counters_aid_present_async; - aid_class->present_finish = sysprof_counters_aid_present_finish; -} - -static void -sysprof_counters_aid_init (SysprofCountersAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Counters")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "org.gnome.Sysprof-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-counters-aid.h b/src/libsysprof-ui/sysprof-counters-aid.h deleted file mode 100644 index 5541b60f..00000000 --- a/src/libsysprof-ui/sysprof-counters-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-counters-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_COUNTERS_AID (sysprof_counters_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofCountersAid, sysprof_counters_aid, SYSPROF, COUNTERS_AID, SysprofAid) - -SysprofAid *sysprof_counters_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-cpu-aid.c b/src/libsysprof-ui/sysprof-cpu-aid.c deleted file mode 100644 index febdf876..00000000 --- a/src/libsysprof-ui/sysprof-cpu-aid.c +++ /dev/null @@ -1,357 +0,0 @@ -/* sysprof-cpu-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-cpu-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-cpu-aid.h" -#include "sysprof-line-visualizer.h" -#include "sysprof-procs-visualizer.h" - -struct _SysprofCpuAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; - GArray *counters; - guint has_processes : 1; -} Present; - -G_DEFINE_TYPE (SysprofCpuAid, sysprof_cpu_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_pointer (&p->counters, g_array_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -/** - * sysprof_cpu_aid_new: - * - * Create a new #SysprofCpuAid. - * - * Returns: (transfer full): a newly created #SysprofCpuAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_cpu_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_CPU_AID, NULL); -} - -static void -sysprof_cpu_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ -#ifdef __linux__ - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_CPU_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_hostinfo_source_new (); - sysprof_profiler_add_source (profiler, source); -#endif -} - -static bool -collect_info (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - Present *p = user_data; - - g_assert (frame != NULL); - g_assert (p != NULL); - g_assert (p->counters != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF) - { - for (guint i = 0; i < def->n_counters; i++) - { - const SysprofCaptureCounter *counter = &def->counters[i]; - - if (g_strcmp0 (counter->category, "CPU Percent") == 0 || - g_strcmp0 (counter->category, "CPU Frequency") == 0) - g_array_append_vals (p->counters, counter, 1); - } - } - else if (!p->has_processes && - (frame->type == SYSPROF_CAPTURE_FRAME_PROCESS || - frame->type == SYSPROF_CAPTURE_FRAME_EXIT)) - { - p->has_processes = TRUE; - } - - return TRUE; -} - -static void -sysprof_cpu_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *present = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_CPU_AID (source_object)); - g_assert (present != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - sysprof_capture_cursor_foreach (present->cursor, collect_info, present); - g_task_return_pointer (task, - g_steal_pointer (&present->counters), - (GDestroyNotify) g_array_unref); -} - -static void -sysprof_cpu_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { - SYSPROF_CAPTURE_FRAME_CTRDEF, - SYSPROF_CAPTURE_FRAME_PROCESS, - SYSPROF_CAPTURE_FRAME_EXIT, - }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_CPU_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - present.counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); - present.has_processes = FALSE; - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_cpu_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_cpu_aid_present_worker); -} - -static gboolean -sysprof_cpu_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) counters = NULL; - Present *present; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_TASK (result)); - - present = g_task_get_task_data (G_TASK (result)); - - if ((counters = g_task_propagate_pointer (G_TASK (result), error))) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - g_autoptr(SysprofColorCycle) freq_cycle = sysprof_color_cycle_new (); - SysprofVisualizerGroup *usage; - SysprofVisualizerGroup *freq; - SysprofVisualizer *freq_row = NULL; - SysprofVisualizer *over_row = NULL; - gboolean found_combined = FALSE; - gboolean has_usage = FALSE; - gboolean has_freq = FALSE; - - usage = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "priority", -1000, - "title", _("CPU Usage"), - "visible", TRUE, - NULL); - - freq = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "priority", -999, - "title", _("CPU Frequency"), - "visible", TRUE, - NULL); - freq_row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", _("CPU Frequency (All)"), - "height-request", 35, - "visible", TRUE, - "y-lower", 0.0, - "y-upper", 100.0, - NULL); - sysprof_visualizer_group_insert (freq, freq_row, -1, FALSE); - - over_row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", _("CPU Usage (All)"), - "height-request", 35, - "visible", TRUE, - "y-lower", 0.0, - "y-upper", 100.0, - NULL); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *ctr = &g_array_index (counters, SysprofCaptureCounter, i); - - if (g_strcmp0 (ctr->category, "CPU Percent") == 0) - { - if (strstr (ctr->name, "Combined") != NULL) - { - GtkWidget *row; - GdkRGBA rgba; - - found_combined = TRUE; - - gdk_rgba_parse (&rgba, "#1a5fb4"); - row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - /* Translators: CPU is the processor. */ - "title", _("CPU Usage (All)"), - "height-request", 35, - "visible", TRUE, - "y-lower", 0.0, - "y-upper", 100.0, - NULL); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - rgba.alpha = 0.5; - sysprof_line_visualizer_set_fill (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - sysprof_visualizer_group_insert (usage, SYSPROF_VISUALIZER (row), 0, FALSE); - has_usage = TRUE; - } - else if (g_str_has_prefix (ctr->name, "Total CPU ")) - { - GtkWidget *row; - GdkRGBA rgba; - - sysprof_color_cycle_next (cycle, &rgba); - row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", ctr->name, - "height-request", 35, - "visible", FALSE, - "y-lower", 0.0, - "y-upper", 100.0, - NULL); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (over_row), ctr->id, &rgba); - rgba.alpha = 0.5; - sysprof_line_visualizer_set_fill (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - sysprof_visualizer_group_insert (usage, SYSPROF_VISUALIZER (row), -1, TRUE); - has_usage = TRUE; - } - } - else if (g_strcmp0 (ctr->category, "CPU Frequency") == 0) - { - if (g_str_has_prefix (ctr->name, "CPU ")) - { - g_autofree gchar *title = g_strdup_printf ("%s Frequency", ctr->name); - GtkWidget *row; - GdkRGBA rgba; - - sysprof_color_cycle_next (freq_cycle, &rgba); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (freq_row), ctr->id, &rgba); - sysprof_line_visualizer_set_dash (SYSPROF_LINE_VISUALIZER (freq_row), ctr->id, TRUE); - - row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", title, - "height-request", 35, - "visible", FALSE, - "y-lower", 0.0, - "y-upper", 100.0, - NULL); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - sysprof_line_visualizer_set_dash (SYSPROF_LINE_VISUALIZER (row), ctr->id, TRUE); - sysprof_visualizer_group_insert (freq, SYSPROF_VISUALIZER (row), -1, TRUE); - - has_freq = TRUE; - } - } - } - - if (present->has_processes) - { - GtkWidget *row; - - row = g_object_new (SYSPROF_TYPE_PROCS_VISUALIZER, - "title", _("Processes"), - "height-request", 35, - "visible", FALSE, - NULL); - sysprof_visualizer_group_insert (usage, SYSPROF_VISUALIZER (row), -1, TRUE); - } - - if (has_usage && !found_combined) - sysprof_visualizer_group_insert (usage, over_row, 0, FALSE); - else - g_object_unref (g_object_ref_sink (over_row)); - - if (has_usage) - sysprof_display_add_group (present->display, usage); - else - g_object_unref (g_object_ref_sink (usage)); - - if (has_freq) - sysprof_display_add_group (present->display, freq); - else - g_object_unref (g_object_ref_sink (freq)); - } - - return counters != NULL; -} - -static void -sysprof_cpu_aid_class_init (SysprofCpuAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_cpu_aid_prepare; - aid_class->present_async = sysprof_cpu_aid_present_async; - aid_class->present_finish = sysprof_cpu_aid_present_finish; -} - -static void -sysprof_cpu_aid_init (SysprofCpuAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("CPU Usage")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "org.gnome.Sysprof-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-cpu-aid.h b/src/libsysprof-ui/sysprof-cpu-aid.h deleted file mode 100644 index 4769885e..00000000 --- a/src/libsysprof-ui/sysprof-cpu-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-cpu-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_CPU_AID (sysprof_cpu_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofCpuAid, sysprof_cpu_aid, SYSPROF, CPU_AID, SysprofAid) - -SysprofAid *sysprof_cpu_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-depth-visualizer.c b/src/libsysprof-ui/sysprof-depth-visualizer.c deleted file mode 100644 index c98e46d8..00000000 --- a/src/libsysprof-ui/sysprof-depth-visualizer.c +++ /dev/null @@ -1,453 +0,0 @@ -/* sysprof-depth-visualizer.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-depth-visualizer" - -#include "config.h" - -#include - -#include "pointcache.h" -#include "sysprof-depth-visualizer.h" - -struct _SysprofDepthVisualizer -{ - SysprofVisualizer parent_instance; - SysprofCaptureReader *reader; - PointCache *points; - guint reload_source; - guint mode; - int last_width; - int last_height; - guint reloading : 1; - guint needs_reload : 1; -}; - -typedef struct -{ - SysprofCaptureReader *reader; - PointCache *pc; - gint64 begin_time; - gint64 end_time; - gint64 duration; - guint max_n_addrs; - guint mode; -} State; - -static void sysprof_depth_visualizer_reload (SysprofDepthVisualizer *self); - -G_DEFINE_TYPE (SysprofDepthVisualizer, sysprof_depth_visualizer, SYSPROF_TYPE_VISUALIZER) - -static void -state_free (State *st) -{ - g_clear_pointer (&st->reader, sysprof_capture_reader_unref); - g_clear_pointer (&st->pc, point_cache_unref); - g_slice_free (State, st); -} - -static bool -discover_max_n_addr (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - const SysprofCaptureSample *sample = (const SysprofCaptureSample *)frame; - State *st = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_SAMPLE); - g_assert (st != NULL); - - st->max_n_addrs = MAX (st->max_n_addrs, sample->n_addrs); - - return TRUE; -} - -static bool -build_point_cache_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - const SysprofCaptureSample *sample = (const SysprofCaptureSample *)frame; - State *st = user_data; - gdouble x, y; - gboolean has_kernel = FALSE; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_SAMPLE); - g_assert (st != NULL); - - x = (frame->time - st->begin_time) / (gdouble)st->duration; - y = sample->n_addrs / (gdouble)st->max_n_addrs; - - /* If this contains a context-switch (meaning we're going into the kernel - * to do some work, use a negative value for Y so that we know later on - * that we should draw it with a different color (after removing the negation - * on the value. - * - * We skip past the first index, which is always a context switch as it is - * our perf handler. - */ - for (guint i = 1; i < sample->n_addrs; i++) - { - SysprofAddressContext kind; - - if (sysprof_address_is_context_switch (sample->addrs[i], &kind)) - { - has_kernel = TRUE; - y = -y; - break; - } - } - - if (!has_kernel) - point_cache_add_point_to_set (st->pc, 1, x, y); - else - point_cache_add_point_to_set (st->pc, 2, x, y); - - return TRUE; -} - -static void -sysprof_depth_visualizer_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_SAMPLE, }; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - SysprofCaptureCondition *condition; - State *st = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_DEPTH_VISUALIZER (source_object)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - if (st->duration != 0) - { - cursor = sysprof_capture_cursor_new (st->reader); - condition = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - sysprof_capture_cursor_foreach (cursor, discover_max_n_addr, st); - sysprof_capture_cursor_reset (cursor); - sysprof_capture_cursor_foreach (cursor, build_point_cache_cb, st); - } - - g_task_return_pointer (task, - g_steal_pointer (&st->pc), - (GDestroyNotify) point_cache_unref); -} - -static void -apply_point_cache_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofDepthVisualizer *self = (SysprofDepthVisualizer *)object; - PointCache *pc; - - g_assert (SYSPROF_IS_DEPTH_VISUALIZER (self)); - g_assert (G_IS_TASK (result)); - - self->reloading = FALSE; - - if ((pc = g_task_propagate_pointer (G_TASK (result), NULL))) - { - g_clear_pointer (&self->points, point_cache_unref); - self->points = g_steal_pointer (&pc); - gtk_widget_queue_draw (GTK_WIDGET (self)); - } - - if (self->needs_reload) - sysprof_depth_visualizer_reload (self); -} - -static void -sysprof_depth_visualizer_reload (SysprofDepthVisualizer *self) -{ - g_autoptr(GTask) task = NULL; - GtkAllocation alloc; - State *st; - - g_assert (SYSPROF_IS_DEPTH_VISUALIZER (self)); - - self->needs_reload = TRUE; - - if (self->reloading) - return; - - self->reloading = TRUE; - self->needs_reload = FALSE; - - gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); - - st = g_slice_new0 (State); - st->reader = sysprof_capture_reader_ref (self->reader); - st->pc = point_cache_new (); - st->max_n_addrs = 0; - st->begin_time = sysprof_capture_reader_get_start_time (self->reader); - st->end_time = sysprof_capture_reader_get_end_time (self->reader); - st->duration = st->end_time - st->begin_time; - st->mode = self->mode; - - point_cache_add_set (st->pc, 1); - point_cache_add_set (st->pc, 2); - - task = g_task_new (self, NULL, apply_point_cache_cb, NULL); - g_task_set_source_tag (task, sysprof_depth_visualizer_reload); - g_task_set_task_data (task, st, (GDestroyNotify) state_free); - g_task_run_in_thread (task, sysprof_depth_visualizer_worker); -} - -static void -sysprof_depth_visualizer_set_reader (SysprofVisualizer *row, - SysprofCaptureReader *reader) -{ - SysprofDepthVisualizer *self = (SysprofDepthVisualizer *)row; - - g_assert (SYSPROF_IS_DEPTH_VISUALIZER (self)); - - if (self->reader != reader) - { - if (self->reader != NULL) - { - sysprof_capture_reader_unref (self->reader); - self->reader = NULL; - } - - if (reader != NULL) - { - self->reader = sysprof_capture_reader_ref (reader); - sysprof_depth_visualizer_reload (self); - } - } -} - -static void -sysprof_depth_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofDepthVisualizer *self = (SysprofDepthVisualizer *)widget; - GtkAllocation alloc; - GdkRectangle clip; - const Point *points; - cairo_t *cr; - guint n_points = 0; - GdkRGBA user; - GdkRGBA system; - - g_assert (SYSPROF_IS_DEPTH_VISUALIZER (self)); - g_assert (snapshot != NULL); - - GTK_WIDGET_CLASS (sysprof_depth_visualizer_parent_class)->snapshot (widget, snapshot); - - if (self->points == NULL) - return; - - gdk_rgba_parse (&user, "#1a5fb4"); - gdk_rgba_parse (&system, "#3584e4"); - - gtk_widget_get_allocation (widget, &alloc); - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height)); - - /* FIXME: we should abstract visualizer drawing into regions so that we - * can still know the region we're drawing. - */ -#if 0 - if (!gdk_cairo_get_clip_rectangle (cr, &clip)) - return; -#else - clip.x = alloc.x = 0; - clip.y = alloc.y = 0; - clip.width = alloc.width; - clip.height = alloc.height; -#endif - - /* Draw user-space stacks */ - if (self->mode != SYSPROF_DEPTH_VISUALIZER_KERNEL_ONLY && - (points = point_cache_get_points (self->points, 1, &n_points))) - { - g_autofree SysprofVisualizerAbsolutePoint *out_points = NULL; - - out_points = g_new (SysprofVisualizerAbsolutePoint, n_points); - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (widget), - (const SysprofVisualizerRelativePoint *)points, - n_points, out_points, n_points); - - cairo_set_line_width (cr, 1.0); - gdk_cairo_set_source_rgba (cr, &user); - - for (guint i = 0; i < n_points; i++) - { - gdouble x, y; - - x = out_points[i].x; - y = out_points[i].y; - - if (x < clip.x) - continue; - - if (x > clip.x + clip.width) - break; - - for (guint j = i + 1; j < n_points; j++) - { - if (out_points[j].x != x) - break; - - y = MIN (y, out_points[j].y); - } - - x += alloc.x; - - cairo_move_to (cr, (guint)x + .5, alloc.height); - cairo_line_to (cr, (guint)x + .5, y); - } - - cairo_stroke (cr); - } - - /* Draw kernel-space stacks */ - if (self->mode != SYSPROF_DEPTH_VISUALIZER_USER_ONLY && - (points = point_cache_get_points (self->points, 2, &n_points))) - { - g_autofree SysprofVisualizerAbsolutePoint *out_points = NULL; - - out_points = g_new (SysprofVisualizerAbsolutePoint, n_points); - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (widget), - (const SysprofVisualizerRelativePoint *)points, - n_points, out_points, n_points); - - cairo_set_line_width (cr, 1.0); - gdk_cairo_set_source_rgba (cr, &system); - - for (guint i = 0; i < n_points; i++) - { - gdouble x, y; - - x = out_points[i].x; - y = out_points[i].y; - - if (x < clip.x) - continue; - - if (x > clip.x + clip.width) - break; - - for (guint j = i + 1; j < n_points; j++) - { - if (out_points[j].x != x) - break; - - y = MIN (y, out_points[j].y); - } - - x += alloc.x; - - cairo_move_to (cr, (guint)x + .5, alloc.height); - cairo_line_to (cr, (guint)x + .5, y); - } - - cairo_stroke (cr); - } - - cairo_destroy (cr); -} - -static gboolean -sysprof_depth_visualizer_do_reload (gpointer data) -{ - SysprofDepthVisualizer *self = data; - self->reload_source = 0; - sysprof_depth_visualizer_reload (self); - return G_SOURCE_REMOVE; -} - -static void -sysprof_depth_visualizer_queue_reload (SysprofDepthVisualizer *self) -{ - g_assert (SYSPROF_IS_DEPTH_VISUALIZER (self)); - - g_clear_handle_id (&self->reload_source, g_source_remove); - self->reload_source = g_idle_add (sysprof_depth_visualizer_do_reload, self); -} - -static void -sysprof_depth_visualizer_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - SysprofDepthVisualizer *self = (SysprofDepthVisualizer *)widget; - - if (width != self->last_width || height != self->last_height) - { - sysprof_depth_visualizer_queue_reload (SYSPROF_DEPTH_VISUALIZER (widget)); - self->last_width = width; - self->last_height = height; - } -} - -static void -sysprof_depth_visualizer_finalize (GObject *object) -{ - SysprofDepthVisualizer *self = (SysprofDepthVisualizer *)object; - - g_clear_pointer (&self->reader, sysprof_capture_reader_unref); - g_clear_handle_id (&self->reload_source, g_source_remove); - - G_OBJECT_CLASS (sysprof_depth_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_depth_visualizer_class_init (SysprofDepthVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofVisualizerClass *row_class = SYSPROF_VISUALIZER_CLASS (klass); - - object_class->finalize = sysprof_depth_visualizer_finalize; - - widget_class->snapshot = sysprof_depth_visualizer_snapshot; - widget_class->size_allocate = sysprof_depth_visualizer_size_allocate; - - row_class->set_reader = sysprof_depth_visualizer_set_reader; -} - -static void -sysprof_depth_visualizer_init (SysprofDepthVisualizer *self) -{ -} - -SysprofVisualizer * -sysprof_depth_visualizer_new (SysprofDepthVisualizerMode mode) -{ - SysprofDepthVisualizer *self; - - g_return_val_if_fail (mode == SYSPROF_DEPTH_VISUALIZER_COMBINED || - mode == SYSPROF_DEPTH_VISUALIZER_KERNEL_ONLY || - mode == SYSPROF_DEPTH_VISUALIZER_USER_ONLY, - NULL); - - self = g_object_new (SYSPROF_TYPE_DEPTH_VISUALIZER, NULL); - self->mode = mode; - - return SYSPROF_VISUALIZER (g_steal_pointer (&self)); -} diff --git a/src/libsysprof-ui/sysprof-depth-visualizer.h b/src/libsysprof-ui/sysprof-depth-visualizer.h deleted file mode 100644 index 425c4d42..00000000 --- a/src/libsysprof-ui/sysprof-depth-visualizer.h +++ /dev/null @@ -1,40 +0,0 @@ -/* sysprof-depth-visualizer.h - * - * Copyright 2019 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-visualizer.h" - -G_BEGIN_DECLS - -typedef enum -{ - SYSPROF_DEPTH_VISUALIZER_COMBINED, - SYSPROF_DEPTH_VISUALIZER_KERNEL_ONLY, - SYSPROF_DEPTH_VISUALIZER_USER_ONLY, -} SysprofDepthVisualizerMode; - -#define SYSPROF_TYPE_DEPTH_VISUALIZER (sysprof_depth_visualizer_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofDepthVisualizer, sysprof_depth_visualizer, SYSPROF, DEPTH_VISUALIZER, SysprofVisualizer) - -SysprofVisualizer *sysprof_depth_visualizer_new (SysprofDepthVisualizerMode mode); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-details-page.c b/src/libsysprof-ui/sysprof-details-page.c deleted file mode 100644 index 0bcffa02..00000000 --- a/src/libsysprof-ui/sysprof-details-page.c +++ /dev/null @@ -1,325 +0,0 @@ -/* sysprof-details-page.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-details-page" - -#include "config.h" - -#include -#include - -#include "sysprof-mark-detail.h" -#include "sysprof-details-page.h" -#include "sysprof-ui-private.h" - -struct _SysprofDetailsPage -{ - GtkWidget parent_instance ; - - /* Template Objects */ - - GListStore *marks_store; - GtkSortListModel *mark_sort_model; - GtkLabel *counters; - GtkLabel *duration; - GtkLabel *filename; - GtkLabel *allocations; - GtkLabel *forks; - GtkLabel *marks; - GtkLabel *processes; - GtkLabel *samples; - GtkLabel *start_time; - GtkLabel *cpu_label; - - guint next_row; -}; - -G_DEFINE_TYPE (SysprofDetailsPage, sysprof_details_page, GTK_TYPE_WIDGET) - -#if GLIB_CHECK_VERSION(2, 56, 0) -# define _g_date_time_new_from_iso8601 g_date_time_new_from_iso8601 -#else -static GDateTime * -_g_date_time_new_from_iso8601 (const gchar *str, - GTimeZone *default_tz) -{ - GTimeVal tv; - - if (g_time_val_from_iso8601 (str, &tv)) - { - g_autoptr(GDateTime) dt = g_date_time_new_from_timeval_utc (&tv); - - if (default_tz) - return g_date_time_to_timezone (dt, default_tz); - else - return g_steal_pointer (&dt); - } - - return NULL; -} -#endif - -char * -format_time (GObject *unused, - gint64 time) -{ - return time ? _sysprof_format_duration (time) : g_strdup("—"); -} - -static void -sysprof_details_page_dispose (GObject *object) -{ - SysprofDetailsPage *self = (SysprofDetailsPage *)object; - GtkWidget *child; - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) - gtk_widget_unparent (child); - - G_OBJECT_CLASS (sysprof_details_page_parent_class)->dispose (object); -} - -static void -sysprof_details_page_class_init (SysprofDetailsPageClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = sysprof_details_page_dispose; - - g_type_ensure (SYSPROF_TYPE_MARK_DETAIL); - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-details-page.ui"); - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, allocations); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, counters); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, cpu_label); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, duration); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, filename); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, forks); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, marks_store); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, mark_sort_model); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, processes); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, samples); - gtk_widget_class_bind_template_child (widget_class, SysprofDetailsPage, start_time); - gtk_widget_class_bind_template_callback (widget_class, format_time); -} - -static void -sysprof_details_page_init (SysprofDetailsPage *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); - - self->next_row = 8; -} - -GtkWidget * -sysprof_details_page_new (void) -{ - return g_object_new (SYSPROF_TYPE_DETAILS_PAGE, NULL); -} - -static void -update_cpu_info_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - g_autoptr(SysprofDetailsPage) self = user_data; - g_autofree gchar *str = NULL; - - g_assert (SYSPROF_IS_DETAILS_PAGE (self)); - g_assert (G_IS_TASK (result)); - - if ((str = g_task_propagate_pointer (G_TASK (result), NULL))) - gtk_label_set_label (self->cpu_label, str); -} - -static bool -cpu_info_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - const SysprofCaptureFileChunk *fc = (gpointer)frame; - const gchar *endptr; - const gchar *line; - gchar **str = user_data; - - line = memmem ((gchar *)fc->data, fc->len, "model name", 10); - - if (!line) - return FALSE; - - endptr = (gchar *)fc->data + fc->len; - endptr = memchr (line, '\n', endptr - line); - - if (endptr) - { - gchar *tmp = *str = g_strndup (line, endptr - line); - for (; *tmp && *tmp != ':'; tmp++) - *tmp = ' '; - if (*tmp == ':') - *tmp = ' '; - g_strstrip (*str); - return FALSE; - } - - return TRUE; -} - -static void -sysprof_details_page_update_cpu_info_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - SysprofCaptureCursor *cursor = task_data; - gchar *str = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (cursor != NULL); - - sysprof_capture_cursor_foreach (cursor, cpu_info_cb, &str); - g_task_return_pointer (task, g_steal_pointer (&str), g_free); -} - -static void -sysprof_details_page_update_cpu_info (SysprofDetailsPage *self, - SysprofCaptureReader *reader) -{ - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - - g_assert (SYSPROF_IS_DETAILS_PAGE (self)); - g_assert (reader != NULL); - - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, - sysprof_capture_condition_new_where_file ("/proc/cpuinfo")); - - task = g_task_new (NULL, NULL, update_cpu_info_cb, g_object_ref (self)); - g_task_set_task_data (task, - g_steal_pointer (&cursor), - (GDestroyNotify) sysprof_capture_cursor_unref); - g_task_run_in_thread (task, sysprof_details_page_update_cpu_info_worker); -} - -void -sysprof_details_page_set_reader (SysprofDetailsPage *self, - SysprofCaptureReader *reader) -{ - g_autoptr(GDateTime) dt = NULL; - g_autoptr(GDateTime) local = NULL; - g_autofree gchar *duration_str = NULL; - const gchar *filename; - const gchar *capture_at; - SysprofCaptureStat st_buf; - gint64 duration; - - g_return_if_fail (SYSPROF_IS_DETAILS_PAGE (self)); - g_return_if_fail (reader != NULL); - - sysprof_details_page_update_cpu_info (self, reader); - - if (!(filename = sysprof_capture_reader_get_filename (reader))) - filename = _("Memory Capture"); - - gtk_label_set_label (self->filename, filename); - - if ((capture_at = sysprof_capture_reader_get_time (reader)) && - (dt = _g_date_time_new_from_iso8601 (capture_at, NULL)) && - (local = g_date_time_to_local (dt))) - { - g_autofree gchar *str = g_date_time_format (local, "%x %X"); - gtk_label_set_label (self->start_time, str); - } - - duration = sysprof_capture_reader_get_end_time (reader) - - sysprof_capture_reader_get_start_time (reader); - duration_str = g_strdup_printf (_("%0.4lf seconds"), duration / (gdouble)SYSPROF_NSEC_PER_SEC); - gtk_label_set_label (self->duration, duration_str); - - if (sysprof_capture_reader_get_stat (reader, &st_buf)) - { -#define SET_FRAME_COUNT(field, TYPE) \ - G_STMT_START { \ - g_autofree gchar *str = NULL; \ - str = g_strdup_printf ("%"G_GSIZE_FORMAT, st_buf.frame_count[TYPE]); \ - gtk_label_set_label (self->field, str); \ - } G_STMT_END - - SET_FRAME_COUNT (samples, SYSPROF_CAPTURE_FRAME_SAMPLE); - SET_FRAME_COUNT (marks, SYSPROF_CAPTURE_FRAME_MARK); - SET_FRAME_COUNT (processes, SYSPROF_CAPTURE_FRAME_PROCESS); - SET_FRAME_COUNT (forks, SYSPROF_CAPTURE_FRAME_FORK); - SET_FRAME_COUNT (counters, SYSPROF_CAPTURE_FRAME_CTRSET); - SET_FRAME_COUNT (allocations, SYSPROF_CAPTURE_FRAME_ALLOCATION); - -#undef SET_FRAME_COUNT - } -} - -void -sysprof_details_page_add_mark (SysprofDetailsPage *self, - const gchar *mark, - gint64 min, - gint64 max, - gint64 avg, - gint64 hits) -{ - SysprofMarkDetail *detail; - - g_return_if_fail (SYSPROF_IS_DETAILS_PAGE (self)); - - detail = sysprof_mark_detail_new (mark, min, max, avg, hits); - - g_list_store_append (self->marks_store, detail); - /*gtk_list_store_append (self->marks_store, &iter); - gtk_list_store_set (self->marks_store, &iter, - 0, mark, - 1, min ? _sysprof_format_duration (min) : "—", - 2, max ? _sysprof_format_duration (max) : "—", - 3, avg ? _sysprof_format_duration (avg) : "—", - 4, hits, - 5, detail, - -1);*/ - g_object_unref (detail); -} - -void -sysprof_details_page_add_marks (SysprofDetailsPage *self, - const SysprofMarkStat *marks, - guint n_marks) -{ - g_return_if_fail (SYSPROF_IS_DETAILS_PAGE (self)); - g_return_if_fail (marks != NULL || n_marks == 0); - - if (marks == NULL || n_marks == 0) - return; - - /* Be reasonable */ - if (n_marks > 100) - n_marks = 100; - - for (guint i = 0; i < n_marks; i++) - sysprof_details_page_add_mark (self, - marks[i].name, - marks[i].min, - marks[i].max, - marks[i].avg, - marks[i].count); -} diff --git a/src/libsysprof-ui/sysprof-details-page.h b/src/libsysprof-ui/sysprof-details-page.h deleted file mode 100644 index 63b919fc..00000000 --- a/src/libsysprof-ui/sysprof-details-page.h +++ /dev/null @@ -1,57 +0,0 @@ -/* sysprof-details-page.h - * - * Copyright 2019 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 -#include - -G_BEGIN_DECLS - -SYSPROF_ALIGNED_BEGIN (8) -typedef struct -{ - gchar name[152]; - guint64 count; - gint64 max; - gint64 min; - gint64 avg; - guint64 avg_count; -} SysprofMarkStat -SYSPROF_ALIGNED_END (8); - -#define SYSPROF_TYPE_DETAILS_PAGE (sysprof_details_page_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofDetailsPage, sysprof_details_page, SYSPROF, DETAILS_PAGE, GtkWidget) - -GtkWidget *sysprof_details_page_new (void); -void sysprof_details_page_set_reader (SysprofDetailsPage *self, - SysprofCaptureReader *reader); -void sysprof_details_page_add_marks (SysprofDetailsPage *self, - const SysprofMarkStat *marks, - guint n_marks); -void sysprof_details_page_add_mark (SysprofDetailsPage *self, - const gchar *mark, - gint64 min, - gint64 max, - gint64 avg, - gint64 hits); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-details-page.ui b/src/libsysprof-ui/sysprof-details-page.ui deleted file mode 100644 index e9de42de..00000000 --- a/src/libsysprof-ui/sysprof-details-page.ui +++ /dev/null @@ -1,361 +0,0 @@ - - - - - marks_store - true - - marks_view - - - - - diff --git a/src/libsysprof-ui/sysprof-diskstat-aid.c b/src/libsysprof-ui/sysprof-diskstat-aid.c deleted file mode 100644 index 676ea4a3..00000000 --- a/src/libsysprof-ui/sysprof-diskstat-aid.c +++ /dev/null @@ -1,269 +0,0 @@ -/* sysprof-diskstat-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-diskstat-aid" - -#include "config.h" - -#include -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-duplex-visualizer.h" -#include "sysprof-diskstat-aid.h" - -struct _SysprofDiskstatAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; -} Present; - -G_DEFINE_TYPE (SysprofDiskstatAid, sysprof_diskstat_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -/** - * sysprof_diskstat_aid_new: - * - * Create a new #SysprofDiskstatAid. - * - * Returns: (transfer full): a newly created #SysprofDiskstatAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_diskstat_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_DISKSTAT_AID, NULL); -} - -static void -sysprof_diskstat_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_DISKSTAT_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_diskstat_source_new (); - sysprof_profiler_add_source (profiler, source); -} - -static bool -collect_diskstat_counters (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - GArray *counters = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (counters != NULL); - - for (guint i = 0; i < def->n_counters; i++) - { - const SysprofCaptureCounter *counter = &def->counters[i]; - - if (strcmp (counter->category, "Disk") == 0 && - (g_str_has_prefix (counter->name, "Total Reads") || - g_str_has_prefix (counter->name, "Total Writes"))) - g_array_append_vals (counters, counter, 1); - } - - return TRUE; -} - -static void -sysprof_diskstat_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *present = task_data; - g_autoptr(GArray) counters = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_DISKSTAT_AID (source_object)); - g_assert (present != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); - sysprof_capture_cursor_foreach (present->cursor, collect_diskstat_counters, counters); - g_task_return_pointer (task, - g_steal_pointer (&counters), - (GDestroyNotify) g_array_unref); -} - -static guint -find_other_id (GArray *counters, - const gchar *name) -{ - g_autofree gchar *other = NULL; - - g_assert (counters); - g_assert (name != NULL); - g_assert (g_str_has_prefix (name, "Total Reads")); - - other = g_strdup_printf ("Total Writes%s", name + strlen ("Total Reads")); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *c = &g_array_index (counters, SysprofCaptureCounter, i); - - if (g_str_equal (c->name, other)) - return c->id; - } - - return 0; -} - -static void -sysprof_diskstat_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_CTRDEF }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_DISKSTAT_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (1, types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_diskstat_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_diskstat_aid_present_worker); -} - -static gboolean -sysprof_diskstat_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) counters = NULL; - Present *present; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_TASK (result)); - - present = g_task_get_task_data (G_TASK (result)); - - if ((counters = g_task_propagate_pointer (G_TASK (result), error))) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - SysprofVisualizerGroup *group; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "title", _("Disk"), - "visible", TRUE, - NULL); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *ctr = &g_array_index (counters, SysprofCaptureCounter, i); - - if (g_str_has_prefix (ctr->name, "Total Reads")) - { - g_autofree gchar *title = NULL; - gboolean is_combined; - GtkWidget *row; - GdkRGBA rgba; - guint other_id; - - if (!(other_id = find_other_id (counters, ctr->name))) - continue; - - is_combined = g_str_equal (ctr->description, "Combined"); - - if (is_combined) - title = g_strdup ("Disk Reads/Writes (All)"); - else - title = g_strdup_printf ("Disk Reads/Writes%s", ctr->name + strlen ("Total Reads")); - - row = g_object_new (SYSPROF_TYPE_DUPLEX_VISUALIZER, - "title", title, - "height-request", 35, - "visible", is_combined, - NULL); - sysprof_color_cycle_next (cycle, &rgba); - sysprof_duplex_visualizer_set_counters (SYSPROF_DUPLEX_VISUALIZER (row), ctr->id, other_id); - sysprof_duplex_visualizer_set_colors (SYSPROF_DUPLEX_VISUALIZER (row), &rgba, &rgba); - sysprof_duplex_visualizer_set_labels (SYSPROF_DUPLEX_VISUALIZER (row), _("Reads"), _("Writes")); - sysprof_duplex_visualizer_set_use_diff (SYSPROF_DUPLEX_VISUALIZER (row), FALSE); - sysprof_visualizer_group_insert (group, SYSPROF_VISUALIZER (row), is_combined ? 0 : -1, !is_combined); - } - } - - if (counters->len > 0) - sysprof_display_add_group (present->display, group); - else - g_object_unref (g_object_ref_sink (group)); - } - - return counters != NULL; -} - -static void -sysprof_diskstat_aid_class_init (SysprofDiskstatAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_diskstat_aid_prepare; - aid_class->present_async = sysprof_diskstat_aid_present_async; - aid_class->present_finish = sysprof_diskstat_aid_present_finish; -} - -static void -sysprof_diskstat_aid_init (SysprofDiskstatAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Disk")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "drive-harddisk-system-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-diskstat-aid.h b/src/libsysprof-ui/sysprof-diskstat-aid.h deleted file mode 100644 index c2938a41..00000000 --- a/src/libsysprof-ui/sysprof-diskstat-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-diskstat-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_DISKSTAT_AID (sysprof_diskstat_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofDiskstatAid, sysprof_diskstat_aid, SYSPROF, DISKSTAT_AID, SysprofAid) - -SysprofAid *sysprof_diskstat_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-display-private.h b/src/libsysprof-ui/sysprof-display-private.h deleted file mode 100644 index 2ca6ad64..00000000 --- a/src/libsysprof-ui/sysprof-display-private.h +++ /dev/null @@ -1,29 +0,0 @@ -/* sysprof-display-private.h - * - * Copyright 2021 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-display.h" - -G_BEGIN_DECLS - -void _sysprof_display_destroy (SysprofDisplay *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-display.c b/src/libsysprof-ui/sysprof-display.c deleted file mode 100644 index 0c0ac27c..00000000 --- a/src/libsysprof-ui/sysprof-display.c +++ /dev/null @@ -1,1340 +0,0 @@ -/* sysprof-display.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-display" - -#include "config.h" - -#include - -#include "egg-paned-private.h" - -#include "sysprof-details-page.h" -#include "sysprof-display-private.h" -#include "sysprof-profiler-assistant.h" -#include "sysprof-failed-state-view.h" -#include "sysprof-recording-state-view.h" -#include "sysprof-theme-manager.h" -#include "sysprof-ui-private.h" -#include "sysprof-visualizers-frame.h" -#include "sysprof-visualizer-group-private.h" - -#include "sysprof-battery-aid.h" -#include "sysprof-callgraph-aid.h" -#include "sysprof-counters-aid.h" -#include "sysprof-cpu-aid.h" -#include "sysprof-diskstat-aid.h" -#include "sysprof-logs-aid.h" -#include "sysprof-marks-aid.h" -#include "sysprof-memory-aid.h" -#include "sysprof-memprof-aid.h" -#include "sysprof-netdev-aid.h" -#include "sysprof-rapl-aid.h" - -typedef enum -{ - SYSPROF_CAPTURE_FLAGS_CAN_REPLAY = 1 << 1, -} SysprofCaptureFlags; - -typedef struct -{ - SysprofCaptureReader *reader; - SysprofCaptureCondition *filter; - GFile *file; - SysprofProfiler *profiler; - GError *error; - - /* Template Widgets */ - SysprofVisualizersFrame *visualizers; - GtkStack *pages; - SysprofDetailsPage *details; - GtkStack *stack; - SysprofProfilerAssistant *assistant; - SysprofRecordingStateView *recording_view; - SysprofFailedStateView *failed_view; - - SysprofCaptureFlags flags; -} SysprofDisplayPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofDisplay, sysprof_display, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_CAN_REPLAY, - PROP_CAN_SAVE, - PROP_RECORDING, - PROP_TITLE, - PROP_VISIBLE_PAGE, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static void -update_title_child_property (SysprofDisplay *self) -{ - GtkWidget *parent; - - g_assert (SYSPROF_IS_DISPLAY (self)); - - if ((parent = gtk_widget_get_parent (GTK_WIDGET (self))) && GTK_IS_NOTEBOOK (parent)) - { - g_autofree gchar *title = sysprof_display_dup_title (self); - gtk_notebook_set_menu_label_text (GTK_NOTEBOOK (parent), GTK_WIDGET (self), title); - } - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); -} - -static void -sysprof_display_profiler_failed_cb (SysprofDisplay *self, - const GError *error, - SysprofProfiler *profiler) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (error != NULL); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - g_clear_object (&priv->profiler); - - /* Save the error for future use */ - g_clear_error (&priv->error); - priv->error = g_error_copy (error); - - gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->failed_view)); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RECORDING]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_REPLAY]); -} - -static void -sysprof_display_profiler_stopped_cb (SysprofDisplay *self, - SysprofProfiler *profiler) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - SysprofCaptureWriter *writer; - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - if ((writer = sysprof_profiler_get_writer (profiler))) - { - g_autoptr(SysprofCaptureReader) reader = NULL; - g_autoptr(GError) error = NULL; - - if (!(reader = sysprof_capture_writer_create_reader_with_error (writer, &error))) - { - g_warning ("Failed to create capture creader: %s\n", error->message); - gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->failed_view)); - goto notify; - } - - sysprof_display_load_async (self, - reader, - NULL, NULL, NULL); - gtk_stack_set_visible_child_name (priv->stack, "view"); - } - -notify: - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_REPLAY]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_SAVE]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RECORDING]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); -} - -static void -sysprof_display_set_profiler (SysprofDisplay *self, - SysprofProfiler *profiler) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - if (g_set_object (&priv->profiler, profiler)) - { - sysprof_recording_state_view_set_profiler (priv->recording_view, profiler); - gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->recording_view)); - - g_signal_connect_object (profiler, - "stopped", - G_CALLBACK (sysprof_display_profiler_stopped_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (profiler, - "failed", - G_CALLBACK (sysprof_display_profiler_failed_cb), - self, - G_CONNECT_SWAPPED); - } - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_RECORDING]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); -} - -static void -sysprof_display_start_recording_cb (SysprofDisplay *self, - SysprofProfiler *profiler, - SysprofProfilerAssistant *assistant) -{ - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - g_assert (!assistant || SYSPROF_IS_PROFILER_ASSISTANT (assistant)); - g_assert (sysprof_display_is_empty (self)); - - sysprof_display_set_profiler (self, profiler); - sysprof_profiler_start (profiler); -} - -static gboolean -sysprof_display_get_is_recording (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_assert (SYSPROF_IS_DISPLAY (self)); - - return GTK_WIDGET (priv->recording_view) == gtk_stack_get_visible_child (priv->stack); -} - -gchar * -sysprof_display_dup_title (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL); - - if (priv->error) - return g_strdup (_("Recording Failed")); - - if (priv->profiler != NULL) - { - if (sysprof_profiler_get_is_running (priv->profiler)) - return g_strdup (_("Recording…")); - } - - if (priv->file != NULL) - return g_file_get_basename (priv->file); - - if (priv->reader != NULL) - { - g_autoptr(GDateTime) dt = NULL; - const gchar *filename; - const gchar *capture_time; - - if ((filename = sysprof_capture_reader_get_filename (priv->reader))) - return g_path_get_basename (filename); - - /* This recording is not yet on disk, but the time it was recorded - * is much more useful than "New Recording". - */ - capture_time = sysprof_capture_reader_get_time (priv->reader); - - if ((dt = g_date_time_new_from_iso8601 (capture_time, NULL))) - { - g_autoptr(GDateTime) local = g_date_time_to_local (dt); - g_autofree gchar *formatted = NULL; - - if (local != NULL) - formatted = g_date_time_format (local, "%X"); - else - formatted = g_date_time_format (dt, "%X"); - - /* translators: %s is replaced with locale specific time of recording */ - return g_strdup_printf (_("Recording at %s"), formatted); - } - } - - return g_strdup (_("New Recording")); -} - -/** - * sysprof_display_new: - * - * Create a new #SysprofDisplay. - * - * Returns: (transfer full): a newly created #SysprofDisplay - */ -GtkWidget * -sysprof_display_new (void) -{ - return g_object_new (SYSPROF_TYPE_DISPLAY, NULL); -} - -static void -sysprof_display_notify_selection_cb (SysprofDisplay *self, - GParamSpec *pspec, - SysprofVisualizersFrame *visualizers) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - SysprofSelection *selection; - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (visualizers)); - - g_clear_pointer (&priv->filter, sysprof_capture_condition_unref); - - if ((selection = sysprof_visualizers_frame_get_selection (visualizers))) - { - SysprofCaptureCondition *cond = NULL; - guint n_ranges = sysprof_selection_get_n_ranges (selection); - - for (guint i = 0; i < n_ranges; i++) - { - SysprofCaptureCondition *c; - gint64 begin, end; - - sysprof_selection_get_nth_range (selection, i, &begin, &end); - c = sysprof_capture_condition_new_where_time_between (begin, end); - - if (cond == NULL) - cond = c; - else - cond = sysprof_capture_condition_new_or (cond, c); - } - - priv->filter = cond; - - /* Opportunistically load pages */ - if (priv->reader != NULL) - { - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (priv->pages)); - child; - child = gtk_widget_get_next_sibling (child)) - { - if (SYSPROF_IS_PAGE (child)) - sysprof_page_load_async (SYSPROF_PAGE (child), - priv->reader, - selection, - priv->filter, - NULL, NULL, NULL); - } - } - } -} - -static void -change_page_cb (GSimpleAction *action, - GVariant *param, - gpointer user_data) -{ - SysprofDisplay *self = user_data; - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_assert (G_IS_SIMPLE_ACTION (action)); - g_assert (param != NULL); - - if (g_variant_is_of_type (param, G_VARIANT_TYPE_STRING)) - { - const gchar *str = g_variant_get_string (param, NULL); - - gtk_stack_set_visible_child_name (priv->pages, str); - - if (g_str_equal (str, "details")) - sysprof_visualizers_frame_unselect_row (priv->visualizers); - } -} - -static void -stop_recording_cb (GSimpleAction *action, - GVariant *param, - gpointer user_data) -{ - SysprofDisplay *self = user_data; - - g_assert (G_IS_SIMPLE_ACTION (action)); - g_assert (SYSPROF_IS_DISPLAY (self)); - - sysprof_display_stop_recording (self); -} - -static void -sysprof_display_dispose (GObject *object) -{ - SysprofDisplay *self = (SysprofDisplay *)object; - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - if (priv->stack) - { - gtk_widget_unparent (GTK_WIDGET (priv->stack)); - priv->stack = NULL; - } - - g_clear_pointer (&priv->reader, sysprof_capture_reader_unref); - g_clear_pointer (&priv->filter, sysprof_capture_condition_unref); - - G_OBJECT_CLASS (sysprof_display_parent_class)->dispose (object); -} - -static void -sysprof_display_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofDisplay *self = SYSPROF_DISPLAY (object); - - switch (prop_id) - { - case PROP_CAN_REPLAY: - g_value_set_boolean (value, sysprof_display_get_can_replay (self)); - break; - - case PROP_CAN_SAVE: - g_value_set_boolean (value, sysprof_display_get_can_save (self)); - break; - - case PROP_RECORDING: - g_value_set_boolean (value, sysprof_display_get_is_recording (self)); - break; - - case PROP_TITLE: - g_value_take_string (value, sysprof_display_dup_title (self)); - break; - - case PROP_VISIBLE_PAGE: - g_value_set_object (value, sysprof_display_get_visible_page (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_display_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofDisplay *self = SYSPROF_DISPLAY (object); - - switch (prop_id) - { - case PROP_VISIBLE_PAGE: - sysprof_display_set_visible_page (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_display_class_init (SysprofDisplayClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_display_dispose; - object_class->get_property = sysprof_display_get_property; - object_class->set_property = sysprof_display_set_property; - - sysprof_theme_manager_register_resource (sysprof_theme_manager_get_default (), - NULL, - NULL, - "/org/gnome/sysprof/css/SysprofDisplay-shared.css"); - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-display.ui"); - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_set_css_name (widget_class, "SysprofDisplay"); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, assistant); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, details); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, failed_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, pages); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, recording_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, stack); - gtk_widget_class_bind_template_child_private (widget_class, SysprofDisplay, visualizers); - - properties [PROP_CAN_REPLAY] = - g_param_spec_boolean ("can-replay", - "Can Replay", - "If the capture contains enough information to re-run the recording", - FALSE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CAN_SAVE] = - g_param_spec_boolean ("can-save", - "Can Save", - "If the display can save a recording", - FALSE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_RECORDING] = - g_param_spec_boolean ("recording", - "Recording", - "If the display is in recording state", - FALSE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_TITLE] = - g_param_spec_string ("title", - "Title", - "The title of the display", - NULL, - (G_PARAM_READABLE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_VISIBLE_PAGE] = - g_param_spec_object ("visible-page", - "Visible Page", - "Visible Page", - SYSPROF_TYPE_PAGE, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - g_type_ensure (EGG_TYPE_PANED); - g_type_ensure (SYSPROF_TYPE_DETAILS_PAGE); - g_type_ensure (SYSPROF_TYPE_FAILED_STATE_VIEW); - g_type_ensure (SYSPROF_TYPE_PROFILER_ASSISTANT); - g_type_ensure (SYSPROF_TYPE_RECORDING_STATE_VIEW); - g_type_ensure (SYSPROF_TYPE_VISUALIZERS_FRAME); -} - -static void -sysprof_display_init (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - g_autoptr(GSimpleActionGroup) group = g_simple_action_group_new (); - static GActionEntry entries[] = { - { "page", change_page_cb, "s" }, - { "stop-recording", stop_recording_cb }, - }; - g_autoptr(GPropertyAction) page = NULL; - - gtk_widget_init_template (GTK_WIDGET (self)); - - g_signal_connect_object (priv->assistant, - "start-recording", - G_CALLBACK (sysprof_display_start_recording_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->visualizers, - "notify::selection", - G_CALLBACK (sysprof_display_notify_selection_cb), - self, - G_CONNECT_SWAPPED); - - page = g_property_action_new ("page", priv->pages, "visible-child-name"); - g_action_map_add_action_entries (G_ACTION_MAP (group), - entries, - G_N_ELEMENTS (entries), - self); - gtk_widget_insert_action_group (GTK_WIDGET (self), "display", G_ACTION_GROUP (group)); -} - -void -sysprof_display_add_group (SysprofDisplay *self, - SysprofVisualizerGroup *group) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (group)); - - if (priv->reader != NULL) - _sysprof_visualizer_group_set_reader (group, priv->reader); - - sysprof_visualizers_frame_add_group (priv->visualizers, group); -} - -void -sysprof_display_add_page (SysprofDisplay *self, - SysprofPage *page) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - SysprofSelection *selection; - const gchar *title; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (SYSPROF_IS_PAGE (page)); - - title = sysprof_page_get_title (page); - gtk_stack_add_titled (priv->pages, GTK_WIDGET (page), NULL, title); - - selection = sysprof_visualizers_frame_get_selection (priv->visualizers); - - sysprof_page_set_size_group (page, - sysprof_visualizers_frame_get_size_group (priv->visualizers)); - - sysprof_page_set_hadjustment (page, - sysprof_visualizers_frame_get_hadjustment (priv->visualizers)); - - if (priv->reader != NULL) - sysprof_page_load_async (page, - priv->reader, - selection, - priv->filter, - NULL, NULL, NULL); -} - -SysprofPage * -sysprof_display_get_visible_page (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - GtkWidget *visible_page; - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL); - - visible_page = gtk_stack_get_visible_child (priv->pages); - - if (SYSPROF_IS_PAGE (visible_page)) - return SYSPROF_PAGE (visible_page); - - return NULL; -} - -void -sysprof_display_set_visible_page (SysprofDisplay *self, - SysprofPage *page) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (SYSPROF_IS_PAGE (page)); - - gtk_stack_set_visible_child (priv->pages, GTK_WIDGET (page)); -} - -static void -sysprof_display_present_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofAid *aid = (SysprofAid *)object; - g_autoptr(GTask) task = user_data; - g_autoptr(GError) error = NULL; - gatomicrefcount *n_active; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - if (!sysprof_aid_present_finish (aid, result, &error)) - { - if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED)) - g_warning ("Failed to present aid %s: %s", G_OBJECT_TYPE_NAME (aid), error->message); - } - - n_active = g_task_get_task_data (task); - - if (g_atomic_ref_count_dec (n_active)) - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_display_present_async (SysprofDisplay *self, - SysprofCaptureReader *reader, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_autoptr(GPtrArray) aids = NULL; - g_autoptr(GTask) task = NULL; - g_autofree gatomicrefcount *aids_len = NULL; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - aids = g_ptr_array_new_with_free_func (g_object_unref); - g_ptr_array_add (aids, sysprof_battery_aid_new ()); - g_ptr_array_add (aids, sysprof_counters_aid_new ()); - g_ptr_array_add (aids, sysprof_cpu_aid_new ()); - g_ptr_array_add (aids, sysprof_callgraph_aid_new ()); - g_ptr_array_add (aids, sysprof_diskstat_aid_new ()); - g_ptr_array_add (aids, sysprof_logs_aid_new ()); - g_ptr_array_add (aids, sysprof_marks_aid_new ()); - g_ptr_array_add (aids, sysprof_memory_aid_new ()); - g_ptr_array_add (aids, sysprof_memprof_aid_new ()); - g_ptr_array_add (aids, sysprof_netdev_aid_new ()); - g_ptr_array_add (aids, sysprof_rapl_aid_new ()); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_display_present_async); - - if (aids->len == 0) - { - g_task_return_boolean (task, TRUE); - return; - } - - aids_len = g_new (gatomicrefcount, 1); - g_atomic_ref_count_init(aids_len); - *aids_len = aids->len; - - g_task_set_task_data (task, g_steal_pointer (&aids_len), g_free); - - for (guint i = 0; i < aids->len; i++) - { - SysprofAid *aid = g_ptr_array_index (aids, i); - - sysprof_aid_present_async (aid, - reader, - self, - cancellable, - sysprof_display_present_cb, - g_object_ref (task)); - } -} - -static gboolean -sysprof_display_present_finish (SysprofDisplay *self, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_display_scan_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - SysprofDisplay *self = source_object; - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - SysprofCaptureReader *reader = task_data; - g_autoptr(GHashTable) mark_stats = NULL; - g_autoptr(GArray) marks = NULL; - SysprofCaptureFrame frame; - SysprofCaptureStat st = {{0}}; - SysprofCaptureFlags flags = 0; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (reader != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - /* Scan the reader until the end so that we know we have gotten - * all of the timing data loaded into the underlying reader. - */ - - mark_stats = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - marks = g_array_new (FALSE, FALSE, sizeof (SysprofMarkStat)); - - while (sysprof_capture_reader_peek_frame (reader, &frame)) - { - if (frame.type < G_N_ELEMENTS (st.frame_count)) - st.frame_count[frame.type]++; - - if (frame.type == SYSPROF_CAPTURE_FRAME_METADATA) - { - const SysprofCaptureMetadata *meta; - - if ((meta = sysprof_capture_reader_read_metadata (reader))) - { - if (g_strcmp0 (meta->id, "local-profiler") == 0) - flags |= SYSPROF_CAPTURE_FLAGS_CAN_REPLAY; - } - } - else if (frame.type == SYSPROF_CAPTURE_FRAME_MARK) - { - const SysprofCaptureMark *mark; - - if ((mark = sysprof_capture_reader_read_mark (reader))) - { - SysprofMarkStat *mstat; - gchar name[152]; - gpointer idx; - - g_snprintf (name, sizeof name, "%s:%s", mark->group, mark->name); - - if (!(idx = g_hash_table_lookup (mark_stats, name))) - { - SysprofMarkStat empty = {{0}}; - - g_strlcpy (empty.name, name, sizeof empty.name); - g_array_append_val (marks, empty); - idx = GUINT_TO_POINTER (marks->len); - g_hash_table_insert (mark_stats, g_strdup (name), idx); - } - - mstat = &g_array_index (marks, SysprofMarkStat, GPOINTER_TO_UINT (idx) - 1); - - if (mark->duration > 0) - { - if (mstat->min == 0 || mark->duration < mstat->min) - mstat->min = mark->duration; - } - - if (mark->duration > mstat->max) - mstat->max = mark->duration; - - if (mark->duration > 0) - { - mstat->avg += mark->duration; - mstat->avg_count++; - } - - mstat->count++; - } - } - else - { - sysprof_capture_reader_skip (reader); - } - } - - { - GHashTableIter iter; - gpointer k,v; - - g_hash_table_iter_init (&iter, mark_stats); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - guint idx = GPOINTER_TO_UINT (v) - 1; - SysprofMarkStat *mstat = &g_array_index (marks, SysprofMarkStat, idx); - - if (mstat->avg_count > 0 && mstat->avg > 0) - mstat->avg /= mstat->avg_count; - -#if 0 - g_print ("%s: count=%ld avg=%ld min=%ld max=%ld\n", - (gchar*)k, - ((SysprofMarkStat *)v)->count, - ((SysprofMarkStat *)v)->avg, - ((SysprofMarkStat *)v)->min, - ((SysprofMarkStat *)v)->max); -#endif - } - } - - g_object_set_data_full (G_OBJECT (task), - "MARK_STAT", - g_steal_pointer (&marks), - (GDestroyNotify) g_array_unref); - - g_atomic_int_set (&priv->flags, flags); - sysprof_capture_reader_reset (reader); - sysprof_capture_reader_set_stat (reader, &st); - - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_display_scan_async (SysprofDisplay *self, - SysprofCaptureReader *reader, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_autoptr(GTask) task = NULL; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_display_scan_async); - g_task_set_task_data (task, - sysprof_capture_reader_ref (reader), - (GDestroyNotify) sysprof_capture_reader_unref); - g_task_run_in_thread (task, sysprof_display_scan_worker); -} - -static gboolean -sysprof_display_scan_finish (SysprofDisplay *self, - GAsyncResult *result, - GError **error) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - GArray *marks; - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - if ((marks = g_object_get_data (G_OBJECT (result), "MARK_STAT"))) - sysprof_details_page_add_marks (priv->details, - (const SysprofMarkStat *)(gpointer)marks->data, - marks->len); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_REPLAY]); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_display_load_present_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofDisplay *self = (SysprofDisplay *)object; - g_autoptr(GError) error = NULL; - g_autoptr(GTask) task = user_data; - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - if (!sysprof_display_present_finish (self, result, &error)) - g_warning ("Error presenting: %s", error->message); - - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_display_load_frame_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofVisualizersFrame *frame = (SysprofVisualizersFrame *)object; - g_autoptr(GError) error = NULL; - g_autoptr(GTask) task = user_data; - SysprofCaptureReader *reader; - SysprofDisplay *self; - GCancellable *cancellable; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (frame)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - self = g_task_get_source_object (task); - reader = g_task_get_task_data (task); - cancellable = g_task_get_cancellable (task); - - if (!sysprof_visualizers_frame_load_finish (frame, result, &error)) - g_task_return_error (task, g_steal_pointer (&error)); - else - sysprof_display_present_async (self, - reader, - cancellable, - sysprof_display_load_present_cb, - g_steal_pointer (&task)); -} - -static void -sysprof_display_load_scan_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofDisplay *self = (SysprofDisplay *)object; - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - g_autoptr(GTask) task = user_data; - g_autoptr(GError) error = NULL; - SysprofCaptureReader *reader; - SysprofSelection *selection; - GCancellable *cancellable; - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - reader = g_task_get_task_data (task); - cancellable = g_task_get_cancellable (task); - - if (!sysprof_display_scan_finish (self, result, &error)) - g_task_return_error (task, g_steal_pointer (&error)); - else - sysprof_visualizers_frame_load_async (priv->visualizers, - reader, - cancellable, - sysprof_display_load_frame_cb, - g_steal_pointer (&task)); - - selection = sysprof_visualizers_frame_get_selection (priv->visualizers); - - sysprof_details_page_set_reader (priv->details, reader); - - /* Opportunistically load pages */ - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (priv->pages)); - child; - child = gtk_widget_get_next_sibling (child)) - { - if (SYSPROF_IS_PAGE (child)) - sysprof_page_load_async (SYSPROF_PAGE (child), - reader, - selection, - priv->filter, - NULL, NULL, NULL); - } - - gtk_stack_set_visible_child_name (priv->stack, "view"); -} - -void -sysprof_display_load_async (SysprofDisplay *self, - SysprofCaptureReader *reader, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - g_autoptr(GTask) task = NULL; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - if (priv->reader != reader) - { - g_clear_pointer (&priv->reader, sysprof_capture_reader_unref); - priv->reader = sysprof_capture_reader_ref (reader); - } - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_display_load_async); - g_task_set_task_data (task, - sysprof_capture_reader_ref (reader), - (GDestroyNotify) sysprof_capture_reader_unref); - - /* First scan the reader for any sort of data we care about before - * we notify aids to load content. That allows us to ensure we have - * proper timing data for the consumers. - */ - sysprof_display_scan_async (self, - reader, - cancellable, - sysprof_display_load_scan_cb, - g_steal_pointer (&task)); -} - -gboolean -sysprof_display_load_finish (SysprofDisplay *self, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -SysprofZoomManager * -sysprof_display_get_zoom_manager (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL); - - return sysprof_visualizers_frame_get_zoom_manager (priv->visualizers); -} - -/** - * sysprof_display_is_empty: - * - * Checks if any content is or will be loaded into @self. - * - * Returns: %TRUE if the tab is unperterbed. - * - * Since: 3.34 - */ -gboolean -sysprof_display_is_empty (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE); - - return priv->file == NULL && - priv->profiler == NULL && - gtk_stack_get_visible_child (priv->stack) == GTK_WIDGET (priv->assistant) && - NULL == priv->reader; -} - -void -sysprof_display_open (SysprofDisplay *self, - GFile *file) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - g_autoptr(SysprofCaptureReader) reader = NULL; - g_autoptr(GError) error = NULL; - g_autofree gchar *path = NULL; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (G_IS_FILE (file)); - g_return_if_fail (g_file_is_native (file)); - g_return_if_fail (sysprof_display_is_empty (self)); - - path = g_file_get_path (file); - - /* If the file is executable, just set the path to the binary - * in the profiler assistant. - */ - if (g_file_test (path, G_FILE_TEST_IS_EXECUTABLE)) - { - sysprof_profiler_assistant_set_executable (priv->assistant, path); - return; - } - - g_set_object (&priv->file, file); - - if (!(reader = sysprof_capture_reader_new_with_error (path, &error))) - { - GtkWidget *dialog; - GtkWidget *window; - - g_warning ("Failed to open capture: %s", error->message); - - window = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_WINDOW); - dialog = gtk_message_dialog_new (NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_WARNING, - GTK_BUTTONS_CLOSE, - "%s", - _("The recording could not be opened")); - gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), - "%s", - error->message); - g_signal_connect (dialog, - "response", - G_CALLBACK (gtk_window_destroy), - NULL); - gtk_window_set_modal (GTK_WINDOW (dialog), TRUE); - gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window)); - gtk_window_present (GTK_WINDOW (dialog)); - - _sysprof_display_destroy (self); - - return; - } - - /* Jump right to the "view" page to avoid a quick view of the - * assistants page when loading. - */ - if (g_strcmp0 ("assistant", gtk_stack_get_visible_child_name (priv->stack)) == 0) - gtk_stack_set_visible_child_name (priv->stack, "view"); - - sysprof_display_load_async (self, reader, NULL, NULL, NULL); - update_title_child_property (self); -} - -gboolean -sysprof_display_get_can_save (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE); - - return priv->reader != NULL; -} - -void -sysprof_display_stop_recording (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - - if (priv->profiler != NULL) - sysprof_profiler_stop (priv->profiler); -} - -void -_sysprof_display_focus_record (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - - _sysprof_profiler_assistant_focus_record (priv->assistant); -} - -gboolean -sysprof_display_get_can_replay (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), FALSE); - - return !sysprof_display_is_empty (self) && - priv->reader != NULL && - !!(priv->flags & SYSPROF_CAPTURE_FLAGS_CAN_REPLAY); -} - -/** - * sysprof_display_replay: - * @self: a #SysprofDisplay - * - * Gets a new display that will re-run the previous recording that is being - * viewed. This requires a capture file which contains enough information to - * replay the operation. - * - * Returns: (nullable) (transfer full): a #SysprofDisplay or %NULL - * - * Since: 3.34 - */ -SysprofDisplay * -sysprof_display_replay (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - g_autoptr(SysprofProfiler) profiler = NULL; - SysprofDisplay *copy; - - g_return_val_if_fail (SYSPROF_IS_DISPLAY (self), NULL); - g_return_val_if_fail (priv->reader != NULL, NULL); - - profiler = sysprof_local_profiler_new_replay (priv->reader); - g_return_val_if_fail (profiler != NULL, NULL); - g_return_val_if_fail (SYSPROF_IS_LOCAL_PROFILER (profiler), NULL); - - copy = g_object_new (SYSPROF_TYPE_DISPLAY, NULL); - sysprof_display_set_profiler (copy, profiler); - sysprof_profiler_start (profiler); - - return g_steal_pointer (©); -} - -GtkWidget * -sysprof_display_new_for_profiler (SysprofProfiler *profiler) -{ - SysprofDisplay *self; - - g_return_val_if_fail (SYSPROF_IS_PROFILER (profiler), NULL); - - self = g_object_new (SYSPROF_TYPE_DISPLAY, NULL); - sysprof_display_set_profiler (self, profiler); - - return GTK_WIDGET (g_steal_pointer (&self)); -} - -static void -on_save_response_cb (SysprofDisplay *self, - int res, - GtkFileChooserNative *chooser) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - g_autoptr(GFile) file = NULL; - - g_assert (SYSPROF_IS_DISPLAY (self)); - g_assert (GTK_IS_FILE_CHOOSER_NATIVE (chooser)); - - switch (res) - { - case GTK_RESPONSE_ACCEPT: - file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (chooser)); - - if (g_file_is_native (file)) - { - g_autofree gchar *path = g_file_get_path (file); - g_autoptr(GError) error = NULL; - - if (!sysprof_capture_reader_save_as_with_error (priv->reader, path, &error)) - { - GtkWidget *msg; - GtkNative *root; - - root = gtk_widget_get_native (GTK_WIDGET (self)); - msg = gtk_message_dialog_new (GTK_WINDOW (root), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_USE_HEADER_BAR, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _("Failed to save recording: %s"), - error->message); - gtk_window_present (GTK_WINDOW (msg)); - g_signal_connect (msg, "response", G_CALLBACK (gtk_window_destroy), NULL); - } - } - else - { - g_autofree char *uri = g_file_get_uri (file); - g_warning ("%s is not native, cannot open", uri); - } - - break; - - default: - break; - } - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); - gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (chooser)); -} - -void -sysprof_display_save (SysprofDisplay *self) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - GtkFileChooserNative *native; - GtkNative *root; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (priv->reader != NULL); - - root = gtk_widget_get_native (GTK_WIDGET (self)); - native = gtk_file_chooser_native_new (_("Save Recording"), - GTK_WINDOW (root), - GTK_FILE_CHOOSER_ACTION_SAVE, - _("Save"), - _("Cancel")); - gtk_file_chooser_set_create_folders (GTK_FILE_CHOOSER (native), TRUE); - gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (native), "capture.syscap"); - - g_signal_connect_object (native, - "response", - G_CALLBACK (on_save_response_cb), - self, - G_CONNECT_SWAPPED); - - gtk_native_dialog_show (GTK_NATIVE_DIALOG (native)); -} - -void -_sysprof_display_reload_page (SysprofDisplay *self, - SysprofPage *page) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - SysprofSelection *selection; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - g_return_if_fail (SYSPROF_IS_PAGE (page)); - g_return_if_fail (priv->reader != NULL); - - selection = sysprof_visualizers_frame_get_selection (priv->visualizers); - - sysprof_page_load_async (page, - priv->reader, - selection, - priv->filter, - NULL, NULL, NULL); -} - -void -sysprof_display_add_to_selection (SysprofDisplay *self, - gint64 begin_time, - gint64 end_time) -{ - SysprofDisplayPrivate *priv = sysprof_display_get_instance_private (self); - SysprofSelection *selection; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - - selection = sysprof_visualizers_frame_get_selection (priv->visualizers); - sysprof_selection_select_range (selection, begin_time, end_time); -} - -void -_sysprof_display_destroy (SysprofDisplay *self) -{ - GtkWidget *parent; - - g_return_if_fail (SYSPROF_IS_DISPLAY (self)); - - if ((parent = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_NOTEBOOK))) - gtk_notebook_remove_page (GTK_NOTEBOOK (parent), - gtk_notebook_page_num (GTK_NOTEBOOK (parent), GTK_WIDGET (self))); -} diff --git a/src/libsysprof-ui/sysprof-display.h b/src/libsysprof-ui/sysprof-display.h deleted file mode 100644 index 16cd9f55..00000000 --- a/src/libsysprof-ui/sysprof-display.h +++ /dev/null @@ -1,96 +0,0 @@ -/* sysprof-display.h - * - * Copyright 2019 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 -#include - -#include "sysprof-page.h" -#include "sysprof-visualizer-group.h" -#include "sysprof-zoom-manager.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_DISPLAY (sysprof_display_get_type()) - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofDisplay, sysprof_display, SYSPROF, DISPLAY, GtkWidget) - -struct _SysprofDisplayClass -{ - GtkWidgetClass parent_class; - - /*< private >*/ - gpointer _reserved[16]; -}; - -SYSPROF_AVAILABLE_IN_ALL -GtkWidget *sysprof_display_new (void); -SYSPROF_AVAILABLE_IN_ALL -GtkWidget *sysprof_display_new_for_profiler (SysprofProfiler *profiler); -SYSPROF_AVAILABLE_IN_ALL -char *sysprof_display_dup_title (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -SysprofProfiler *sysprof_display_get_profiler (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_add_group (SysprofDisplay *self, - SysprofVisualizerGroup *group); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_add_page (SysprofDisplay *self, - SysprofPage *page); -SYSPROF_AVAILABLE_IN_ALL -SysprofPage *sysprof_display_get_visible_page (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_set_visible_page (SysprofDisplay *self, - SysprofPage *page); -SYSPROF_AVAILABLE_IN_ALL -SysprofZoomManager *sysprof_display_get_zoom_manager (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_load_async (SysprofDisplay *self, - SysprofCaptureReader *reader, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_display_load_finish (SysprofDisplay *self, - GAsyncResult *result, - GError **error); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_display_is_empty (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_open (SysprofDisplay *self, - GFile *file); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_save (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_display_get_can_save (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_display_stop_recording (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_display_get_can_replay (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_ALL -SysprofDisplay *sysprof_display_replay (SysprofDisplay *self); -SYSPROF_AVAILABLE_IN_3_38 -void sysprof_display_add_to_selection (SysprofDisplay *self, - gint64 begin_time, - gint64 end_time); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-display.ui b/src/libsysprof-ui/sysprof-display.ui deleted file mode 100644 index 61fceb7a..00000000 --- a/src/libsysprof-ui/sysprof-display.ui +++ /dev/null @@ -1,71 +0,0 @@ - - - - - diff --git a/src/libsysprof-ui/sysprof-duplex-visualizer.c b/src/libsysprof-ui/sysprof-duplex-visualizer.c deleted file mode 100644 index e9289a62..00000000 --- a/src/libsysprof-ui/sysprof-duplex-visualizer.c +++ /dev/null @@ -1,633 +0,0 @@ -/* sysprof-duplex-visualizer.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-duplex-visualizer" - -#include "config.h" - -#include "pointcache.h" -#include "sysprof-duplex-visualizer.h" - -#define LABEL_HEIGHT_PX 10 - -struct _SysprofDuplexVisualizer -{ - SysprofVisualizer parent_instance; - - gint64 begin_time; - gint64 duration; - - guint rx_counter; - guint tx_counter; - - GdkRGBA rx_rgba; - GdkRGBA tx_rgba; - - gchar *rx_label; - gchar *tx_label; - - PointCache *cache; - - guint rx_rgba_set : 1; - guint tx_rgba_set : 1; - guint use_diff : 1; -}; - -typedef struct -{ - PointCache *cache; - - gint64 begin_time; - gint64 duration; - - gint64 max_change; - - /* Last value to convert to rate of change */ - gint64 last_rx_val; - gint64 last_tx_val; - - /* Counter IDs */ - guint rx; - guint tx; - - /* Do we need to subtract previous value */ - guint use_diff : 1; -} Collect; - -G_DEFINE_TYPE (SysprofDuplexVisualizer, sysprof_duplex_visualizer, SYSPROF_TYPE_VISUALIZER) - -static bool -collect_ranges_cb (const SysprofCaptureFrame *frame, - gpointer data) -{ - Collect *state = data; - - g_assert (frame != NULL); - g_assert (state != NULL); - g_assert (state->cache != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET) - { - const SysprofCaptureCounterSet *set = (gconstpointer)frame; - - for (guint i = 0; i < set->n_values; i++) - { - const SysprofCaptureCounterValues *values = &set->values[i]; - - for (guint j = 0; j < G_N_ELEMENTS (values->ids); j++) - { - gint64 v64 = values->values[j].v64; - guint id = values->ids[j]; - gint64 max_change = 0; - - if (id == 0) - break; - - if (id == state->rx) - { - if (state->last_rx_val != G_MININT64) - max_change = v64 - state->last_rx_val; - state->last_rx_val = v64; - } - else if (id == state->tx) - { - if (state->last_tx_val != G_MININT64) - max_change = v64 - state->last_tx_val; - state->last_tx_val = v64; - } - else - { - continue; - } - - if (max_change > state->max_change) - state->max_change = max_change; - } - } - } - - return TRUE; -} - -static bool -collect_values_cb (const SysprofCaptureFrame *frame, - gpointer data) -{ - Collect *state = data; - - g_assert (frame != NULL); - g_assert (state != NULL); - g_assert (state->cache != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET) - { - const SysprofCaptureCounterSet *set = (gconstpointer)frame; - gdouble x = (frame->time - state->begin_time) / (gdouble)state->duration; - - for (guint i = 0; i < set->n_values; i++) - { - const SysprofCaptureCounterValues *values = &set->values[i]; - - for (guint j = 0; j < G_N_ELEMENTS (values->ids); j++) - { - gint64 v64 = values->values[j].v64; - guint id = values->ids[j]; - gint64 val = v64; - gdouble y = 0.5; - - if (id == 0) - break; - - if (id == state->rx) - { - if (state->use_diff) - { - if (state->last_rx_val == G_MININT64) - val = 0; - else - val -= state->last_rx_val; - } - - /* RX goes upward from half point */ - if (state->max_change != 0) - y += (gdouble)val / (gdouble)state->max_change / 2.0; - - state->last_rx_val = v64; - } - else if (id == state->tx) - { - if (state->use_diff) - { - if (state->last_tx_val == G_MININT64) - val = 0; - else - val -= state->last_tx_val; - } - - /* TX goes downward from half point */ - if (state->max_change != 0) - y -= (gdouble)val / (gdouble)state->max_change / 2.0; - - state->last_tx_val = v64; - } - else - { - continue; - } - - point_cache_add_point_to_set (state->cache, id, x, y); - } - } - } - - return TRUE; -} - -static void -sysprof_duplex_visualizer_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - SysprofCaptureCursor *cursor = task_data; - SysprofDuplexVisualizer *self = source_object; - Collect state = {0}; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - g_assert (cursor != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - state.cache = point_cache_new (); - state.begin_time = self->begin_time; - state.duration = self->duration; - state.rx = g_atomic_int_get (&self->rx_counter); - state.tx = g_atomic_int_get (&self->tx_counter); - state.last_rx_val = G_MININT64; - state.last_tx_val = G_MININT64; - state.max_change = 0; - state.use_diff = self->use_diff; - - point_cache_add_set (state.cache, state.rx); - point_cache_add_set (state.cache, state.tx); - - sysprof_capture_cursor_foreach (cursor, collect_ranges_cb, &state); - sysprof_capture_cursor_reset (cursor); - - /* Give just a bit of overhead */ - state.max_change *= 1.1; - - /* Reset for calculations */ - state.last_rx_val = G_MININT64; - state.last_tx_val = G_MININT64; - - sysprof_capture_cursor_foreach (cursor, collect_values_cb, &state); - - g_task_return_pointer (task, - g_steal_pointer (&state.cache), - (GDestroyNotify) point_cache_unref); -} - -static void -load_data_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofDuplexVisualizer *self = (SysprofDuplexVisualizer *)object; - g_autoptr(PointCache) pc = NULL; - - g_assert (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - g_assert (G_IS_TASK (result)); - - if ((pc = g_task_propagate_pointer (G_TASK (result), NULL))) - { - g_clear_pointer (&self->cache, point_cache_unref); - self->cache = g_steal_pointer (&pc); - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -sysprof_duplex_visualizer_set_reader (SysprofVisualizer *visualizer, - SysprofCaptureReader *reader) -{ - SysprofDuplexVisualizer *self = (SysprofDuplexVisualizer *)visualizer; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - SysprofCaptureCondition *c; - guint counters[2]; - - g_assert (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - g_assert (reader != NULL); - - self->begin_time = sysprof_capture_reader_get_start_time (reader); - self->duration = sysprof_capture_reader_get_end_time (reader) - - sysprof_capture_reader_get_start_time (reader); - - counters[0] = self->rx_counter; - counters[1] = self->tx_counter; - - cursor = sysprof_capture_cursor_new (reader); - c = sysprof_capture_condition_new_where_counter_in (G_N_ELEMENTS (counters), counters); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&c)); - - task = g_task_new (self, NULL, load_data_cb, NULL); - g_task_set_source_tag (task, sysprof_duplex_visualizer_set_reader); - g_task_set_task_data (task, - g_steal_pointer (&cursor), - (GDestroyNotify)sysprof_capture_cursor_unref); - g_task_run_in_thread (task, sysprof_duplex_visualizer_worker); -} - -static void -sysprof_duplex_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - static const gdouble dashes[] = { 1.0, 2.0 }; - SysprofDuplexVisualizer *self = (SysprofDuplexVisualizer *)widget; - PangoFontDescription *font_desc; - GtkStyleContext *style_context; - PangoLayout *layout; - cairo_t *cr; - GtkAllocation alloc; - GdkRGBA fg; - guint mid; - - g_assert (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - g_assert (snapshot != NULL); - - /* FIXME: This should all be drawn offscreen and then drawn to the snapshot - * using GdkMemoryTexture so that we can avoid extra GPU uploads. - */ - - gtk_widget_get_allocation (widget, &alloc); - - mid = alloc.height / 2; - - GTK_WIDGET_CLASS (sysprof_duplex_visualizer_parent_class)->snapshot (widget, snapshot); - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height)); - - style_context = gtk_widget_get_style_context (widget); - gtk_style_context_get_color (style_context, &fg); - fg.alpha *= 0.4; - - /* Draw our center line */ - cairo_save (cr); - cairo_set_line_width (cr, 1.0); - cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0); - cairo_move_to (cr, 0, mid); - cairo_line_to (cr, alloc.width, mid); - gdk_cairo_set_source_rgba (cr, &fg); - cairo_stroke (cr); - cairo_restore (cr); - - if (self->cache != NULL) - { - g_autofree SysprofVisualizerAbsolutePoint *points = NULL; - const Point *fpoints; - guint n_fpoints = 0; - - cairo_save (cr); - cairo_set_line_width (cr, 1.0); - if (self->rx_rgba_set) - gdk_cairo_set_source_rgba (cr, &self->rx_rgba); - - fpoints = point_cache_get_points (self->cache, self->rx_counter, &n_fpoints); - - if (n_fpoints > 0) - { - GdkRGBA rgba = self->rx_rgba; - gdouble last_x; - gdouble last_y; - guint p; - - points = g_realloc_n (points, n_fpoints, sizeof *points); - - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self), - (const SysprofVisualizerRelativePoint *)fpoints, - n_fpoints, - points, - n_fpoints); - - /* Skip past data that we won't see anyway */ -#if 0 - for (p = 0; p < n_fpoints; p++) - { - if (points[p].x >= clip.x) - break; - } - - if (p >= n_fpoints) - return; -#endif - - /* But get at least one data point to anchor out of view */ - if (p > 0) - p--; - - last_x = points[p].x; - last_y = points[p].y; - - cairo_move_to (cr, last_x, mid); - cairo_line_to (cr, last_x, last_y); - - for (guint i = p + 1; i < n_fpoints; i++) - { - cairo_curve_to (cr, - last_x + ((points[i].x - last_x) / 2), - last_y, - last_x + ((points[i].x - last_x) / 2), - points[i].y, - points[i].x, - points[i].y); - - last_x = points[i].x; - last_y = points[i].y; - -#if 0 - if (points[i].x > clip.x + clip.width) - break; -#endif - } - - cairo_line_to (cr, last_x, mid); - cairo_close_path (cr); - cairo_stroke_preserve (cr); - rgba.alpha *= 0.5; - gdk_cairo_set_source_rgba (cr, &rgba); - cairo_fill (cr); - } - - cairo_restore (cr); - - /* AND NOW Tx */ - - cairo_save (cr); - cairo_set_line_width (cr, 1.0); - if (self->tx_rgba_set) - gdk_cairo_set_source_rgba (cr, &self->tx_rgba); - - fpoints = point_cache_get_points (self->cache, self->tx_counter, &n_fpoints); - - if (n_fpoints > 0) - { - GdkRGBA rgba = self->tx_rgba; - gdouble last_x; - gdouble last_y; - guint p; - - points = g_realloc_n (points, n_fpoints, sizeof *points); - - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self), - (const SysprofVisualizerRelativePoint *)fpoints, - n_fpoints, - points, - n_fpoints); - -#if 0 - /* Skip past data that we won't see anyway */ - for (p = 0; p < n_fpoints; p++) - { - if (points[p].x >= clip.x) - break; - } - - if (p >= n_fpoints) - return ret; -#endif - - /* But get at least one data point to anchor out of view */ - if (p > 0) - p--; - - last_x = points[p].x; - last_y = points[p].y; - - cairo_move_to (cr, last_x, mid); - cairo_line_to (cr, last_x, last_y); - - for (guint i = p + 1; i < n_fpoints; i++) - { - cairo_curve_to (cr, - last_x + ((points[i].x - last_x) / 2), - last_y, - last_x + ((points[i].x - last_x) / 2), - points[i].y, - points[i].x, - points[i].y); - - last_x = points[i].x; - last_y = points[i].y; - -#if 0 - if (points[i].x > clip.x + clip.width) - break; -#endif - } - - cairo_line_to (cr, last_x, mid); - cairo_close_path (cr); - cairo_stroke_preserve (cr); - rgba.alpha *= 0.5; - gdk_cairo_set_source_rgba (cr, &rgba); - cairo_fill (cr); - } - - cairo_restore (cr); - } - - layout = gtk_widget_create_pango_layout (widget, ""); - - font_desc = pango_font_description_new (); - pango_font_description_set_family_static (font_desc, "Monospace"); - pango_font_description_set_absolute_size (font_desc, LABEL_HEIGHT_PX * PANGO_SCALE); - pango_layout_set_font_description (layout, font_desc); - - gdk_cairo_set_source_rgba (cr, &fg); - - cairo_move_to (cr, 2, 2); - if (self->rx_label != NULL) - pango_layout_set_text (layout, self->rx_label, -1); - else - pango_layout_set_text (layout, "RX", 2); - pango_cairo_show_layout (cr, layout); - - cairo_move_to (cr, 2, mid + 2); - if (self->tx_label != NULL) - pango_layout_set_text (layout, self->tx_label, -1); - else - pango_layout_set_text (layout, "TX", 2); - pango_cairo_show_layout (cr, layout); - - pango_font_description_free (font_desc); - g_object_unref (layout); - - cairo_destroy (cr); -} - -static void -sysprof_duplex_visualizer_finalize (GObject *object) -{ - SysprofDuplexVisualizer *self = (SysprofDuplexVisualizer *)object; - - g_clear_pointer (&self->cache, point_cache_unref); - g_clear_pointer (&self->rx_label, g_free); - g_clear_pointer (&self->tx_label, g_free); - - G_OBJECT_CLASS (sysprof_duplex_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_duplex_visualizer_class_init (SysprofDuplexVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofVisualizerClass *visualizer_class = SYSPROF_VISUALIZER_CLASS (klass); - - object_class->finalize = sysprof_duplex_visualizer_finalize; - - widget_class->snapshot = sysprof_duplex_visualizer_snapshot; - - visualizer_class->set_reader = sysprof_duplex_visualizer_set_reader; -} - -static void -sysprof_duplex_visualizer_init (SysprofDuplexVisualizer *self) -{ - self->use_diff = TRUE; -} - -GtkWidget * -sysprof_duplex_visualizer_new (void) -{ - return g_object_new (SYSPROF_TYPE_DUPLEX_VISUALIZER, NULL); -} - -void -sysprof_duplex_visualizer_set_counters (SysprofDuplexVisualizer *self, - guint rx_counter, - guint tx_counter) -{ - g_return_if_fail (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - g_return_if_fail (rx_counter != 0); - g_return_if_fail (tx_counter != 0); - - self->rx_counter = rx_counter; - self->tx_counter = tx_counter; -} - -void -sysprof_duplex_visualizer_set_colors (SysprofDuplexVisualizer *self, - const GdkRGBA *rx_rgba, - const GdkRGBA *tx_rgba) -{ - g_return_if_fail (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - - if (rx_rgba) - self->rx_rgba = *rx_rgba; - self->rx_rgba_set = !!rx_rgba; - - if (tx_rgba) - self->tx_rgba = *tx_rgba; - self->tx_rgba_set = !!tx_rgba; - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -gboolean -sysprof_duplex_visualizer_get_use_diff (SysprofDuplexVisualizer *self) -{ - g_return_val_if_fail (SYSPROF_IS_DUPLEX_VISUALIZER (self), FALSE); - - return self->use_diff; -} - -void -sysprof_duplex_visualizer_set_use_diff (SysprofDuplexVisualizer *self, - gboolean use_diff) -{ - g_return_if_fail (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - - self->use_diff = !!use_diff; - gtk_widget_queue_allocate (GTK_WIDGET (self)); -} - -void -sysprof_duplex_visualizer_set_labels (SysprofDuplexVisualizer *self, - const gchar *rx_label, - const gchar *tx_label) -{ - g_return_if_fail (SYSPROF_IS_DUPLEX_VISUALIZER (self)); - - if (g_strcmp0 (rx_label, self->rx_label) != 0) - { - g_free (self->rx_label); - self->rx_label = g_strdup (rx_label); - } - - if (g_strcmp0 (tx_label, self->tx_label) != 0) - { - g_free (self->tx_label); - self->tx_label = g_strdup (tx_label); - } - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} diff --git a/src/libsysprof-ui/sysprof-duplex-visualizer.h b/src/libsysprof-ui/sysprof-duplex-visualizer.h deleted file mode 100644 index 0b7dec53..00000000 --- a/src/libsysprof-ui/sysprof-duplex-visualizer.h +++ /dev/null @@ -1,45 +0,0 @@ -/* sysprof-duplex-visualizer.h - * - * Copyright 2019 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-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_DUPLEX_VISUALIZER (sysprof_duplex_visualizer_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofDuplexVisualizer, sysprof_duplex_visualizer, SYSPROF, DUPLEX_VISUALIZER, SysprofVisualizer) - -GtkWidget *sysprof_duplex_visualizer_new (void); -gboolean sysprof_duplex_visualizer_get_use_diff (SysprofDuplexVisualizer *self); -void sysprof_duplex_visualizer_set_use_diff (SysprofDuplexVisualizer *self, - gboolean use_diff); -void sysprof_duplex_visualizer_set_labels (SysprofDuplexVisualizer *self, - const gchar *rx_label, - const gchar *tx_label); -void sysprof_duplex_visualizer_set_counters (SysprofDuplexVisualizer *self, - guint rx_counter, - guint tx_counter); -void sysprof_duplex_visualizer_set_colors (SysprofDuplexVisualizer *self, - const GdkRGBA *rx_rgba, - const GdkRGBA *tx_rgba); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-environ-editor-row.c b/src/libsysprof-ui/sysprof-environ-editor-row.c deleted file mode 100644 index a7dd7b0c..00000000 --- a/src/libsysprof-ui/sysprof-environ-editor-row.c +++ /dev/null @@ -1,277 +0,0 @@ -/* sysprof-environ-editor-row.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-environ-editor-row" - -#include "config.h" - -#include "sysprof-environ-editor-row.h" - -struct _SysprofEnvironEditorRow -{ - GtkListBoxRow parent_instance; - - SysprofEnvironVariable *variable; - - GtkEntry *key_entry; - GtkEntry *value_entry; - GtkButton *delete_button; - - GBinding *key_binding; - GBinding *value_binding; -}; - -enum { - PROP_0, - PROP_VARIABLE, - LAST_PROP -}; - -enum { - DELETE, - LAST_SIGNAL -}; - -G_DEFINE_TYPE (SysprofEnvironEditorRow, sysprof_environ_editor_row, GTK_TYPE_LIST_BOX_ROW) - -static GParamSpec *properties [LAST_PROP]; -static guint signals [LAST_SIGNAL]; - -static gboolean -null_safe_mapping (GBinding *binding, - const GValue *from_value, - GValue *to_value, - gpointer user_data) -{ - const gchar *str = g_value_get_string (from_value); - g_value_set_string (to_value, str ?: ""); - return TRUE; -} - -static void -sysprof_environ_editor_row_connect (SysprofEnvironEditorRow *self) -{ - g_assert (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - g_assert (SYSPROF_IS_ENVIRON_VARIABLE (self->variable)); - - self->key_binding = - g_object_bind_property_full (self->variable, "key", self->key_entry, "text", - G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL, - null_safe_mapping, NULL, NULL, NULL); - - self->value_binding = - g_object_bind_property_full (self->variable, "value", self->value_entry, "text", - G_BINDING_SYNC_CREATE | G_BINDING_BIDIRECTIONAL, - null_safe_mapping, NULL, NULL, NULL); -} - -static void -sysprof_environ_editor_row_disconnect (SysprofEnvironEditorRow *self) -{ - g_assert (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - g_assert (SYSPROF_IS_ENVIRON_VARIABLE (self->variable)); - - g_clear_pointer (&self->key_binding, g_binding_unbind); - g_clear_pointer (&self->value_binding, g_binding_unbind); -} - -static void -delete_button_clicked (GtkButton *button, - SysprofEnvironEditorRow *self) -{ - g_assert (GTK_IS_BUTTON (button)); - g_assert (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - - g_signal_emit (self, signals [DELETE], 0); -} - -static void -key_entry_activate (GtkWidget *entry, - SysprofEnvironEditorRow *self) -{ - g_assert (GTK_IS_ENTRY (entry)); - g_assert (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - - gtk_widget_grab_focus (GTK_WIDGET (self->value_entry)); -} - -static void -value_entry_activate (GtkWidget *entry, - SysprofEnvironEditorRow *self) -{ - GtkWidget *parent; - - g_assert (GTK_IS_ENTRY (entry)); - g_assert (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - - gtk_widget_grab_focus (GTK_WIDGET (self)); - parent = gtk_widget_get_ancestor (GTK_WIDGET (self), GTK_TYPE_LIST_BOX); - g_signal_emit_by_name (parent, "move-cursor", GTK_MOVEMENT_DISPLAY_LINES, 1); -} - -static void -sysprof_environ_editor_row_dispose (GObject *object) -{ - SysprofEnvironEditorRow *self = (SysprofEnvironEditorRow *)object; - - if (self->variable != NULL) - { - sysprof_environ_editor_row_disconnect (self); - g_clear_object (&self->variable); - } - - G_OBJECT_CLASS (sysprof_environ_editor_row_parent_class)->dispose (object); -} - -static void -sysprof_environ_editor_row_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofEnvironEditorRow *self = SYSPROF_ENVIRON_EDITOR_ROW (object); - - switch (prop_id) - { - case PROP_VARIABLE: - g_value_set_object (value, sysprof_environ_editor_row_get_variable (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_environ_editor_row_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofEnvironEditorRow *self = SYSPROF_ENVIRON_EDITOR_ROW (object); - - switch (prop_id) - { - case PROP_VARIABLE: - sysprof_environ_editor_row_set_variable (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_environ_editor_row_class_init (SysprofEnvironEditorRowClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_environ_editor_row_dispose; - object_class->get_property = sysprof_environ_editor_row_get_property; - object_class->set_property = sysprof_environ_editor_row_set_property; - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-environ-editor-row.ui"); - gtk_widget_class_bind_template_child (widget_class, SysprofEnvironEditorRow, delete_button); - gtk_widget_class_bind_template_child (widget_class, SysprofEnvironEditorRow, key_entry); - gtk_widget_class_bind_template_child (widget_class, SysprofEnvironEditorRow, value_entry); - - properties [PROP_VARIABLE] = - g_param_spec_object ("variable", - "Variable", - "Variable", - SYSPROF_TYPE_ENVIRON_VARIABLE, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, LAST_PROP, properties); - - signals [DELETE] = - g_signal_new ("delete", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, NULL, G_TYPE_NONE, 0); -} - -static void -sysprof_environ_editor_row_init (SysprofEnvironEditorRow *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); - - g_signal_connect (self->delete_button, - "clicked", - G_CALLBACK (delete_button_clicked), - self); - - g_signal_connect (self->key_entry, - "activate", - G_CALLBACK (key_entry_activate), - self); - - g_signal_connect (self->value_entry, - "activate", - G_CALLBACK (value_entry_activate), - self); -} - -/** - * sysprof_environ_editor_row_get_variable: - * - * Returns: (transfer none) (nullable): An #SysprofEnvironVariable. - */ -SysprofEnvironVariable * -sysprof_environ_editor_row_get_variable (SysprofEnvironEditorRow *self) -{ - g_return_val_if_fail (SYSPROF_IS_ENVIRON_EDITOR_ROW (self), NULL); - - return self->variable; -} - -void -sysprof_environ_editor_row_set_variable (SysprofEnvironEditorRow *self, - SysprofEnvironVariable *variable) -{ - g_return_if_fail (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - g_return_if_fail (!variable || SYSPROF_IS_ENVIRON_VARIABLE (variable)); - - if (variable != self->variable) - { - if (self->variable != NULL) - { - sysprof_environ_editor_row_disconnect (self); - g_clear_object (&self->variable); - } - - if (variable != NULL) - { - self->variable = g_object_ref (variable); - sysprof_environ_editor_row_connect (self); - } - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_VARIABLE]); - } -} - -void -sysprof_environ_editor_row_start_editing (SysprofEnvironEditorRow *self) -{ - g_return_if_fail (SYSPROF_IS_ENVIRON_EDITOR_ROW (self)); - - gtk_widget_grab_focus (GTK_WIDGET (self->key_entry)); -} diff --git a/src/libsysprof-ui/sysprof-environ-editor-row.h b/src/libsysprof-ui/sysprof-environ-editor-row.h deleted file mode 100644 index 39437e5a..00000000 --- a/src/libsysprof-ui/sysprof-environ-editor-row.h +++ /dev/null @@ -1,38 +0,0 @@ -/* ide-environ-editor-row.h - * - * Copyright 2016-2019 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 - -#include "sysprof-environ-variable.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_ENVIRON_EDITOR_ROW (sysprof_environ_editor_row_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofEnvironEditorRow, sysprof_environ_editor_row, SYSPROF, ENVIRON_EDITOR_ROW, GtkListBoxRow) - -SysprofEnvironVariable *sysprof_environ_editor_row_get_variable (SysprofEnvironEditorRow *self); -void sysprof_environ_editor_row_set_variable (SysprofEnvironEditorRow *self, - SysprofEnvironVariable *variable); -void sysprof_environ_editor_row_start_editing (SysprofEnvironEditorRow *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-environ-editor-row.ui b/src/libsysprof-ui/sysprof-environ-editor-row.ui deleted file mode 100644 index 8735f770..00000000 --- a/src/libsysprof-ui/sysprof-environ-editor-row.ui +++ /dev/null @@ -1,40 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-environ-editor.c b/src/libsysprof-ui/sysprof-environ-editor.c deleted file mode 100644 index 7c641aca..00000000 --- a/src/libsysprof-ui/sysprof-environ-editor.c +++ /dev/null @@ -1,343 +0,0 @@ -/* sysprof-environ-editor.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-environ-editor" - -#include "config.h" - -#include - -#include "sysprof-environ-editor.h" -#include "sysprof-environ-editor-row.h" -#include "sysprof-theme-manager.h" - -struct _SysprofEnvironEditor -{ - GtkWidget parent_instance; - GtkListBox *list_box; - SysprofEnviron *environ; - GtkWidget *dummy_row; - SysprofEnvironVariable *dummy; -}; - -G_DEFINE_TYPE (SysprofEnvironEditor, sysprof_environ_editor, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_ENVIRON, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_environ_editor_delete_row (SysprofEnvironEditor *self, - SysprofEnvironEditorRow *row) -{ - SysprofEnvironVariable *variable; - - g_assert (SYSPROF_IS_ENVIRON_EDITOR (self)); - g_assert (SYSPROF_IS_ENVIRON_EDITOR_ROW (row)); - - variable = sysprof_environ_editor_row_get_variable (row); - sysprof_environ_remove (self->environ, variable); -} - -static GtkWidget * -sysprof_environ_editor_create_dummy_row (SysprofEnvironEditor *self) -{ - GtkWidget *row; - GtkWidget *label; - - g_assert (SYSPROF_IS_ENVIRON_EDITOR (self)); - - label = g_object_new (GTK_TYPE_LABEL, - "label", _("New environment variable…"), - "margin-start", 6, - "margin-end", 6, - "margin-top", 6, - "margin-bottom", 6, - "visible", TRUE, - "xalign", 0.0f, - NULL); - gtk_style_context_add_class (gtk_widget_get_style_context (label), "dim-label"); - - row = g_object_new (GTK_TYPE_LIST_BOX_ROW, - "child", label, - "visible", TRUE, - NULL); - - return row; -} - -static GtkWidget * -sysprof_environ_editor_create_row (gpointer item, - gpointer user_data) -{ - SysprofEnvironVariable *variable = item; - SysprofEnvironEditor *self = user_data; - SysprofEnvironEditorRow *row; - - g_assert (SYSPROF_IS_ENVIRON_EDITOR (self)); - g_assert (SYSPROF_IS_ENVIRON_VARIABLE (variable)); - - row = g_object_new (SYSPROF_TYPE_ENVIRON_EDITOR_ROW, - "variable", variable, - "visible", TRUE, - NULL); - - g_signal_connect_object (row, - "delete", - G_CALLBACK (sysprof_environ_editor_delete_row), - self, - G_CONNECT_SWAPPED); - - return GTK_WIDGET (row); -} - -static void -sysprof_environ_editor_disconnect (SysprofEnvironEditor *self) -{ - g_assert (SYSPROF_IS_ENVIRON_EDITOR (self)); - g_assert (SYSPROF_IS_ENVIRON (self->environ)); - - gtk_list_box_bind_model (self->list_box, NULL, NULL, NULL, NULL); - g_clear_object (&self->dummy); -} - -static void -sysprof_environ_editor_connect (SysprofEnvironEditor *self) -{ - g_assert (SYSPROF_IS_ENVIRON_EDITOR (self)); - g_assert (SYSPROF_IS_ENVIRON (self->environ)); - - gtk_list_box_bind_model (self->list_box, - G_LIST_MODEL (self->environ), - sysprof_environ_editor_create_row, self, NULL); - - self->dummy_row = sysprof_environ_editor_create_dummy_row (self); - gtk_list_box_append (self->list_box, self->dummy_row); -} - -static void -find_row_cb (GtkWidget *widget, - gpointer data) -{ - struct { - SysprofEnvironVariable *variable; - SysprofEnvironEditorRow *row; - } *lookup = data; - - g_assert (lookup != NULL); - g_assert (GTK_IS_LIST_BOX_ROW (widget)); - - if (SYSPROF_IS_ENVIRON_EDITOR_ROW (widget)) - { - SysprofEnvironVariable *variable; - - variable = sysprof_environ_editor_row_get_variable (SYSPROF_ENVIRON_EDITOR_ROW (widget)); - - if (variable == lookup->variable) - lookup->row = SYSPROF_ENVIRON_EDITOR_ROW (widget); - } -} - -static SysprofEnvironEditorRow * -find_row (SysprofEnvironEditor *self, - SysprofEnvironVariable *variable) -{ - struct { - SysprofEnvironVariable *variable; - SysprofEnvironEditorRow *row; - } lookup = { variable, NULL }; - - g_assert (SYSPROF_IS_ENVIRON_EDITOR (self)); - g_assert (SYSPROF_IS_ENVIRON_VARIABLE (variable)); - - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->list_box)); - child; - child = gtk_widget_get_next_sibling (child)) - find_row_cb (child, &lookup); - - return lookup.row; -} - -static void -sysprof_environ_editor_row_activated (SysprofEnvironEditor *self, - GtkListBoxRow *row, - GtkListBox *list_box) -{ - g_assert (GTK_IS_LIST_BOX (list_box)); - g_assert (GTK_IS_LIST_BOX_ROW (row)); - - if (self->environ == NULL) - return; - - if (self->dummy_row == GTK_WIDGET (row)) - { - g_autoptr(SysprofEnvironVariable) variable = NULL; - - variable = sysprof_environ_variable_new (NULL, NULL); - sysprof_environ_append (self->environ, variable); - sysprof_environ_editor_row_start_editing (find_row (self, variable)); - } -} - -static void -sysprof_environ_editor_dispose (GObject *object) -{ - SysprofEnvironEditor *self = (SysprofEnvironEditor *)object; - - if (self->list_box) - { - gtk_widget_unparent (GTK_WIDGET (self->list_box)); - self->list_box = NULL; - } - - g_clear_object (&self->environ); - - G_OBJECT_CLASS (sysprof_environ_editor_parent_class)->dispose (object); -} - -static void -sysprof_environ_editor_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofEnvironEditor *self = SYSPROF_ENVIRON_EDITOR (object); - - switch (prop_id) - { - case PROP_ENVIRON: - g_value_set_object (value, sysprof_environ_editor_get_environ (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - -static void -sysprof_environ_editor_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofEnvironEditor *self = SYSPROF_ENVIRON_EDITOR (object); - - switch (prop_id) - { - case PROP_ENVIRON: - sysprof_environ_editor_set_environ (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - -static void -sysprof_environ_editor_class_init (SysprofEnvironEditorClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofThemeManager *theme_manager = sysprof_theme_manager_get_default (); - - object_class->dispose = sysprof_environ_editor_dispose; - object_class->get_property = sysprof_environ_editor_get_property; - object_class->set_property = sysprof_environ_editor_set_property; - - properties [PROP_ENVIRON] = - g_param_spec_object ("environ", - "Environment", - "Environment", - SYSPROF_TYPE_ENVIRON, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - - sysprof_theme_manager_register_resource (theme_manager, NULL, NULL, "/org/gnome/sysprof/css/SysprofEnvironEditor-shared.css"); -} - -static void -sysprof_environ_editor_init (SysprofEnvironEditor *self) -{ - self->list_box = GTK_LIST_BOX (gtk_list_box_new ()); - gtk_widget_set_parent (GTK_WIDGET (self->list_box), GTK_WIDGET (self)); - - gtk_list_box_set_selection_mode (self->list_box, GTK_SELECTION_NONE); - - gtk_widget_add_css_class (GTK_WIDGET (self), "environ-editor"); - - g_signal_connect_object (self->list_box, - "row-activated", - G_CALLBACK (sysprof_environ_editor_row_activated), - self, - G_CONNECT_SWAPPED); -} - -GtkWidget * -sysprof_environ_editor_new (void) -{ - return g_object_new (SYSPROF_TYPE_ENVIRON_EDITOR, NULL); -} - -void -sysprof_environ_editor_set_environ (SysprofEnvironEditor *self, - SysprofEnviron *environ_) -{ - g_return_if_fail (SYSPROF_IS_ENVIRON_EDITOR (self)); - g_return_if_fail (SYSPROF_IS_ENVIRON (environ_)); - - if (self->environ != environ_) - { - if (self->environ != NULL) - { - sysprof_environ_editor_disconnect (self); - g_clear_object (&self->environ); - } - - if (environ_ != NULL) - { - self->environ = g_object_ref (environ_); - sysprof_environ_editor_connect (self); - } - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ENVIRON]); - } -} - -/** - * sysprof_environ_editor_get_environ: - * - * Returns: (nullable) (transfer none): An #SysprofEnviron or %NULL. - * - * Since: 3.34 - */ -SysprofEnviron * -sysprof_environ_editor_get_environ (SysprofEnvironEditor *self) -{ - g_return_val_if_fail (SYSPROF_IS_ENVIRON_EDITOR (self), NULL); - - return self->environ; -} diff --git a/src/libsysprof-ui/sysprof-environ-editor.h b/src/libsysprof-ui/sysprof-environ-editor.h deleted file mode 100644 index 403ab797..00000000 --- a/src/libsysprof-ui/sysprof-environ-editor.h +++ /dev/null @@ -1,38 +0,0 @@ -/* sysprof-environ-editor.h - * - * Copyright 2016-2019 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 - -#include "sysprof-environ.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_ENVIRON_EDITOR (sysprof_environ_editor_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofEnvironEditor, sysprof_environ_editor, SYSPROF, ENVIRON_EDITOR, GtkWidget) - -GtkWidget *sysprof_environ_editor_new (void); -SysprofEnviron *sysprof_environ_editor_get_environ (SysprofEnvironEditor *self); -void sysprof_environ_editor_set_environ (SysprofEnvironEditor *self, - SysprofEnviron *environ); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-environ-variable.c b/src/libsysprof-ui/sysprof-environ-variable.c deleted file mode 100644 index 660b3457..00000000 --- a/src/libsysprof-ui/sysprof-environ-variable.c +++ /dev/null @@ -1,185 +0,0 @@ -/* sysprof-environ-variable.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-environ-variable" - -#include "config.h" - -#include "sysprof-environ-variable.h" - -struct _SysprofEnvironVariable -{ - GObject parent_instance; - gchar *key; - gchar *value; -}; - -G_DEFINE_TYPE (SysprofEnvironVariable, sysprof_environ_variable, G_TYPE_OBJECT) - -enum { - PROP_0, - PROP_KEY, - PROP_VALUE, - LAST_PROP -}; - -static GParamSpec *properties [LAST_PROP]; - -static void -sysprof_environ_variable_finalize (GObject *object) -{ - SysprofEnvironVariable *self = (SysprofEnvironVariable *)object; - - g_clear_pointer (&self->key, g_free); - g_clear_pointer (&self->value, g_free); - - G_OBJECT_CLASS (sysprof_environ_variable_parent_class)->finalize (object); -} - -static void -sysprof_environ_variable_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofEnvironVariable *self = SYSPROF_ENVIRON_VARIABLE(object); - - switch (prop_id) - { - case PROP_KEY: - g_value_set_string (value, self->key); - break; - - case PROP_VALUE: - g_value_set_string (value, self->value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - -static void -sysprof_environ_variable_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofEnvironVariable *self = SYSPROF_ENVIRON_VARIABLE(object); - - switch (prop_id) - { - case PROP_KEY: - sysprof_environ_variable_set_key (self, g_value_get_string (value)); - break; - - case PROP_VALUE: - sysprof_environ_variable_set_value (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); - } -} - -static void -sysprof_environ_variable_class_init (SysprofEnvironVariableClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_environ_variable_finalize; - object_class->get_property = sysprof_environ_variable_get_property; - object_class->set_property = sysprof_environ_variable_set_property; - - properties [PROP_KEY] = - g_param_spec_string ("key", - "Key", - "The key for the environment variable", - NULL, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_VALUE] = - g_param_spec_string ("value", - "Value", - "The value for the environment variable", - NULL, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, LAST_PROP, properties); -} - -static void -sysprof_environ_variable_init (SysprofEnvironVariable *self) -{ -} - -const gchar * -sysprof_environ_variable_get_key (SysprofEnvironVariable *self) -{ - g_return_val_if_fail (SYSPROF_IS_ENVIRON_VARIABLE (self), NULL); - - return self->key; -} - -void -sysprof_environ_variable_set_key (SysprofEnvironVariable *self, - const gchar *key) -{ - g_return_if_fail (SYSPROF_IS_ENVIRON_VARIABLE (self)); - - if (g_strcmp0 (key, self->key) != 0) - { - g_free (self->key); - self->key = g_strdup (key); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_KEY]); - } -} - -const gchar * -sysprof_environ_variable_get_value (SysprofEnvironVariable *self) -{ - g_return_val_if_fail (SYSPROF_IS_ENVIRON_VARIABLE (self), NULL); - - return self->value; -} - -void -sysprof_environ_variable_set_value (SysprofEnvironVariable *self, - const gchar *value) -{ - g_return_if_fail (SYSPROF_IS_ENVIRON_VARIABLE (self)); - - if (g_strcmp0 (value, self->value) != 0) - { - g_free (self->value); - self->value = g_strdup (value); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_VALUE]); - } -} - -SysprofEnvironVariable * -sysprof_environ_variable_new (const gchar *key, - const gchar *value) -{ - return g_object_new (SYSPROF_TYPE_ENVIRON_VARIABLE, - "key", key, - "value", value, - NULL); -} diff --git a/src/libsysprof-ui/sysprof-environ-variable.h b/src/libsysprof-ui/sysprof-environ-variable.h deleted file mode 100644 index ee19876a..00000000 --- a/src/libsysprof-ui/sysprof-environ-variable.h +++ /dev/null @@ -1,40 +0,0 @@ -/* sysprof-environ-variable.h - * - * Copyright 2016-2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_ENVIRON_VARIABLE (sysprof_environ_variable_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofEnvironVariable, sysprof_environ_variable, SYSPROF, ENVIRON_VARIABLE, GObject) - -SysprofEnvironVariable *sysprof_environ_variable_new (const gchar *key, - const gchar *value); -const gchar *sysprof_environ_variable_get_key (SysprofEnvironVariable *self); -void sysprof_environ_variable_set_key (SysprofEnvironVariable *self, - const gchar *key); -const gchar *sysprof_environ_variable_get_value (SysprofEnvironVariable *self); -void sysprof_environ_variable_set_value (SysprofEnvironVariable *self, - const gchar *value); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-environ.c b/src/libsysprof-ui/sysprof-environ.c deleted file mode 100644 index a1200d46..00000000 --- a/src/libsysprof-ui/sysprof-environ.c +++ /dev/null @@ -1,379 +0,0 @@ -/* sysprof-environ.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-environ" - -#include "config.h" - -#include - -#include "sysprof-environ.h" -#include "sysprof-environ-variable.h" - -struct _SysprofEnviron -{ - GObject parent_instance; - GPtrArray *variables; -}; - -static void list_model_iface_init (GListModelInterface *iface); - -G_DEFINE_TYPE_EXTENDED (SysprofEnviron, sysprof_environ, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, list_model_iface_init)) - -enum { - CHANGED, - LAST_SIGNAL -}; - -static guint signals [LAST_SIGNAL]; - -static void -sysprof_environ_finalize (GObject *object) -{ - SysprofEnviron *self = (SysprofEnviron *)object; - - g_clear_pointer (&self->variables, g_ptr_array_unref); - - G_OBJECT_CLASS (sysprof_environ_parent_class)->finalize (object); -} - -static void -sysprof_environ_class_init (SysprofEnvironClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_environ_finalize; - - signals [CHANGED] = - g_signal_new ("changed", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); - g_signal_set_va_marshaller (signals [CHANGED], - G_TYPE_FROM_CLASS (klass), - g_cclosure_marshal_VOID__VOIDv); -} - -static void -sysprof_environ_items_changed (SysprofEnviron *self) -{ - g_assert (SYSPROF_IS_ENVIRON (self)); - - g_signal_emit (self, signals [CHANGED], 0); -} - -static void -sysprof_environ_init (SysprofEnviron *self) -{ - self->variables = g_ptr_array_new_with_free_func (g_object_unref); - - g_signal_connect (self, - "items-changed", - G_CALLBACK (sysprof_environ_items_changed), - NULL); -} - -static GType -sysprof_environ_get_item_type (GListModel *model) -{ - return SYSPROF_TYPE_ENVIRON_VARIABLE; -} - -static gpointer -sysprof_environ_get_item (GListModel *model, - guint position) -{ - SysprofEnviron *self = (SysprofEnviron *)model; - - g_return_val_if_fail (SYSPROF_IS_ENVIRON (self), NULL); - g_return_val_if_fail (position < self->variables->len, NULL); - - return g_object_ref (g_ptr_array_index (self->variables, position)); -} - -static guint -sysprof_environ_get_n_items (GListModel *model) -{ - SysprofEnviron *self = (SysprofEnviron *)model; - - g_return_val_if_fail (SYSPROF_IS_ENVIRON (self), 0); - - return self->variables->len; -} - -static void -list_model_iface_init (GListModelInterface *iface) -{ - iface->get_n_items = sysprof_environ_get_n_items; - iface->get_item = sysprof_environ_get_item; - iface->get_item_type = sysprof_environ_get_item_type; -} - -static void -sysprof_environ_variable_notify (SysprofEnviron *self, - GParamSpec *pspec, - SysprofEnvironVariable *variable) -{ - g_assert (SYSPROF_IS_ENVIRON (self)); - - g_signal_emit (self, signals [CHANGED], 0); -} - -void -sysprof_environ_setenv (SysprofEnviron *self, - const gchar *key, - const gchar *value) -{ - guint i; - - g_return_if_fail (SYSPROF_IS_ENVIRON (self)); - g_return_if_fail (key != NULL); - - for (i = 0; i < self->variables->len; i++) - { - SysprofEnvironVariable *var = g_ptr_array_index (self->variables, i); - const gchar *var_key = sysprof_environ_variable_get_key (var); - - if (g_strcmp0 (key, var_key) == 0) - { - if (value == NULL) - { - g_ptr_array_remove_index (self->variables, i); - g_list_model_items_changed (G_LIST_MODEL (self), i, 1, 0); - return; - } - - sysprof_environ_variable_set_value (var, value); - return; - } - } - - if (value != NULL) - { - SysprofEnvironVariable *var; - guint position = self->variables->len; - - var = g_object_new (SYSPROF_TYPE_ENVIRON_VARIABLE, - "key", key, - "value", value, - NULL); - g_signal_connect_object (var, - "notify", - G_CALLBACK (sysprof_environ_variable_notify), - self, - G_CONNECT_SWAPPED); - g_ptr_array_add (self->variables, var); - g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1); - } -} - -const gchar * -sysprof_environ_getenv (SysprofEnviron *self, - const gchar *key) -{ - guint i; - - g_return_val_if_fail (SYSPROF_IS_ENVIRON (self), NULL); - g_return_val_if_fail (key != NULL, NULL); - - for (i = 0; i < self->variables->len; i++) - { - SysprofEnvironVariable *var = g_ptr_array_index (self->variables, i); - const gchar *var_key = sysprof_environ_variable_get_key (var); - - if (g_strcmp0 (key, var_key) == 0) - return sysprof_environ_variable_get_value (var); - } - - return NULL; -} - -/** - * sysprof_environ_get_environ: - * @self: An #SysprofEnviron - * - * Gets the environment as a set of key=value pairs, suitable for use - * in various GLib process functions. - * - * Returns: (transfer full): A newly allocated string array. - * - * Since: 3.32 - */ -gchar ** -sysprof_environ_get_environ (SysprofEnviron *self) -{ - GPtrArray *ar; - guint i; - - g_return_val_if_fail (SYSPROF_IS_ENVIRON (self), NULL); - - ar = g_ptr_array_new (); - - for (i = 0; i < self->variables->len; i++) - { - SysprofEnvironVariable *var = g_ptr_array_index (self->variables, i); - const gchar *key = sysprof_environ_variable_get_key (var); - const gchar *value = sysprof_environ_variable_get_value (var); - - if (value == NULL) - value = ""; - - if (key != NULL) - g_ptr_array_add (ar, g_strdup_printf ("%s=%s", key, value)); - } - - g_ptr_array_add (ar, NULL); - - return (gchar **)g_ptr_array_free (ar, FALSE); -} - -SysprofEnviron * -sysprof_environ_new (void) -{ - return g_object_new (SYSPROF_TYPE_ENVIRON, NULL); -} - -void -sysprof_environ_remove (SysprofEnviron *self, - SysprofEnvironVariable *variable) -{ - guint i; - - g_return_if_fail (SYSPROF_IS_ENVIRON (self)); - g_return_if_fail (SYSPROF_IS_ENVIRON_VARIABLE (variable)); - - for (i = 0; i < self->variables->len; i++) - { - SysprofEnvironVariable *item = g_ptr_array_index (self->variables, i); - - if (item == variable) - { - g_ptr_array_remove_index (self->variables, i); - g_list_model_items_changed (G_LIST_MODEL (self), i, 1, 0); - break; - } - } -} - -void -sysprof_environ_append (SysprofEnviron *self, - SysprofEnvironVariable *variable) -{ - guint position; - - g_return_if_fail (SYSPROF_IS_ENVIRON (self)); - g_return_if_fail (SYSPROF_IS_ENVIRON_VARIABLE (variable)); - - position = self->variables->len; - - g_signal_connect_object (variable, - "notify", - G_CALLBACK (sysprof_environ_variable_notify), - self, - G_CONNECT_SWAPPED); - g_ptr_array_add (self->variables, g_object_ref (variable)); - g_list_model_items_changed (G_LIST_MODEL (self), position, 0, 1); -} - -/** - * sysprof_environ_copy: - * @self: An #SysprofEnviron - * - * Copies the contents of #SysprofEnviron into a newly allocated #SysprofEnviron. - * - * Returns: (transfer full): An #SysprofEnviron. - * - * Since: 3.32 - */ -SysprofEnviron * -sysprof_environ_copy (SysprofEnviron *self) -{ - g_autoptr(SysprofEnviron) copy = NULL; - - g_return_val_if_fail (SYSPROF_IS_ENVIRON (self), NULL); - - copy = sysprof_environ_new (); - sysprof_environ_copy_into (self, copy, TRUE); - - return g_steal_pointer (©); -} - -void -sysprof_environ_copy_into (SysprofEnviron *self, - SysprofEnviron *dest, - gboolean replace) -{ - g_return_if_fail (SYSPROF_IS_ENVIRON (self)); - g_return_if_fail (SYSPROF_IS_ENVIRON (dest)); - - for (guint i = 0; i < self->variables->len; i++) - { - SysprofEnvironVariable *var = g_ptr_array_index (self->variables, i); - const gchar *key = sysprof_environ_variable_get_key (var); - const gchar *value = sysprof_environ_variable_get_value (var); - - if (replace || sysprof_environ_getenv (dest, key) == NULL) - sysprof_environ_setenv (dest, key, value); - } -} - -/** - * ide_environ_parse: - * @pair: the KEY=VALUE pair - * @key: (out) (optional): a location for a @key - * @value: (out) (optional): a location for a @value - * - * Parses a KEY=VALUE style key-pair into @key and @value. - * - * Returns: %TRUE if @pair was successfully parsed - * - * Since: 3.32 - */ -gboolean -ide_environ_parse (const gchar *pair, - gchar **key, - gchar **value) -{ - const gchar *eq; - - g_return_val_if_fail (pair != NULL, FALSE); - - if (key != NULL) - *key = NULL; - - if (value != NULL) - *value = NULL; - - if ((eq = strchr (pair, '='))) - { - if (key != NULL) - *key = g_strndup (pair, eq - pair); - - if (value != NULL) - *value = g_strdup (eq + 1); - - return TRUE; - } - - return FALSE; -} diff --git a/src/libsysprof-ui/sysprof-environ.h b/src/libsysprof-ui/sysprof-environ.h deleted file mode 100644 index ef5e5f83..00000000 --- a/src/libsysprof-ui/sysprof-environ.h +++ /dev/null @@ -1,52 +0,0 @@ -/* sysprof-environ.h - * - * Copyright 2016-2019 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 - -#include "sysprof-environ-variable.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_ENVIRON (sysprof_environ_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofEnviron, sysprof_environ, SYSPROF, ENVIRON, GObject) - -gboolean ide_environ_parse (const gchar *pair, - gchar **key, - gchar **value); -SysprofEnviron *sysprof_environ_new (void); -void sysprof_environ_setenv (SysprofEnviron *self, - const gchar *key, - const gchar *value); -const gchar *sysprof_environ_getenv (SysprofEnviron *self, - const gchar *key); -gchar **sysprof_environ_get_environ (SysprofEnviron *self); -void sysprof_environ_append (SysprofEnviron *self, - SysprofEnvironVariable *variable); -void sysprof_environ_remove (SysprofEnviron *self, - SysprofEnvironVariable *variable); -SysprofEnviron *sysprof_environ_copy (SysprofEnviron *self); -void sysprof_environ_copy_into (SysprofEnviron *self, - SysprofEnviron *dest, - gboolean replace); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-failed-state-view.c b/src/libsysprof-ui/sysprof-failed-state-view.c deleted file mode 100644 index 6ca02e7d..00000000 --- a/src/libsysprof-ui/sysprof-failed-state-view.c +++ /dev/null @@ -1,62 +0,0 @@ -/* sysprof-failed-state-view.c - * - * Copyright 2016-2019 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-failed-state-view.h" - -G_DEFINE_TYPE (SysprofFailedStateView, sysprof_failed_state_view, GTK_TYPE_WIDGET) - -GtkWidget * -sysprof_failed_state_view_new (void) -{ - return g_object_new (SYSPROF_TYPE_FAILED_STATE_VIEW, NULL); -} - -static void -sysprof_failed_state_view_dispose (GObject *object) -{ - SysprofFailedStateView *self = (SysprofFailedStateView *)object; - GtkWidget *child; - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) - gtk_widget_unparent (child); - - G_OBJECT_CLASS (sysprof_failed_state_view_parent_class)->dispose (object); -} - -static void -sysprof_failed_state_view_class_init (SysprofFailedStateViewClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_failed_state_view_dispose; - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_set_template_from_resource (widget_class, - "/org/gnome/sysprof/ui/sysprof-failed-state-view.ui"); -} - -static void -sysprof_failed_state_view_init (SysprofFailedStateView *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); -} diff --git a/src/libsysprof-ui/sysprof-failed-state-view.h b/src/libsysprof-ui/sysprof-failed-state-view.h deleted file mode 100644 index 4657abe1..00000000 --- a/src/libsysprof-ui/sysprof-failed-state-view.h +++ /dev/null @@ -1,41 +0,0 @@ -/* sysprof-failed-state-view.h - * - * Copyright 2016-2019 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 -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_FAILED_STATE_VIEW (sysprof_failed_state_view_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofFailedStateView, sysprof_failed_state_view, SYSPROF, FAILED_STATE_VIEW, GtkWidget) - -struct _SysprofFailedStateViewClass -{ - GtkWidgetClass parent; -}; - -GtkWidget *sysprof_failed_state_view_new (void); -void sysprof_failed_state_view_set_profiler (SysprofFailedStateView *self, - SysprofProfiler *profiler); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-failed-state-view.ui b/src/libsysprof-ui/sysprof-failed-state-view.ui deleted file mode 100644 index 8b01a009..00000000 --- a/src/libsysprof-ui/sysprof-failed-state-view.ui +++ /dev/null @@ -1,47 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-line-visualizer.c b/src/libsysprof-ui/sysprof-line-visualizer.c deleted file mode 100644 index 046be4a8..00000000 --- a/src/libsysprof-ui/sysprof-line-visualizer.c +++ /dev/null @@ -1,909 +0,0 @@ -/* sysprof-line-visualizer.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-line-visualizer" - -#include "config.h" - -#include -#include -#include - -#include "pointcache.h" -#include "sysprof-line-visualizer.h" - -typedef struct -{ - /* - * Our reader as assigned by the visualizer system. - */ - SysprofCaptureReader *reader; - - /* - * An array of LineInfo which contains information about the counters - * we need to render. - */ - GArray *lines; - - /* - * This is our set of cached points to render. Once it is assigned here, - * it is immutable (and therefore may be shared with worker processes - * that are rendering the points). - */ - PointCache *cache; - - /* The format for units (such as mHz, Watts, etc). */ - gchar *units; - - /* - * Range of the scale for lower and upper. - */ - gdouble y_lower; - gdouble y_upper; - - /* - * If we have a new counter discovered or the reader is set, we might - * want to delay loading until we return to the main loop. This can - * help us avoid doing duplicate work. - */ - guint queued_load; - - guint y_lower_set : 1; - guint y_upper_set : 1; -} SysprofLineVisualizerPrivate; - -typedef struct -{ - guint id; - guint type; - gdouble line_width; - GdkRGBA foreground; - GdkRGBA background; - guint use_default_style : 1; - guint fill : 1; - guint use_dash : 1; -} LineInfo; - -typedef struct -{ - SysprofCaptureCursor *cursor; - GArray *lines; - PointCache *cache; - gint64 begin_time; - gint64 end_time; - gdouble y_lower; - gdouble y_upper; - guint y_lower_set : 1; - guint y_upper_set : 1; -} LoadData; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofLineVisualizer, sysprof_line_visualizer, SYSPROF_TYPE_VISUALIZER) - -static void sysprof_line_visualizer_load_data_async (SysprofLineVisualizer *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -static PointCache *sysprof_line_visualizer_load_data_finish (SysprofLineVisualizer *self, - GAsyncResult *result, - GError **error); - -enum { - PROP_0, - PROP_Y_LOWER, - PROP_Y_UPPER, - PROP_UNITS, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; -static const gdouble dashes[] = { 1.0, 2.0 }; - -static void -load_data_free (gpointer data) -{ - LoadData *load = data; - - if (load != NULL) - { - g_clear_pointer (&load->lines, g_array_unref); - g_clear_pointer (&load->cursor, sysprof_capture_cursor_unref); - g_clear_pointer (&load->cache, point_cache_unref); - g_slice_free (LoadData, load); - } -} - -static GArray * -copy_array (GArray *ar) -{ - GArray *ret; - - ret = g_array_sized_new (FALSE, FALSE, g_array_get_element_size (ar), ar->len); - g_array_set_size (ret, ar->len); - memcpy (ret->data, ar->data, ar->len * g_array_get_element_size (ret)); - - return ret; -} - -static void -sysprof_line_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - static PangoAttrList *attrs = NULL; - SysprofLineVisualizer *self = (SysprofLineVisualizer *)widget; - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - g_autofree gchar *upper = NULL; - GtkStyleContext *style_context; - PangoLayout *layout; - cairo_t *cr; - GtkAllocation alloc; - GdkRectangle clip; - GdkRGBA foreground; - - g_assert (SYSPROF_IS_LINE_VISUALIZER (widget)); - g_assert (snapshot != NULL); - - gtk_widget_get_allocation (widget, &alloc); - - GTK_WIDGET_CLASS (sysprof_line_visualizer_parent_class)->snapshot (widget, snapshot); - - if (priv->cache == NULL) - return; - -#if 0 - if (!gdk_cairo_get_clip_rectangle (cr, &clip)) - return ret; -#else - clip.x = 0; - clip.y = 0; - clip.width = alloc.width; - clip.height = alloc.height; -#endif - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height)); - - style_context = gtk_widget_get_style_context (widget); - gtk_style_context_get_color (style_context, &foreground); - - for (guint line = 0; line < priv->lines->len; line++) - { - g_autofree SysprofVisualizerAbsolutePoint *points = NULL; - const LineInfo *line_info = &g_array_index (priv->lines, LineInfo, line); - const Point *fpoints; - guint n_fpoints = 0; - GdkRGBA color; - - fpoints = point_cache_get_points (priv->cache, line_info->id, &n_fpoints); - - if (n_fpoints > 0) - { - gdouble last_x = 0; - gdouble last_y = 0; - guint p; - - points = g_new0 (SysprofVisualizerAbsolutePoint, n_fpoints); - - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self), - (const SysprofVisualizerRelativePoint *)fpoints, - n_fpoints, - points, - n_fpoints); - - for (p = 0; p < n_fpoints; p++) - { - if (points[p].x >= clip.x) - break; - } - - if (p >= n_fpoints) - goto cleanup; - - if (p > 0) - p--; - - last_x = points[p].x; - last_y = points[p].y; - - if (line_info->fill) - { - cairo_move_to (cr, last_x, alloc.height); - cairo_line_to (cr, last_x, last_y); - } - else - { - cairo_move_to (cr, last_x, last_y); - } - - for (guint i = p + 1; i < n_fpoints; i++) - { - cairo_curve_to (cr, - last_x + ((points[i].x - last_x) / 2), - last_y, - last_x + ((points[i].x - last_x) / 2), - points[i].y, - points[i].x, - points[i].y); - - last_x = points[i].x; - last_y = points[i].y; - - if (points[i].x > clip.x + clip.width) - break; - } - - if (line_info->fill) - { - cairo_line_to (cr, last_x, alloc.height); - cairo_close_path (cr); - } - - cairo_set_line_width (cr, line_info->line_width); - - if (line_info->use_dash) - cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0); - - if (line_info->fill) - { - gdk_cairo_set_source_rgba (cr, &line_info->background); - cairo_fill_preserve (cr); - } - - if (line_info->use_default_style) - color = foreground; - else - color = line_info->foreground; - - gdk_cairo_set_source_rgba (cr, &color); - cairo_stroke (cr); - } - } - - if (!attrs) - { - attrs = pango_attr_list_new (); - pango_attr_list_insert (attrs, pango_attr_scale_new (0.666)); - } - - if (priv->y_upper != 100.0) - { - if (priv->units) - upper = g_strdup_printf ("%lg %s", priv->y_upper, priv->units); - else - upper = g_strdup_printf ("%lg", priv->y_upper); - - layout = gtk_widget_create_pango_layout (widget, upper); - pango_layout_set_attributes (layout, attrs); - cairo_move_to (cr, 2, 2); - foreground.alpha *= 0.5; - gdk_cairo_set_source_rgba (cr, &foreground); - pango_cairo_show_layout (cr, layout); - g_clear_object (&layout); - } - -cleanup: - cairo_destroy (cr); -} - -static void -sysprof_line_visualizer_load_data_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofLineVisualizer *self = (SysprofLineVisualizer *)object; - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - g_autoptr(GError) error = NULL; - g_autoptr(PointCache) cache = NULL; - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - - cache = sysprof_line_visualizer_load_data_finish (self, result, &error); - - if (cache == NULL) - { - g_warning ("%s", error->message); - return; - } - - g_clear_pointer (&priv->cache, point_cache_unref); - priv->cache = g_steal_pointer (&cache); - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static gboolean -sysprof_line_visualizer_do_reload (gpointer data) -{ - SysprofLineVisualizer *self = data; - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - - priv->queued_load = 0; - - if (priv->reader != NULL) - { - sysprof_line_visualizer_load_data_async (self, - NULL, - sysprof_line_visualizer_load_data_cb, - NULL); - } - - return G_SOURCE_REMOVE; -} - -static void -sysprof_line_visualizer_queue_reload (SysprofLineVisualizer *self) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - - if (priv->queued_load == 0) - priv->queued_load = g_idle_add_full (G_PRIORITY_LOW, - sysprof_line_visualizer_do_reload, - self, - NULL); -} - -static void -sysprof_line_visualizer_set_reader (SysprofVisualizer *row, - SysprofCaptureReader *reader) -{ - SysprofLineVisualizer *self = (SysprofLineVisualizer *)row; - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - - if (priv->reader != reader) - { - if (priv->reader != NULL) - { - sysprof_capture_reader_unref (priv->reader); - priv->reader = NULL; - } - - if (reader != NULL) - priv->reader = sysprof_capture_reader_ref (reader); - - sysprof_line_visualizer_queue_reload (self); - } -} - -static void -sysprof_line_visualizer_finalize (GObject *object) -{ - SysprofLineVisualizer *self = (SysprofLineVisualizer *)object; - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_clear_pointer (&priv->units, g_free); - g_clear_pointer (&priv->lines, g_array_unref); - g_clear_pointer (&priv->cache, point_cache_unref); - g_clear_pointer (&priv->reader, sysprof_capture_reader_unref); - - g_clear_handle_id (&priv->queued_load, g_source_remove); - - G_OBJECT_CLASS (sysprof_line_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_line_visualizer_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofLineVisualizer *self = SYSPROF_LINE_VISUALIZER (object); - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - switch (prop_id) - { - case PROP_Y_LOWER: - g_value_set_double (value, priv->y_lower); - break; - - case PROP_Y_UPPER: - g_value_set_double (value, priv->y_upper); - break; - - case PROP_UNITS: - g_value_set_string (value, priv->units); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_line_visualizer_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofLineVisualizer *self = SYSPROF_LINE_VISUALIZER (object); - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - switch (prop_id) - { - case PROP_Y_LOWER: - priv->y_lower = g_value_get_double (value); - priv->y_lower_set = TRUE; - gtk_widget_queue_allocate (GTK_WIDGET (self)); - break; - - case PROP_Y_UPPER: - priv->y_upper = g_value_get_double (value); - priv->y_upper_set = TRUE; - gtk_widget_queue_allocate (GTK_WIDGET (self)); - break; - - case PROP_UNITS: - g_free (priv->units); - priv->units = g_value_dup_string (value); - gtk_widget_queue_allocate (GTK_WIDGET (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_line_visualizer_class_init (SysprofLineVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofVisualizerClass *visualizer_class = SYSPROF_VISUALIZER_CLASS (klass); - - object_class->finalize = sysprof_line_visualizer_finalize; - object_class->get_property = sysprof_line_visualizer_get_property; - object_class->set_property = sysprof_line_visualizer_set_property; - - widget_class->snapshot = sysprof_line_visualizer_snapshot; - - visualizer_class->set_reader = sysprof_line_visualizer_set_reader; - - properties [PROP_Y_LOWER] = - g_param_spec_double ("y-lower", - "Y Lower", - "The lowest Y value for the visualizer", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_Y_UPPER] = - g_param_spec_double ("y-upper", - "Y Upper", - "The highest Y value for the visualizer", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 100.0, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_UNITS] = - g_param_spec_string ("units", - "Units", - "The format for units (mHz, Watts, etc)", - NULL, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_line_visualizer_init (SysprofLineVisualizer *self) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - priv->lines = g_array_new (FALSE, FALSE, sizeof (LineInfo)); -} - -void -sysprof_line_visualizer_add_counter (SysprofLineVisualizer *self, - guint counter_id, - const GdkRGBA *color) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - LineInfo line_info = { 0 }; - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - g_assert (priv->lines != NULL); - - line_info.id = counter_id; - line_info.line_width = 1.0; - line_info.type = SYSPROF_CAPTURE_COUNTER_DOUBLE; - - if (color != NULL) - { - line_info.foreground = *color; - line_info.use_default_style = FALSE; - } - else - { - gdk_rgba_parse (&line_info.foreground, "#000"); - line_info.use_default_style = TRUE; - } - - g_array_append_val (priv->lines, line_info); - - if (SYSPROF_LINE_VISUALIZER_GET_CLASS (self)->counter_added) - SYSPROF_LINE_VISUALIZER_GET_CLASS (self)->counter_added (self, counter_id); - - sysprof_line_visualizer_queue_reload (self); -} - -void -sysprof_line_visualizer_clear (SysprofLineVisualizer *self) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_LINE_VISUALIZER (self)); - - if (priv->lines->len > 0) - g_array_remove_range (priv->lines, 0, priv->lines->len); - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static inline gboolean -contains_id (GArray *ar, - guint id) -{ - for (guint i = 0; i < ar->len; i++) - { - const LineInfo *info = &g_array_index (ar, LineInfo, i); - - if (info->id == id) - return TRUE; - } - - return FALSE; -} - -static inline guint8 -counter_type (LoadData *load, - guint counter_id) -{ - for (guint i = 0; i < load->lines->len; i++) - { - const LineInfo *info = &g_array_index (load->lines, LineInfo, i); - - if (info->id == counter_id) - return info->type; - } - - return SYSPROF_CAPTURE_COUNTER_DOUBLE; -} - -static inline gdouble -calc_x (gint64 lower, - gint64 upper, - gint64 value) -{ - return (gdouble)(value - lower) / (gdouble)(upper - lower); -} - -static inline gdouble -calc_y_double (gdouble lower, - gdouble upper, - gdouble value) -{ - return (value - lower) / (upper - lower); -} - -static inline gdouble -calc_y_int64 (gint64 lower, - gint64 upper, - gint64 value) -{ - return (gdouble)(value - lower) / (gdouble)(upper - lower); -} - -static bool -sysprof_line_visualizer_load_data_frame_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - LoadData *load = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET || - frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (load != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET) - { - const SysprofCaptureCounterSet *set = (SysprofCaptureCounterSet *)frame; - gdouble x = calc_x (load->begin_time, load->end_time, frame->time); - - for (guint i = 0; i < set->n_values; i++) - { - const SysprofCaptureCounterValues *group = &set->values[i]; - - for (guint j = 0; j < G_N_ELEMENTS (group->ids); j++) - { - guint counter_id = group->ids[j]; - - if (counter_id != 0 && contains_id (load->lines, counter_id)) - { - gdouble y; - - if (counter_type (load, counter_id) == SYSPROF_CAPTURE_COUNTER_DOUBLE) - y = calc_y_double (load->y_lower, load->y_upper, group->values[j].vdbl); - else - y = calc_y_int64 (load->y_lower, load->y_upper, group->values[j].v64); - - point_cache_add_point_to_set (load->cache, counter_id, x, y); - } - } - } - } - - return TRUE; -} - -static bool -sysprof_line_visualizer_load_data_range_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - LoadData *load = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET || - frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (load != NULL); - g_assert (load->y_upper_set == FALSE || - load->y_lower_set == FALSE); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF) - { - const SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - - for (guint i = 0; i < def->n_counters; i++) - { - const SysprofCaptureCounter *ctr = &def->counters[i]; - - for (guint j = 0; j < load->lines->len; j++) - { - LineInfo *info = &g_array_index (load->lines, LineInfo, j); - - if (info->id == ctr->id) - { - info->type = ctr->type; - break; - } - } - } - } - else if (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET) - { - const SysprofCaptureCounterSet *set = (SysprofCaptureCounterSet *)frame; - - for (guint i = 0; i < set->n_values; i++) - { - const SysprofCaptureCounterValues *group = &set->values[i]; - - for (guint j = 0; j < G_N_ELEMENTS (group->ids); j++) - { - guint counter_id = group->ids[j]; - - if (counter_id != 0 && contains_id (load->lines, counter_id)) - { - gdouble y; - - if (counter_type (load, counter_id) == SYSPROF_CAPTURE_COUNTER_DOUBLE) - y = group->values[j].vdbl; - else - y = group->values[j].v64; - - if (!load->y_upper_set) - load->y_upper = MAX (load->y_upper, y); - - if (!load->y_lower_set) - load->y_lower = MIN (load->y_lower, y); - } - } - } - } - - return TRUE; -} - -static void -sysprof_line_visualizer_load_data_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - LoadData *load = task_data; - g_autoptr(GArray) counter_ids = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_LINE_VISUALIZER (source_object)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - counter_ids = g_array_new (FALSE, FALSE, sizeof (guint)); - - for (guint i = 0; i < load->lines->len; i++) - { - const LineInfo *line_info = &g_array_index (load->lines, LineInfo, i); - g_array_append_val (counter_ids, line_info->id); - } - - sysprof_capture_cursor_add_condition (load->cursor, - sysprof_capture_condition_new_where_counter_in (counter_ids->len, - (guint *)(gpointer)counter_ids->data)); - - /* If y boundaries are not set, we need to discover them by scaning the data. */ - if (!load->y_lower_set || !load->y_upper_set) - { - sysprof_capture_cursor_foreach (load->cursor, sysprof_line_visualizer_load_data_range_cb, load); - sysprof_capture_cursor_reset (load->cursor); - - /* Add extra boundary for some space above the graph line */ - if (G_MAXDOUBLE - load->y_upper > (load->y_upper * .25)) - load->y_upper = load->y_upper + ((load->y_upper - load->y_lower) * .25); - } - - sysprof_capture_cursor_foreach (load->cursor, sysprof_line_visualizer_load_data_frame_cb, load); - g_task_return_pointer (task, g_steal_pointer (&load->cache), (GDestroyNotify)point_cache_unref); -} - -static void -sysprof_line_visualizer_load_data_async (SysprofLineVisualizer *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - g_autoptr(GTask) task = NULL; - LoadData *load; - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_priority (task, G_PRIORITY_LOW); - g_task_set_source_tag (task, sysprof_line_visualizer_load_data_async); - - if (priv->reader == NULL) - { - g_task_return_new_error (task, - G_IO_ERROR, - G_IO_ERROR_FAILED, - "No data loaded"); - return; - } - - load = g_slice_new0 (LoadData); - load->cache = point_cache_new (); - load->y_lower = priv->y_lower_set ? priv->y_lower : G_MAXDOUBLE; - load->y_upper = priv->y_upper_set ? priv->y_upper : -G_MAXDOUBLE; - load->y_lower_set = priv->y_lower_set; - load->y_upper_set = priv->y_upper_set; - load->begin_time = sysprof_capture_reader_get_start_time (priv->reader); - load->end_time = sysprof_capture_reader_get_end_time (priv->reader); - load->cursor = sysprof_capture_cursor_new (priv->reader); - load->lines = copy_array (priv->lines); - - for (guint i = 0; i < load->lines->len; i++) - { - const LineInfo *line_info = &g_array_index (load->lines, LineInfo, i); - - point_cache_add_set (load->cache, line_info->id); - } - - g_task_set_task_data (task, load, load_data_free); - g_task_run_in_thread (task, sysprof_line_visualizer_load_data_worker); -} - -static PointCache * -sysprof_line_visualizer_load_data_finish (SysprofLineVisualizer *self, - GAsyncResult *result, - GError **error) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - LoadData *state; - - g_assert (SYSPROF_IS_LINE_VISUALIZER (self)); - g_assert (G_IS_TASK (result)); - - state = g_task_get_task_data (G_TASK (result)); - - if (!priv->y_lower_set && priv->y_lower != state->y_lower) - { - priv->y_lower = state->y_lower; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_Y_LOWER]); - } - - if (!priv->y_upper_set && priv->y_upper != state->y_upper) - { - priv->y_upper = state->y_upper; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_Y_UPPER]); - } - - return g_task_propagate_pointer (G_TASK (result), error); -} - -void -sysprof_line_visualizer_set_line_width (SysprofLineVisualizer *self, - guint counter_id, - gdouble width) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_LINE_VISUALIZER (self)); - - for (guint i = 0; i < priv->lines->len; i++) - { - LineInfo *info = &g_array_index (priv->lines, LineInfo, i); - - if (info->id == counter_id) - { - info->line_width = width; - sysprof_line_visualizer_queue_reload (self); - break; - } - } -} - -void -sysprof_line_visualizer_set_fill (SysprofLineVisualizer *self, - guint counter_id, - const GdkRGBA *color) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_LINE_VISUALIZER (self)); - - for (guint i = 0; i < priv->lines->len; i++) - { - LineInfo *info = &g_array_index (priv->lines, LineInfo, i); - - if (info->id == counter_id) - { - info->fill = !!color; - if (color != NULL) - info->background = *color; - sysprof_line_visualizer_queue_reload (self); - break; - } - } -} - -void -sysprof_line_visualizer_set_dash (SysprofLineVisualizer *self, - guint counter_id, - gboolean use_dash) -{ - SysprofLineVisualizerPrivate *priv = sysprof_line_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_LINE_VISUALIZER (self)); - - for (guint i = 0; i < priv->lines->len; i++) - { - LineInfo *info = &g_array_index (priv->lines, LineInfo, i); - - if (info->id == counter_id) - { - info->use_dash = !!use_dash; - sysprof_line_visualizer_queue_reload (self); - break; - } - } -} diff --git a/src/libsysprof-ui/sysprof-line-visualizer.h b/src/libsysprof-ui/sysprof-line-visualizer.h deleted file mode 100644 index 4fac8855..00000000 --- a/src/libsysprof-ui/sysprof-line-visualizer.h +++ /dev/null @@ -1,57 +0,0 @@ -/* sysprof-line-visualizer.h - * - * Copyright 2016-2019 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-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_LINE_VISUALIZER (sysprof_line_visualizer_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofLineVisualizer, sysprof_line_visualizer, SYSPROF, LINE_VISUALIZER, SysprofVisualizer) - -struct _SysprofLineVisualizerClass -{ - SysprofVisualizerClass parent_class; - - void (*counter_added) (SysprofLineVisualizer *self, - guint counter_id); - - /*< private >*/ - gpointer _reserved[16]; -}; - -GtkWidget *sysprof_line_visualizer_new (void); -void sysprof_line_visualizer_clear (SysprofLineVisualizer *self); -void sysprof_line_visualizer_add_counter (SysprofLineVisualizer *self, - guint counter_id, - const GdkRGBA *color); -void sysprof_line_visualizer_set_line_width (SysprofLineVisualizer *self, - guint counter_id, - gdouble width); -void sysprof_line_visualizer_set_fill (SysprofLineVisualizer *self, - guint counter_id, - const GdkRGBA *color); -void sysprof_line_visualizer_set_dash (SysprofLineVisualizer *self, - guint counter_id, - gboolean use_dash); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-log-model.c b/src/libsysprof-ui/sysprof-log-model.c deleted file mode 100644 index 8d67254f..00000000 --- a/src/libsysprof-ui/sysprof-log-model.c +++ /dev/null @@ -1,422 +0,0 @@ -/* sysprof-log-model.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-log-model" - -#include "config.h" - -#include -#include -#include - -#include "sysprof-log-model.h" - -struct _SysprofLogModel -{ - GObject parent_instance; - GStringChunk *chunks; - GArray *items; - gint64 begin_time; -}; - -typedef struct -{ - gint64 time; - const gchar *domain; - const gchar *message; - guint16 severity; -} Item; - -static gint -sysprof_log_model_get_n_columns (GtkTreeModel *model) -{ - return SYSPROF_LOG_MODEL_COLUMN_LAST; -} - -static GType -sysprof_log_model_get_column_type (GtkTreeModel *model, - gint column) -{ - switch (column) - { - case SYSPROF_LOG_MODEL_COLUMN_TIME: - return G_TYPE_INT64; - - case SYSPROF_LOG_MODEL_COLUMN_SEVERITY: - case SYSPROF_LOG_MODEL_COLUMN_DOMAIN: - case SYSPROF_LOG_MODEL_COLUMN_MESSAGE: - case SYSPROF_LOG_MODEL_COLUMN_TIME_STRING: - return G_TYPE_STRING; - - default: - return 0; - } -} - -static GtkTreePath * -sysprof_log_model_get_path (GtkTreeModel *model, - GtkTreeIter *iter) -{ - gint off; - - g_assert (SYSPROF_IS_LOG_MODEL (model)); - g_assert (iter != NULL); - - off = GPOINTER_TO_INT (iter->user_data); - - return gtk_tree_path_new_from_indices (off, -1); -} - -static gboolean -sysprof_log_model_get_iter (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreePath *path) -{ - SysprofLogModel *self = (SysprofLogModel *)model; - gint off; - - g_assert (SYSPROF_IS_LOG_MODEL (self)); - g_assert (iter != NULL); - g_assert (path != NULL); - - memset (iter, 0, sizeof *iter); - - if (gtk_tree_path_get_depth (path) != 1) - return FALSE; - - off = gtk_tree_path_get_indices (path)[0]; - iter->user_data = GINT_TO_POINTER (off); - - return off >= 0 && off < self->items->len; -} - -static gboolean -sysprof_log_model_iter_next (GtkTreeModel *model, - GtkTreeIter *iter) -{ - SysprofLogModel *self = (SysprofLogModel *)model; - gint off; - - g_assert (SYSPROF_IS_LOG_MODEL (self)); - g_assert (iter != NULL); - - off = GPOINTER_TO_INT (iter->user_data); - off++; - iter->user_data = GINT_TO_POINTER (off); - - return off < self->items->len; -} - -static gboolean -sysprof_log_model_iter_nth_child (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n) -{ - SysprofLogModel *self = (SysprofLogModel *)model; - - g_assert (SYSPROF_IS_LOG_MODEL (self)); - g_assert (iter != NULL); - - if (parent != NULL) - return FALSE; - - iter->user_data = GINT_TO_POINTER (n); - - return n < self->items->len; -} - -static gint -sysprof_log_model_iter_n_children (GtkTreeModel *model, - GtkTreeIter *iter) -{ - SysprofLogModel *self = (SysprofLogModel *)model; - - g_assert (SYSPROF_IS_LOG_MODEL (self)); - - return iter ? 0 : self->items->len; -} - -static gboolean -sysprof_log_model_iter_has_child (GtkTreeModel *model, - GtkTreeIter *iter) -{ - return FALSE; -} - -static GtkTreeModelFlags -sysprof_log_model_get_flags (GtkTreeModel *model) -{ - return GTK_TREE_MODEL_LIST_ONLY; -} - -static void -sysprof_log_model_get_value (GtkTreeModel *model, - GtkTreeIter *iter, - gint column, - GValue *value) -{ - SysprofLogModel *self = (SysprofLogModel *)model; - const Item *item; - - g_assert (SYSPROF_IS_LOG_MODEL (self)); - g_assert (iter != NULL); - g_assert (column < SYSPROF_LOG_MODEL_COLUMN_LAST); - - item = &g_array_index (self->items, Item, GPOINTER_TO_INT (iter->user_data)); - - switch (column) - { - case SYSPROF_LOG_MODEL_COLUMN_TIME_STRING: - { - gint64 offset = item->time - self->begin_time; - gint min = offset / SYSPROF_NSEC_PER_SEC / 60L; - gint seconds = ((offset - (min * SYSPROF_NSEC_PER_SEC)) / SYSPROF_NSEC_PER_SEC) % 60; - gint msec = (offset % SYSPROF_NSEC_PER_SEC) / (SYSPROF_NSEC_PER_SEC / 1000L); - - g_value_init (value, G_TYPE_STRING); - g_value_take_string (value, - g_strdup_printf ("%02d:%02d.%03d", min, seconds, msec)); - } - break; - - case SYSPROF_LOG_MODEL_COLUMN_TIME: - g_value_init (value, G_TYPE_INT64); - g_value_set_int64 (value, item->time); - break; - - case SYSPROF_LOG_MODEL_COLUMN_SEVERITY: - g_value_init (value, G_TYPE_STRING); - switch (item->severity) - { - case G_LOG_LEVEL_MESSAGE: - g_value_set_static_string (value, _("Message")); - break; - case G_LOG_LEVEL_INFO: - g_value_set_static_string (value, _("Info")); - break; - case G_LOG_LEVEL_CRITICAL: - g_value_set_static_string (value, _("Critical")); - break; - case G_LOG_LEVEL_ERROR: - g_value_set_static_string (value, _("Error")); - break; - case G_LOG_LEVEL_DEBUG: - g_value_set_static_string (value, _("Debug")); - break; - case G_LOG_LEVEL_WARNING: - g_value_set_static_string (value, _("Warning")); - break; - default: - g_value_set_static_string (value, ""); - break; - } - break; - - case SYSPROF_LOG_MODEL_COLUMN_DOMAIN: - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, item->domain); - break; - - case SYSPROF_LOG_MODEL_COLUMN_MESSAGE: - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, item->message); - break; - - default: - break; - } -} - -static void -tree_model_iface_init (GtkTreeModelIface *iface) -{ - iface->get_n_columns = sysprof_log_model_get_n_columns; - iface->get_column_type = sysprof_log_model_get_column_type; - iface->get_iter = sysprof_log_model_get_iter; - iface->get_path = sysprof_log_model_get_path; - iface->iter_next = sysprof_log_model_iter_next; - iface->iter_n_children = sysprof_log_model_iter_n_children; - iface->iter_nth_child = sysprof_log_model_iter_nth_child; - iface->iter_has_child = sysprof_log_model_iter_has_child; - iface->get_flags = sysprof_log_model_get_flags; - iface->get_value = sysprof_log_model_get_value; -} - -G_DEFINE_TYPE_WITH_CODE (SysprofLogModel, sysprof_log_model, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, tree_model_iface_init)) - -static void -sysprof_log_model_finalize (GObject *object) -{ - SysprofLogModel *self = (SysprofLogModel *)object; - - g_clear_pointer (&self->items, g_array_unref); - g_clear_pointer (&self->chunks, g_string_chunk_free); - - G_OBJECT_CLASS (sysprof_log_model_parent_class)->finalize (object); -} - -static void -sysprof_log_model_class_init (SysprofLogModelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_log_model_finalize; -} - -static void -sysprof_log_model_init (SysprofLogModel *self) -{ - self->chunks = g_string_chunk_new (4096*16); - self->items = g_array_new (FALSE, FALSE, sizeof (Item)); -} - -static bool -cursor_foreach_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofLogModel *self = user_data; - SysprofCaptureLog *log = (SysprofCaptureLog *)frame; - Item item; - - g_assert (SYSPROF_IS_LOG_MODEL (self)); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_LOG); - - item.time = frame->time; - item.severity = log->severity; - item.domain = g_string_chunk_insert_const (self->chunks, log->domain); - item.message = g_string_chunk_insert_const (self->chunks, log->message); - - g_array_append_val (self->items, item); - - return TRUE; -} - -static gint -item_compare (gconstpointer a, - gconstpointer b) -{ - const Item *ia = a; - const Item *ib = b; - - if (ia->time < ib->time) - return -1; - else if (ia->time > ib->time) - return 1; - else - return 0; -} - -static void -sysprof_log_model_new_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - g_autoptr(SysprofLogModel) self = NULL; - SysprofCaptureCursor *cursor = task_data; - SysprofCaptureReader *reader; - - g_assert (G_IS_TASK (task)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - self = g_object_new (SYSPROF_TYPE_LOG_MODEL, NULL); - - reader = sysprof_capture_cursor_get_reader (cursor); - self->begin_time = sysprof_capture_reader_get_start_time (reader); - - sysprof_capture_cursor_foreach (cursor, cursor_foreach_cb, self); - g_array_sort (self->items, item_compare); - - g_task_return_pointer (task, g_steal_pointer (&self), g_object_unref); -} - -static void -sysprof_log_model_selection_foreach_cb (SysprofSelection *selection, - gint64 begin, - gint64 end, - gpointer user_data) -{ - SysprofCaptureCondition **condition = user_data; - SysprofCaptureCondition *c; - - g_assert (SYSPROF_IS_SELECTION (selection)); - g_assert (condition != NULL); - - c = sysprof_capture_condition_new_where_time_between (begin, end); - - if (*condition != NULL) - *condition = sysprof_capture_condition_new_or (g_steal_pointer (&c), - g_steal_pointer (condition)); - else - *condition = g_steal_pointer (&c); -} - -void -sysprof_log_model_new_async (SysprofCaptureReader *reader, - SysprofSelection *selection, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { - SYSPROF_CAPTURE_FRAME_LOG, - }; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - SysprofCaptureCondition *c; - g_autoptr(GTask) task = NULL; - - g_return_if_fail (reader != NULL); - g_return_if_fail (!selection || SYSPROF_IS_SELECTION (selection)); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - cursor = sysprof_capture_cursor_new (reader); - c = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - - if (selection) - { - SysprofCaptureCondition *condition = NULL; - - sysprof_selection_foreach (selection, - sysprof_log_model_selection_foreach_cb, - &condition); - if (condition) - c = sysprof_capture_condition_new_and (c, g_steal_pointer (&condition)); - } - - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&c)); - - task = g_task_new (NULL, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_log_model_new_async); - g_task_set_task_data (task, - g_steal_pointer (&cursor), - (GDestroyNotify) sysprof_capture_cursor_unref); - g_task_run_in_thread (task, sysprof_log_model_new_worker); -} - -SysprofLogModel * -sysprof_log_model_new_finish (GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (G_IS_TASK (result), NULL); - - return g_task_propagate_pointer (G_TASK (result), error); -} diff --git a/src/libsysprof-ui/sysprof-log-model.h b/src/libsysprof-ui/sysprof-log-model.h deleted file mode 100644 index 7edb25fa..00000000 --- a/src/libsysprof-ui/sysprof-log-model.h +++ /dev/null @@ -1,49 +0,0 @@ -/* sysprof-log-model.h - * - * Copyright 2019 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 - -G_BEGIN_DECLS - -typedef enum -{ - SYSPROF_LOG_MODEL_COLUMN_TIME, - SYSPROF_LOG_MODEL_COLUMN_SEVERITY, - SYSPROF_LOG_MODEL_COLUMN_DOMAIN, - SYSPROF_LOG_MODEL_COLUMN_MESSAGE, - SYSPROF_LOG_MODEL_COLUMN_TIME_STRING, - SYSPROF_LOG_MODEL_COLUMN_LAST -} SysprofLogModelColumn; - -#define SYSPROF_TYPE_LOG_MODEL (sysprof_log_model_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofLogModel, sysprof_log_model, SYSPROF, LOG_MODEL, GObject) - -void sysprof_log_model_new_async (SysprofCaptureReader *reader, - SysprofSelection *selection, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -SysprofLogModel *sysprof_log_model_new_finish (GAsyncResult *result, - GError **error); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-logs-aid.c b/src/libsysprof-ui/sysprof-logs-aid.c deleted file mode 100644 index 8807cbe5..00000000 --- a/src/libsysprof-ui/sysprof-logs-aid.c +++ /dev/null @@ -1,237 +0,0 @@ -/* sysprof-logs-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-logs-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-logs-aid.h" -#include "sysprof-logs-page.h" -#include "sysprof-mark-visualizer.h" - -struct _SysprofLogsAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofDisplay *display; - SysprofCaptureCursor *cursor; - GArray *log_marks; -} Present; - -G_DEFINE_TYPE (SysprofLogsAid, sysprof_logs_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->log_marks, g_array_unref); - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -static void -on_group_activated_cb (SysprofVisualizerGroup *group, - SysprofPage *page) -{ - SysprofDisplay *display; - - g_assert (SYSPROF_IS_VISUALIZER_GROUP (group)); - g_assert (SYSPROF_IS_PAGE (page)); - - display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (page), SYSPROF_TYPE_DISPLAY)); - sysprof_display_set_visible_page (display, page); -} - -/** - * sysprof_logs_aid_new: - * - * Create a new #SysprofLogsAid. - * - * Returns: (transfer full): a newly created #SysprofLogsAid - */ -SysprofAid * -sysprof_logs_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_LOGS_AID, NULL); -} - -static bool -find_marks_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - Present *p = user_data; - - g_assert (frame != NULL); - g_assert (p != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_LOG) - { - SysprofMarkTimeSpan span = { frame->time, frame->time }; - g_array_append_val (p->log_marks, span); - } - - return TRUE; -} - -static gint -compare_span (const SysprofMarkTimeSpan *a, - const SysprofMarkTimeSpan *b) -{ - if (a->kind < b->kind) - return -1; - - if (b->kind < a->kind) - return 1; - - if (a->begin < b->begin) - return -1; - - if (b->begin < a->begin) - return 1; - - if (b->end > a->end) - return -1; - - return 0; -} - -static void -sysprof_logs_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *p = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (p != NULL); - g_assert (SYSPROF_IS_DISPLAY (p->display)); - g_assert (p->cursor != NULL); - g_assert (SYSPROF_IS_LOGS_AID (source_object)); - - sysprof_capture_cursor_foreach (p->cursor, find_marks_cb, p); - g_array_sort (p->log_marks, (GCompareFunc)compare_span); - - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_logs_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType logs[] = { - SYSPROF_CAPTURE_FRAME_LOG, - }; - SysprofLogsAid *self = (SysprofLogsAid *)aid; - g_autoptr(GTask) task = NULL; - Present p = {0}; - - g_assert (SYSPROF_IS_LOGS_AID (self)); - - p.display = g_object_ref (display); - p.log_marks = g_array_new (FALSE, FALSE, sizeof (SysprofMarkTimeSpan)); - p.cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (p.cursor, - sysprof_capture_condition_new_where_type_in (1, logs)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_logs_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &p), - present_free); - g_task_run_in_thread (task, sysprof_logs_aid_present_worker); -} - -static gboolean -sysprof_logs_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - Present *p; - - g_assert (SYSPROF_IS_LOGS_AID (aid)); - g_assert (G_IS_TASK (result)); - - p = g_task_get_task_data (G_TASK (result)); - - if (p->log_marks->len > 0) - { - g_autoptr(GHashTable) items = NULL; - SysprofVisualizerGroup *group; - SysprofVisualizer *marks; - SysprofPage *page; - - items = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, - (GDestroyNotify) g_array_unref); - g_hash_table_insert (items, g_strdup (_("Logs")), g_array_ref (p->log_marks)); - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "title", _("Logs"), - "visible", TRUE, - NULL); - - marks = sysprof_mark_visualizer_new (items); - sysprof_visualizer_set_title (marks, _("Logs")); - gtk_widget_show (GTK_WIDGET (marks)); - sysprof_visualizer_group_insert (group, marks, 0, FALSE); - sysprof_display_add_group (p->display, group); - - page = g_object_new (SYSPROF_TYPE_LOGS_PAGE, - "title", _("Logs"), - "visible", TRUE, - NULL); - sysprof_display_add_page (p->display, page); - - g_signal_connect_object (group, - "group-activated", - G_CALLBACK (on_group_activated_cb), - page, - 0); - } - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_logs_aid_class_init (SysprofLogsAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->present_async = sysprof_logs_aid_present_async; - aid_class->present_finish = sysprof_logs_aid_present_finish; -} - -static void -sysprof_logs_aid_init (SysprofLogsAid *self) -{ -} diff --git a/src/libsysprof-ui/sysprof-logs-aid.h b/src/libsysprof-ui/sysprof-logs-aid.h deleted file mode 100644 index 2f2d13ad..00000000 --- a/src/libsysprof-ui/sysprof-logs-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-logs-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_LOGS_AID (sysprof_logs_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofLogsAid, sysprof_logs_aid, SYSPROF, LOGS_AID, SysprofAid) - -SysprofAid *sysprof_logs_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-logs-page.c b/src/libsysprof-ui/sysprof-logs-page.c deleted file mode 100644 index f2b46af8..00000000 --- a/src/libsysprof-ui/sysprof-logs-page.c +++ /dev/null @@ -1,116 +0,0 @@ -/* sysprof-logs-page.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-logs-page" - -#include "config.h" - -#include "sysprof-log-model.h" -#include "sysprof-logs-page.h" - -struct _SysprofLogsPage -{ - SysprofPage parent_instance; - - /* Template Widgets */ - GtkTreeView *tree_view; -}; - -G_DEFINE_TYPE (SysprofLogsPage, sysprof_logs_page, SYSPROF_TYPE_PAGE) - -static void -sysprof_logs_page_load_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofLogsPage *self; - g_autoptr(SysprofLogModel) model = NULL; - g_autoptr(GError) error = NULL; - g_autoptr(GTask) task = user_data; - - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - if (!(model = sysprof_log_model_new_finish (result, &error))) - g_task_return_error (task, g_steal_pointer (&error)); - else - g_task_return_boolean (task, TRUE); - - self = g_task_get_source_object (task); - - gtk_tree_view_set_model (self->tree_view, GTK_TREE_MODEL (model)); -} - -static void -sysprof_logs_page_load_async (SysprofPage *page, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *filter, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofLogsPage *self = (SysprofLogsPage *)page; - g_autoptr(GTask) task = NULL; - - g_assert (SYSPROF_IS_LOGS_PAGE (self)); - g_assert (reader != NULL); - g_assert (!selection || SYSPROF_IS_SELECTION (selection)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_logs_page_load_async); - - sysprof_log_model_new_async (reader, - selection, - cancellable, - sysprof_logs_page_load_cb, - g_steal_pointer (&task)); -} - -static gboolean -sysprof_logs_page_load_finish (SysprofPage *page, - GAsyncResult *result, - GError **error) -{ - g_assert (SYSPROF_IS_LOGS_PAGE (page)); - g_assert (G_IS_TASK (result)); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_logs_page_class_init (SysprofLogsPageClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofPageClass *page_class = SYSPROF_PAGE_CLASS (klass); - - page_class->load_async = sysprof_logs_page_load_async; - page_class->load_finish = sysprof_logs_page_load_finish; - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-logs-page.ui"); - gtk_widget_class_bind_template_child (widget_class, SysprofLogsPage, tree_view); -} - -static void -sysprof_logs_page_init (SysprofLogsPage *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); -} diff --git a/src/libsysprof-ui/sysprof-logs-page.h b/src/libsysprof-ui/sysprof-logs-page.h deleted file mode 100644 index 97bb2455..00000000 --- a/src/libsysprof-ui/sysprof-logs-page.h +++ /dev/null @@ -1,31 +0,0 @@ -/* sysprof-logs-page.h - * - * Copyright 2019 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-page.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_LOGS_PAGE (sysprof_logs_page_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofLogsPage, sysprof_logs_page, SYSPROF, LOGS_PAGE, SysprofPage) - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-logs-page.ui b/src/libsysprof-ui/sysprof-logs-page.ui deleted file mode 100644 index 2f4d565b..00000000 --- a/src/libsysprof-ui/sysprof-logs-page.ui +++ /dev/null @@ -1,73 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-mark-detail.c b/src/libsysprof-ui/sysprof-mark-detail.c deleted file mode 100644 index d0899149..00000000 --- a/src/libsysprof-ui/sysprof-mark-detail.c +++ /dev/null @@ -1,208 +0,0 @@ -/* sysprof-mark-detail.c - * - * Copyright 2022 Corentin Noël - * - * 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 - */ - -#define G_LOG_DOMAIN "sysprof-mark-detail" - -#include "config.h" - -#include - -#include "sysprof-mark-detail.h" - -struct _SysprofMarkDetail -{ - GObject parent_instance; - - gchar *label; - gint64 min; - gint64 max; - gint64 average; - gint64 hits; -}; - -G_DEFINE_TYPE (SysprofMarkDetail, sysprof_mark_detail, G_TYPE_OBJECT) - -enum { - PROP_0, - PROP_LABEL, - PROP_MIN, - PROP_MAX, - PROP_AVERAGE, - PROP_HITS, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -/** - * sysprof_mark_detail_new: - * - * Create a new #SysprofMarkDetail. - * - * Returns: (transfer full): a newly created #SysprofMarkDetail - */ -SysprofMarkDetail * -sysprof_mark_detail_new (const gchar *mark, - gint64 min, - gint64 max, - gint64 avg, - gint64 hits) -{ - return g_object_new (SYSPROF_TYPE_MARK_DETAIL, - "label", mark, - "min", min, - "max", max, - "average", avg, - "hits", hits, - NULL); -} - -static void -sysprof_mark_detail_finalize (GObject *object) -{ - SysprofMarkDetail *self = (SysprofMarkDetail *)object; - - g_clear_pointer (&self->label, g_free); - - G_OBJECT_CLASS (sysprof_mark_detail_parent_class)->finalize (object); -} - -static void -sysprof_mark_detail_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofMarkDetail *self = SYSPROF_MARK_DETAIL(object); - - switch (prop_id) - { - case PROP_LABEL: - g_value_set_string (value, self->label); - break; - - case PROP_MIN: - g_value_set_int64 (value, self->min); - break; - - case PROP_MAX: - g_value_set_int64 (value, self->max); - break; - - case PROP_AVERAGE: - g_value_set_int64 (value, self->average); - break; - - case PROP_HITS: - g_value_set_int64 (value, self->hits); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_mark_detail_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofMarkDetail *self = SYSPROF_MARK_DETAIL(object); - - switch (prop_id) - { - case PROP_LABEL: - g_assert(self->label == NULL); - self->label = g_value_dup_string (value); - break; - - case PROP_MIN: - self->min = g_value_get_int64 (value); - break; - - case PROP_MAX: - self->max = g_value_get_int64 (value); - break; - - case PROP_AVERAGE: - self->average = g_value_get_int64 (value); - break; - - case PROP_HITS: - self->hits = g_value_get_int64 (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_mark_detail_class_init (SysprofMarkDetailClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_mark_detail_finalize; - object_class->get_property = sysprof_mark_detail_get_property; - object_class->set_property = sysprof_mark_detail_set_property; - - properties [PROP_LABEL] = - g_param_spec_string ("label", - "Label", - "The label of the mark", - NULL, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_MIN] = - g_param_spec_int64 ("min", - "Min", - "The minimal timespan", - 0, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_MAX] = - g_param_spec_int64 ("max", - "max", - "The maximal timespan", - 0, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_AVERAGE] = - g_param_spec_int64 ("average", - "Average", - "The average timespan", - 0, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_HITS] = - g_param_spec_int64 ("hits", - "Hits", - "The number of hits", - 0, G_MAXINT64, 0, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_mark_detail_init (SysprofMarkDetail *self) -{ -} diff --git a/src/libsysprof-ui/sysprof-mark-detail.h b/src/libsysprof-ui/sysprof-mark-detail.h deleted file mode 100644 index 35b292e7..00000000 --- a/src/libsysprof-ui/sysprof-mark-detail.h +++ /dev/null @@ -1,37 +0,0 @@ -/* sysprof-mark-detail.h - * - * Copyright 2022 Corentin Noël - * - * 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MARK_DETAIL (sysprof_mark_detail_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMarkDetail, sysprof_mark_detail, SYSPROF, MARK_DETAIL, GObject) - -SysprofMarkDetail *sysprof_mark_detail_new (const gchar *mark, - gint64 min, - gint64 max, - gint64 avg, - gint64 hits); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-mark-visualizer.c b/src/libsysprof-ui/sysprof-mark-visualizer.c deleted file mode 100644 index ab8a67f9..00000000 --- a/src/libsysprof-ui/sysprof-mark-visualizer.c +++ /dev/null @@ -1,276 +0,0 @@ -/* sysprof-mark-visualizer.c - * - * Copyright 2018-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-mark-visualizer" - -#include "config.h" - -#include "sysprof-mark-visualizer.h" - -#define RECT_HEIGHT (4) -#define RECT_MIN_WIDTH (3) -#define RECT_OVERLAP (-1) - -struct _SysprofMarkVisualizer -{ - SysprofVisualizer parent_instance; - GHashTable *spans_by_group; - GHashTable *rgba_by_group; - GHashTable *rgba_by_kind; - GHashTable *row_by_kind; - guint x_is_dirty : 1; -}; - -G_DEFINE_TYPE (SysprofMarkVisualizer, sysprof_mark_visualizer, SYSPROF_TYPE_VISUALIZER) - -static void -reset_positions (SysprofMarkVisualizer *self) -{ - g_assert (SYSPROF_IS_MARK_VISUALIZER (self)); - - self->x_is_dirty = TRUE; - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -SysprofVisualizer * -sysprof_mark_visualizer_new (GHashTable *groups) -{ - SysprofMarkVisualizer *self; - guint n_items; - gint height; - - g_return_val_if_fail (groups != NULL, NULL); - - self = g_object_new (SYSPROF_TYPE_MARK_VISUALIZER, NULL); - self->spans_by_group = g_hash_table_ref (groups); - - reset_positions (self); - - n_items = g_hash_table_size (groups); - height = MAX (35, n_items * (RECT_HEIGHT - RECT_OVERLAP)); - gtk_widget_set_size_request (GTK_WIDGET (self), -1, height); - - return SYSPROF_VISUALIZER (g_steal_pointer (&self)); -} - -static void -sysprof_mark_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofMarkVisualizer *self = (SysprofMarkVisualizer *)widget; - SysprofVisualizer *vis = (SysprofVisualizer *)widget; - static const GdkRGBA black = {0,0,0,1}; - const GdkRGBA *rgba = &black; - GHashTableIter iter; - GtkAllocation alloc; - gpointer k, v; - int n_groups = 0; - int y = 0; - - g_assert (SYSPROF_IS_MARK_VISUALIZER (self)); - g_assert (snapshot != NULL); - - GTK_WIDGET_CLASS (sysprof_mark_visualizer_parent_class)->snapshot (widget, snapshot); - - if (self->spans_by_group == NULL) - return; - - gtk_widget_get_allocation (widget, &alloc); - - /* Pre-calculate all time slots so we can join later */ - if (self->x_is_dirty) - { - g_hash_table_iter_init (&iter, self->spans_by_group); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - const GArray *spans = v; - - for (guint i = 0; i < spans->len; i++) - { - SysprofMarkTimeSpan *span = &g_array_index (spans, SysprofMarkTimeSpan, i); - - span->x = sysprof_visualizer_get_x_for_time (vis, span->begin); - span->x2 = sysprof_visualizer_get_x_for_time (vis, span->end); - } - } - - self->x_is_dirty = FALSE; - } - - n_groups = g_hash_table_size (self->spans_by_group); - - g_hash_table_iter_init (&iter, self->spans_by_group); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - SysprofMarkTimeSpan *span; - const gchar *group = k; - const GArray *spans = v; - const GdkRGBA *kindrgba; - const GdkRGBA *grouprgba; - - if ((grouprgba = g_hash_table_lookup (self->rgba_by_group, group))) - rgba = grouprgba; - - for (guint i = 0; i < spans->len; i++) - { - gint x1, x2; - - span = &g_array_index (spans, SysprofMarkTimeSpan, i); - - if (n_groups == 1) - { - rgba = &black; - if ((kindrgba = g_hash_table_lookup (self->rgba_by_kind, GUINT_TO_POINTER (span->kind)))) - rgba = kindrgba; - else if ((grouprgba = g_hash_table_lookup (self->rgba_by_group, group))) - rgba = grouprgba; - } - - x1 = span->x; - x2 = x1 + RECT_MIN_WIDTH; - - if (span->x2 > x2) - x2 = span->x2; - - /* If we are limited to one group, we might need to get the row - * height for the kind of span this is. - */ - if (n_groups == 1) - { - gint row = GPOINTER_TO_INT (g_hash_table_lookup (self->row_by_kind, GUINT_TO_POINTER (span->kind))); - y = row * (RECT_HEIGHT - RECT_OVERLAP); - } - - for (guint j = i + 1; j < spans->len; j++) - { - const SysprofMarkTimeSpan *next = &g_array_index (spans, SysprofMarkTimeSpan, j); - - /* Don't join this if we are about to draw a different kind */ - if (n_groups == 1 && next->kind != span->kind) - break; - - if (next->x <= x2) - { - x2 = MAX (x2, next->x2); - i++; - continue; - } - - break; - } - - gtk_snapshot_append_color (snapshot, rgba, &GRAPHENE_RECT_INIT (x1, y, x2 - x1, RECT_HEIGHT)); - } - - y += RECT_HEIGHT + RECT_OVERLAP; - } -} - -static void -sysprof_mark_visualizer_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - SysprofMarkVisualizer *self = (SysprofMarkVisualizer *)widget; - - g_assert (SYSPROF_IS_MARK_VISUALIZER (self)); - - GTK_WIDGET_CLASS (sysprof_mark_visualizer_parent_class)->size_allocate (widget, width, height, baseline); - - reset_positions (self); -} - -static void -sysprof_mark_visualizer_finalize (GObject *object) -{ - SysprofMarkVisualizer *self = (SysprofMarkVisualizer *)object; - - g_clear_pointer (&self->spans_by_group, g_hash_table_unref); - g_clear_pointer (&self->rgba_by_group, g_hash_table_unref); - g_clear_pointer (&self->rgba_by_kind, g_hash_table_unref); - g_clear_pointer (&self->row_by_kind, g_hash_table_unref); - - G_OBJECT_CLASS (sysprof_mark_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_mark_visualizer_class_init (SysprofMarkVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->finalize = sysprof_mark_visualizer_finalize; - - widget_class->snapshot = sysprof_mark_visualizer_snapshot; - widget_class->size_allocate = sysprof_mark_visualizer_size_allocate; -} - -static void -sysprof_mark_visualizer_init (SysprofMarkVisualizer *self) -{ - self->rgba_by_kind = g_hash_table_new_full (NULL, NULL, NULL, g_free); - self->row_by_kind = g_hash_table_new (NULL, NULL); - self->rgba_by_group = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); -} - -void -sysprof_mark_visualizer_set_group_rgba (SysprofMarkVisualizer *self, - const gchar *group, - const GdkRGBA *rgba) -{ - g_return_if_fail (SYSPROF_IS_MARK_VISUALIZER (self)); - g_return_if_fail (group != NULL); - - g_hash_table_insert (self->rgba_by_group, - g_strdup (group), - g_memdup2 (rgba, sizeof *rgba)); -} - -void -sysprof_mark_visualizer_set_kind_rgba (SysprofMarkVisualizer *self, - GHashTable *rgba_by_kind) -{ - g_return_if_fail (SYSPROF_IS_MARK_VISUALIZER (self)); - - if (rgba_by_kind != self->rgba_by_kind) - { - g_hash_table_remove_all (self->row_by_kind); - - g_clear_pointer (&self->rgba_by_kind, g_hash_table_unref); - - if (rgba_by_kind) - { - GHashTableIter iter; - guint row = 0; - gpointer k; - - self->rgba_by_kind = g_hash_table_ref (rgba_by_kind); - - g_hash_table_iter_init (&iter, rgba_by_kind); - while (g_hash_table_iter_next (&iter, &k, NULL)) - g_hash_table_insert (self->row_by_kind, k, GUINT_TO_POINTER (row++)); - - gtk_widget_set_size_request (GTK_WIDGET (self), - -1, - MAX (35, row * (RECT_HEIGHT - RECT_OVERLAP))); - } - } -} diff --git a/src/libsysprof-ui/sysprof-mark-visualizer.h b/src/libsysprof-ui/sysprof-mark-visualizer.h deleted file mode 100644 index 36327e13..00000000 --- a/src/libsysprof-ui/sysprof-mark-visualizer.h +++ /dev/null @@ -1,47 +0,0 @@ -/* sysprof-mark-visualizer.h - * - * Copyright 2018-2019 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-visualizer.h" - -G_BEGIN_DECLS - -typedef struct -{ - gint64 begin; - gint64 end; - guint kind; - gint x; - gint x2; -} SysprofMarkTimeSpan; - -#define SYSPROF_TYPE_MARK_VISUALIZER (sysprof_mark_visualizer_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMarkVisualizer, sysprof_mark_visualizer, SYSPROF, MARK_VISUALIZER, SysprofVisualizer) - -SysprofVisualizer *sysprof_mark_visualizer_new (GHashTable *groups); -void sysprof_mark_visualizer_set_group_rgba (SysprofMarkVisualizer *self, - const gchar *group, - const GdkRGBA *rgba); -void sysprof_mark_visualizer_set_kind_rgba (SysprofMarkVisualizer *self, - GHashTable *rgba_by_kind); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-marks-aid.c b/src/libsysprof-ui/sysprof-marks-aid.c deleted file mode 100644 index 4361dfab..00000000 --- a/src/libsysprof-ui/sysprof-marks-aid.c +++ /dev/null @@ -1,490 +0,0 @@ -/* sysprof-marks-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-marks-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-marks-aid.h" -#include "sysprof-marks-page.h" -#include "sysprof-mark-visualizer.h" - -struct _SysprofMarksAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofDisplay *display; - SysprofCaptureCursor *cursor; - GHashTable *categories; - GHashTable *kinds; - guint last_kind; - guint has_marks : 1; -} Present; - -G_DEFINE_TYPE (SysprofMarksAid, sysprof_marks_aid, SYSPROF_TYPE_AID) - -static void -rgb_to_hls (gdouble *r, - gdouble *g, - gdouble *b) -{ - gdouble min; - gdouble max; - gdouble red; - gdouble green; - gdouble blue; - gdouble h, l, s; - gdouble delta; - - red = *r; - green = *g; - blue = *b; - if (red > green) - { - if (red > blue) - max = red; - else - max = blue; - if (green < blue) - min = green; - else - min = blue; - } - else - { - if (green > blue) - max = green; - else - max = blue; - if (red < blue) - min = red; - else - min = blue; - } - l = (max + min) / 2; - s = 0; - h = 0; - if (max != min) - { - if (l <= 0.5) - s = (max - min) / (max + min); - else - s = (max - min) / (2 - max - min); - delta = max - min; - if (red == max) - h = (green - blue) / delta; - else if (green == max) - h = 2 + (blue - red) / delta; - else if (blue == max) - h = 4 + (red - green) / delta; - h *= 60; - if (h < 0.0) - h += 360; - } - *r = h; - *g = l; - *b = s; -} - -static void -hls_to_rgb (gdouble *h, - gdouble *l, - gdouble *s) -{ - gdouble hue; - gdouble lightness; - gdouble saturation; - gdouble m1, m2; - gdouble r, g, b; - - lightness = *l; - saturation = *s; - if (lightness <= 0.5) - m2 = lightness * (1 + saturation); - else - m2 = lightness + saturation - lightness * saturation; - m1 = 2 * lightness - m2; - if (saturation == 0) - { - *h = lightness; - *l = lightness; - *s = lightness; - } - else - { - hue = *h + 120; - while (hue > 360) - hue -= 360; - while (hue < 0) - hue += 360; - if (hue < 60) - r = m1 + (m2 - m1) * hue / 60; - else if (hue < 180) - r = m2; - else if (hue < 240) - r = m1 + (m2 - m1) * (240 - hue) / 60; - else - r = m1; - hue = *h; - while (hue > 360) - hue -= 360; - while (hue < 0) - hue += 360; - if (hue < 60) - g = m1 + (m2 - m1) * hue / 60; - else if (hue < 180) - g = m2; - else if (hue < 240) - g = m1 + (m2 - m1) * (240 - hue) / 60; - else - g = m1; - hue = *h - 120; - while (hue > 360) - hue -= 360; - while (hue < 0) - hue += 360; - if (hue < 60) - b = m1 + (m2 - m1) * hue / 60; - else if (hue < 180) - b = m2; - else if (hue < 240) - b = m1 + (m2 - m1) * (240 - hue) / 60; - else - b = m1; - *h = r; - *l = g; - *s = b; - } -} - -static void -rgba_shade (const GdkRGBA *rgba, - GdkRGBA *dst, - gdouble k) -{ - gdouble red; - gdouble green; - gdouble blue; - - red = rgba->red; - green = rgba->green; - blue = rgba->blue; - - rgb_to_hls (&red, &green, &blue); - - green *= k; - - if (green > 1.0) - green = 1.0; - else if (green < 0.0) - green = 0.0; - - blue *= k; - - if (blue > 1.0) - blue = 1.0; - else if (blue < 0.0) - blue = 0.0; - - hls_to_rgb (&red, &green, &blue); - - dst->red = red; - dst->green = green; - dst->blue = blue; - dst->alpha = rgba->alpha; -} - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->categories, g_hash_table_unref); - g_clear_pointer (&p->kinds, g_hash_table_unref); - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -static void -on_group_activated_cb (SysprofVisualizerGroup *group, - SysprofPage *page) -{ - SysprofDisplay *display; - - g_assert (SYSPROF_IS_VISUALIZER_GROUP (group)); - g_assert (SYSPROF_IS_PAGE (page)); - - display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (page), SYSPROF_TYPE_DISPLAY)); - sysprof_display_set_visible_page (display, page); -} - -/** - * sysprof_marks_aid_new: - * - * Create a new #SysprofMarksAid. - * - * Returns: (transfer full): a newly created #SysprofMarksAid - */ -SysprofAid * -sysprof_marks_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_MARKS_AID, NULL); -} - -static bool -find_marks_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - Present *p = user_data; - - g_assert (frame != NULL); - g_assert (p != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_MARK) - { - const SysprofCaptureMark *mark = (const SysprofCaptureMark *)frame; - SysprofMarkTimeSpan span = { frame->time, frame->time + mark->duration }; - gchar joined[64]; - gpointer kptr; - GArray *items; - - p->has_marks = TRUE; - - if G_UNLIKELY (!(items = g_hash_table_lookup (p->categories, mark->group))) - { - items = g_array_new (FALSE, FALSE, sizeof (SysprofMarkTimeSpan)); - g_hash_table_insert (p->categories, g_strdup (mark->group), items); - } - - g_snprintf (joined, sizeof joined, "%s:%s", mark->group, mark->name); - - if G_UNLIKELY (!(kptr = g_hash_table_lookup (p->kinds, joined))) - { - p->last_kind++; - kptr = GINT_TO_POINTER (p->last_kind); - g_hash_table_insert (p->kinds, g_strdup (joined), kptr); - } - - span.kind = GPOINTER_TO_INT (kptr); - - g_array_append_val (items, span); - } - - return TRUE; -} - -static gint -compare_span (const SysprofMarkTimeSpan *a, - const SysprofMarkTimeSpan *b) -{ - if (a->kind < b->kind) - return -1; - - if (b->kind < a->kind) - return 1; - - if (a->begin < b->begin) - return -1; - - if (b->begin < a->begin) - return 1; - - if (b->end > a->end) - return -1; - - return 0; -} - -static void -sysprof_marks_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *p = task_data; - GHashTableIter iter; - gpointer k, v; - - g_assert (G_IS_TASK (task)); - g_assert (p != NULL); - g_assert (SYSPROF_IS_DISPLAY (p->display)); - g_assert (p->cursor != NULL); - g_assert (SYSPROF_IS_MARKS_AID (source_object)); - - sysprof_capture_cursor_foreach (p->cursor, find_marks_cb, p); - - g_hash_table_iter_init (&iter, p->categories); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - GArray *spans = v; - - g_array_sort (spans, (GCompareFunc)compare_span); - } - - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_marks_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType marks[] = { - SYSPROF_CAPTURE_FRAME_MARK, - }; - SysprofMarksAid *self = (SysprofMarksAid *)aid; - g_autoptr(GTask) task = NULL; - Present p = {0}; - - g_assert (SYSPROF_IS_MARKS_AID (self)); - - p.display = g_object_ref (display); - p.categories = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, - (GDestroyNotify) g_array_unref); - p.kinds = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); - p.cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (p.cursor, - sysprof_capture_condition_new_where_type_in (1, marks)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_marks_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &p), - present_free); - g_task_run_in_thread (task, sysprof_marks_aid_present_worker); -} - -static gboolean -sysprof_marks_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - Present *p; - - g_assert (SYSPROF_IS_MARKS_AID (aid)); - g_assert (G_IS_TASK (result)); - - p = g_task_get_task_data (G_TASK (result)); - - if (p->has_marks) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - SysprofVisualizerGroup *group; - SysprofVisualizer *marks; - SysprofPage *page; - GHashTableIter iter; - gpointer k, v; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "has-page", TRUE, - "title", _("Timings"), - "visible", TRUE, - NULL); - - marks = sysprof_mark_visualizer_new (p->categories); - sysprof_visualizer_set_title (marks, _("Timings")); - gtk_widget_show (GTK_WIDGET (marks)); - - g_hash_table_iter_init (&iter, p->categories); - while (g_hash_table_iter_next (&iter, &k, &v)) - { - g_autoptr(GHashTable) seen = g_hash_table_new_full (NULL, NULL, NULL, g_free); - g_autoptr(GHashTable) scoped = NULL; - SysprofVisualizer *scoped_vis; - GArray *spans = v; - const gchar *name = k; - GdkRGBA rgba; - GdkRGBA kind_rgba; - gdouble ratio; - - sysprof_color_cycle_next (cycle, &rgba); - sysprof_mark_visualizer_set_group_rgba (SYSPROF_MARK_VISUALIZER (marks), name, &rgba); - - /* Now make a scoped row just for this group */ - scoped = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, - (GDestroyNotify)g_array_unref); - g_hash_table_insert (scoped, g_strdup (name), g_array_ref (spans)); - - scoped_vis = sysprof_mark_visualizer_new (scoped); - sysprof_visualizer_set_title (scoped_vis, name); - sysprof_mark_visualizer_set_group_rgba (SYSPROF_MARK_VISUALIZER (scoped_vis), name, &rgba); - sysprof_visualizer_group_insert (group, scoped_vis, -1, TRUE); - - ratio = .4 / p->last_kind; - - for (guint i = 0; i < spans->len; i++) - { - const SysprofMarkTimeSpan *span = &g_array_index (spans, SysprofMarkTimeSpan, i); - - if (!g_hash_table_contains (seen, GUINT_TO_POINTER (span->kind))) - { - rgba_shade (&rgba, &kind_rgba, 1 + (ratio * span->kind)); - g_hash_table_insert (seen, - GUINT_TO_POINTER (span->kind), - g_memdup2 (&kind_rgba, sizeof kind_rgba)); - } - } - - sysprof_mark_visualizer_set_kind_rgba (SYSPROF_MARK_VISUALIZER (scoped_vis), seen); - } - - page = g_object_new (SYSPROF_TYPE_MARKS_PAGE, - "zoom-manager", sysprof_display_get_zoom_manager (p->display), - "visible", TRUE, - NULL); - - g_signal_connect_object (group, - "group-activated", - G_CALLBACK (on_group_activated_cb), - page, - 0); - - sysprof_visualizer_group_insert (group, marks, 0, FALSE); - sysprof_display_add_group (p->display, group); - sysprof_display_add_page (p->display, page); - } - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_marks_aid_class_init (SysprofMarksAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->present_async = sysprof_marks_aid_present_async; - aid_class->present_finish = sysprof_marks_aid_present_finish; -} - -static void -sysprof_marks_aid_init (SysprofMarksAid *self) -{ -} diff --git a/src/libsysprof-ui/sysprof-marks-aid.h b/src/libsysprof-ui/sysprof-marks-aid.h deleted file mode 100644 index f201f3aa..00000000 --- a/src/libsysprof-ui/sysprof-marks-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-marks-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MARKS_AID (sysprof_marks_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMarksAid, sysprof_marks_aid, SYSPROF, MARKS_AID, SysprofAid) - -SysprofAid *sysprof_marks_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-marks-model.c b/src/libsysprof-ui/sysprof-marks-model.c deleted file mode 100644 index 08000641..00000000 --- a/src/libsysprof-ui/sysprof-marks-model.c +++ /dev/null @@ -1,592 +0,0 @@ -/* sysprof-marks-model.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-marks-model" - -#include "config.h" - -#include - -#include "sysprof-marks-model.h" - -struct _SysprofMarksModel -{ - GObject parent_instance; - GStringChunk *chunks; - GHashTable *counters; - GArray *items; - gint64 max_end_time; -}; - -typedef struct -{ - gint64 begin_time; - gint64 end_time; - const gchar *group; - const gchar *name; - const gchar *message; - SysprofCaptureCounterValue value; - guint is_counter : 1; - guint counter_type : 8; -} Item; - -static void -counter_free (gpointer data) -{ - g_slice_free (SysprofCaptureCounter, data); -} - -static gint -sysprof_marks_model_get_n_columns (GtkTreeModel *model) -{ - return SYSPROF_MARKS_MODEL_COLUMN_LAST; -} - -static GType -sysprof_marks_model_get_column_type (GtkTreeModel *model, - gint column) -{ - switch (column) - { - case SYSPROF_MARKS_MODEL_COLUMN_GROUP: - return G_TYPE_STRING; - - case SYSPROF_MARKS_MODEL_COLUMN_NAME: - return G_TYPE_STRING; - - case SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME: - return G_TYPE_INT64; - - case SYSPROF_MARKS_MODEL_COLUMN_END_TIME: - return G_TYPE_INT64; - - case SYSPROF_MARKS_MODEL_COLUMN_DURATION: - return G_TYPE_DOUBLE; - - case SYSPROF_MARKS_MODEL_COLUMN_TEXT: - return G_TYPE_STRING; - - default: - return 0; - } -} - -static GtkTreePath * -sysprof_marks_model_get_path (GtkTreeModel *model, - GtkTreeIter *iter) -{ - gint off; - - g_assert (SYSPROF_IS_MARKS_MODEL (model)); - g_assert (iter != NULL); - - off = GPOINTER_TO_INT (iter->user_data); - - return gtk_tree_path_new_from_indices (off, -1); -} - -static gboolean -sysprof_marks_model_get_iter (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreePath *path) -{ - SysprofMarksModel *self = (SysprofMarksModel *)model; - gint off; - - g_assert (SYSPROF_IS_MARKS_MODEL (self)); - g_assert (iter != NULL); - g_assert (path != NULL); - - memset (iter, 0, sizeof *iter); - - if (gtk_tree_path_get_depth (path) != 1) - return FALSE; - - off = gtk_tree_path_get_indices (path)[0]; - iter->user_data = GINT_TO_POINTER (off); - - return off >= 0 && off < self->items->len; -} - -static gboolean -sysprof_marks_model_iter_next (GtkTreeModel *model, - GtkTreeIter *iter) -{ - SysprofMarksModel *self = (SysprofMarksModel *)model; - gint off; - - g_assert (SYSPROF_IS_MARKS_MODEL (self)); - g_assert (iter != NULL); - - off = GPOINTER_TO_INT (iter->user_data); - off++; - iter->user_data = GINT_TO_POINTER (off); - - return off < self->items->len; -} - -static gboolean -sysprof_marks_model_iter_nth_child (GtkTreeModel *model, - GtkTreeIter *iter, - GtkTreeIter *parent, - gint n) -{ - SysprofMarksModel *self = (SysprofMarksModel *)model; - - g_assert (SYSPROF_IS_MARKS_MODEL (self)); - g_assert (iter != NULL); - - if (parent != NULL) - return FALSE; - - iter->user_data = GINT_TO_POINTER (n); - - return n < self->items->len; -} - -static gint -sysprof_marks_model_iter_n_children (GtkTreeModel *model, - GtkTreeIter *iter) -{ - SysprofMarksModel *self = (SysprofMarksModel *)model; - - g_assert (SYSPROF_IS_MARKS_MODEL (self)); - - return iter ? 0 : self->items->len; -} - -static gboolean -sysprof_marks_model_iter_has_child (GtkTreeModel *model, - GtkTreeIter *iter) -{ - return FALSE; -} - -static GtkTreeModelFlags -sysprof_marks_model_get_flags (GtkTreeModel *model) -{ - return GTK_TREE_MODEL_LIST_ONLY; -} - -static void -sysprof_marks_model_get_value (GtkTreeModel *model, - GtkTreeIter *iter, - gint column, - GValue *value) -{ - SysprofMarksModel *self = (SysprofMarksModel *)model; - const Item *item; - - g_assert (SYSPROF_IS_MARKS_MODEL (self)); - g_assert (iter != NULL); - g_assert (column < SYSPROF_MARKS_MODEL_COLUMN_LAST); - - item = &g_array_index (self->items, Item, GPOINTER_TO_INT (iter->user_data)); - - switch (column) - { - case SYSPROF_MARKS_MODEL_COLUMN_GROUP: - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, item->group); - break; - - case SYSPROF_MARKS_MODEL_COLUMN_NAME: - g_value_init (value, G_TYPE_STRING); - g_value_set_string (value, item->name); - break; - - case SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME: - g_value_init (value, G_TYPE_INT64); - g_value_set_int64 (value, item->begin_time); - break; - - case SYSPROF_MARKS_MODEL_COLUMN_END_TIME: - g_value_init (value, G_TYPE_INT64); - g_value_set_int64 (value, item->end_time); - break; - - case SYSPROF_MARKS_MODEL_COLUMN_DURATION: - g_value_init (value, G_TYPE_DOUBLE); - if (item->end_time) - g_value_set_double (value, (item->end_time - item->begin_time) / (double)(G_USEC_PER_SEC * 1000)); - break; - - case SYSPROF_MARKS_MODEL_COLUMN_TEXT: - g_value_init (value, G_TYPE_STRING); - if (item->is_counter) - { - gchar *val = NULL; - - if (item->counter_type == SYSPROF_CAPTURE_COUNTER_DOUBLE) - val = g_strdup_printf ("%s — %s = %.4lf", item->group, item->name, item->value.vdbl); - else if (item->counter_type == SYSPROF_CAPTURE_COUNTER_INT64) - val = g_strdup_printf ("%s — %s = %"G_GINT64_FORMAT, item->group, item->name, item->value.v64); - - g_value_take_string (value, g_steal_pointer (&val)); - } - else - { - if (item->message && item->message[0]) - g_value_take_string (value, g_strdup_printf ("%s — %s", item->name, item->message)); - else - g_value_set_string (value, item->name); - } - break; - - default: - break; - } -} - -static void -tree_model_iface_init (GtkTreeModelIface *iface) -{ - iface->get_n_columns = sysprof_marks_model_get_n_columns; - iface->get_column_type = sysprof_marks_model_get_column_type; - iface->get_iter = sysprof_marks_model_get_iter; - iface->get_path = sysprof_marks_model_get_path; - iface->iter_next = sysprof_marks_model_iter_next; - iface->iter_n_children = sysprof_marks_model_iter_n_children; - iface->iter_nth_child = sysprof_marks_model_iter_nth_child; - iface->iter_has_child = sysprof_marks_model_iter_has_child; - iface->get_flags = sysprof_marks_model_get_flags; - iface->get_value = sysprof_marks_model_get_value; -} - -G_DEFINE_TYPE_WITH_CODE (SysprofMarksModel, sysprof_marks_model, G_TYPE_OBJECT, - G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL, tree_model_iface_init)) - -static void -sysprof_marks_model_finalize (GObject *object) -{ - SysprofMarksModel *self = (SysprofMarksModel *)object; - - g_clear_pointer (&self->counters, g_hash_table_unref); - g_clear_pointer (&self->items, g_array_unref); - g_clear_pointer (&self->chunks, g_string_chunk_free); - - G_OBJECT_CLASS (sysprof_marks_model_parent_class)->finalize (object); -} - -static void -sysprof_marks_model_class_init (SysprofMarksModelClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_marks_model_finalize; -} - -static void -sysprof_marks_model_init (SysprofMarksModel *self) -{ - self->counters = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, counter_free); - self->chunks = g_string_chunk_new (4096*16); - self->items = g_array_new (FALSE, FALSE, sizeof (Item)); -} - -static bool -cursor_foreach_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofMarksModel *self = user_data; - Item item; - - g_assert (SYSPROF_IS_MARKS_MODEL (self)); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_MARK || - frame->type == SYSPROF_CAPTURE_FRAME_CTRSET || - frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF || - frame->type == SYSPROF_CAPTURE_FRAME_FORK); - - if (frame->type == SYSPROF_CAPTURE_FRAME_MARK) - { - SysprofCaptureMark *mark = (SysprofCaptureMark *)frame; - - item.begin_time = frame->time; - item.end_time = item.begin_time + mark->duration; - item.group = g_string_chunk_insert_const (self->chunks, mark->group); - item.name = g_string_chunk_insert_const (self->chunks, mark->name); - item.message = g_string_chunk_insert_const (self->chunks, mark->message); - item.value.v64 = 0; - item.is_counter = FALSE; - item.counter_type = 0; - - if G_LIKELY (item.end_time > self->max_end_time) - self->max_end_time = item.end_time; - - g_array_append_val (self->items, item); - } - else if (frame->type == SYSPROF_CAPTURE_FRAME_FORK) - { - SysprofCaptureFork *fk = (SysprofCaptureFork *)frame; - g_autofree gchar *message = g_strdup_printf ("PID: %d, Child PID: %d", frame->pid, fk->child_pid); - - item.begin_time = frame->time; - item.end_time = item.begin_time; - item.group = g_string_chunk_insert_const (self->chunks, "fork"); - item.name = g_string_chunk_insert_const (self->chunks, "Fork"); - item.message = g_string_chunk_insert_const (self->chunks, message); - item.value.v64 = 0; - item.is_counter = FALSE; - item.counter_type = 0; - - g_array_append_val (self->items, item); - } - else if (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF) - { - SysprofCaptureCounterDefine *ctrdef = (SysprofCaptureCounterDefine *)frame; - - for (guint i = 0; i < ctrdef->n_counters; i++) - { - SysprofCaptureCounter *ctr = &ctrdef->counters[i]; - - g_hash_table_insert (self->counters, - GUINT_TO_POINTER ((guint)ctr->id), - g_slice_dup (SysprofCaptureCounter, ctr)); - } - } - else if (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET) - { - SysprofCaptureCounterSet *ctrset = (SysprofCaptureCounterSet *)frame; - - for (guint i = 0; i < ctrset->n_values; i++) - { - SysprofCaptureCounterValues *values = &ctrset->values[i]; - - for (guint j = 0; j < G_N_ELEMENTS (values->ids); j++) - { - guint32 id = values->ids[j]; - SysprofCaptureCounter *ctr = NULL; - - if (id == 0) - break; - - if ((ctr = g_hash_table_lookup (self->counters, GUINT_TO_POINTER (id)))) - { - item.begin_time = frame->time; - item.end_time = frame->time; - item.group = ctr->category; - item.name = ctr->name; - item.message = NULL; - item.is_counter = TRUE; - item.counter_type = ctr->type; - - memcpy (&item.value, &values->values[j], sizeof item.value); - - g_array_append_val (self->items, item); - } - } - - } - } - - return TRUE; -} - -static gint -item_compare (gconstpointer a, - gconstpointer b) -{ - const Item *ia = a; - const Item *ib = b; - - if (ia->begin_time < ib->begin_time) - return -1; - else if (ia->begin_time > ib->begin_time) - return 1; - - /* Sort items with longer duration first, as they might be - * "overarching" marks containing other marks. - */ - if (ia->end_time > ib->end_time) - return -1; - else if (ib->end_time > ia->end_time) - return 1; - - return 0; -} - -static void -sysprof_marks_model_new_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - g_autoptr(SysprofMarksModel) self = NULL; - SysprofCaptureCursor *cursor = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - self = g_object_new (SYSPROF_TYPE_MARKS_MODEL, NULL); - sysprof_capture_cursor_foreach (cursor, cursor_foreach_cb, self); - g_array_sort (self->items, item_compare); - - g_task_return_pointer (task, g_steal_pointer (&self), g_object_unref); -} - -static void -sysprof_marks_model_selection_foreach_cb (SysprofSelection *selection, - gint64 begin, - gint64 end, - gpointer user_data) -{ - SysprofCaptureCondition **condition = user_data; - SysprofCaptureCondition *c; - - g_assert (SYSPROF_IS_SELECTION (selection)); - g_assert (condition != NULL); - - c = sysprof_capture_condition_new_where_time_between (begin, end); - - if (*condition != NULL) - *condition = sysprof_capture_condition_new_or (g_steal_pointer (&c), - g_steal_pointer (condition)); - else - *condition = g_steal_pointer (&c); -} - -void -sysprof_marks_model_new_async (SysprofCaptureReader *reader, - SysprofMarksModelKind kind, - SysprofSelection *selection, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType ctrset[] = { SYSPROF_CAPTURE_FRAME_CTRDEF }; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - SysprofCaptureCondition *c; - - g_return_if_fail (reader != NULL); - g_return_if_fail (!selection || SYSPROF_IS_SELECTION (selection)); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - cursor = sysprof_capture_cursor_new (reader); - - if (kind == SYSPROF_MARKS_MODEL_BOTH) - { - static const SysprofCaptureFrameType types[] = { - SYSPROF_CAPTURE_FRAME_CTRSET, - SYSPROF_CAPTURE_FRAME_MARK, - }; - - c = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - } - else if (kind == SYSPROF_MARKS_MODEL_MARKS) - { - static const SysprofCaptureFrameType types[] = { - SYSPROF_CAPTURE_FRAME_MARK, - SYSPROF_CAPTURE_FRAME_FORK, - }; - - c = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - } - else if (kind == SYSPROF_MARKS_MODEL_COUNTERS) - { - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_CTRSET }; - - c = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - } - else - { - g_task_report_new_error (NULL, callback, user_data, - sysprof_marks_model_new_async, - G_IO_ERROR, - G_IO_ERROR_INVAL, - "Invalid arguments"); - return; - } - - if (selection) - { - SysprofCaptureCondition *condition = NULL; - - sysprof_selection_foreach (selection, - sysprof_marks_model_selection_foreach_cb, - &condition); - if (condition) - c = sysprof_capture_condition_new_and (c, g_steal_pointer (&condition)); - } - - if (kind & SYSPROF_MARKS_MODEL_COUNTERS) - { - c = sysprof_capture_condition_new_or ( - sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (ctrset), ctrset), - g_steal_pointer (&c)); - } - - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&c)); - - task = g_task_new (NULL, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_marks_model_new_async); - g_task_set_task_data (task, - g_steal_pointer (&cursor), - (GDestroyNotify) sysprof_capture_cursor_unref); - g_task_run_in_thread (task, sysprof_marks_model_new_worker); -} - -SysprofMarksModel * -sysprof_marks_model_new_finish (GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (G_IS_TASK (result), NULL); - - return g_task_propagate_pointer (G_TASK (result), error); -} - -void -sysprof_marks_model_get_range (SysprofMarksModel *self, - gint64 *begin_time, - gint64 *end_time) -{ - g_return_if_fail (SYSPROF_IS_MARKS_MODEL (self)); - - if (begin_time != NULL) - { - *begin_time = 0; - - if (self->items->len > 0) - *begin_time = g_array_index (self->items, Item, 0).begin_time; - } - - if (end_time != NULL) - *end_time = self->max_end_time; -} - -GType -sysprof_marks_model_kind_get_type (void) -{ - static GType type_id; - - if (g_once_init_enter (&type_id)) - { - static const GEnumValue values[] = { - { SYSPROF_MARKS_MODEL_MARKS, "SYSPROF_MARKS_MODEL_MARKS", "marks" }, - { SYSPROF_MARKS_MODEL_COUNTERS, "SYSPROF_MARKS_MODEL_COUNTERS", "counters" }, - { SYSPROF_MARKS_MODEL_BOTH, "SYSPROF_MARKS_MODEL_BOTH", "both" }, - { 0 }, - }; - GType _type_id = g_enum_register_static ("SysprofMarksModelKind", values); - g_once_init_leave (&type_id, _type_id); - } - - return type_id; -} diff --git a/src/libsysprof-ui/sysprof-marks-model.h b/src/libsysprof-ui/sysprof-marks-model.h deleted file mode 100644 index 203ad8ec..00000000 --- a/src/libsysprof-ui/sysprof-marks-model.h +++ /dev/null @@ -1,65 +0,0 @@ -/* sysprof-marks-model.h - * - * Copyright 2019 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 -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MARKS_MODEL (sysprof_marks_model_get_type()) -#define SYSPROF_TYPE_MARKS_MODEL_KIND (sysprof_marks_model_kind_get_type()) - -typedef enum -{ - SYSPROF_MARKS_MODEL_COLUMN_GROUP, - SYSPROF_MARKS_MODEL_COLUMN_NAME, - SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME, - SYSPROF_MARKS_MODEL_COLUMN_END_TIME, - SYSPROF_MARKS_MODEL_COLUMN_DURATION, - SYSPROF_MARKS_MODEL_COLUMN_TEXT, -} SysprofMarksModelColumn; - -typedef enum -{ - SYSPROF_MARKS_MODEL_MARKS = 1, - SYSPROF_MARKS_MODEL_COUNTERS, - SYSPROF_MARKS_MODEL_BOTH = SYSPROF_MARKS_MODEL_MARKS | SYSPROF_MARKS_MODEL_COUNTERS, -} SysprofMarksModelKind; - -#define SYSPROF_MARKS_MODEL_COLUMN_LAST (SYSPROF_MARKS_MODEL_COLUMN_TEXT+1) - -G_DECLARE_FINAL_TYPE (SysprofMarksModel, sysprof_marks_model, SYSPROF, MARKS_MODEL, GObject) - -GType sysprof_marks_model_kind_get_type (void) G_GNUC_CONST; -void sysprof_marks_model_new_async (SysprofCaptureReader *reader, - SysprofMarksModelKind kind, - SysprofSelection *selection, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -SysprofMarksModel *sysprof_marks_model_new_finish (GAsyncResult *result, - GError **error); -void sysprof_marks_model_get_range (SysprofMarksModel *self, - gint64 *begin_time, - gint64 *end_time); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-marks-page.c b/src/libsysprof-ui/sysprof-marks-page.c deleted file mode 100644 index c08381b9..00000000 --- a/src/libsysprof-ui/sysprof-marks-page.c +++ /dev/null @@ -1,610 +0,0 @@ -/* sysprof-marks-page.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-marks-page" - -#include "config.h" - -#include "sysprof-cell-renderer-duration.h" -#include "sysprof-marks-model.h" -#include "sysprof-marks-page.h" -#include "sysprof-ui-private.h" -#include "sysprof-zoom-manager.h" - -typedef struct -{ - SysprofMarksModelKind kind; - - SysprofZoomManager *zoom_manager; - - gint64 capture_begin_time; - gint64 capture_end_time; - - /* Template objects */ - GtkScrolledWindow *scroller; - GtkTreeView *tree_view; - GtkBox *details_box; - GtkTreeViewColumn *duration_column; - SysprofCellRendererDuration *duration_cell; - GtkStack *stack; - GtkLabel *group; - GtkLabel *mark; - GtkLabel *time; - GtkLabel *end; - GtkLabel *duration; - GtkTextView *message; - GtkWidget *failed; - GtkWidget *marks; -} SysprofMarksPagePrivate; - -enum { - PROP_0, - PROP_KIND, - PROP_ZOOM_MANAGER, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofMarksPage, sysprof_marks_page, SYSPROF_TYPE_PAGE) - -static gboolean -sysprof_marks_page_tree_view_key_press_event_cb (SysprofMarksPage *self, - guint keyval, - guint keycode, - GdkModifierType state, - GtkEventControllerKey *controller) -{ - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - gint dir = 0; - - g_assert (SYSPROF_MARKS_PAGE (self)); - g_assert (GTK_IS_EVENT_CONTROLLER_KEY (controller)); - - if ((state & (GDK_SHIFT_MASK|GDK_CONTROL_MASK|GDK_ALT_MASK)) == 0) - { - switch (keyval) - { - case GDK_KEY_Left: - dir = -1; - break; - - case GDK_KEY_Right: - dir = 1; - break; - - default: - break; - } - - if (dir) - { - GtkAdjustment *adj = gtk_scrolled_window_get_hadjustment (priv->scroller); - gdouble step = gtk_adjustment_get_step_increment (adj); - gdouble val = CLAMP (gtk_adjustment_get_value (adj) + (step * dir), - gtk_adjustment_get_lower (adj), - gtk_adjustment_get_upper (adj)); - gtk_adjustment_set_value (adj, val); - return GDK_EVENT_STOP; - } - } - - return GDK_EVENT_PROPAGATE; -} - -static gboolean -get_first_selected (GtkTreeSelection *selection, - GtkTreeModel **model, - GtkTreeIter *iter) -{ - GtkTreeModel *m; - - g_assert (GTK_IS_TREE_SELECTION (selection)); - - if (gtk_tree_selection_count_selected_rows (selection) != 1) - return FALSE; - - m = gtk_tree_view_get_model (gtk_tree_selection_get_tree_view (selection)); - if (model) - *model = m; - - if (iter) - { - GList *paths = gtk_tree_selection_get_selected_rows (selection, model); - gtk_tree_model_get_iter (m, iter, paths->data); - g_list_free_full (paths, (GDestroyNotify)gtk_tree_path_free); - } - - return TRUE; -} - -static void -sysprof_marks_page_selection_changed_cb (SysprofMarksPage *self, - GtkTreeSelection *selection) -{ - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - GtkTreeModel *model; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_MARKS_PAGE (self)); - g_assert (GTK_IS_TREE_SELECTION (selection)); - - if (get_first_selected (selection, &model, &iter)) - { - g_autofree gchar *group = NULL; - g_autofree gchar *name = NULL; - g_autofree gchar *duration_str = NULL; - g_autofree gchar *time_str = NULL; - g_autofree gchar *end_str = NULL; - g_autofree gchar *text = NULL; - GtkAdjustment *adj; - gdouble x; - gint64 begin_time; - gint64 end_time; - gint64 duration; - gint64 etime; - gint64 otime; - gdouble lower; - gdouble upper; - gdouble value; - gdouble page_size; - gint width; - - gtk_tree_model_get (model, &iter, - SYSPROF_MARKS_MODEL_COLUMN_GROUP, &group, - SYSPROF_MARKS_MODEL_COLUMN_NAME, &name, - SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME, &begin_time, - SYSPROF_MARKS_MODEL_COLUMN_END_TIME, &end_time, - SYSPROF_MARKS_MODEL_COLUMN_TEXT, &text, - -1); - - duration = end_time - begin_time; - duration_str = _sysprof_format_duration (duration); - - otime = begin_time - priv->capture_begin_time; - time_str = _sysprof_format_duration (otime); - - etime = end_time - priv->capture_begin_time; - end_str = _sysprof_format_duration (etime); - - gtk_label_set_label (priv->group, group); - gtk_label_set_label (priv->mark, name); - gtk_label_set_label (priv->duration, duration_str); - gtk_label_set_label (priv->time, time_str); - gtk_label_set_label (priv->end, end_str); - - gtk_text_buffer_set_text (gtk_text_view_get_buffer (priv->message), text, -1); - - adj = gtk_scrolled_window_get_hadjustment (priv->scroller); - width = gtk_tree_view_column_get_width (priv->duration_column); - x = sysprof_zoom_manager_get_offset_at_time (priv->zoom_manager, - begin_time - priv->capture_begin_time, - width); - - g_object_get (adj, - "lower", &lower, - "upper", &upper, - "value", &value, - "page-size", &page_size, - NULL); - - if (x < value) - gtk_adjustment_set_value (adj, MAX (lower, x - (page_size / 3.0))); - else if (x > (value + page_size)) - gtk_adjustment_set_value (adj, MIN (upper - page_size, (x - (page_size / 3.0)))); - } -} - -static gboolean -sysprof_marks_page_tree_view_query_tooltip_cb (SysprofMarksPage *self, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip *tooltip, - GtkTreeView *tree_view) -{ - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - GtkTreeViewColumn *column; - GtkTreePath *path = NULL; - gint cell_x, cell_y; - gboolean ret = FALSE; - - g_assert (SYSPROF_IS_MARKS_PAGE (self)); - g_assert (GTK_IS_TOOLTIP (tooltip)); - g_assert (GTK_IS_TREE_VIEW (tree_view)); - - if (gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, &column, &cell_x, &cell_y)) - { - GtkTreeModel *model = gtk_tree_view_get_model (tree_view); - GtkTreeIter iter; - - if (gtk_tree_model_get_iter (model, &iter, path)) - { - g_autofree gchar *text = NULL; - g_autofree gchar *timestr = NULL; - g_autofree gchar *tooltip_text = NULL; - g_autofree gchar *durationstr = NULL; - gint64 begin_time; - gint64 end_time; - gint64 duration; - - gtk_tree_model_get (model, &iter, - SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME, &begin_time, - SYSPROF_MARKS_MODEL_COLUMN_END_TIME, &end_time, - SYSPROF_MARKS_MODEL_COLUMN_TEXT, &text, - -1); - - duration = end_time - begin_time; - begin_time -= priv->capture_begin_time; - durationstr = _sysprof_format_duration (duration); - - if (duration != 0) - timestr = g_strdup_printf ("%0.4lf (%s)", begin_time / (gdouble)SYSPROF_NSEC_PER_SEC, durationstr); - else - timestr = g_strdup_printf ("%0.4lf", begin_time / (gdouble)SYSPROF_NSEC_PER_SEC); - - tooltip_text = g_strdup_printf ("%s: %s", timestr, text); - - gtk_tooltip_set_text (tooltip, tooltip_text); - - ret = TRUE; - } - } - - gtk_tree_path_free (path); - - return ret; -} - -static void -sysprof_marks_page_load_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - g_autoptr(SysprofMarksModel) model = NULL; - g_autoptr(GError) error = NULL; - g_autoptr(GTask) task = user_data; - SysprofMarksPagePrivate *priv; - SysprofCaptureReader *reader; - SysprofMarksPage *self; - - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - self = g_task_get_source_object (task); - priv = sysprof_marks_page_get_instance_private (self); - - if (!(model = sysprof_marks_model_new_finish (result, &error))) - { - g_task_return_error (task, g_steal_pointer (&error)); - return; - } - - reader = g_task_get_task_data (task); - g_assert (reader != NULL); - - priv->capture_begin_time = sysprof_capture_reader_get_start_time (reader); - priv->capture_end_time = sysprof_capture_reader_get_end_time (reader); - - g_object_set (priv->duration_cell, - "capture-begin-time", priv->capture_begin_time, - "capture-end-time", priv->capture_end_time, - "zoom-manager", priv->zoom_manager, - NULL); - - gtk_tree_view_set_model (priv->tree_view, GTK_TREE_MODEL (model)); - - if (gtk_tree_model_iter_n_children (GTK_TREE_MODEL (model), NULL) == 0) - gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->failed)); - else - gtk_stack_set_visible_child (priv->stack, GTK_WIDGET (priv->marks)); - - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_marks_page_load_async (SysprofPage *page, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *filter, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofMarksPage *self = (SysprofMarksPage *)page; - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - g_autoptr(GTask) task = NULL; - - g_return_if_fail (SYSPROF_IS_MARKS_PAGE (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (!selection || SYSPROF_IS_SELECTION (selection)); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_marks_page_load_async); - g_task_set_task_data (task, - sysprof_capture_reader_ref (reader), - (GDestroyNotify) sysprof_capture_reader_unref); - - sysprof_marks_model_new_async (reader, - priv->kind, - selection, - cancellable, - sysprof_marks_page_load_cb, - g_steal_pointer (&task)); -} - -static gboolean -sysprof_marks_page_load_finish (SysprofPage *page, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_MARKS_PAGE (page), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_marks_page_set_hadjustment (SysprofPage *page, - GtkAdjustment *hadjustment) -{ - SysprofMarksPage *self = (SysprofMarksPage *)page; - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - - g_assert (SYSPROF_IS_MARKS_PAGE (self)); - g_assert (!hadjustment || GTK_IS_ADJUSTMENT (hadjustment)); - - gtk_scrolled_window_set_hadjustment (priv->scroller, hadjustment); -} - -static void -sysprof_marks_page_set_size_group (SysprofPage *page, - GtkSizeGroup *size_group) -{ - SysprofMarksPage *self = (SysprofMarksPage *)page; - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - - g_assert (SYSPROF_IS_MARKS_PAGE (self)); - g_assert (GTK_IS_SIZE_GROUP (size_group)); - - gtk_size_group_add_widget (size_group, GTK_WIDGET (priv->details_box)); -} - -static void -sysprof_marks_page_tree_view_row_activated_cb (SysprofMarksPage *self, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkTreeView *tree_view) -{ - GtkTreeModel *model; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_MARKS_PAGE (self)); - g_assert (path != NULL); - g_assert (GTK_IS_TREE_VIEW_COLUMN (column)); - g_assert (GTK_IS_TREE_VIEW (tree_view)); - - model = gtk_tree_view_get_model (tree_view); - - if (gtk_tree_model_get_iter (model, &iter, path)) - { - SysprofDisplay *display; - gint64 begin_time; - gint64 end_time; - - gtk_tree_model_get (model, &iter, - SYSPROF_MARKS_MODEL_COLUMN_BEGIN_TIME, &begin_time, - SYSPROF_MARKS_MODEL_COLUMN_END_TIME, &end_time, - -1); - - display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (self), SYSPROF_TYPE_DISPLAY)); - sysprof_display_add_to_selection (display, begin_time, end_time); - } -} - -static void -sysprof_marks_page_finalize (GObject *object) -{ - SysprofMarksPage *self = (SysprofMarksPage *)object; - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - - g_clear_object (&priv->zoom_manager); - - G_OBJECT_CLASS (sysprof_marks_page_parent_class)->finalize (object); -} - -static void -sysprof_marks_page_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofMarksPage *self = SYSPROF_MARKS_PAGE (object); - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - - switch (prop_id) - { - case PROP_KIND: - g_value_set_enum (value, priv->kind); - break; - - case PROP_ZOOM_MANAGER: - g_value_set_object (value, priv->zoom_manager); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_marks_page_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofMarksPage *self = SYSPROF_MARKS_PAGE (object); - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - - switch (prop_id) - { - case PROP_KIND: - priv->kind = g_value_get_enum (value); - break; - - case PROP_ZOOM_MANAGER: - if (g_set_object (&priv->zoom_manager, g_value_get_object (value))) - { - g_object_set (priv->duration_cell, - "zoom-manager", priv->zoom_manager, - NULL); - if (priv->zoom_manager) - g_signal_connect_object (priv->zoom_manager, - "notify::zoom", - G_CALLBACK (gtk_tree_view_column_queue_resize), - priv->duration_column, - G_CONNECT_SWAPPED); - } - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_marks_page_class_init (SysprofMarksPageClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofPageClass *page_class = SYSPROF_PAGE_CLASS (klass); - - object_class->finalize = sysprof_marks_page_finalize; - object_class->get_property = sysprof_marks_page_get_property; - object_class->set_property = sysprof_marks_page_set_property; - - page_class->load_async = sysprof_marks_page_load_async; - page_class->load_finish = sysprof_marks_page_load_finish; - page_class->set_hadjustment = sysprof_marks_page_set_hadjustment; - page_class->set_size_group = sysprof_marks_page_set_size_group; - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-marks-page.ui"); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, end); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, details_box); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, duration_cell); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, duration_column); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, scroller); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, stack); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, tree_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, group); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, mark); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, duration); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, time); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, message); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, marks); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMarksPage, failed); - - properties [PROP_KIND] = - g_param_spec_enum ("kind", NULL, NULL, - SYSPROF_TYPE_MARKS_MODEL_KIND, - SYSPROF_MARKS_MODEL_MARKS, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_ZOOM_MANAGER] = - g_param_spec_object ("zoom-manager", NULL, NULL, - SYSPROF_TYPE_ZOOM_MANAGER, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - g_type_ensure (SYSPROF_TYPE_CELL_RENDERER_DURATION); -} - -static void -sysprof_marks_page_init (SysprofMarksPage *self) -{ - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - GtkEventController *controller; - - priv->kind = SYSPROF_MARKS_MODEL_MARKS; - - gtk_widget_init_template (GTK_WIDGET (self)); - - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (priv->tree_view), - GTK_SELECTION_MULTIPLE); - - controller = gtk_event_controller_key_new (); - gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE); - g_signal_connect_object (controller, - "key-pressed", - G_CALLBACK (sysprof_marks_page_tree_view_key_press_event_cb), - self, - G_CONNECT_SWAPPED); - gtk_widget_add_controller (GTK_WIDGET (self), controller); - - g_signal_connect_object (priv->tree_view, - "row-activated", - G_CALLBACK (sysprof_marks_page_tree_view_row_activated_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->tree_view, - "query-tooltip", - G_CALLBACK (sysprof_marks_page_tree_view_query_tooltip_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (gtk_tree_view_get_selection (priv->tree_view), - "changed", - G_CALLBACK (sysprof_marks_page_selection_changed_cb), - self, - G_CONNECT_SWAPPED); -} - -GtkWidget * -sysprof_marks_page_new (SysprofZoomManager *zoom_manager, - SysprofMarksModelKind kind) -{ - SysprofMarksPage *self; - SysprofMarksPagePrivate *priv; - - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (zoom_manager), NULL); - - self = g_object_new (SYSPROF_TYPE_MARKS_PAGE, - "zoom-manager", zoom_manager, - NULL); - priv = sysprof_marks_page_get_instance_private (self); - priv->kind = kind; - - return GTK_WIDGET (self); -} - -void -_sysprof_marks_page_set_hadjustment (SysprofMarksPage *self, - GtkAdjustment *hadjustment) -{ - SysprofMarksPagePrivate *priv = sysprof_marks_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_MARKS_PAGE (self)); - g_return_if_fail (GTK_IS_ADJUSTMENT (hadjustment)); - - gtk_scrolled_window_set_hadjustment (priv->scroller, hadjustment); -} diff --git a/src/libsysprof-ui/sysprof-marks-page.h b/src/libsysprof-ui/sysprof-marks-page.h deleted file mode 100644 index 5070b1ae..00000000 --- a/src/libsysprof-ui/sysprof-marks-page.h +++ /dev/null @@ -1,44 +0,0 @@ -/* sysprof-marks-page.h - * - * Copyright 2019 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-marks-model.h" -#include "sysprof-page.h" -#include "sysprof-zoom-manager.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MARKS_PAGE (sysprof_marks_page_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofMarksPage, sysprof_marks_page, SYSPROF, MARKS_PAGE, SysprofPage) - -struct _SysprofMarksPageClass -{ - SysprofPageClass parent_class; - - /*< private >*/ - gpointer _reserved[16]; -}; - -GtkWidget *sysprof_marks_page_new (SysprofZoomManager *zoom_manager, - SysprofMarksModelKind kind); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-marks-page.ui b/src/libsysprof-ui/sysprof-marks-page.ui deleted file mode 100644 index 49936079..00000000 --- a/src/libsysprof-ui/sysprof-marks-page.ui +++ /dev/null @@ -1,259 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-memory-aid.c b/src/libsysprof-ui/sysprof-memory-aid.c deleted file mode 100644 index 67341ace..00000000 --- a/src/libsysprof-ui/sysprof-memory-aid.c +++ /dev/null @@ -1,70 +0,0 @@ -/* sysprof-memory-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-memory-aid" - -#include "config.h" - -#include - -#include "sysprof-memory-aid.h" - -struct _SysprofMemoryAid -{ - SysprofAid parent_instance; -}; - -G_DEFINE_TYPE (SysprofMemoryAid, sysprof_memory_aid, SYSPROF_TYPE_AID) - -SysprofAid * -sysprof_memory_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_MEMORY_AID, NULL); -} - -static void -sysprof_memory_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ -#ifdef __linux__ - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_MEMORY_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_memory_source_new (); - sysprof_profiler_add_source (profiler, source); -#endif -} - -static void -sysprof_memory_aid_class_init (SysprofMemoryAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_memory_aid_prepare; -} - -static void -sysprof_memory_aid_init (SysprofMemoryAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Memory Usage")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "org.gnome.Sysprof-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-memory-aid.h b/src/libsysprof-ui/sysprof-memory-aid.h deleted file mode 100644 index d33a1d8c..00000000 --- a/src/libsysprof-ui/sysprof-memory-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-memory-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MEMORY_AID (sysprof_memory_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMemoryAid, sysprof_memory_aid, SYSPROF, MEMORY_AID, SysprofAid) - -SysprofAid *sysprof_memory_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-memprof-aid.c b/src/libsysprof-ui/sysprof-memprof-aid.c deleted file mode 100644 index 21325177..00000000 --- a/src/libsysprof-ui/sysprof-memprof-aid.c +++ /dev/null @@ -1,226 +0,0 @@ -/* sysprof-memprof-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-memprof-aid" - -#include "config.h" - -#include - -#include "sysprof-memprof-aid.h" -#include "sysprof-memprof-page.h" -#include "sysprof-memprof-source.h" -#include "sysprof-memprof-visualizer.h" - -struct _SysprofMemprofAid -{ - SysprofAid parent_instance; -}; - -G_DEFINE_TYPE (SysprofMemprofAid, sysprof_memprof_aid, SYSPROF_TYPE_AID) - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; - guint has_allocs : 1; -} Present; - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -static void -on_group_activated_cb (SysprofVisualizerGroup *group, - SysprofPage *page) -{ - SysprofDisplay *display; - - g_assert (SYSPROF_IS_VISUALIZER_GROUP (group)); - g_assert (SYSPROF_IS_PAGE (page)); - - display = SYSPROF_DISPLAY (gtk_widget_get_ancestor (GTK_WIDGET (page), SYSPROF_TYPE_DISPLAY)); - sysprof_display_set_visible_page (display, page); -} - -SysprofAid * -sysprof_memprof_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_MEMPROF_AID, NULL); -} - -static void -sysprof_memprof_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ -#ifdef __linux__ - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_MEMPROF_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_memprof_source_new (); - sysprof_profiler_add_source (profiler, source); -#endif -} - -static bool -discover_samples_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - Present *p = user_data; - - g_assert (frame != NULL); - g_assert (p != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_ALLOCATION) - { - p->has_allocs = TRUE; - return FALSE; - } - - return TRUE; -} - -static void -sysprof_memprof_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *p = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_MEMPROF_AID (source_object)); - g_assert (p != NULL); - g_assert (p->cursor != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - sysprof_capture_cursor_foreach (p->cursor, discover_samples_cb, p); - g_task_return_boolean (task, TRUE); -} - -static void -sysprof_memprof_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_ALLOCATION }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_MEMPROF_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (1, types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_memprof_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_memprof_aid_present_worker); -} - -static gboolean -sysprof_memprof_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - Present *p; - - g_assert (SYSPROF_IS_MEMPROF_AID (aid)); - g_assert (G_IS_TASK (result)); - - p = g_task_get_task_data (G_TASK (result)); - - if (p->has_allocs) - { - SysprofVisualizerGroup *group; - SysprofVisualizer *row; - SysprofPage *page; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "has-page", TRUE, - "priority", -300, - "title", _("Memory"), - "visible", TRUE, - NULL); - - row = sysprof_memprof_visualizer_new (FALSE); - sysprof_visualizer_group_insert (group, row, 0, FALSE); - - row = sysprof_memprof_visualizer_new (TRUE); - sysprof_visualizer_group_insert (group, row, 1, FALSE); - - page = g_object_new (SYSPROF_TYPE_MEMPROF_PAGE, - "title", _("Memory Allocations"), - "vexpand", TRUE, - "visible", TRUE, - NULL); - sysprof_display_add_page (p->display, page); - - g_signal_connect_object (group, - "group-activated", - G_CALLBACK (on_group_activated_cb), - page, - 0); - - sysprof_display_add_group (p->display, group); - } - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_memprof_aid_class_init (SysprofMemprofAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_memprof_aid_prepare; - aid_class->present_async = sysprof_memprof_aid_present_async; - aid_class->present_finish = sysprof_memprof_aid_present_finish; -} - -static void -sysprof_memprof_aid_init (SysprofMemprofAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Track Allocations")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "org.gnome.Sysprof-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-memprof-aid.h b/src/libsysprof-ui/sysprof-memprof-aid.h deleted file mode 100644 index b5294d57..00000000 --- a/src/libsysprof-ui/sysprof-memprof-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-memprof-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MEMPROF_AID (sysprof_memprof_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMemprofAid, sysprof_memprof_aid, SYSPROF, MEMPROF_AID, SysprofAid) - -SysprofAid *sysprof_memprof_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-memprof-page.c b/src/libsysprof-ui/sysprof-memprof-page.c deleted file mode 100644 index 00e98961..00000000 --- a/src/libsysprof-ui/sysprof-memprof-page.c +++ /dev/null @@ -1,1552 +0,0 @@ -/* sysprof-memprof-page.c - * - * Copyright 2016-2019 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 - */ - -/* Sysprof -- Sampling, systemwide CPU profiler - * Copyright 2004, Red Hat, Inc. - * Copyright 2004, 2005, 2006, Soeren Sandmann - * - * 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 2 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, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "config.h" - -#include - -#include "../stackstash.h" - -#include "egg-paned-private.h" - -#include "sysprof-cell-renderer-percent.h" -#include "sysprof-memprof-page.h" -#include "sysprof-profile.h" - -typedef struct -{ - SysprofMemprofProfile *profile; - - GtkTreeView *callers_view; - GtkTreeView *functions_view; - GtkTreeView *descendants_view; - GtkTreeViewColumn *descendants_name_column; - GtkTreeViewColumn *function_size_column; - GtkCellRendererText *function_size_cell; - GtkStack *stack; - GtkToggleButton *summary; - GtkToggleButton *all_allocs; - GtkToggleButton *temp_allocs; - GtkToggleButton *leaked_allocs_button; - GtkLabel *temp_allocs_count; - GtkLabel *num_allocs; - GtkLabel *leaked_allocs; - GtkListBox *by_size; - GtkWidget *callgraph; - GtkWidget *summary_page; - GtkWidget *loading_state; - GtkWidget *empty_state; - - GCancellable *cancellable; - - GQueue *history; - - SysprofMemprofMode mode; - - guint profile_size; - guint loading; -} SysprofMemprofPagePrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofMemprofPage, sysprof_memprof_page, SYSPROF_TYPE_PAGE) - -enum { - PROP_0, - PROP_PROFILE, - N_PROPS -}; - -enum { - GO_PREVIOUS, - N_SIGNALS -}; - -enum { - COLUMN_NAME, - COLUMN_SELF, - COLUMN_TOTAL, - COLUMN_POINTER, - COLUMN_SIZE, -}; - -static void sysprof_memprof_page_update_descendants (SysprofMemprofPage *self, - StackNode *node); - -static GParamSpec *properties [N_PROPS]; -static guint signals [N_SIGNALS]; - -static guint -sysprof_memprof_page_get_profile_size (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - StackStash *stash; - StackNode *node; - guint size = 0; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - - if (priv->profile_size != 0) - return priv->profile_size; - - if (priv->profile == NULL) - return 0; - - if (NULL == (stash = sysprof_memprof_profile_get_stash (priv->profile))) - return 0; - - for (node = stack_stash_get_root (stash); node != NULL; node = node->siblings) - size += node->total; - - priv->profile_size = size; - - return size; -} - -static void -build_functions_store (StackNode *node, - gpointer user_data) -{ - struct { - GtkListStore *store; - gdouble profile_size; - } *state = user_data; - GtkTreeIter iter; - const StackNode *n; - guint64 size = 0; - guint64 total = 0; - - g_assert (state != NULL); - g_assert (GTK_IS_LIST_STORE (state->store)); - - for (n = node; n != NULL; n = n->next) - { - size += n->size; - if (n->toplevel) - total += n->total; - } - - gtk_list_store_append (state->store, &iter); - gtk_list_store_set (state->store, &iter, - COLUMN_NAME, U64_TO_POINTER (node->data), - COLUMN_SELF, 100.0 * size / state->profile_size, - COLUMN_TOTAL, 100.0 * total / state->profile_size, - COLUMN_POINTER, node, - COLUMN_SIZE, (guint64)total, - -1); - -} - -static void -update_summary (SysprofMemprofPage *self, - SysprofMemprofProfile *profile) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - SysprofMemprofStats stats; - g_autoptr(GString) str = NULL; - GtkWidget *child; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (SYSPROF_IS_MEMPROF_PROFILE (profile)); - - sysprof_memprof_profile_get_stats (profile, &stats); - - str = g_string_new (NULL); - - g_string_append_printf (str, "%"G_GINT64_FORMAT, stats.n_allocs); - gtk_label_set_label (priv->num_allocs, str->str); - g_string_truncate (str, 0); - - g_string_append_printf (str, "%"G_GINT64_FORMAT, stats.leaked_allocs); - gtk_label_set_label (priv->leaked_allocs, str->str); - g_string_truncate (str, 0); - - g_string_append_printf (str, "%"G_GINT64_FORMAT, stats.temp_allocs); - gtk_label_set_label (priv->temp_allocs_count, str->str); - g_string_truncate (str, 0); - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (priv->by_size)))) - gtk_list_box_remove (priv->by_size, child); - - for (guint i = 0; i < G_N_ELEMENTS (stats.by_size); i++) - { - g_autofree gchar *prevstr = NULL; - g_autofree gchar *sizestr = NULL; - g_autofree gchar *title_str = NULL; - g_autofree gchar *subtitle_str = NULL; - g_autofree gchar *allocstr = NULL; - g_autofree gchar *tempstr = NULL; - g_autofree gchar *allstr = NULL; - GtkWidget *row; - GtkWidget *title; - GtkWidget *subtitle; - GtkWidget *prog; - GtkWidget *box; - - if (stats.by_size[i].n_allocs == 0) - continue; - - row = gtk_list_box_row_new (); - title = gtk_label_new (NULL); - subtitle = gtk_label_new (NULL); - prog = gtk_level_bar_new_for_interval (0, stats.n_allocs); - box = g_object_new (GTK_TYPE_BOX, - "orientation", GTK_ORIENTATION_VERTICAL, - "spacing", 6, - "margin-top", 6, - "margin-start", 6, - "margin-bottom", 6, - "margin-end", 6, - NULL); - - sizestr = g_format_size_full (stats.by_size[i].bucket, G_FORMAT_SIZE_IEC_UNITS); - if (i == 0) - { - title_str = g_strdup_printf ("≤ %s", sizestr); - } - else - { - /* translators: %s is replaced with a memory size such as "32 bytes" */ - prevstr = g_format_size_full (stats.by_size[i-1].bucket, G_FORMAT_SIZE_IEC_UNITS); - /* translators: %s is replaced with the the lower and upper bound memory sizes in bytes */ - title_str = g_strdup_printf (_("> %s to %s"), prevstr, sizestr); - } - - gtk_label_set_label (GTK_LABEL (title), title_str); - gtk_label_set_xalign (GTK_LABEL (title), 0); - gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (title)), "dim-label"); - - gtk_widget_set_margin_start (box, 6); - gtk_widget_set_margin_end (box, 6); - - gtk_widget_set_margin_top (prog, 1); - gtk_widget_set_margin_bottom (prog, 1); - - allocstr = g_strdup_printf ("%"G_GINT64_FORMAT, stats.by_size[i].n_allocs); - tempstr = g_strdup_printf ("%"G_GINT64_FORMAT, stats.by_size[i].temp_allocs); - allstr = g_format_size_full (stats.by_size[i].allocated, - G_FORMAT_SIZE_IEC_UNITS); - subtitle_str = g_strdup_printf ("%s allocations, %s temporary, %s", - allocstr, tempstr, allstr); - - gtk_label_set_label (GTK_LABEL (subtitle), subtitle_str); - gtk_label_set_xalign (GTK_LABEL (subtitle), 0); - -#if 0 - /* TODO: Make this chunked by [temp][rest]... */ - gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (prog), - GTK_LEVEL_BAR_OFFSET_HIGH, - stats.by_size[i].temp_allocs); - gtk_level_bar_add_offset_value (GTK_LEVEL_BAR (prog), - GTK_LEVEL_BAR_OFFSET_LOW, - stats.by_size[i].n_allocs); -#endif - gtk_level_bar_set_value (GTK_LEVEL_BAR (prog), - stats.by_size[i].n_allocs); - - gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (row), box); - gtk_box_append (GTK_BOX (box), title); - gtk_box_append (GTK_BOX (box), prog); - gtk_box_append (GTK_BOX (box), subtitle); - gtk_list_box_append (priv->by_size, row); - } -} - -static void -sysprof_memprof_page_load (SysprofMemprofPage *self, - SysprofMemprofProfile *profile) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkListStore *functions; - StackStash *stash; - StackNode *n; - GtkTreeIter iter; - struct { - GtkListStore *store; - gdouble profile_size; - } state = { 0 }; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (SYSPROF_IS_MEMPROF_PROFILE (profile)); - - /* - * TODO: This is probably the type of thing we want to do off the main - * thread. We should be able to build the tree models off thread - * and then simply apply them on the main thread. - * - * In the mean time, we should set the state of the widget to - * insensitive and give some indication of loading progress. - */ - - if (!g_set_object (&priv->profile, profile)) - return; - - update_summary (self, profile); - - if (sysprof_memprof_profile_is_empty (profile)) - { - gtk_stack_set_visible_child (priv->stack, priv->summary_page); - return; - } - - stash = sysprof_memprof_profile_get_stash (profile); - - for (n = stack_stash_get_root (stash); n; n = n->siblings) - state.profile_size += n->total; - - functions = gtk_list_store_new (5, - G_TYPE_STRING, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE, - G_TYPE_POINTER, - G_TYPE_UINT64); - - state.store = functions; - stack_stash_foreach_by_address (stash, build_functions_store, &state); - - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (functions), - COLUMN_TOTAL, - GTK_SORT_DESCENDING); - - gtk_tree_view_set_model (priv->functions_view, GTK_TREE_MODEL (functions)); - gtk_tree_view_set_model (priv->callers_view, NULL); - gtk_tree_view_set_model (priv->descendants_view, NULL); - - if (gtk_tree_model_get_iter_first (GTK_TREE_MODEL (functions), &iter)) - { - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (priv->functions_view); - gtk_tree_selection_select_iter (selection, &iter); - } - - gtk_stack_set_visible_child (priv->stack, priv->callgraph); - - g_clear_object (&functions); -} - -void -_sysprof_memprof_page_set_failed (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_MEMPROF_PAGE (self)); - - gtk_stack_set_visible_child (priv->stack, priv->empty_state); -} - -static void -sysprof_memprof_page_unload (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (SYSPROF_IS_MEMPROF_PROFILE (priv->profile)); - - g_queue_clear (priv->history); - g_clear_object (&priv->profile); - priv->profile_size = 0; - - gtk_tree_view_set_model (priv->callers_view, NULL); - gtk_tree_view_set_model (priv->functions_view, NULL); - gtk_tree_view_set_model (priv->descendants_view, NULL); - - gtk_stack_set_visible_child (priv->stack, priv->empty_state); -} - -/** - * sysprof_memprof_page_get_profile: - * - * Returns: (transfer none): An #SysprofMemprofProfile. - */ -SysprofMemprofProfile * -sysprof_memprof_page_get_profile (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_MEMPROF_PAGE (self), NULL); - - return priv->profile; -} - -void -sysprof_memprof_page_set_profile (SysprofMemprofPage *self, - SysprofMemprofProfile *profile) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_MEMPROF_PAGE (self)); - g_return_if_fail (!profile || SYSPROF_IS_MEMPROF_PROFILE (profile)); - - if (profile != priv->profile) - { - if (priv->profile) - sysprof_memprof_page_unload (self); - - if (profile) - sysprof_memprof_page_load (self, profile); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PROFILE]); - } -} - -static void -sysprof_memprof_page_expand_descendants (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeModel *model; - GList *all_paths = NULL; - GtkTreePath *first_path; - GtkTreeIter iter; - gdouble top_value = 0; - gint max_rows = 40; /* FIXME */ - gint n_rows; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - - model = gtk_tree_view_get_model (priv->descendants_view); - first_path = gtk_tree_path_new_first (); - all_paths = g_list_prepend (all_paths, first_path); - n_rows = 1; - - gtk_tree_model_get_iter (model, &iter, first_path); - gtk_tree_model_get (model, &iter, - COLUMN_TOTAL, &top_value, - -1); - - while ((all_paths != NULL) && (n_rows < max_rows)) - { - GtkTreeIter best_iter; - GtkTreePath *best_path = NULL; - GList *list; - gdouble best_value = 0.0; - gint n_children; - gint i; - - for (list = all_paths; list != NULL; list = list->next) - { - GtkTreePath *path = list->data; - - g_assert (path != NULL); - - if (gtk_tree_model_get_iter (model, &iter, path)) - { - gdouble value; - - gtk_tree_model_get (model, &iter, - COLUMN_TOTAL, &value, - -1); - - if (value >= best_value) - { - best_value = value; - best_path = path; - best_iter = iter; - } - } - } - - n_children = gtk_tree_model_iter_n_children (model, &best_iter); - - if ((n_children > 0) && - ((best_value / top_value) > 0.04) && - ((n_children + gtk_tree_path_get_depth (best_path)) / (gdouble)max_rows) < (best_value / top_value)) - { - gtk_tree_view_expand_row (priv->descendants_view, best_path, FALSE); - n_rows += n_children; - - if (gtk_tree_path_get_depth (best_path) < 4) - { - GtkTreePath *path; - - path = gtk_tree_path_copy (best_path); - gtk_tree_path_down (path); - - for (i = 0; i < n_children; i++) - { - all_paths = g_list_prepend (all_paths, path); - - path = gtk_tree_path_copy (path); - gtk_tree_path_next (path); - } - - gtk_tree_path_free (path); - } - } - - all_paths = g_list_remove (all_paths, best_path); - - /* Always expand at least once */ - if ((all_paths == NULL) && (n_rows == 1)) - gtk_tree_view_expand_row (priv->descendants_view, best_path, FALSE); - - gtk_tree_path_free (best_path); - } - - g_list_free_full (all_paths, (GDestroyNotify)gtk_tree_path_free); -} - -typedef struct -{ - StackNode *node; - const gchar *name; - guint self; - guint total; -} Caller; - -static Caller * -caller_new (StackNode *node) -{ - Caller *c; - - c = g_slice_new (Caller); - c->name = U64_TO_POINTER (node->data); - c->self = 0; - c->total = 0; - c->node = node; - - return c; -} - -static void -caller_free (gpointer data) -{ - Caller *c = data; - g_slice_free (Caller, c); -} - -static void -sysprof_memprof_page_function_selection_changed (SysprofMemprofPage *self, - GtkTreeSelection *selection) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeModel *model = NULL; - GtkTreeIter iter; - GtkListStore *callers_store; - g_autoptr(GHashTable) callers = NULL; - g_autoptr(GHashTable) processed = NULL; - StackNode *callees = NULL; - StackNode *node; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (GTK_IS_TREE_SELECTION (selection)); - - if (!gtk_tree_selection_get_selected (selection, &model, &iter)) - { - gtk_tree_view_set_model (priv->callers_view, NULL); - gtk_tree_view_set_model (priv->descendants_view, NULL); - return; - } - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &callees, - -1); - - sysprof_memprof_page_update_descendants (self, callees); - - callers_store = gtk_list_store_new (5, - G_TYPE_STRING, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE, - G_TYPE_POINTER, - G_TYPE_UINT64); - - callers = g_hash_table_new_full (NULL, NULL, NULL, caller_free); - processed = g_hash_table_new (NULL, NULL); - - for (node = callees; node != NULL; node = node->next) - { - Caller *c; - - if (!node->parent) - continue; - - c = g_hash_table_lookup (callers, U64_TO_POINTER (node->parent->data)); - - if (c == NULL) - { - c = caller_new (node->parent); - g_hash_table_insert (callers, (gpointer)c->name, c); - } - } - - for (node = callees; node != NULL; node = node->next) - { - StackNode *top_caller = node->parent; - StackNode *top_callee = node; - StackNode *n; - Caller *c; - - if (!node->parent) - continue; - - /* - * We could have a situation where the function was called in a - * reentrant fashion, so we want to take the top-most match in the - * stack. - */ - for (n = node; n && n->parent; n = n->parent) - { - if (n->data == node->data && n->parent->data == node->parent->data) - { - top_caller = n->parent; - top_callee = n; - } - } - - c = g_hash_table_lookup (callers, U64_TO_POINTER (node->parent->data)); - - g_assert (c != NULL); - - if (!g_hash_table_lookup (processed, top_caller)) - { - c->total += top_callee->total; - g_hash_table_insert (processed, top_caller, top_caller); - } - - c->self += node->size; - } - - { - GHashTableIter hiter; - gpointer key, value; - guint64 size = 0; - - size = MAX (1, sysprof_memprof_page_get_profile_size (self)); - - g_hash_table_iter_init (&hiter, callers); - - while (g_hash_table_iter_next (&hiter, &key, &value)) - { - Caller *c = value; - - gtk_list_store_append (callers_store, &iter); - gtk_list_store_set (callers_store, &iter, - COLUMN_NAME, c->name, - COLUMN_SELF, c->self * 100.0 / size, - COLUMN_TOTAL, c->total * 100.0 / size, - COLUMN_POINTER, c->node, - COLUMN_SIZE, (guint64)c->total, - -1); - } - } - - gtk_tree_view_set_model (priv->callers_view, GTK_TREE_MODEL (callers_store)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (callers_store), - COLUMN_TOTAL, - GTK_SORT_DESCENDING); - - g_clear_object (&callers_store); -} - -static void -sysprof_memprof_page_set_node (SysprofMemprofPage *self, - StackNode *node) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeModel *model; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (node != NULL); - - if (priv->profile == NULL) - return; - - model = gtk_tree_view_get_model (priv->functions_view); - - if (gtk_tree_model_get_iter_first (model, &iter)) - { - do - { - StackNode *item = NULL; - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &item, - -1); - - if (item != NULL && item->data == node->data) - { - GtkTreeSelection *selection; - - selection = gtk_tree_view_get_selection (priv->functions_view); - gtk_tree_selection_select_iter (selection, &iter); - - break; - } - } - while (gtk_tree_model_iter_next (model, &iter)); - } -} - -static void -sysprof_memprof_page_descendant_activated (SysprofMemprofPage *self, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkTreeView *tree_view) -{ - GtkTreeModel *model; - StackNode *node = NULL; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (GTK_IS_TREE_VIEW (tree_view)); - g_assert (path != NULL); - g_assert (GTK_IS_TREE_VIEW_COLUMN (column)); - - model = gtk_tree_view_get_model (tree_view); - - if (!gtk_tree_model_get_iter (model, &iter, path)) - return; - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &node, - -1); - - if (node != NULL) - sysprof_memprof_page_set_node (self, node); -} - -static void -sysprof_memprof_page_caller_activated (SysprofMemprofPage *self, - GtkTreePath *path, - GtkTreeViewColumn *column, - GtkTreeView *tree_view) -{ - GtkTreeModel *model; - StackNode *node = NULL; - GtkTreeIter iter; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (GTK_IS_TREE_VIEW (tree_view)); - g_assert (path != NULL); - g_assert (GTK_IS_TREE_VIEW_COLUMN (column)); - - model = gtk_tree_view_get_model (tree_view); - - if (!gtk_tree_model_get_iter (model, &iter, path)) - return; - - gtk_tree_model_get (model, &iter, - COLUMN_POINTER, &node, - -1); - - if (node != NULL) - sysprof_memprof_page_set_node (self, node); -} - -static void -sysprof_memprof_page_size_data_func (GtkTreeViewColumn *column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - g_autofree gchar *size_str = NULL; - guint64 size; - - gtk_tree_model_get (model, iter, COLUMN_SIZE, &size, -1); - if (size) - size_str = g_format_size_full (size, G_FORMAT_SIZE_IEC_UNITS); - g_object_set (cell, "text", size_str, NULL); -} - -static void -sysprof_memprof_page_tag_data_func (GtkTreeViewColumn *column, - GtkCellRenderer *cell, - GtkTreeModel *model, - GtkTreeIter *iter, - gpointer data) -{ - SysprofMemprofPage *self = data; - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - StackNode *node = NULL; - const gchar *str = NULL; - - if (priv->profile == NULL) - return; - - gtk_tree_model_get (model, iter, COLUMN_POINTER, &node, -1); - - if (node && node->data) - { - GQuark tag; - - tag = sysprof_memprof_profile_get_tag (priv->profile, GSIZE_TO_POINTER (node->data)); - if (tag != 0) - str = g_quark_to_string (tag); - } - - g_object_set (cell, "text", str, NULL); -} - -static void -sysprof_memprof_page_real_go_previous (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - StackNode *node; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - - node = g_queue_pop_head (priv->history); - - if (NULL != (node = g_queue_peek_head (priv->history))) - sysprof_memprof_page_set_node (self, node); -} - -static void -descendants_view_move_cursor_cb (GtkTreeView *descendants_view, - GtkMovementStep step, - int direction, - gpointer user_data) -{ - if (step == GTK_MOVEMENT_VISUAL_POSITIONS) - { - GtkTreePath *path; - - gtk_tree_view_get_cursor (descendants_view, &path, NULL); - - if (direction == 1) - { - gtk_tree_view_expand_row (descendants_view, path, FALSE); - g_signal_stop_emission_by_name (descendants_view, "move-cursor"); - } - else if (direction == -1) - { - gtk_tree_view_collapse_row (descendants_view, path); - g_signal_stop_emission_by_name (descendants_view, "move-cursor"); - } - - gtk_tree_path_free (path); - } -} - -static void -copy_tree_view_selection_cb (GtkTreeModel *model, - GtkTreePath *path, - GtkTreeIter *iter, - gpointer data) -{ - g_autofree gchar *name = NULL; - g_autofree gchar *size_str = NULL; - gchar tstr[16]; - GString *str = data; - gdouble total; - guint64 size; - gint depth; - - g_assert (GTK_IS_TREE_MODEL (model)); - g_assert (path != NULL); - g_assert (iter != NULL); - g_assert (str != NULL); - - depth = gtk_tree_path_get_depth (path); - gtk_tree_model_get (model, iter, - COLUMN_NAME, &name, - COLUMN_TOTAL, &total, - COLUMN_SIZE, &size, - -1); - - size_str = g_format_size_full (size, G_FORMAT_SIZE_IEC_UNITS); - g_snprintf (tstr, sizeof tstr, "%.2lf%%", total); - - g_string_append_printf (str, "[%12s] [%8s] ", size_str, tstr); - - for (gint i = 1; i < depth; i++) - g_string_append (str, " "); - g_string_append (str, name); - g_string_append_c (str, '\n'); -} - -static void -copy_tree_view_selection (GtkTreeView *tree_view) -{ - g_autoptr(GString) str = NULL; - GdkClipboard *clipboard; - - g_assert (GTK_IS_TREE_VIEW (tree_view)); - - str = g_string_new (" ALLOCATED TOTAL FUNCTION\n"); - gtk_tree_selection_selected_foreach (gtk_tree_view_get_selection (tree_view), - copy_tree_view_selection_cb, - str); - - clipboard = gtk_widget_get_clipboard (GTK_WIDGET (tree_view)); - gdk_clipboard_set_text (clipboard, str->str); -} - -static void -sysprof_memprof_page_copy_cb (GtkWidget *widget, - const char *action_name, - GVariant *param) -{ - SysprofMemprofPage *self = (SysprofMemprofPage *)widget; - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkWidget *focus; - GtkRoot *toplevel; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - - if (!(toplevel = gtk_widget_get_root (widget)) || - !GTK_IS_ROOT (toplevel) || - !(focus = gtk_root_get_focus (toplevel))) - return; - - if (focus == GTK_WIDGET (priv->descendants_view)) - copy_tree_view_selection (priv->descendants_view); - else if (focus == GTK_WIDGET (priv->callers_view)) - copy_tree_view_selection (priv->callers_view); - else if (focus == GTK_WIDGET (priv->functions_view)) - copy_tree_view_selection (priv->functions_view); -} - -static void -sysprof_memprof_page_generate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofProfile *profile = (SysprofProfile *)object; - SysprofMemprofPage *self; - g_autoptr(GTask) task = user_data; - g_autoptr(GError) error = NULL; - - g_assert (SYSPROF_IS_PROFILE (profile)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (G_IS_TASK (task)); - - self = g_task_get_source_object (task); - - if (!sysprof_profile_generate_finish (profile, result, &error)) - g_task_return_error (task, g_error_copy (error)); - else - sysprof_memprof_page_set_profile (self, SYSPROF_MEMPROF_PROFILE (profile)); -} - -static void -sysprof_memprof_page_load_async (SysprofPage *page, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *filter, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofMemprofPage *self = (SysprofMemprofPage *)page; - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - g_autoptr(SysprofCaptureReader) copy = NULL; - g_autoptr(SysprofProfile) profile = NULL; - g_autoptr(GTask) task = NULL; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_SELECTION (selection)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - g_cancellable_cancel (priv->cancellable); - - if (cancellable == NULL) - cancellable = priv->cancellable = g_cancellable_new (); - else - g_set_object (&priv->cancellable, cancellable); - - gtk_stack_set_visible_child (priv->stack, priv->loading_state); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_memprof_page_load_async); - - copy = sysprof_capture_reader_copy (reader); - - profile = sysprof_memprof_profile_new_with_selection (selection); - sysprof_memprof_profile_set_mode (SYSPROF_MEMPROF_PROFILE (profile), priv->mode); - sysprof_profile_set_reader (profile, reader); - sysprof_profile_generate (profile, - cancellable, - sysprof_memprof_page_generate_cb, - g_steal_pointer (&task)); -} - -static gboolean -sysprof_memprof_page_load_finish (SysprofPage *page, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_MEMPROF_PAGE (page), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -do_allocs (SysprofMemprofPage *self, - SysprofMemprofMode mode) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - - priv->mode = mode; - sysprof_page_reload (SYSPROF_PAGE (self)); -} - -static void -mode_notify_active (SysprofMemprofPage *self, - GParamSpec *pspec, - GtkToggleButton *button) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - g_assert (GTK_IS_TOGGLE_BUTTON (button)); - - if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button))) - { - if (button == priv->summary) - do_allocs (self, SYSPROF_MEMPROF_MODE_SUMMARY); - else if (button == priv->all_allocs) - do_allocs (self, SYSPROF_MEMPROF_MODE_ALL_ALLOCS); - else if (button == priv->temp_allocs) - do_allocs (self, SYSPROF_MEMPROF_MODE_TEMP_ALLOCS); - else if (button == priv->leaked_allocs_button) - do_allocs (self, SYSPROF_MEMPROF_MODE_LEAKED_ALLOCS); - } -} - -static void -sep_header_func (GtkListBoxRow *row, - GtkListBoxRow *before, - gpointer user_data) -{ - if (before != NULL) - gtk_list_box_row_set_header (row, - g_object_new (GTK_TYPE_SEPARATOR, - "orientation", GTK_ORIENTATION_HORIZONTAL, - "visible", TRUE, - NULL)); -} - -static void -sysprof_memprof_page_finalize (GObject *object) -{ - SysprofMemprofPage *self = (SysprofMemprofPage *)object; - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_clear_pointer (&priv->history, g_queue_free); - g_clear_object (&priv->profile); - g_clear_object (&priv->cancellable); - - G_OBJECT_CLASS (sysprof_memprof_page_parent_class)->finalize (object); -} - -static void -sysprof_memprof_page_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofMemprofPage *self = SYSPROF_MEMPROF_PAGE (object); - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - switch (prop_id) - { - case PROP_PROFILE: - g_value_set_object (value, priv->profile); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_memprof_page_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofMemprofPage *self = SYSPROF_MEMPROF_PAGE (object); - - switch (prop_id) - { - case PROP_PROFILE: - sysprof_memprof_page_set_profile (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_memprof_page_class_init (SysprofMemprofPageClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofPageClass *page_class = SYSPROF_PAGE_CLASS (klass); - - object_class->finalize = sysprof_memprof_page_finalize; - object_class->get_property = sysprof_memprof_page_get_property; - object_class->set_property = sysprof_memprof_page_set_property; - - page_class->load_async = sysprof_memprof_page_load_async; - page_class->load_finish = sysprof_memprof_page_load_finish; - - klass->go_previous = sysprof_memprof_page_real_go_previous; - - properties [PROP_PROFILE] = - g_param_spec_object ("profile", - "Profile", - "The callgraph profile to view", - SYSPROF_TYPE_MEMPROF_PROFILE, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - signals [GO_PREVIOUS] = - g_signal_new ("go-previous", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION, - G_STRUCT_OFFSET (SysprofMemprofPageClass, go_previous), - NULL, NULL, NULL, G_TYPE_NONE, 0); - - gtk_widget_class_set_template_from_resource (widget_class, - "/org/gnome/sysprof/ui/sysprof-memprof-page.ui"); - - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, by_size); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, callers_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, function_size_cell); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, function_size_column); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, functions_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, descendants_view); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, descendants_name_column); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, stack); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, all_allocs); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, temp_allocs); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, summary); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, temp_allocs_count); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, num_allocs); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, leaked_allocs); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, leaked_allocs_button); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, loading_state); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, empty_state); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, summary_page); - gtk_widget_class_bind_template_child_private (widget_class, SysprofMemprofPage, callgraph); - - gtk_widget_class_install_action (widget_class, "page.copy", NULL, sysprof_memprof_page_copy_cb); - - gtk_widget_class_add_binding_action (widget_class, GDK_KEY_c, GDK_CONTROL_MASK, "page.copy", NULL); - gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Left, GDK_ALT_MASK, "go-previous", NULL); - - g_type_ensure (EGG_TYPE_PANED); - g_type_ensure (SYSPROF_TYPE_CELL_RENDERER_PERCENT); -} - -static void -sysprof_memprof_page_init (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeSelection *selection; - GtkCellRenderer *cell; - - priv->history = g_queue_new (); - priv->mode = SYSPROF_MEMPROF_MODE_ALL_ALLOCS; - - gtk_widget_init_template (GTK_WIDGET (self)); - - gtk_stack_set_visible_child (priv->stack, priv->empty_state); - - gtk_list_box_set_header_func (priv->by_size, sep_header_func, NULL, NULL); - - g_signal_connect_object (priv->all_allocs, - "notify::active", - G_CALLBACK (mode_notify_active), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (priv->temp_allocs, - "notify::active", - G_CALLBACK (mode_notify_active), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (priv->leaked_allocs_button, - "notify::active", - G_CALLBACK (mode_notify_active), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (priv->summary, - "notify::active", - G_CALLBACK (mode_notify_active), - self, - G_CONNECT_SWAPPED); - - selection = gtk_tree_view_get_selection (priv->functions_view); - - g_signal_connect_object (selection, - "changed", - G_CALLBACK (sysprof_memprof_page_function_selection_changed), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->descendants_view, - "row-activated", - G_CALLBACK (sysprof_memprof_page_descendant_activated), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->callers_view, - "row-activated", - G_CALLBACK (sysprof_memprof_page_caller_activated), - self, - G_CONNECT_SWAPPED); - - g_signal_connect (priv->descendants_view, - "move-cursor", - G_CALLBACK (descendants_view_move_cursor_cb), - NULL); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, - "ellipsize", PANGO_ELLIPSIZE_MIDDLE, - "xalign", 0.0f, - NULL); - gtk_tree_view_column_pack_start (priv->descendants_name_column, cell, TRUE); - gtk_tree_view_column_add_attribute (priv->descendants_name_column, cell, "text", 0); - - cell = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT, - "foreground", "#666666", - "scale", PANGO_SCALE_SMALL, - "xalign", 1.0f, - NULL); - gtk_tree_view_column_pack_start (priv->descendants_name_column, cell, FALSE); - gtk_tree_view_column_set_cell_data_func (priv->descendants_name_column, cell, - sysprof_memprof_page_tag_data_func, - self, NULL); - - gtk_tree_view_column_set_cell_data_func (priv->function_size_column, - GTK_CELL_RENDERER (priv->function_size_cell), - sysprof_memprof_page_size_data_func, - self, NULL); - - gtk_tree_selection_set_mode (gtk_tree_view_get_selection (priv->descendants_view), - GTK_SELECTION_MULTIPLE); -} - -typedef struct _Descendant Descendant; - -struct _Descendant -{ - const gchar *name; - guint self; - guint cumulative; - Descendant *parent; - Descendant *siblings; - Descendant *children; -}; - -static void -build_tree_cb (StackLink *trace, - gint size, - gpointer user_data) -{ - Descendant **tree = user_data; - Descendant *parent = NULL; - StackLink *link; - - g_assert (trace != NULL); - g_assert (tree != NULL); - - /* Get last item */ - link = trace; - while (link->next) - link = link->next; - - for (; link != NULL; link = link->prev) - { - const gchar *address = U64_TO_POINTER (link->data); - Descendant *prev = NULL; - Descendant *match = NULL; - - for (match = *tree; match != NULL; match = match->siblings) - { - if (match->name == address) - { - if (prev != NULL) - { - /* Move to front */ - prev->siblings = match->siblings; - match->siblings = *tree; - *tree = match; - } - break; - } - } - - if (match == NULL) - { - /* Have we seen this object further up the tree? */ - for (match = parent; match != NULL; match = match->parent) - { - if (match->name == address) - break; - } - } - - if (match == NULL) - { - match = g_slice_new (Descendant); - match->name = address; - match->cumulative = 0; - match->self = 0; - match->children = NULL; - match->parent = parent; - match->siblings = *tree; - *tree = match; - } - - tree = &match->children; - parent = match; - } - - parent->self += size; - - for (; parent != NULL; parent = parent->parent) - parent->cumulative += size; -} - -static Descendant * -build_tree (StackNode *node) -{ - Descendant *tree = NULL; - - for (; node != NULL; node = node->next) - { - if (node->toplevel) - stack_node_foreach_trace (node, build_tree_cb, &tree); - } - - return tree; -} - -static void -append_to_tree_and_free (SysprofMemprofPage *self, - StackStash *stash, - GtkTreeStore *store, - Descendant *item, - GtkTreeIter *parent) -{ - StackNode *node = NULL; - GtkTreeIter iter; - guint profile_size; - - g_assert (GTK_IS_TREE_STORE (store)); - g_assert (item != NULL); - - profile_size = MAX (1, sysprof_memprof_page_get_profile_size (self)); - - gtk_tree_store_append (store, &iter, parent); - - node = stack_stash_find_node (stash, (gpointer)item->name); - - gtk_tree_store_set (store, &iter, - COLUMN_NAME, item->name, - COLUMN_SELF, item->self * 100.0 / (gdouble)profile_size, - COLUMN_TOTAL, item->cumulative * 100.0 / (gdouble)profile_size, - COLUMN_POINTER, node, - COLUMN_SIZE, item->cumulative, - -1); - - if (item->siblings != NULL) - append_to_tree_and_free (self, stash, store, item->siblings, parent); - - if (item->children != NULL) - append_to_tree_and_free (self, stash, store, item->children, &iter); - - g_slice_free (Descendant, item); -} - -static void -sysprof_memprof_page_update_descendants (SysprofMemprofPage *self, - StackNode *node) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeStore *store; - - g_assert (SYSPROF_IS_MEMPROF_PAGE (self)); - - if (g_queue_peek_head (priv->history) != node) - g_queue_push_head (priv->history, node); - - store = gtk_tree_store_new (5, - G_TYPE_STRING, - G_TYPE_DOUBLE, - G_TYPE_DOUBLE, - G_TYPE_POINTER, - G_TYPE_UINT64); - - if (priv->profile != NULL) - { - StackStash *stash; - - stash = sysprof_memprof_profile_get_stash (priv->profile); - if (stash != NULL) - { - Descendant *tree; - - tree = build_tree (node); - if (tree != NULL) - append_to_tree_and_free (self, stash, store, tree, NULL); - } - } - - gtk_tree_view_set_model (priv->descendants_view, GTK_TREE_MODEL (store)); - gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (store), - COLUMN_TOTAL, GTK_SORT_DESCENDING); - sysprof_memprof_page_expand_descendants (self); - - g_clear_object (&store); -} - -/** - * sysprof_memprof_page_screenshot: - * @self: A #SysprofMemprofPage. - * - * This function will generate a text representation of the descendants tree. - * This is useful if you want to include various profiling information in a - * commit message or email. - * - * The text generated will match the current row expansion in the tree view. - * - * Returns: (nullable) (transfer full): A newly allocated string that should be freed - * with g_free(). - */ -gchar * -sysprof_memprof_page_screenshot (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeView *tree_view; - GtkTreeModel *model; - GtkTreePath *tree_path; - GString *str; - GtkTreeIter iter; - - g_return_val_if_fail (SYSPROF_IS_MEMPROF_PAGE (self), NULL); - - tree_view = priv->descendants_view; - - if (NULL == (model = gtk_tree_view_get_model (tree_view))) - return NULL; - - /* - * To avoid having to precalculate the deepest visible row, we - * put the timing information at the beginning of the line. - */ - - str = g_string_new (" SELF CUMULATIVE FUNCTION\n"); - tree_path = gtk_tree_path_new_first (); - - for (;;) - { - if (gtk_tree_model_get_iter (model, &iter, tree_path)) - { - guint depth = gtk_tree_path_get_depth (tree_path); - StackNode *node; - gdouble in_self; - gdouble total; - guint i; - - gtk_tree_model_get (model, &iter, - COLUMN_SELF, &in_self, - COLUMN_TOTAL, &total, - COLUMN_POINTER, &node, - -1); - - g_string_append_printf (str, "[% 7.2lf%%] [% 7.2lf%%] ", in_self, total); - - for (i = 0; i < depth; i++) - g_string_append (str, " "); - g_string_append (str, GSIZE_TO_POINTER (node->data)); - g_string_append_c (str, '\n'); - - if (gtk_tree_view_row_expanded (tree_view, tree_path)) - gtk_tree_path_down (tree_path); - else - gtk_tree_path_next (tree_path); - - continue; - } - - if (!gtk_tree_path_up (tree_path) || !gtk_tree_path_get_depth (tree_path)) - break; - - gtk_tree_path_next (tree_path); - } - - gtk_tree_path_free (tree_path); - - return g_string_free (str, FALSE); -} - -guint -sysprof_memprof_page_get_n_functions (SysprofMemprofPage *self) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - GtkTreeModel *model; - guint ret = 0; - - g_return_val_if_fail (SYSPROF_IS_MEMPROF_PAGE (self), 0); - - if (NULL != (model = gtk_tree_view_get_model (priv->functions_view))) - ret = gtk_tree_model_iter_n_children (model, NULL); - - return ret; -} - -void -_sysprof_memprof_page_set_loading (SysprofMemprofPage *self, - gboolean loading) -{ - SysprofMemprofPagePrivate *priv = sysprof_memprof_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_MEMPROF_PAGE (self)); - - if (loading) - priv->loading++; - else - priv->loading--; - - if (priv->loading) - gtk_stack_set_visible_child (priv->stack, priv->loading_state); - else - gtk_stack_set_visible_child (priv->stack, priv->callgraph); -} diff --git a/src/libsysprof-ui/sysprof-memprof-page.h b/src/libsysprof-ui/sysprof-memprof-page.h deleted file mode 100644 index 1b3f7af3..00000000 --- a/src/libsysprof-ui/sysprof-memprof-page.h +++ /dev/null @@ -1,51 +0,0 @@ -/* sysprof-memprof-page.h - * - * Copyright 2016-2019 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 -#include - -#include "sysprof-page.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MEMPROF_PAGE (sysprof_memprof_page_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofMemprofPage, sysprof_memprof_page, SYSPROF, MEMPROF_PAGE, SysprofPage) - -struct _SysprofMemprofPageClass -{ - SysprofPageClass parent_class; - - void (*go_previous) (SysprofMemprofPage *self); - - /*< private >*/ - gpointer _reserved[16]; -}; - -GtkWidget *sysprof_memprof_page_new (void); -SysprofMemprofProfile *sysprof_memprof_page_get_profile (SysprofMemprofPage *self); -void sysprof_memprof_page_set_profile (SysprofMemprofPage *self, - SysprofMemprofProfile *profile); -gchar *sysprof_memprof_page_screenshot (SysprofMemprofPage *self); -guint sysprof_memprof_page_get_n_functions (SysprofMemprofPage *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-memprof-page.ui b/src/libsysprof-ui/sysprof-memprof-page.ui deleted file mode 100644 index ca22240a..00000000 --- a/src/libsysprof-ui/sysprof-memprof-page.ui +++ /dev/null @@ -1,330 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-memprof-visualizer.c b/src/libsysprof-ui/sysprof-memprof-visualizer.c deleted file mode 100644 index a117dd7f..00000000 --- a/src/libsysprof-ui/sysprof-memprof-visualizer.c +++ /dev/null @@ -1,613 +0,0 @@ -/* sysprof-memprof-visualizer.c - * - * Copyright 2020 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" - -#define G_LOG_DOMAIN "sysprof-memprof-visualizer" - -#include -#include -#include - -#include "rax.h" - -#include "sysprof-memprof-visualizer.h" - -typedef struct -{ - cairo_surface_t *surface; - SysprofCaptureReader *reader; - rax *rax; - GtkAllocation alloc; - gint64 begin_time; - gint64 duration; - gint64 total_alloc; - gint64 max_alloc; - GdkRGBA fg; - GdkRGBA fg2; - guint scale; -} DrawContext; - -struct _SysprofMemprofVisualizer -{ - SysprofVisualizer parent_instance; - - SysprofCaptureReader *reader; - GCancellable *cancellable; - - cairo_surface_t *surface; - gint surface_w; - gint surface_h; - - guint queued_draw; - - gint64 begin_time; - gint64 duration; - - gint64 cached_total_alloc; - gint64 cached_max_alloc; - - guint mode : 1; -}; - -enum { - MODE_ALLOCS, - MODE_TOTAL, -}; - -G_DEFINE_TYPE (SysprofMemprofVisualizer, sysprof_memprof_visualizer, SYSPROF_TYPE_VISUALIZER) - -static void -draw_context_free (DrawContext *draw) -{ - g_clear_pointer (&draw->reader, sysprof_capture_reader_unref); - g_clear_pointer (&draw->surface, cairo_surface_destroy); - g_clear_pointer (&draw->rax, raxFree); - g_slice_free (DrawContext, draw); -} - -static void -sysprof_memprof_visualizer_set_reader (SysprofVisualizer *visualizer, - SysprofCaptureReader *reader) -{ - SysprofMemprofVisualizer *self = (SysprofMemprofVisualizer *)visualizer; - - g_assert (SYSPROF_IS_MEMPROF_VISUALIZER (self)); - - if (reader == self->reader) - return; - - g_clear_pointer (&self->reader, sysprof_capture_reader_unref); - - self->reader = sysprof_capture_reader_ref (reader); - self->begin_time = sysprof_capture_reader_get_start_time (reader); - self->duration = sysprof_capture_reader_get_end_time (reader) - - sysprof_capture_reader_get_start_time (reader); - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -SysprofVisualizer * -sysprof_memprof_visualizer_new (gboolean total_allocs) -{ - SysprofMemprofVisualizer *self; - - self = g_object_new (SYSPROF_TYPE_MEMPROF_VISUALIZER, - "title", total_allocs ? _("Memory Used") : _("Memory Allocations"), - "height-request", 35, - "visible", TRUE, - NULL); - - if (total_allocs) - self->mode = MODE_TOTAL; - else - self->mode = MODE_ALLOCS; - - return SYSPROF_VISUALIZER (self); -} - -static guint64 -get_max_alloc (SysprofCaptureReader *reader) -{ - SysprofCaptureFrameType type; - gint64 ret = 0; - - while (sysprof_capture_reader_peek_type (reader, &type)) - { - const SysprofCaptureAllocation *ev; - - if (type == SYSPROF_CAPTURE_FRAME_ALLOCATION) - { - if (!(ev = sysprof_capture_reader_read_allocation (reader))) - break; - - if (ev->alloc_size > ret) - ret = ev->alloc_size; - } - else - { - if (!sysprof_capture_reader_skip (reader)) - break; - continue; - } - } - - sysprof_capture_reader_reset (reader); - - return ret; -} - -static guint64 -get_total_alloc (SysprofCaptureReader *reader) -{ - SysprofCaptureFrameType type; - guint64 total = 0; - guint64 max = 0; - rax *r; - - r = raxNew (); - - while (sysprof_capture_reader_peek_type (reader, &type)) - { - const SysprofCaptureAllocation *ev; - - if (type == SYSPROF_CAPTURE_FRAME_ALLOCATION) - { - if (!(ev = sysprof_capture_reader_read_allocation (reader))) - break; - - if (ev->alloc_size > 0) - { - raxInsert (r, - (guint8 *)&ev->alloc_addr, - sizeof ev->alloc_addr, - GSIZE_TO_POINTER (ev->alloc_size), - NULL); - - total += ev->alloc_size; - - if (total > max) - max = total; - } - else - { - gpointer res = raxFind (r, (guint8 *)&ev->alloc_addr, sizeof ev->alloc_addr); - - if (res != raxNotFound) - { - total -= GPOINTER_TO_SIZE (res); - raxRemove (r, - (guint8 *)&ev->alloc_addr, - sizeof ev->alloc_addr, - NULL); - } - } - } - else - { - if (!sysprof_capture_reader_skip (reader)) - break; - continue; - } - } - - sysprof_capture_reader_reset (reader); - raxFree (r); - - return max; -} - -static void -draw_total_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - SysprofCaptureFrameType type; - DrawContext *draw = task_data; - gint64 total = 0; - cairo_t *cr; - rax *r; - gint x = 0; - - g_assert (G_IS_TASK (task)); - g_assert (draw != NULL); - g_assert (draw->surface != NULL); - g_assert (draw->reader != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - if (draw->total_alloc == 0) - draw->total_alloc = get_total_alloc (draw->reader); - - r = raxNew (); - - /* To avoid sorting, this code assums that all allocation information - * is sorted and in order. Generally this is the case, but a crafted - * syscap file could break it on purpose if they tried. - */ - - cr = cairo_create (draw->surface); - cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); - cairo_set_source_rgb (cr, 0, 0, 0); - - while (sysprof_capture_reader_peek_type (draw->reader, &type)) - { - const SysprofCaptureAllocation *ev; - gint y; - - if (type == SYSPROF_CAPTURE_FRAME_ALLOCATION) - { - if (!(ev = sysprof_capture_reader_read_allocation (draw->reader))) - break; - - if (ev->alloc_size > 0) - { - raxInsert (r, - (guint8 *)&ev->alloc_addr, - sizeof ev->alloc_addr, - GSIZE_TO_POINTER (ev->alloc_size), - NULL); - - total += ev->alloc_size; - } - else - { - gpointer res = raxFind (r, (guint8 *)&ev->alloc_addr, sizeof ev->alloc_addr); - - if (res != raxNotFound) - { - total -= GPOINTER_TO_SIZE (res); - raxRemove (r, - (guint8 *)&ev->alloc_addr, - sizeof ev->alloc_addr, - NULL); - } - } - } - else - { - if (!sysprof_capture_reader_skip (draw->reader)) - break; - continue; - } - - x = (ev->frame.time - draw->begin_time) / (gdouble)draw->duration * draw->alloc.width; - y = draw->alloc.height - ((gdouble)total / (gdouble)draw->total_alloc * (gdouble)draw->alloc.height); - - cairo_rectangle (cr, x, y, 1, 1); - cairo_fill (cr); - } - - cairo_destroy (cr); - - g_task_return_boolean (task, TRUE); - - raxFree (r); -} - -static void -draw_alloc_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - static const gdouble dashes[] = { 1.0, 2.0 }; - DrawContext *draw = task_data; - SysprofCaptureFrameType type; - GdkRGBA *last; - GdkRGBA mid; - cairo_t *cr; - guint counter = 0; - gint midpt; - gdouble log_max; - - g_assert (G_IS_TASK (task)); - g_assert (draw != NULL); - g_assert (draw->surface != NULL); - g_assert (draw->reader != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - if (draw->max_alloc == 0) - draw->max_alloc = get_max_alloc (draw->reader); - - log_max = log10 (draw->max_alloc); - midpt = draw->alloc.height / 2; - - cr = cairo_create (draw->surface); - - /* Draw mid-point line */ - mid = draw->fg; - mid.alpha *= 0.4; - cairo_set_line_width (cr, 1.0); - gdk_cairo_set_source_rgba (cr, &mid); - cairo_move_to (cr, 0, midpt); - cairo_line_to (cr, draw->alloc.width, midpt); - cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0); - cairo_stroke (cr); - - cairo_set_antialias (cr, CAIRO_ANTIALIAS_NONE); - gdk_cairo_set_source_rgba (cr, &draw->fg); - last = &draw->fg; - - /* Now draw data points */ - while (sysprof_capture_reader_peek_type (draw->reader, &type)) - { - const SysprofCaptureAllocation *ev; - gint64 size; - gdouble l; - gint x; - gint y; - - /* Cancellation check every 1000 frames */ - if G_UNLIKELY (++counter == 1000) - { - if (g_task_return_error_if_cancelled (task)) - { - cairo_destroy (cr); - return; - } - - counter = 0; - } - - /* We only care about memory frames here */ - if (type != SYSPROF_CAPTURE_FRAME_ALLOCATION) - { - if (!sysprof_capture_reader_skip (draw->reader)) - break; - continue; - } - - if (!(ev = sysprof_capture_reader_read_allocation (draw->reader))) - break; - - if (ev->alloc_size > 0) - { - size = ev->alloc_size; - raxInsert (draw->rax, (guint8 *)&ev->alloc_addr, sizeof ev->alloc_addr, GSIZE_TO_POINTER (size), NULL); - - if (last != &draw->fg) - { - gdk_cairo_set_source_rgba (cr, &draw->fg); - last = &draw->fg; - } - } - else - { - size = GPOINTER_TO_SIZE (raxFind (draw->rax, (guint8 *)&ev->alloc_addr, sizeof ev->alloc_addr)); - if (size) - raxRemove (draw->rax, (guint8 *)&ev->alloc_addr, sizeof ev->alloc_addr, NULL); - - if (last != &draw->fg2) - { - gdk_cairo_set_source_rgba (cr, &draw->fg2); - last = &draw->fg2; - } - } - - l = log10 (size); - - x = (ev->frame.time - draw->begin_time) / (gdouble)draw->duration * draw->alloc.width; - - if (ev->alloc_size > 0) - y = midpt - ((l / log_max) * midpt); - else - y = midpt + ((l / log_max) * midpt); - - /* Fill immediately instead of batching draws so that - * we don't take a lot of memory to hold on to the - * path while drawing. - */ - cairo_rectangle (cr, x, y, 1, 1); - cairo_fill (cr); - } - - cairo_destroy (cr); - - g_task_return_boolean (task, TRUE); -} - -static void -draw_finished (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - g_autoptr(SysprofMemprofVisualizer) self = user_data; - g_autoptr(GError) error = NULL; - - g_assert (object == NULL); - g_assert (G_IS_TASK (result)); - g_assert (SYSPROF_IS_MEMPROF_VISUALIZER (self)); - - if (g_task_propagate_boolean (G_TASK (result), &error)) - { - DrawContext *draw = g_task_get_task_data (G_TASK (result)); - - g_clear_pointer (&self->surface, cairo_surface_destroy); - - self->surface = g_steal_pointer (&draw->surface); - self->surface_w = draw->alloc.width; - self->surface_h = draw->alloc.height; - self->cached_max_alloc = draw->max_alloc; - self->cached_total_alloc = draw->total_alloc; - - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static gboolean -sysprof_memprof_visualizer_begin_draw (SysprofMemprofVisualizer *self) -{ - g_autoptr(GTask) task = NULL; - GtkAllocation alloc; - DrawContext *draw; - - g_assert (SYSPROF_IS_MEMPROF_VISUALIZER (self)); - - self->queued_draw = 0; - - /* Make sure we even need to draw */ - gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); - if (self->reader == NULL || - !gtk_widget_get_visible (GTK_WIDGET (self)) || - !gtk_widget_get_mapped (GTK_WIDGET (self)) || - alloc.width == 0 || alloc.height == 0) - return G_SOURCE_REMOVE; - - /* Some GPUs (Intel) cannot deal with graphics textures larger than - * 8000x8000. So here we are going to cheat a bit and just use that as our - * max, and scale when drawing. The biggest issue here is that long term we - * need a tiling solution that lets us render lots of tiles and then draw - * them as necessary. - */ - if (alloc.width > 8000) - alloc.width = 8000; - - draw = g_slice_new0 (DrawContext); - draw->rax = raxNew (); - draw->alloc.width = alloc.width; - draw->alloc.height = alloc.height; - draw->reader = sysprof_capture_reader_copy (self->reader); - draw->begin_time = self->begin_time; - draw->duration = self->duration; - draw->scale = gtk_widget_get_scale_factor (GTK_WIDGET (self)); - draw->max_alloc = self->cached_max_alloc; - draw->total_alloc = self->cached_total_alloc; - - gdk_rgba_parse (&draw->fg, "rgba(246,97,81,1)"); - gdk_rgba_parse (&draw->fg2, "rgba(245,194,17,1)"); - - draw->surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, - alloc.width * draw->scale, - alloc.height * draw->scale); - cairo_surface_set_device_scale (draw->surface, draw->scale, draw->scale); - - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); - self->cancellable = g_cancellable_new (); - - task = g_task_new (NULL, self->cancellable, draw_finished, g_object_ref (self)); - g_task_set_source_tag (task, sysprof_memprof_visualizer_begin_draw); - g_task_set_task_data (task, g_steal_pointer (&draw), (GDestroyNotify)draw_context_free); - - if (self->mode == MODE_ALLOCS) - g_task_run_in_thread (task, draw_alloc_worker); - else - g_task_run_in_thread (task, draw_total_worker); - - return G_SOURCE_REMOVE; -} - -static void -sysprof_memprof_visualizer_queue_redraw (SysprofMemprofVisualizer *self) -{ - g_assert (SYSPROF_IS_MEMPROF_VISUALIZER (self)); - - if (self->queued_draw == 0) - self->queued_draw = g_idle_add_full (G_PRIORITY_HIGH_IDLE, - (GSourceFunc) sysprof_memprof_visualizer_begin_draw, - g_object_ref (self), - g_object_unref); -} - -static void -sysprof_memprof_visualizer_size_allocate (GtkWidget *widget, - int width, - int height, - int baseline) -{ - sysprof_memprof_visualizer_queue_redraw (SYSPROF_MEMPROF_VISUALIZER (widget)); -} - -static void -sysprof_memprof_visualizer_dispose (GObject *object) -{ - SysprofMemprofVisualizer *self = (SysprofMemprofVisualizer *)object; - - g_clear_pointer (&self->reader, sysprof_capture_reader_unref); - g_clear_pointer (&self->surface, cairo_surface_destroy); - g_clear_handle_id (&self->queued_draw, g_source_remove); - - G_OBJECT_CLASS (sysprof_memprof_visualizer_parent_class)->dispose (object); -} - -static void -sysprof_memprof_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofMemprofVisualizer *self = (SysprofMemprofVisualizer *)widget; - - g_assert (SYSPROF_IS_MEMPROF_VISUALIZER (self)); - g_assert (GTK_IS_SNAPSHOT (snapshot)); - - GTK_WIDGET_CLASS (sysprof_memprof_visualizer_parent_class)->snapshot (widget, snapshot); - - if (self->surface != NULL) - { - cairo_t *cr; - GtkAllocation alloc; - - gtk_widget_get_allocation (widget, &alloc); - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height)); - - cairo_save (cr); - cairo_rectangle (cr, 0, 0, alloc.width, alloc.height); - - /* We might be drawing an updated image in the background, and this - * will take our current surface (which is the wrong size) and draw - * it stretched to fit the allocation. That gives us *something* that - * represents the end result even if it is a bit blurry in the mean - * time. Allocators take a while to render anyway. - */ - if (self->surface_w != alloc.width || self->surface_h != alloc.height) - { - cairo_scale (cr, - (gdouble)alloc.width / (gdouble)self->surface_w, - (gdouble)alloc.height / (gdouble)self->surface_h); - } - - cairo_set_source_surface (cr, self->surface, 0, 0); - cairo_paint (cr); - cairo_restore (cr); - - cairo_destroy (cr); - } -} - -static void -sysprof_memprof_visualizer_class_init (SysprofMemprofVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofVisualizerClass *visualizer_class = SYSPROF_VISUALIZER_CLASS (klass); - - object_class->dispose = sysprof_memprof_visualizer_dispose; - - widget_class->snapshot = sysprof_memprof_visualizer_snapshot; - widget_class->size_allocate = sysprof_memprof_visualizer_size_allocate; - - visualizer_class->set_reader = sysprof_memprof_visualizer_set_reader; -} - -static void -sysprof_memprof_visualizer_init (SysprofMemprofVisualizer *self) -{ -} diff --git a/src/libsysprof-ui/sysprof-memprof-visualizer.h b/src/libsysprof-ui/sysprof-memprof-visualizer.h deleted file mode 100644 index 04f078c8..00000000 --- a/src/libsysprof-ui/sysprof-memprof-visualizer.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-memprof-visualizer.h - * - * Copyright 2020 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-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MEMPROF_VISUALIZER (sysprof_memprof_visualizer_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofMemprofVisualizer, sysprof_memprof_visualizer, SYSPROF, MEMPROF_VISUALIZER, SysprofVisualizer) - -SysprofVisualizer *sysprof_memprof_visualizer_new (gboolean total_allocs); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-model-filter.c b/src/libsysprof-ui/sysprof-model-filter.c deleted file mode 100644 index 48c9386e..00000000 --- a/src/libsysprof-ui/sysprof-model-filter.c +++ /dev/null @@ -1,497 +0,0 @@ -/* sysprof-model-filter.c - * - * Copyright 2016-2019 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-model-filter.h" - -typedef struct -{ - GSequenceIter *child_iter; - GSequenceIter *filter_iter; -} SysprofModelFilterItem; - -typedef struct -{ - /* The list we are filtering */ - GListModel *child_model; - - /* - * Both sequences point to the same SysprofModelFilterItem which - * contains cross-referencing stable GSequenceIter pointers. - * The child_seq is considered the "owner" and used to release - * allocated resources. - */ - GSequence *child_seq; - GSequence *filter_seq; - - /* - * Typical set of callback/closure/free function pointers and data. - * Called for child items to determine visibility state. - */ - SysprofModelFilterFunc filter_func; - gpointer filter_func_data; - GDestroyNotify filter_func_data_destroy; - - /* - * If set, we will not emit items-changed. This is useful during - * invalidation so that we can do a single emission for all items - * that have changed. - */ - guint supress_items_changed : 1; -} SysprofModelFilterPrivate; - -static void list_model_iface_init (GListModelInterface *iface); - -G_DEFINE_TYPE_EXTENDED (SysprofModelFilter, sysprof_model_filter, G_TYPE_OBJECT, 0, - G_ADD_PRIVATE (SysprofModelFilter) - G_IMPLEMENT_INTERFACE (G_TYPE_LIST_MODEL, - list_model_iface_init)) - -enum { - PROP_0, - PROP_CHILD_MODEL, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; -static guint signal_id; - -static void -sysprof_model_filter_item_free (gpointer data) -{ - SysprofModelFilterItem *item = data; - - g_clear_pointer (&item->filter_iter, g_sequence_remove); - item->child_iter = NULL; - g_slice_free (SysprofModelFilterItem, item); -} - -static gboolean -sysprof_model_filter_default_filter_func (GObject *item, - gpointer user_data) -{ - return TRUE; -} - -/* - * Locates the next item in the filter sequence starting from - * the cross-reference found at @iter. If none are found, the - * end_iter for the filter sequence is returned. - * - * This returns an iter in the filter_sequence, not the child_seq. - * - * Returns: a #GSequenceIter from the filter sequence. - */ -static GSequenceIter * -find_next_visible_filter_iter (SysprofModelFilter *self, - GSequenceIter *iter) -{ - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - g_assert (SYSPROF_IS_MODEL_FILTER (self)); - g_assert (iter != NULL); - - for (; !g_sequence_iter_is_end (iter); iter = g_sequence_iter_next (iter)) - { - SysprofModelFilterItem *item = g_sequence_get (iter); - - g_assert (item->child_iter == iter); - g_assert (item->filter_iter == NULL || - g_sequence_iter_get_sequence (item->filter_iter) == priv->filter_seq); - - if (item->filter_iter != NULL) - return item->filter_iter; - } - - return g_sequence_get_end_iter (priv->filter_seq); -} - -static void -sysprof_model_filter_child_model_items_changed (SysprofModelFilter *self, - guint position, - guint n_removed, - guint n_added, - GListModel *child_model) -{ - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - gboolean unblocked; - - g_assert (SYSPROF_IS_MODEL_FILTER (self)); - g_assert (G_IS_LIST_MODEL (child_model)); - g_assert (priv->child_model == child_model); - g_assert (position <= (guint)g_sequence_get_length (priv->child_seq)); - g_assert ((g_sequence_get_length (priv->child_seq) - n_removed + n_added) == - g_list_model_get_n_items (child_model)); - - unblocked = !priv->supress_items_changed; - - if (n_removed > 0) - { - GSequenceIter *iter = g_sequence_get_iter_at_pos (priv->child_seq, position); - gint first_position = -1; - guint count = 0; - - g_assert (!g_sequence_iter_is_end (iter)); - - /* Small shortcut when all items are removed */ - if (n_removed == (guint)g_sequence_get_length (priv->child_seq)) - { - g_sequence_remove_range (g_sequence_get_begin_iter (priv->child_seq), - g_sequence_get_end_iter (priv->child_seq)); - g_assert (g_sequence_is_empty (priv->child_seq)); - g_assert (g_sequence_is_empty (priv->filter_seq)); - goto add_new_items; - } - - for (guint i = 0; i < n_removed; i++) - { - GSequenceIter *to_remove = iter; - SysprofModelFilterItem *item = g_sequence_get (iter); - - g_assert (item != NULL); - g_assert (item->child_iter == iter); - g_assert (item->filter_iter == NULL || - g_sequence_iter_get_sequence (item->filter_iter) == priv->filter_seq); - - /* If this is visible, we need to notify about removal */ - if (unblocked && item->filter_iter != NULL) - { - if (first_position < 0) - first_position = g_sequence_iter_get_position (item->filter_iter); - - count++; - } - - /* Fetch the next while the iter is still valid */ - iter = g_sequence_iter_next (iter); - - /* Cascades into also removing from filter_seq. */ - g_sequence_remove (to_remove); - } - - if (unblocked && first_position >= 0) - g_list_model_items_changed (G_LIST_MODEL (self), first_position, count, 0); - } - -add_new_items: - - if (n_added > 0) - { - GSequenceIter *iter = g_sequence_get_iter_at_pos (priv->child_seq, position); - GSequenceIter *filter_iter = find_next_visible_filter_iter (self, iter); - guint filter_position = g_sequence_iter_get_position (filter_iter); - guint count = 0; - - /* Walk backwards to insert items into the filter list so that - * we can use the same filter_position for each items-changed - * signal emission. - */ - for (guint i = position + n_added; i > position; i--) - { - g_autoptr(GObject) instance = NULL; - SysprofModelFilterItem *item; - - item = g_slice_new0 (SysprofModelFilterItem); - item->filter_iter = NULL; - item->child_iter = g_sequence_insert_before (iter, item); - - instance = g_list_model_get_item (child_model, i - 1); - g_assert (G_IS_OBJECT (instance)); - - /* Check if this item is visible */ - if (priv->filter_func (instance, priv->filter_func_data)) - { - item->filter_iter = g_sequence_insert_before (filter_iter, item); - - /* Use this in the future for relative positioning */ - filter_iter = item->filter_iter; - - count++; - } - - /* Insert next item before this */ - iter = item->child_iter; - } - - if (unblocked && count) - g_list_model_items_changed (G_LIST_MODEL (self), filter_position, 0, count); - } - - g_assert ((guint)g_sequence_get_length (priv->child_seq) == - g_list_model_get_n_items (child_model)); -} - -static void -sysprof_model_filter_finalize (GObject *object) -{ - SysprofModelFilter *self = (SysprofModelFilter *)object; - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - g_clear_pointer (&priv->child_seq, g_sequence_free); - g_clear_pointer (&priv->filter_seq, g_sequence_free); - - if (priv->filter_func_data_destroy) - { - g_clear_pointer (&priv->filter_func_data, priv->filter_func_data_destroy); - priv->filter_func_data_destroy = NULL; - } - - g_clear_object (&priv->child_model); - - G_OBJECT_CLASS (sysprof_model_filter_parent_class)->finalize (object); -} - -static void -sysprof_model_filter_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofModelFilter *self = SYSPROF_MODEL_FILTER (object); - - switch (prop_id) - { - case PROP_CHILD_MODEL: - g_value_set_object (value, sysprof_model_filter_get_child_model (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_model_filter_class_init (SysprofModelFilterClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_model_filter_finalize; - object_class->get_property = sysprof_model_filter_get_property; - - properties [PROP_CHILD_MODEL] = - g_param_spec_object ("child-model", - "Child Model", - "The child model being filtered.", - G_TYPE_LIST_MODEL, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - signal_id = g_signal_lookup ("items-changed", SYSPROF_TYPE_MODEL_FILTER); -} - -static void -sysprof_model_filter_init (SysprofModelFilter *self) -{ - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - priv->filter_func = sysprof_model_filter_default_filter_func; - priv->child_seq = g_sequence_new (sysprof_model_filter_item_free); - priv->filter_seq = g_sequence_new (NULL); -} - -static GType -sysprof_model_filter_get_item_type (GListModel *model) -{ - SysprofModelFilter *self = (SysprofModelFilter *)model; - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - g_assert (SYSPROF_IS_MODEL_FILTER (self)); - - return g_list_model_get_item_type (priv->child_model); -} - -static guint -sysprof_model_filter_get_n_items (GListModel *model) -{ - SysprofModelFilter *self = (SysprofModelFilter *)model; - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - g_assert (SYSPROF_IS_MODEL_FILTER (self)); - g_assert (priv->filter_seq != NULL); - - return g_sequence_get_length (priv->filter_seq); -} - -static gpointer -sysprof_model_filter_get_item (GListModel *model, - guint position) -{ - SysprofModelFilter *self = (SysprofModelFilter *)model; - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - SysprofModelFilterItem *item; - GSequenceIter *iter; - guint child_position; - - g_assert (SYSPROF_IS_MODEL_FILTER (self)); - g_assert (position < (guint)g_sequence_get_length (priv->filter_seq)); - - iter = g_sequence_get_iter_at_pos (priv->filter_seq, position); - g_assert (!g_sequence_iter_is_end (iter)); - - item = g_sequence_get (iter); - g_assert (item != NULL); - g_assert (item->filter_iter == iter); - g_assert (item->child_iter != NULL); - g_assert (g_sequence_iter_get_sequence (item->child_iter) == priv->child_seq); - - child_position = g_sequence_iter_get_position (item->child_iter); - - return g_list_model_get_item (priv->child_model, child_position); -} - -static void -list_model_iface_init (GListModelInterface *iface) -{ - iface->get_item_type = sysprof_model_filter_get_item_type; - iface->get_n_items = sysprof_model_filter_get_n_items; - iface->get_item = sysprof_model_filter_get_item; -} - -SysprofModelFilter * -sysprof_model_filter_new (GListModel *child_model) -{ - SysprofModelFilter *ret; - SysprofModelFilterPrivate *priv; - - g_return_val_if_fail (G_IS_LIST_MODEL (child_model), NULL); - - ret = g_object_new (SYSPROF_TYPE_MODEL_FILTER, NULL); - priv = sysprof_model_filter_get_instance_private (ret); - priv->child_model = g_object_ref (child_model); - - g_signal_connect_object (child_model, - "items-changed", - G_CALLBACK (sysprof_model_filter_child_model_items_changed), - ret, - G_CONNECT_SWAPPED); - - sysprof_model_filter_invalidate (ret); - - return ret; -} - -/** - * sysprof_model_filter_get_child_model: - * @self: A #SysprofModelFilter - * - * Gets the child model that is being filtered. - * - * Returns: (transfer none): A #GListModel. - */ -GListModel * -sysprof_model_filter_get_child_model (SysprofModelFilter *self) -{ - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_MODEL_FILTER (self), NULL); - - return priv->child_model; -} - -void -sysprof_model_filter_invalidate (SysprofModelFilter *self) -{ - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - guint n_items; - - g_return_if_fail (SYSPROF_IS_MODEL_FILTER (self)); - - /* We block emission while in invalidate so that we can use - * a single larger items-changed rather lots of small emissions. - */ - priv->supress_items_changed = TRUE; - - /* First determine how many items we need to synthesize as a removal */ - n_items = g_sequence_get_length (priv->filter_seq); - - /* - * If we have a child store, we want to rebuild our list of items - * from scratch, so just remove everything. - */ - if (!g_sequence_is_empty (priv->child_seq)) - g_sequence_remove_range (g_sequence_get_begin_iter (priv->child_seq), - g_sequence_get_end_iter (priv->child_seq)); - - g_assert (g_sequence_is_empty (priv->child_seq)); - g_assert (g_sequence_is_empty (priv->filter_seq)); - g_assert (!priv->child_model || G_IS_LIST_MODEL (priv->child_model)); - - /* - * Now add the new items by synthesizing the addition of all the - * itmes in the list. - */ - if (priv->child_model != NULL) - { - guint child_n_items; - - /* - * Now add all the items as one shot to our list so that - * we get populate our sequence and filter sequence. - */ - child_n_items = g_list_model_get_n_items (priv->child_model); - sysprof_model_filter_child_model_items_changed (self, 0, 0, child_n_items, priv->child_model); - - g_assert ((guint)g_sequence_get_length (priv->child_seq) == child_n_items); - g_assert ((guint)g_sequence_get_length (priv->filter_seq) <= child_n_items); - } - - priv->supress_items_changed = FALSE; - - /* Now that we've updated our sequences, notify of all the changes - * as a single series of updates to the consumers. - */ - if (n_items > 0 || !g_sequence_is_empty (priv->filter_seq)) - g_list_model_items_changed (G_LIST_MODEL (self), - 0, - n_items, - g_sequence_get_length (priv->filter_seq)); -} - -void -sysprof_model_filter_set_filter_func (SysprofModelFilter *self, - SysprofModelFilterFunc filter_func, - gpointer filter_func_data, - GDestroyNotify filter_func_data_destroy) -{ - SysprofModelFilterPrivate *priv = sysprof_model_filter_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_MODEL_FILTER (self)); - g_return_if_fail (filter_func || (!filter_func_data && !filter_func_data_destroy)); - - if (priv->filter_func_data_destroy != NULL) - g_clear_pointer (&priv->filter_func_data, priv->filter_func_data_destroy); - - if (filter_func != NULL) - { - priv->filter_func = filter_func; - priv->filter_func_data = filter_func_data; - priv->filter_func_data_destroy = filter_func_data_destroy; - } - else - { - priv->filter_func = sysprof_model_filter_default_filter_func; - priv->filter_func_data = NULL; - priv->filter_func_data_destroy = NULL; - } - - sysprof_model_filter_invalidate (self); -} diff --git a/src/libsysprof-ui/sysprof-model-filter.h b/src/libsysprof-ui/sysprof-model-filter.h deleted file mode 100644 index a1b97bd4..00000000 --- a/src/libsysprof-ui/sysprof-model-filter.h +++ /dev/null @@ -1,60 +0,0 @@ -/* sysprof-model-filter.h - * - * Copyright 2016-2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include - -#include "sysprof-version-macros.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_MODEL_FILTER (sysprof_model_filter_get_type()) - -typedef gboolean (*SysprofModelFilterFunc) (GObject *object, - gpointer user_data); - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofModelFilter, sysprof_model_filter, SYSPROF, MODEL_FILTER, GObject) - -struct _SysprofModelFilterClass -{ - GObjectClass parent_class; - - gpointer padding[8]; -}; - -SYSPROF_AVAILABLE_IN_ALL -SysprofModelFilter *sysprof_model_filter_new (GListModel *child_model); -SYSPROF_AVAILABLE_IN_ALL -GListModel *sysprof_model_filter_get_child_model (SysprofModelFilter *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_model_filter_invalidate (SysprofModelFilter *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_model_filter_set_filter_func (SysprofModelFilter *self, - SysprofModelFilterFunc filter_func, - gpointer filter_func_data, - GDestroyNotify filter_func_data_destroy); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-netdev-aid.c b/src/libsysprof-ui/sysprof-netdev-aid.c deleted file mode 100644 index 5f1c9f2c..00000000 --- a/src/libsysprof-ui/sysprof-netdev-aid.c +++ /dev/null @@ -1,266 +0,0 @@ -/* sysprof-netdev-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-netdev-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-duplex-visualizer.h" -#include "sysprof-netdev-aid.h" - -struct _SysprofNetdevAid -{ - SysprofAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; -} Present; - -G_DEFINE_TYPE (SysprofNetdevAid, sysprof_netdev_aid, SYSPROF_TYPE_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -/** - * sysprof_netdev_aid_new: - * - * Create a new #SysprofNetdevAid. - * - * Returns: (transfer full): a newly created #SysprofNetdevAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_netdev_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_NETDEV_AID, NULL); -} - -static void -sysprof_netdev_aid_prepare (SysprofAid *self, - SysprofProfiler *profiler) -{ - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_NETDEV_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_netdev_source_new (); - sysprof_profiler_add_source (profiler, source); -} - -static bool -collect_netdev_counters (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - GArray *counters = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (counters != NULL); - - for (guint i = 0; i < def->n_counters; i++) - { - const SysprofCaptureCounter *counter = &def->counters[i]; - - if (strcmp (counter->category, "Network") == 0 && - (g_str_has_prefix (counter->name, "RX Bytes") || - g_str_has_prefix (counter->name, "TX Bytes"))) - g_array_append_vals (counters, counter, 1); - } - - return TRUE; -} - -static void -sysprof_netdev_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *present = task_data; - g_autoptr(GArray) counters = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_NETDEV_AID (source_object)); - g_assert (present != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); - sysprof_capture_cursor_foreach (present->cursor, collect_netdev_counters, counters); - g_task_return_pointer (task, - g_steal_pointer (&counters), - (GDestroyNotify) g_array_unref); -} - -static guint -find_other_id (GArray *counters, - const gchar *rx) -{ - g_autofree gchar *other = NULL; - - g_assert (counters); - g_assert (rx != NULL); - - other = g_strdup (rx); - other[0] = 'T'; - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *c = &g_array_index (counters, SysprofCaptureCounter, i); - - if (g_str_equal (c->name, other)) - return c->id; - } - - return 0; -} - -static void -sysprof_netdev_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_CTRDEF }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_NETDEV_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (1, types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_netdev_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_netdev_aid_present_worker); -} - -static gboolean -sysprof_netdev_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) counters = NULL; - Present *present; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_TASK (result)); - - present = g_task_get_task_data (G_TASK (result)); - - if ((counters = g_task_propagate_pointer (G_TASK (result), error))) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - SysprofVisualizerGroup *group; - - group = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "title", _("Network"), - "visible", TRUE, - NULL); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *ctr = &g_array_index (counters, SysprofCaptureCounter, i); - - if (g_str_has_prefix (ctr->name, "RX Bytes")) - { - g_autofree gchar *title = NULL; - gboolean is_combined; - GtkWidget *row; - GdkRGBA rgba; - guint other_id; - - if (!(other_id = find_other_id (counters, ctr->name))) - continue; - - is_combined = g_str_equal (ctr->description, "Combined"); - - if (is_combined) - title = g_strdup ("Network Bytes (All)"); - else - title = g_strdup_printf ("Network Bytes%s", ctr->name + strlen ("RX Bytes")); - - row = g_object_new (SYSPROF_TYPE_DUPLEX_VISUALIZER, - "title", title, - "height-request", 35, - "visible", is_combined, - NULL); - sysprof_color_cycle_next (cycle, &rgba); - sysprof_duplex_visualizer_set_counters (SYSPROF_DUPLEX_VISUALIZER (row), ctr->id, other_id); - sysprof_duplex_visualizer_set_colors (SYSPROF_DUPLEX_VISUALIZER (row), &rgba, &rgba); - sysprof_visualizer_group_insert (group, SYSPROF_VISUALIZER (row), is_combined ? 0 : -1, !is_combined); - } - } - - if (counters->len > 0) - sysprof_display_add_group (present->display, group); - else - g_object_unref (g_object_ref_sink (group)); - } - - return counters != NULL; -} - -static void -sysprof_netdev_aid_class_init (SysprofNetdevAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->prepare = sysprof_netdev_aid_prepare; - aid_class->present_async = sysprof_netdev_aid_present_async; - aid_class->present_finish = sysprof_netdev_aid_present_finish; -} - -static void -sysprof_netdev_aid_init (SysprofNetdevAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Network")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "preferences-system-network-symbolic"); -} diff --git a/src/libsysprof-ui/sysprof-netdev-aid.h b/src/libsysprof-ui/sysprof-netdev-aid.h deleted file mode 100644 index 6bff1765..00000000 --- a/src/libsysprof-ui/sysprof-netdev-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-netdev-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_NETDEV_AID (sysprof_netdev_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofNetdevAid, sysprof_netdev_aid, SYSPROF, NETDEV_AID, SysprofAid) - -SysprofAid *sysprof_netdev_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-notebook.c b/src/libsysprof-ui/sysprof-notebook.c deleted file mode 100644 index 1a040c28..00000000 --- a/src/libsysprof-ui/sysprof-notebook.c +++ /dev/null @@ -1,561 +0,0 @@ -/* sysprof-notebook.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-notebook" - -#include "config.h" - -#include "sysprof-display.h" -#include "sysprof-notebook.h" -#include "sysprof-tab.h" -#include "sysprof-ui-private.h" - -typedef struct -{ - GtkNotebook *notebook; - guint always_show_tabs : 1; -} SysprofNotebookPrivate; - -static void buildable_iface_init (GtkBuildableIface *iface); - -G_DEFINE_TYPE_WITH_CODE (SysprofNotebook, sysprof_notebook, GTK_TYPE_WIDGET, - G_ADD_PRIVATE (SysprofNotebook) - G_IMPLEMENT_INTERFACE (GTK_TYPE_BUILDABLE, buildable_iface_init)) - -enum { - PROP_0, - PROP_ALWAYS_SHOW_TABS, - PROP_CAN_REPLAY, - PROP_CAN_SAVE, - PROP_CURRENT, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -/** - * sysprof_notebook_new: - * - * Create a new #SysprofNotebook. - * - * Returns: (transfer full): a newly created #SysprofNotebook - * - * Since: 3.34 - */ -GtkWidget * -sysprof_notebook_new (void) -{ - return g_object_new (SYSPROF_TYPE_NOTEBOOK, NULL); -} - -static void -sysprof_notebook_notify_can_save_cb (SysprofNotebook *self, - GParamSpec *pspec, - SysprofDisplay *display) -{ - g_assert (SYSPROF_IS_NOTEBOOK (self)); - g_assert (SYSPROF_IS_DISPLAY (display)); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_SAVE]); -} - -static void -sysprof_notebook_notify_can_replay_cb (SysprofNotebook *self, - GParamSpec *pspec, - SysprofDisplay *display) -{ - g_assert (SYSPROF_IS_NOTEBOOK (self)); - g_assert (SYSPROF_IS_DISPLAY (display)); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_REPLAY]); -} - -static void -sysprof_notebook_page_added (SysprofNotebook *self, - GtkWidget *child, - guint page_num, - GtkNotebook *notebook) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_assert (SYSPROF_IS_NOTEBOOK (self)); - g_assert (GTK_IS_WIDGET (child)); - g_assert (GTK_IS_NOTEBOOK (notebook)); - - gtk_notebook_set_show_tabs (notebook, - (priv->always_show_tabs || - gtk_notebook_get_n_pages (notebook) > 1)); - - if (SYSPROF_IS_DISPLAY (child)) - { - GtkWidget *tab = sysprof_tab_new (SYSPROF_DISPLAY (child)); - - gtk_notebook_set_tab_label (notebook, child, tab); - gtk_notebook_set_tab_reorderable (notebook, child, TRUE); - - g_signal_connect_object (child, - "notify::can-replay", - G_CALLBACK (sysprof_notebook_notify_can_replay_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (child, - "notify::can-save", - G_CALLBACK (sysprof_notebook_notify_can_save_cb), - self, - G_CONNECT_SWAPPED); - - g_object_notify_by_pspec (G_OBJECT (notebook), properties [PROP_CAN_REPLAY]); - g_object_notify_by_pspec (G_OBJECT (notebook), properties [PROP_CAN_SAVE]); - g_object_notify_by_pspec (G_OBJECT (notebook), properties [PROP_CURRENT]); - - _sysprof_display_focus_record (SYSPROF_DISPLAY (child)); - } -} - -static void -sysprof_notebook_page_removed (SysprofNotebook *self, - GtkWidget *child, - guint page_num, - GtkNotebook *notebook) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_assert (SYSPROF_IS_NOTEBOOK (self)); - g_assert (GTK_IS_WIDGET (child)); - g_assert (GTK_IS_NOTEBOOK (notebook)); - - if (gtk_widget_in_destruction (GTK_WIDGET (notebook))) - return; - - if (gtk_notebook_get_n_pages (notebook) == 0) - { - child = sysprof_display_new (); - gtk_notebook_append_page (notebook, child, NULL); - gtk_widget_show (child); - - g_signal_handlers_disconnect_by_func (child, - G_CALLBACK (sysprof_notebook_notify_can_save_cb), - notebook); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_REPLAY]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_SAVE]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CURRENT]); - } - - gtk_notebook_set_show_tabs (notebook, - (priv->always_show_tabs || - gtk_notebook_get_n_pages (notebook) > 1)); -} - -static void -sysprof_notebook_switch_page (SysprofNotebook *self, - GtkWidget *widget, - guint page, - GtkNotebook *notebook) -{ - g_assert (SYSPROF_IS_NOTEBOOK (self)); - g_assert (GTK_IS_NOTEBOOK (notebook)); - g_assert (GTK_IS_WIDGET (widget)); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_REPLAY]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_SAVE]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CURRENT]); -} - -static void -sysprof_notebook_dispose (GObject *object) -{ - SysprofNotebook *self = (SysprofNotebook *)object; - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - if (priv->notebook) - { - gtk_widget_unparent (GTK_WIDGET (priv->notebook)); - priv->notebook = NULL; - } - - G_OBJECT_CLASS (sysprof_notebook_parent_class)->dispose (object); -} - -static void -sysprof_notebook_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofNotebook *self = (SysprofNotebook *)object; - - switch (prop_id) - { - case PROP_ALWAYS_SHOW_TABS: - g_value_set_boolean (value, sysprof_notebook_get_always_show_tabs (self)); - break; - - case PROP_CAN_REPLAY: - g_value_set_boolean (value, sysprof_notebook_get_can_replay (self)); - break; - - case PROP_CAN_SAVE: - g_value_set_boolean (value, sysprof_notebook_get_can_save (self)); - break; - - case PROP_CURRENT: - g_value_set_object (value, sysprof_notebook_get_current (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_notebook_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofNotebook *self = (SysprofNotebook *)object; - - switch (prop_id) - { - case PROP_ALWAYS_SHOW_TABS: - sysprof_notebook_set_always_show_tabs (self, g_value_get_boolean (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_notebook_class_init (SysprofNotebookClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_notebook_dispose; - object_class->get_property = sysprof_notebook_get_property; - object_class->set_property = sysprof_notebook_set_property; - - properties [PROP_ALWAYS_SHOW_TABS] = - g_param_spec_boolean ("always-show-tabs", - "Always Show Tabs", - "Always Show Tabs", - FALSE, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CAN_REPLAY] = - g_param_spec_boolean ("can-replay", - "Can Replay", - "If the current display can replay a recording", - FALSE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CAN_SAVE] = - g_param_spec_boolean ("can-save", - "Can Save", - "If the current display can save a recording", - FALSE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CURRENT] = - g_param_spec_object ("current", - "Current", - "The current display", - SYSPROF_TYPE_DISPLAY, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); -} - -static void -sysprof_notebook_init (SysprofNotebook *self) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ()); - gtk_widget_set_parent (GTK_WIDGET (priv->notebook), GTK_WIDGET (self)); - - gtk_notebook_set_show_border (priv->notebook, FALSE); - gtk_notebook_set_scrollable (priv->notebook, TRUE); - gtk_notebook_popup_enable (priv->notebook); - - g_signal_connect_object (priv->notebook, - "page-added", - G_CALLBACK (sysprof_notebook_page_added), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->notebook, - "page-removed", - G_CALLBACK (sysprof_notebook_page_removed), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (priv->notebook, - "switch-page", - G_CALLBACK (sysprof_notebook_switch_page), - self, - G_CONNECT_SWAPPED | G_CONNECT_AFTER); -} - -void -sysprof_notebook_close_current (SysprofNotebook *self) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - gint page; - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - - if ((page = gtk_notebook_get_current_page (priv->notebook)) >= 0) - gtk_notebook_remove_page (priv->notebook, page); -} - -void -sysprof_notebook_open (SysprofNotebook *self, - GFile *file) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - SysprofDisplay *display = NULL; - int page; - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - g_return_if_fail (g_file_is_native (file)); - - for (page = 0; page < sysprof_notebook_get_n_pages (self); page++) - { - SysprofDisplay *child = sysprof_notebook_get_nth_page (self, page); - - if (sysprof_display_is_empty (child)) - { - display = child; - break; - } - } - - if (display == NULL) - { - display = SYSPROF_DISPLAY (sysprof_display_new ()); - page = sysprof_notebook_append (self, display); - } - else - { - page = gtk_notebook_page_num (priv->notebook, GTK_WIDGET (display)); - } - - sysprof_notebook_set_current_page (self, page); - - sysprof_display_open (SYSPROF_DISPLAY (display), file); -} - -SysprofDisplay * -sysprof_notebook_get_current (SysprofNotebook *self) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - gint page; - - g_assert (SYSPROF_IS_NOTEBOOK (self)); - - if ((page = gtk_notebook_get_current_page (priv->notebook)) >= 0) - return SYSPROF_DISPLAY (gtk_notebook_get_nth_page (priv->notebook, page)); - - return NULL; -} - -void -sysprof_notebook_save (SysprofNotebook *self) -{ - SysprofDisplay *display; - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - - if ((display = sysprof_notebook_get_current (self))) - sysprof_display_save (display); -} - -gboolean -sysprof_notebook_get_can_save (SysprofNotebook *self) -{ - SysprofDisplay *display; - - g_return_val_if_fail (SYSPROF_IS_NOTEBOOK (self), FALSE); - - if ((display = sysprof_notebook_get_current (self))) - return sysprof_display_get_can_save (display); - - return FALSE; -} - -gboolean -sysprof_notebook_get_can_replay (SysprofNotebook *self) -{ - SysprofDisplay *display; - - g_return_val_if_fail (SYSPROF_IS_NOTEBOOK (self), FALSE); - - if ((display = sysprof_notebook_get_current (self))) - return sysprof_display_get_can_replay (display); - - return FALSE; -} - -void -sysprof_notebook_replay (SysprofNotebook *self) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - SysprofDisplay *display; - SysprofDisplay *replay; - gint page; - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - - if (!(display = sysprof_notebook_get_current (self)) || - !sysprof_display_get_can_replay (display) || - !(replay = sysprof_display_replay (display))) - return; - - g_return_if_fail (SYSPROF_IS_DISPLAY (replay)); - - gtk_widget_show (GTK_WIDGET (replay)); - gtk_notebook_append_page (priv->notebook, GTK_WIDGET (replay), NULL); - page = gtk_notebook_page_num (priv->notebook, GTK_WIDGET (replay)); - gtk_notebook_set_current_page (priv->notebook, page); -} - -void -sysprof_notebook_add_profiler (SysprofNotebook *self, - SysprofProfiler *profiler) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - GtkWidget *display; - gint page; - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - g_return_if_fail (SYSPROF_IS_PROFILER (profiler)); - - display = sysprof_display_new_for_profiler (profiler); - - gtk_widget_show (display); - gtk_notebook_append_page (priv->notebook, GTK_WIDGET (display), NULL); - page = gtk_notebook_page_num (priv->notebook, display); - gtk_notebook_set_current_page (priv->notebook, page); -} - -gboolean -sysprof_notebook_get_always_show_tabs (SysprofNotebook *self) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_NOTEBOOK (self), FALSE); - - return priv->always_show_tabs; -} - -void -sysprof_notebook_set_always_show_tabs (SysprofNotebook *self, - gboolean always_show_tabs) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - - always_show_tabs = !!always_show_tabs; - - if (always_show_tabs != priv->always_show_tabs) - { - priv->always_show_tabs = always_show_tabs; - gtk_notebook_set_show_tabs (priv->notebook, - (priv->always_show_tabs || - gtk_notebook_get_n_pages (priv->notebook) > 1)); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ALWAYS_SHOW_TABS]); - } -} - -static void -sysprof_notebook_add_child (GtkBuildable *buildable, - GtkBuilder *builder, - GObject *child, - const char *type) -{ - SysprofNotebook *self = (SysprofNotebook *)buildable; - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_assert (SYSPROF_IS_NOTEBOOK (self)); - - if (SYSPROF_IS_DISPLAY (child)) - gtk_notebook_append_page (priv->notebook, GTK_WIDGET (child), NULL); - else - g_warning ("Cannot add child of type %s to %s", - G_OBJECT_TYPE_NAME (child), - G_OBJECT_TYPE_NAME (self)); -} - -static void -buildable_iface_init (GtkBuildableIface *iface) -{ - iface->add_child = sysprof_notebook_add_child; -} - -guint -sysprof_notebook_get_n_pages (SysprofNotebook *self) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_NOTEBOOK (self), 0); - - return gtk_notebook_get_n_pages (priv->notebook); -} - -SysprofDisplay * -sysprof_notebook_get_nth_page (SysprofNotebook *self, - guint nth) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_NOTEBOOK (self), NULL); - - return SYSPROF_DISPLAY (gtk_notebook_get_nth_page (priv->notebook, nth)); -} - -void -sysprof_notebook_set_current_page (SysprofNotebook *self, - int nth) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_NOTEBOOK (self)); - - gtk_notebook_set_current_page (priv->notebook, nth); -} - -int -sysprof_notebook_append (SysprofNotebook *self, - SysprofDisplay *display) -{ - SysprofNotebookPrivate *priv = sysprof_notebook_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_NOTEBOOK (self), -1); - g_return_val_if_fail (SYSPROF_IS_DISPLAY (display), -1); - - return gtk_notebook_append_page (priv->notebook, GTK_WIDGET (display), NULL); -} diff --git a/src/libsysprof-ui/sysprof-notebook.h b/src/libsysprof-ui/sysprof-notebook.h deleted file mode 100644 index 943dc1f1..00000000 --- a/src/libsysprof-ui/sysprof-notebook.h +++ /dev/null @@ -1,85 +0,0 @@ -/* sysprof-notebook.h - * - * Copyright 2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include -#include - -#include "sysprof-display.h" -#include "sysprof-version-macros.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_NOTEBOOK (sysprof_notebook_get_type()) - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofNotebook, sysprof_notebook, SYSPROF, NOTEBOOK, GtkWidget) - -struct _SysprofNotebookClass -{ - GtkWidgetClass parent_class; - - /*< private >*/ - gpointer _reserved[16]; -}; - -SYSPROF_AVAILABLE_IN_ALL -GtkWidget *sysprof_notebook_new (void); -SYSPROF_AVAILABLE_IN_ALL -SysprofDisplay *sysprof_notebook_get_current (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_close_current (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_open (SysprofNotebook *self, - GFile *file); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_save (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_notebook_get_can_save (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_replay (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_notebook_get_can_replay (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_add_profiler (SysprofNotebook *self, - SysprofProfiler *profiler); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_notebook_get_always_show_tabs (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_set_always_show_tabs (SysprofNotebook *self, - gboolean always_show_tabs); -SYSPROF_AVAILABLE_IN_ALL -guint sysprof_notebook_get_n_pages (SysprofNotebook *self); -SYSPROF_AVAILABLE_IN_ALL -SysprofDisplay *sysprof_notebook_get_nth_page (SysprofNotebook *self, - guint nth); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_notebook_set_current_page (SysprofNotebook *self, - int page); -SYSPROF_AVAILABLE_IN_ALL -int sysprof_notebook_append (SysprofNotebook *self, - SysprofDisplay *display); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-page.c b/src/libsysprof-ui/sysprof-page.c deleted file mode 100644 index 45f61152..00000000 --- a/src/libsysprof-ui/sysprof-page.c +++ /dev/null @@ -1,256 +0,0 @@ -/* sysprof-page.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-page" - -#include "config.h" - -#include "sysprof-display.h" -#include "sysprof-page.h" -#include "sysprof-ui-private.h" - -typedef struct -{ - gchar *title; -} SysprofPagePrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofPage, sysprof_page, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_TITLE, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -/** - * sysprof_page_new: - * - * Create a new #SysprofPage. - * - * Returns: (transfer full) (type SysprofPage): a newly created #SysprofPage - */ -GtkWidget * -sysprof_page_new (void) -{ - return g_object_new (SYSPROF_TYPE_PAGE, NULL); -} - -const gchar * -sysprof_page_get_title (SysprofPage *self) -{ - SysprofPagePrivate *priv = sysprof_page_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_PAGE (self), NULL); - - return priv->title; -} - -void -sysprof_page_set_title (SysprofPage *self, - const gchar *title) -{ - SysprofPagePrivate *priv = sysprof_page_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_PAGE (self)); - - if (g_strcmp0 (priv->title, title) != 0) - { - g_free (priv->title); - priv->title = g_strdup (title); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); - } -} - -static void -sysprof_page_real_load_async (SysprofPage *self, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *condition, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_task_report_new_error (self, callback, user_data, - sysprof_page_load_async, - G_IO_ERROR, - G_IO_ERROR_NOT_SUPPORTED, - "Operation not supported"); -} - -static gboolean -sysprof_page_real_load_finish (SysprofPage *self, - GAsyncResult *result, - GError **error) -{ - return g_task_propagate_boolean (G_TASK (result), error); -} - -static void -sysprof_page_dispose (GObject *object) -{ - SysprofPage *self = (SysprofPage *)object; - SysprofPagePrivate *priv = sysprof_page_get_instance_private (self); - GtkWidget *child; - - g_clear_pointer (&priv->title, g_free); - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) - gtk_widget_unparent (child); - - G_OBJECT_CLASS (sysprof_page_parent_class)->dispose (object); -} - -static void -sysprof_page_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofPage *self = SYSPROF_PAGE (object); - - switch (prop_id) - { - case PROP_TITLE: - g_value_set_string (value, sysprof_page_get_title (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_page_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofPage *self = SYSPROF_PAGE (object); - - switch (prop_id) - { - case PROP_TITLE: - sysprof_page_set_title (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_page_class_init (SysprofPageClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_page_dispose; - object_class->get_property = sysprof_page_get_property; - object_class->set_property = sysprof_page_set_property; - - klass->load_async = sysprof_page_real_load_async; - klass->load_finish = sysprof_page_real_load_finish; - - properties [PROP_TITLE] = - g_param_spec_string ("title", - "Title", - "The title for the page", - NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); -} - -static void -sysprof_page_init (SysprofPage *self) -{ - gtk_widget_set_vexpand (GTK_WIDGET (self), TRUE); -} - -/** - * sysprof_page_load_async: - * @condition: (nullable): a #sysprofCaptureCondition or %NULL - * @cancellable: (nullable): a #GCancellable or %NULL - * - * Since: 3.34 - */ -void -sysprof_page_load_async (SysprofPage *self, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *condition, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_return_if_fail (SYSPROF_IS_PAGE (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - SYSPROF_PAGE_GET_CLASS (self)->load_async (self, reader, selection, condition, cancellable, callback, user_data); -} - -gboolean -sysprof_page_load_finish (SysprofPage *self, - GAsyncResult *result, - GError **error) -{ - g_return_val_if_fail (SYSPROF_IS_PAGE (self), FALSE); - g_return_val_if_fail (G_IS_ASYNC_RESULT (result), FALSE); - - return SYSPROF_PAGE_GET_CLASS (self)->load_finish (self, result, error); -} - -void -sysprof_page_set_size_group (SysprofPage *self, - GtkSizeGroup *size_group) -{ - g_return_if_fail (SYSPROF_IS_PAGE (self)); - g_return_if_fail (!size_group || GTK_IS_SIZE_GROUP (size_group)); - - if (SYSPROF_PAGE_GET_CLASS (self)->set_size_group) - SYSPROF_PAGE_GET_CLASS (self)->set_size_group (self, size_group); -} - -void -sysprof_page_set_hadjustment (SysprofPage *self, - GtkAdjustment *hadjustment) -{ - g_return_if_fail (SYSPROF_IS_PAGE (self)); - g_return_if_fail (!hadjustment || GTK_IS_ADJUSTMENT (hadjustment)); - - if (SYSPROF_PAGE_GET_CLASS (self)->set_hadjustment) - SYSPROF_PAGE_GET_CLASS (self)->set_hadjustment (self, hadjustment); -} - -void -sysprof_page_reload (SysprofPage *self) -{ - GtkWidget *display; - - g_return_if_fail (SYSPROF_IS_PAGE (self)); - - if ((display = gtk_widget_get_ancestor (GTK_WIDGET (self), SYSPROF_TYPE_DISPLAY))) - _sysprof_display_reload_page (SYSPROF_DISPLAY (display), self); -} diff --git a/src/libsysprof-ui/sysprof-page.h b/src/libsysprof-ui/sysprof-page.h deleted file mode 100644 index 22d55044..00000000 --- a/src/libsysprof-ui/sysprof-page.h +++ /dev/null @@ -1,88 +0,0 @@ -/* sysprof-page.h - * - * Copyright 2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_PAGE (sysprof_page_get_type()) - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofPage, sysprof_page, SYSPROF, PAGE, GtkWidget) - -struct _SysprofPageClass -{ - GtkWidgetClass parent_class; - - void (*load_async) (SysprofPage *self, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *condition, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); - gboolean (*load_finish) (SysprofPage *self, - GAsyncResult *result, - GError **error); - void (*set_hadjustment) (SysprofPage *self, - GtkAdjustment *hadjustment); - void (*set_size_group) (SysprofPage *self, - GtkSizeGroup *size_group); - - /*< private >*/ - gpointer _reserved[16]; -}; - -SYSPROF_AVAILABLE_IN_ALL -GtkWidget *sysprof_page_new (void); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_page_load_async (SysprofPage *self, - SysprofCaptureReader *reader, - SysprofSelection *selection, - SysprofCaptureCondition *condition, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_page_load_finish (SysprofPage *self, - GAsyncResult *result, - GError **error); -SYSPROF_AVAILABLE_IN_3_36 -void sysprof_page_reload (SysprofPage *self); -SYSPROF_AVAILABLE_IN_ALL -const gchar *sysprof_page_get_title (SysprofPage *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_page_set_title (SysprofPage *self, - const gchar *title); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_page_set_hadjustment (SysprofPage *self, - GtkAdjustment *hadjustment); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_page_set_size_group (SysprofPage *self, - GtkSizeGroup *size_group); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-process-model-row.c b/src/libsysprof-ui/sysprof-process-model-row.c deleted file mode 100644 index aa046f39..00000000 --- a/src/libsysprof-ui/sysprof-process-model-row.c +++ /dev/null @@ -1,258 +0,0 @@ -/* sysprof-process-model-row.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-process-model-row" - -#include "config.h" - -#include "sysprof-process-model-row.h" - -typedef struct -{ - SysprofProcessModelItem *item; - - GtkLabel *args_label; - GtkLabel *label; - GtkLabel *pid; - GtkImage *image; - GtkImage *check; -} SysprofProcessModelRowPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofProcessModelRow, sysprof_process_model_row, GTK_TYPE_LIST_BOX_ROW) - -enum { - PROP_0, - PROP_ITEM, - PROP_SELECTED, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -GtkWidget * -sysprof_process_model_row_new (SysprofProcessModelItem *item) -{ - return g_object_new (SYSPROF_TYPE_PROCESS_MODEL_ROW, - "item", item, - NULL); -} - -SysprofProcessModelItem * -sysprof_process_model_row_get_item (SysprofProcessModelRow *self) -{ - SysprofProcessModelRowPrivate *priv = sysprof_process_model_row_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_PROCESS_MODEL_ROW (self), NULL); - - return priv->item; -} - -static void -sysprof_process_model_row_set_item (SysprofProcessModelRow *self, - SysprofProcessModelItem *item) -{ - SysprofProcessModelRowPrivate *priv = sysprof_process_model_row_get_instance_private (self); - - g_assert (SYSPROF_IS_PROCESS_MODEL_ROW (self)); - g_assert (SYSPROF_IS_PROCESS_MODEL_ITEM (item)); - - if (g_set_object (&priv->item, item)) - { - const gchar *command_line; - g_auto(GStrv) parts = NULL; - g_autofree gchar *pidstr = NULL; - const gchar * const *argv; - GPid pid; - - command_line = sysprof_process_model_item_get_command_line (item); - parts = g_strsplit (command_line ?: "", "\n", 0); - gtk_label_set_label (priv->label, parts [0]); - - if ((NULL != (argv = sysprof_process_model_item_get_argv (item))) && (argv[0] != NULL)) - { - g_autofree gchar *argvstr = g_strjoinv (" ", (gchar **)&argv[1]); - g_autofree gchar *escaped = g_markup_escape_text (argvstr, -1); - - gtk_label_set_label (priv->args_label, escaped); - } - - pid = sysprof_process_model_item_get_pid (item); - pidstr = g_strdup_printf ("%u", pid); - gtk_label_set_label (priv->pid, pidstr); - gtk_label_set_use_markup (priv->pid, TRUE); - } -} - -gboolean -sysprof_process_model_row_get_selected (SysprofProcessModelRow *self) -{ - SysprofProcessModelRowPrivate *priv = sysprof_process_model_row_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_PROCESS_MODEL_ROW (self), FALSE); - - return gtk_widget_get_visible (GTK_WIDGET (priv->check)); -} - -void -sysprof_process_model_row_set_selected (SysprofProcessModelRow *self, - gboolean selected) -{ - SysprofProcessModelRowPrivate *priv = sysprof_process_model_row_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_PROCESS_MODEL_ROW (self)); - - selected = !!selected; - - if (selected != sysprof_process_model_row_get_selected (self)) - { - gtk_widget_set_visible (GTK_WIDGET (priv->check), selected); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SELECTED]); - } -} - -static gboolean -sysprof_process_model_row_query_tooltip (GtkWidget *widget, - gint x, - gint y, - gboolean keyboard_mode, - GtkTooltip *tooltip) -{ - SysprofProcessModelRow *self = (SysprofProcessModelRow *)widget; - SysprofProcessModelRowPrivate *priv = sysprof_process_model_row_get_instance_private (self); - - g_assert (SYSPROF_IS_PROCESS_MODEL_ROW (self)); - g_assert (GTK_IS_TOOLTIP (tooltip)); - - if (priv->item != NULL) - { - const gchar * const *argv = sysprof_process_model_item_get_argv (priv->item); - - if (argv != NULL) - { - g_autofree gchar *str = g_strjoinv (" ", (gchar **)argv); - gtk_tooltip_set_text (tooltip, str); - return TRUE; - } - } - - return FALSE; -} - -static void -sysprof_process_model_row_finalize (GObject *object) -{ - SysprofProcessModelRow *self = (SysprofProcessModelRow *)object; - SysprofProcessModelRowPrivate *priv = sysprof_process_model_row_get_instance_private (self); - - g_clear_object (&priv->item); - - G_OBJECT_CLASS (sysprof_process_model_row_parent_class)->finalize (object); -} - -static void -sysprof_process_model_row_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofProcessModelRow *self = SYSPROF_PROCESS_MODEL_ROW (object); - - switch (prop_id) - { - case PROP_ITEM: - g_value_set_object (value, sysprof_process_model_row_get_item (self)); - break; - - case PROP_SELECTED: - g_value_set_boolean (value, sysprof_process_model_row_get_selected (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_process_model_row_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofProcessModelRow *self = SYSPROF_PROCESS_MODEL_ROW (object); - - switch (prop_id) - { - case PROP_ITEM: - sysprof_process_model_row_set_item (self, g_value_get_object (value)); - break; - - case PROP_SELECTED: - sysprof_process_model_row_set_selected (self, g_value_get_boolean (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_process_model_row_class_init (SysprofProcessModelRowClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->finalize = sysprof_process_model_row_finalize; - object_class->get_property = sysprof_process_model_row_get_property; - object_class->set_property = sysprof_process_model_row_set_property; - - widget_class->query_tooltip = sysprof_process_model_row_query_tooltip; - - properties [PROP_ITEM] = - g_param_spec_object ("item", - "Item", - "Item", - SYSPROF_TYPE_PROCESS_MODEL_ITEM, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_SELECTED] = - g_param_spec_boolean ("selected", - "Selected", - "Selected", - FALSE, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_template_from_resource (widget_class, - "/org/gnome/sysprof/ui/sysprof-process-model-row.ui"); - gtk_widget_class_bind_template_child_private (widget_class, SysprofProcessModelRow, args_label); - gtk_widget_class_bind_template_child_private (widget_class, SysprofProcessModelRow, image); - gtk_widget_class_bind_template_child_private (widget_class, SysprofProcessModelRow, label); - gtk_widget_class_bind_template_child_private (widget_class, SysprofProcessModelRow, pid); - gtk_widget_class_bind_template_child_private (widget_class, SysprofProcessModelRow, check); -} - -static void -sysprof_process_model_row_init (SysprofProcessModelRow *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); - - gtk_widget_set_has_tooltip (GTK_WIDGET (self), TRUE); -} diff --git a/src/libsysprof-ui/sysprof-process-model-row.h b/src/libsysprof-ui/sysprof-process-model-row.h deleted file mode 100644 index 63100357..00000000 --- a/src/libsysprof-ui/sysprof-process-model-row.h +++ /dev/null @@ -1,54 +0,0 @@ -/* sysprof-process-model-row.h - * - * Copyright 2016-2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_PROCESS_MODEL_ROW (sysprof_process_model_row_get_type()) - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofProcessModelRow, sysprof_process_model_row, SYSPROF, PROCESS_MODEL_ROW, GtkListBoxRow) - -struct _SysprofProcessModelRowClass -{ - GtkListBoxRowClass parent; - - gpointer padding[4]; -}; - -SYSPROF_AVAILABLE_IN_ALL -GtkWidget *sysprof_process_model_row_new (SysprofProcessModelItem *item); -SYSPROF_AVAILABLE_IN_ALL -SysprofProcessModelItem *sysprof_process_model_row_get_item (SysprofProcessModelRow *self); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_process_model_row_get_selected (SysprofProcessModelRow *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_process_model_row_set_selected (SysprofProcessModelRow *self, - gboolean selected); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-process-model-row.ui b/src/libsysprof-ui/sysprof-process-model-row.ui deleted file mode 100644 index ee23e296..00000000 --- a/src/libsysprof-ui/sysprof-process-model-row.ui +++ /dev/null @@ -1,52 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-procs-visualizer.c b/src/libsysprof-ui/sysprof-procs-visualizer.c deleted file mode 100644 index 4c09cb33..00000000 --- a/src/libsysprof-ui/sysprof-procs-visualizer.c +++ /dev/null @@ -1,296 +0,0 @@ -/* sysprof-procs-visualizer.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-procs-visualizer" - -#include "config.h" - -#include - -#include "pointcache.h" -#include "sysprof-procs-visualizer.h" - -typedef struct -{ - volatile gint ref_count; - guint n_procs; - guint max_n_procs; - gint64 begin_time; - gint64 end_time; - gint64 duration; - PointCache *cache; - SysprofCaptureCursor *cursor; -} Discovery; - -struct _SysprofProcsVisualizer -{ - SysprofVisualizer parent_instance; - Discovery *discovery; -}; - -G_DEFINE_TYPE (SysprofProcsVisualizer, sysprof_procs_visualizer, SYSPROF_TYPE_VISUALIZER) - -static void -discovery_unref (Discovery *d) -{ - if (g_atomic_int_dec_and_test (&d->ref_count)) - { - g_clear_pointer (&d->cache, point_cache_unref); - g_clear_pointer (&d->cursor, sysprof_capture_cursor_unref); - g_slice_free (Discovery, d); - } -} - -static Discovery * -discovery_ref (Discovery *d) -{ - g_atomic_int_inc (&d->ref_count); - return d; -} - -static bool -discover_max_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - Discovery *d = user_data; - - g_assert (frame != NULL); - g_assert (d != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_PROCESS) - d->n_procs++; - else if (frame->type == SYSPROF_CAPTURE_FRAME_EXIT) - d->n_procs--; - - if (d->n_procs > d->max_n_procs) - d->max_n_procs = d->n_procs; - - return TRUE; -} - -static bool -calc_points_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - Discovery *d = user_data; - gdouble x, y; - - g_assert (frame != NULL); - g_assert (d != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_PROCESS) - d->n_procs++; - else if (frame->type == SYSPROF_CAPTURE_FRAME_EXIT) - d->n_procs--; - - x = (frame->time - d->begin_time) / (gdouble)d->duration; - y = (d->n_procs / (gdouble)d->max_n_procs) * .85; - - point_cache_add_point_to_set (d->cache, 1, x, y); - - return TRUE; -} - -static void -discovery_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Discovery *d = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_PROCS_VISUALIZER (source_object)); - - sysprof_capture_cursor_foreach (d->cursor, discover_max_cb, d); - - d->n_procs = 0; - sysprof_capture_cursor_reset (d->cursor); - - sysprof_capture_cursor_foreach (d->cursor, calc_points_cb, d); - - g_task_return_pointer (task, - discovery_ref (d), - (GDestroyNotify) discovery_unref); -} - -static void -handle_data_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofProcsVisualizer *self = (SysprofProcsVisualizer *)object; - Discovery *d; - - g_assert (SYSPROF_IS_PROCS_VISUALIZER (self)); - g_assert (G_IS_TASK (result)); - - if ((d = g_task_propagate_pointer (G_TASK (result), NULL))) - { - g_clear_pointer (&self->discovery, discovery_unref); - self->discovery = g_steal_pointer (&d); - gtk_widget_queue_allocate (GTK_WIDGET (self)); - } -} - -static void -sysprof_procs_visualizer_set_reader (SysprofVisualizer *visualizer, - SysprofCaptureReader *reader) -{ - static const SysprofCaptureFrameType types[] = { - SYSPROF_CAPTURE_FRAME_PROCESS, - SYSPROF_CAPTURE_FRAME_EXIT, - }; - SysprofProcsVisualizer *self = (SysprofProcsVisualizer *)visualizer; - g_autoptr(GTask) task = NULL; - Discovery *d; - - g_assert (SYSPROF_IS_PROCS_VISUALIZER (self)); - g_assert (reader != NULL); - - d = g_slice_new0 (Discovery); - d->ref_count = 1; - d->cache = point_cache_new (); - d->begin_time = sysprof_capture_reader_get_start_time (reader); - d->end_time = sysprof_capture_reader_get_end_time (reader); - d->cursor = sysprof_capture_cursor_new (reader); - d->duration = d->end_time - d->begin_time; - - point_cache_add_set (d->cache, 1); - sysprof_capture_cursor_add_condition (d->cursor, - sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types)); - - task = g_task_new (self, NULL, handle_data_cb, NULL); - g_task_set_source_tag (task, sysprof_procs_visualizer_set_reader); - g_task_set_task_data (task, d, (GDestroyNotify) discovery_unref); - g_task_run_in_thread (task, discovery_worker); -} - -static void -sysprof_procs_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofProcsVisualizer *self = (SysprofProcsVisualizer *)widget; - g_autofree SysprofVisualizerAbsolutePoint *points = NULL; - GtkAllocation alloc; - GdkRGBA background; - GdkRGBA foreground; - const Point *fpoints; - guint n_fpoints = 0; - Discovery *d; - cairo_t *cr; - gdouble last_x = 0; - gdouble last_y = 0; - - g_assert (SYSPROF_IS_PROCS_VISUALIZER (self)); - g_assert (snapshot != NULL); - - gtk_widget_get_allocation (widget, &alloc); - - gdk_rgba_parse (&foreground, "#813d9c"); - background = foreground; - background.alpha *= .5; - - GTK_WIDGET_CLASS (sysprof_procs_visualizer_parent_class)->snapshot (widget, snapshot); - - if (!(d = self->discovery) || d->cache == NULL) - return; - - if (!(fpoints = point_cache_get_points (d->cache, 1, &n_fpoints))) - return; - - /* This is all going to need offscreen drawing instead of new cairo every frame */ - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height)); - points = g_new0 (SysprofVisualizerAbsolutePoint, n_fpoints); - - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self), - (const SysprofVisualizerRelativePoint *)fpoints, - n_fpoints, - points, - n_fpoints); - - last_x = points[0].x; - last_y = points[0].y; - - cairo_move_to (cr, last_x, alloc.height); - cairo_line_to (cr, last_x, last_y); - - for (guint i = 1; i < n_fpoints; i++) - { - cairo_curve_to (cr, - last_x + ((points[i].x - last_x) / 2), - last_y, - last_x + ((points[i].x - last_x) / 2), - points[i].y, - points[i].x, - points[i].y); - - last_x = points[i].x; - last_y = points[i].y; - } - - cairo_line_to (cr, last_x, alloc.height); - cairo_close_path (cr); - - cairo_set_line_width (cr, 1.0); - - gdk_cairo_set_source_rgba (cr, &background); - cairo_fill_preserve (cr); - gdk_cairo_set_source_rgba (cr, &foreground); - cairo_stroke (cr); - - cairo_destroy (cr); -} - -static void -sysprof_procs_visualizer_finalize (GObject *object) -{ - SysprofProcsVisualizer *self = (SysprofProcsVisualizer *)object; - - g_clear_pointer (&self->discovery, discovery_unref); - - G_OBJECT_CLASS (sysprof_procs_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_procs_visualizer_class_init (SysprofProcsVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofVisualizerClass *visualizer_class = SYSPROF_VISUALIZER_CLASS (klass); - - object_class->finalize = sysprof_procs_visualizer_finalize; - - widget_class->snapshot = sysprof_procs_visualizer_snapshot; - - visualizer_class->set_reader = sysprof_procs_visualizer_set_reader; -} - -static void -sysprof_procs_visualizer_init (SysprofProcsVisualizer *self) -{ -} - -SysprofVisualizer * -sysprof_procs_visualizer_new (void) -{ - return g_object_new (SYSPROF_TYPE_PROCS_VISUALIZER, NULL); -} diff --git a/src/libsysprof-ui/sysprof-procs-visualizer.h b/src/libsysprof-ui/sysprof-procs-visualizer.h deleted file mode 100644 index c7679754..00000000 --- a/src/libsysprof-ui/sysprof-procs-visualizer.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-procs-visualizer.h - * - * Copyright 2019 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-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_PROCS_VISUALIZER (sysprof_procs_visualizer_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofProcsVisualizer, sysprof_procs_visualizer, SYSPROF, PROCS_VISUALIZER, SysprofVisualizer) - -SysprofVisualizer *sysprof_procs_visualizer_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.c b/src/libsysprof-ui/sysprof-profiler-assistant.c deleted file mode 100644 index e6721e3b..00000000 --- a/src/libsysprof-ui/sysprof-profiler-assistant.c +++ /dev/null @@ -1,493 +0,0 @@ -/* sysprof-profiler-assistant.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-profiler-assistant" - -#include "config.h" - -#include -#include - -#include "sysprof-platform.h" - -#include "sysprof-aid-icon.h" -#include "sysprof-control-source.h" -#include "sysprof-environ-editor.h" -#include "sysprof-model-filter.h" -#include "sysprof-profiler-assistant.h" -#include "sysprof-process-model-row.h" -#include "sysprof-theme-manager.h" -#include "sysprof-ui-private.h" - -#include "sysprof-battery-aid.h" -#include "sysprof-callgraph-aid.h" -#include "sysprof-cpu-aid.h" -#include "sysprof-memory-aid.h" -#include "sysprof-memprof-aid.h" -#include "sysprof-netdev-aid.h" -#include "sysprof-proxy-aid.h" -#include "sysprof-rapl-aid.h" - -struct _SysprofProfilerAssistant -{ - GtkWidget parent_instance; - - SysprofProcessModel *process_model; - - /* Template Objects */ - GtkSwitch *allow_throttling; - GtkButton *record_button; - AdwEntryRow *command_line; - GtkSearchEntry *search_entry; - GtkListBox *process_list_box; - SysprofEnvironEditor *environ_editor; - GtkFlowBox *aid_flow_box; - GtkSwitch *whole_system_switch; - GtkSwitch *launch_switch; - GtkSwitch *inherit_switch; -}; - -enum { - START_RECORDING, - N_SIGNALS -}; - -static guint signals [N_SIGNALS]; - -G_DEFINE_TYPE (SysprofProfilerAssistant, sysprof_profiler_assistant, GTK_TYPE_WIDGET) - -/** - * sysprof_profiler_assistant_new: - * - * Create a new #SysprofProfilerAssistant. - * - * Returns: (transfer full): a newly created #SysprofProfilerAssistant - * - * Since: 3.34 - */ -GtkWidget * -sysprof_profiler_assistant_new (void) -{ - return g_object_new (SYSPROF_TYPE_PROFILER_ASSISTANT, NULL); -} - -static void -sysprof_profiler_assistant_aid_activated_cb (SysprofProfilerAssistant *self, - SysprofAidIcon *icon, - GtkFlowBox *flow_box) -{ - g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self)); - g_assert (SYSPROF_IS_AID_ICON (icon)); - g_assert (GTK_IS_FLOW_BOX (flow_box)); - - sysprof_aid_icon_toggle (icon); -} - -static GtkWidget * -create_process_row_cb (gpointer item_, - gpointer user_data) -{ - SysprofProcessModelItem *item = item_; - - g_assert (SYSPROF_IS_PROCESS_MODEL_ITEM (item)); - - return sysprof_process_model_row_new (item); -} - -static void -sysprof_profiler_assistant_notify_active_cb (SysprofProfilerAssistant *self, - GParamSpec *pspec, - GtkSwitch *switch_) -{ - g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self)); - g_assert (GTK_IS_SWITCH (switch_)); - - if (gtk_switch_get_active (switch_)) - return; - - if (self->process_model == NULL) - { - self->process_model = sysprof_process_model_new (); - gtk_list_box_bind_model (self->process_list_box, - G_LIST_MODEL (self->process_model), - create_process_row_cb, - NULL, NULL); - sysprof_process_model_reload (self->process_model); - } -} - -static void -sysprof_profiler_assistant_row_activated_cb (SysprofProfilerAssistant *self, - SysprofProcessModelRow *row, - GtkListBox *list_box) -{ - g_assert (SYSPROF_PROFILER_ASSISTANT (self)); - g_assert (SYSPROF_IS_PROCESS_MODEL_ROW (row)); - g_assert (GTK_IS_LIST_BOX (list_box)); - - sysprof_process_model_row_set_selected (row, - !sysprof_process_model_row_get_selected (row)); -} - -static void -sysprof_profiler_assistant_command_line_changed_cb (SysprofProfilerAssistant *self, - GtkEntry *entry) -{ - g_auto(GStrv) argv = NULL; - GtkStyleContext *style_context; - const gchar *text; - gint argc; - - g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self)); - g_assert (ADW_IS_ENTRY_ROW (entry)); - - style_context = gtk_widget_get_style_context (GTK_WIDGET (entry)); - text = gtk_editable_get_text (GTK_EDITABLE (entry)); - - if (text == NULL || text[0] == 0 || g_shell_parse_argv (text, &argc, &argv, NULL)) - gtk_style_context_remove_class (style_context, "error"); - else - gtk_style_context_add_class (style_context, "error"); -} - -static void -sysprof_profiler_assistant_foreach_cb (GtkWidget *widget, - SysprofProfiler *profiler) -{ - g_assert (GTK_IS_WIDGET (widget)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - if (SYSPROF_IS_PROCESS_MODEL_ROW (widget) && - sysprof_process_model_row_get_selected (SYSPROF_PROCESS_MODEL_ROW (widget))) - { - SysprofProcessModelItem *item; - GPid pid; - - item = sysprof_process_model_row_get_item (SYSPROF_PROCESS_MODEL_ROW (widget)); - pid = sysprof_process_model_item_get_pid (item); - - sysprof_profiler_add_pid (profiler, pid); - } - else if (SYSPROF_IS_AID_ICON (widget)) - { - if (sysprof_aid_icon_is_selected (SYSPROF_AID_ICON (widget))) - { - SysprofAid *aid = sysprof_aid_icon_get_aid (SYSPROF_AID_ICON (widget)); - - sysprof_aid_prepare (aid, profiler); - } - } -} - -static void -sysprof_profiler_assistant_record_clicked_cb (SysprofProfilerAssistant *self, - GtkButton *button) -{ - g_autoptr(SysprofProfiler) profiler = NULL; - g_autoptr(SysprofCaptureWriter) writer = NULL; - g_autoptr(SysprofSource) symbols_source = NULL; -#ifdef __linux__ - g_autoptr(SysprofSource) proc_source = NULL; -#endif - gint fd; - - g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self)); - g_assert (GTK_IS_BUTTON (button)); - - gtk_widget_set_sensitive (GTK_WIDGET (self), FALSE); - - /* Setup a writer immediately */ - if (-1 == (fd = sysprof_memfd_create ("[sysprof-capture]")) || - !(writer = sysprof_capture_writer_new_from_fd (fd, 0))) - { - if (fd != -1) - close (fd); - return; - } - - profiler = sysprof_local_profiler_new (); - sysprof_profiler_set_writer (profiler, writer); - - /* Add pids to profiler */ - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->process_list_box)); - child; - child = gtk_widget_get_next_sibling (child)) - sysprof_profiler_assistant_foreach_cb (child, profiler); - - /* Setup whole system profiling */ - sysprof_profiler_set_whole_system (profiler, gtk_switch_get_active (self->whole_system_switch)); - - if (gtk_switch_get_active (self->launch_switch)) - { - g_auto(GStrv) argv = NULL; - g_auto(GStrv) env = NULL; - SysprofEnviron *environ_; - const gchar *command; - gint argc; - - command = gtk_editable_get_text (GTK_EDITABLE (self->command_line)); - g_shell_parse_argv (command, &argc, &argv, NULL); - - sysprof_profiler_set_spawn (profiler, TRUE); - sysprof_profiler_set_spawn_argv (profiler, (const gchar * const *)argv); - - environ_ = sysprof_environ_editor_get_environ (self->environ_editor); - env = sysprof_environ_get_environ (environ_); - sysprof_profiler_set_spawn_env (profiler, (const gchar * const *)env); - - sysprof_profiler_set_spawn_inherit_environ (profiler, - gtk_switch_get_active (self->inherit_switch)); - } - -#ifdef __linux__ - /* Always add the proc source */ - proc_source = sysprof_proc_source_new (); - sysprof_profiler_add_source (profiler, proc_source); - - { - g_autoptr(SysprofSource) governor = sysprof_governor_source_new (); - sysprof_governor_source_set_disable_governor (SYSPROF_GOVERNOR_SOURCE (governor), - !gtk_switch_get_active (self->allow_throttling)); - sysprof_profiler_add_source (profiler, governor); - } -#endif - - /* Always add symbol decoder to save to file immediately */ - symbols_source = sysprof_symbols_source_new (); - sysprof_profiler_add_source (profiler, symbols_source); - - /* Now allow the aids to add their sources */ - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->aid_flow_box)); - child; - child = gtk_widget_get_next_sibling (child)) - sysprof_profiler_assistant_foreach_cb (child, profiler); - - g_signal_emit (self, signals [START_RECORDING], 0, profiler); -} - -static gboolean -filter_by_search_text (GObject *object, - gpointer user_data) -{ - SysprofProcessModelItem *item = SYSPROF_PROCESS_MODEL_ITEM (object); - const gchar *haystack; - const gchar * const *argv; - const gchar *text = user_data; - - haystack = sysprof_process_model_item_get_command_line (item); - - if (haystack) - { - if (strcasestr (haystack, text) != NULL) - return TRUE; - } - - argv = sysprof_process_model_item_get_argv (item); - - if (argv) - { - for (guint i = 0; argv[i]; i++) - { - if (strcasestr (argv[i], text) != NULL) - return TRUE; - } - } - - return FALSE; -} - -static void -sysprof_profiler_assistant_search_changed_cb (SysprofProfilerAssistant *self, - GtkEditable *search_entry) -{ - g_autoptr(SysprofModelFilter) filter = NULL; - const char *text; - - g_assert (SYSPROF_IS_PROFILER_ASSISTANT (self)); - g_assert (GTK_IS_EDITABLE (search_entry)); - - if (self->process_model == NULL) - return; - - sysprof_process_model_queue_reload (self->process_model); - - text = gtk_editable_get_text (GTK_EDITABLE (search_entry)); - - if (text[0] == 0) - { - gtk_list_box_bind_model (self->process_list_box, - G_LIST_MODEL (self->process_model), - create_process_row_cb, - NULL, NULL); - return; - } - - filter = sysprof_model_filter_new (G_LIST_MODEL (self->process_model)); - sysprof_model_filter_set_filter_func (filter, - filter_by_search_text, - g_strdup (text), - g_free); - gtk_list_box_bind_model (self->process_list_box, - G_LIST_MODEL (filter), - create_process_row_cb, - NULL, NULL); -} - -static void -sysprof_profiler_assistant_dispose (GObject *object) -{ - SysprofProfilerAssistant *self = (SysprofProfilerAssistant *)object; - GtkWidget *child; - - g_clear_object (&self->process_model); - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) - gtk_widget_unparent (child); - - G_OBJECT_CLASS (sysprof_profiler_assistant_parent_class)->dispose (object); -} - -static void -sysprof_profiler_assistant_class_init (SysprofProfilerAssistantClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_profiler_assistant_dispose; - - /** - * SysprofProfilerAssistant::start-recording: - * @self: a #SysprofProfilerAssistant - * @profiler: a #SysprofProfiler - * - * This signal is emitted when a new profiling session should start. - */ - signals [START_RECORDING] = - g_signal_new ("start-recording", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, NULL, NULL, - g_cclosure_marshal_VOID__OBJECT, - G_TYPE_NONE, 1, SYSPROF_TYPE_PROFILER); - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-profiler-assistant.ui"); - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, allow_throttling); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, aid_flow_box); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, command_line); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, environ_editor); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, process_list_box); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, record_button); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, whole_system_switch); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, launch_switch); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, inherit_switch); - gtk_widget_class_bind_template_child (widget_class, SysprofProfilerAssistant, search_entry); - - sysprof_theme_manager_register_resource (sysprof_theme_manager_get_default (), - NULL, - NULL, - "/org/gnome/sysprof/css/SysprofProfilerAssistant-shared.css"); - - g_type_ensure (SYSPROF_TYPE_AID_ICON); - g_type_ensure (SYSPROF_TYPE_BATTERY_AID); - g_type_ensure (SYSPROF_TYPE_CALLGRAPH_AID); - g_type_ensure (SYSPROF_TYPE_CONTROL_SOURCE); - g_type_ensure (SYSPROF_TYPE_CPU_AID); - g_type_ensure (SYSPROF_TYPE_DISKSTAT_SOURCE); - g_type_ensure (SYSPROF_TYPE_ENVIRON_EDITOR); - g_type_ensure (SYSPROF_TYPE_MEMORY_AID); - g_type_ensure (SYSPROF_TYPE_MEMPROF_AID); - g_type_ensure (SYSPROF_TYPE_NETDEV_AID); - g_type_ensure (SYSPROF_TYPE_PROXY_AID); - g_type_ensure (SYSPROF_TYPE_RAPL_AID); -} - -static void -sysprof_profiler_assistant_init (SysprofProfilerAssistant *self) -{ - g_autoptr(SysprofEnviron) environ_ = sysprof_environ_new (); - - gtk_widget_init_template (GTK_WIDGET (self)); - - g_signal_connect_object (self->record_button, - "clicked", - G_CALLBACK (sysprof_profiler_assistant_record_clicked_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->command_line, - "changed", - G_CALLBACK (sysprof_profiler_assistant_command_line_changed_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->process_list_box, - "row-activated", - G_CALLBACK (sysprof_profiler_assistant_row_activated_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->whole_system_switch, - "notify::active", - G_CALLBACK (sysprof_profiler_assistant_notify_active_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->aid_flow_box, - "child-activated", - G_CALLBACK (sysprof_profiler_assistant_aid_activated_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->search_entry, - "changed", - G_CALLBACK (sysprof_profiler_assistant_search_changed_cb), - self, - G_CONNECT_SWAPPED); - - sysprof_environ_editor_set_environ (self->environ_editor, environ_); -} - -void -_sysprof_profiler_assistant_focus_record (SysprofProfilerAssistant *self) -{ - g_return_if_fail (SYSPROF_IS_PROFILER_ASSISTANT (self)); - - gtk_widget_grab_focus (GTK_WIDGET (self->record_button)); -} - -void -sysprof_profiler_assistant_set_executable (SysprofProfilerAssistant *self, - const gchar *path) -{ - g_return_if_fail (SYSPROF_IS_PROFILER_ASSISTANT (self)); - - if (path == NULL || path[0] == 0) - { - gtk_editable_set_text (GTK_EDITABLE (self->command_line), ""); - gtk_switch_set_active (self->launch_switch, FALSE); - } - else - { - gtk_editable_set_text (GTK_EDITABLE (self->command_line), path); - gtk_switch_set_active (self->launch_switch, TRUE); - gtk_widget_grab_focus (GTK_WIDGET (self->command_line)); - } -} diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.h b/src/libsysprof-ui/sysprof-profiler-assistant.h deleted file mode 100644 index ff06c78b..00000000 --- a/src/libsysprof-ui/sysprof-profiler-assistant.h +++ /dev/null @@ -1,37 +0,0 @@ -/* sysprof-profiler-assistant.h - * - * Copyright 2019 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 - -#include "sysprof-version-macros.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_PROFILER_ASSISTANT (sysprof_profiler_assistant_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofProfilerAssistant, sysprof_profiler_assistant, SYSPROF, PROFILER_ASSISTANT, GtkWidget) - -GtkWidget *sysprof_profiler_assistant_new (void); -void sysprof_profiler_assistant_set_executable (SysprofProfilerAssistant *self, - const gchar *path); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-profiler-assistant.ui b/src/libsysprof-ui/sysprof-profiler-assistant.ui deleted file mode 100644 index 669c21ab..00000000 --- a/src/libsysprof-ui/sysprof-profiler-assistant.ui +++ /dev/null @@ -1,279 +0,0 @@ - - - - sysprof-cpu - - - sysprof-memory - - - sysprof-allocations - - - sysprof-calgraph - - - sysprof-networking - - - sysprof-rapl - - - /org/gnome/Sysprof3/Profiler - session - org.gnome.Shell - - GNOME Shell - sysprof-library - - - Speedtrack - sysprof-gtk - - - libsysprof-speedtrack-4.so - - - - - GJS - sysprof-cli - - - - - - Application - sysprof-trace-app - - - SYSPROF_TRACE_FD - - - - - sysprof-battery - - - Disk - sysprof-disk - - - - - - diff --git a/src/libsysprof-ui/sysprof-proxy-aid.c b/src/libsysprof-ui/sysprof-proxy-aid.c deleted file mode 100644 index 6fd05c0e..00000000 --- a/src/libsysprof-ui/sysprof-proxy-aid.c +++ /dev/null @@ -1,209 +0,0 @@ -/* sysprof-proxy-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-proxy-aid" - -#include "sysprof-proxy-aid.h" - -typedef struct -{ - GBusType bus_type; - gchar *bus_name; - gchar *object_path; -} SysprofProxyAidPrivate; - -enum { - PROP_0, - PROP_BUS_TYPE, - PROP_BUS_NAME, - PROP_OBJECT_PATH, - N_PROPS -}; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofProxyAid, sysprof_proxy_aid, SYSPROF_TYPE_AID) - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_proxy_aid_prepare (SysprofAid *aid, - SysprofProfiler *profiler) -{ - SysprofProxyAid *self = (SysprofProxyAid *)aid; - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - g_autoptr(SysprofSource) source = NULL; - - g_assert (SYSPROF_IS_PROXY_AID (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - source = sysprof_proxy_source_new (priv->bus_type, priv->bus_name, priv->object_path); - sysprof_profiler_add_source (profiler, source); -} - -static void -sysprof_proxy_aid_finalize (GObject *object) -{ - SysprofProxyAid *self = (SysprofProxyAid *)object; - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - - g_clear_pointer (&priv->bus_name, g_free); - g_clear_pointer (&priv->object_path, g_free); - - G_OBJECT_CLASS (sysprof_proxy_aid_parent_class)->finalize (object); -} - -static void -sysprof_proxy_aid_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofProxyAid *self = SYSPROF_PROXY_AID (object); - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - - switch (prop_id) - { - case PROP_BUS_NAME: - g_value_set_string (value, priv->bus_name); - break; - - case PROP_OBJECT_PATH: - g_value_set_string (value, priv->object_path); - break; - - case PROP_BUS_TYPE: - g_value_set_enum (value, priv->bus_type); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_proxy_aid_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofProxyAid *self = SYSPROF_PROXY_AID (object); - - switch (prop_id) - { - case PROP_BUS_NAME: - sysprof_proxy_aid_set_bus_name (self, g_value_get_string (value)); - break; - - case PROP_BUS_TYPE: - sysprof_proxy_aid_set_bus_type (self, g_value_get_enum (value)); - break; - - case PROP_OBJECT_PATH: - sysprof_proxy_aid_set_object_path (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_proxy_aid_class_init (SysprofProxyAidClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - object_class->finalize = sysprof_proxy_aid_finalize; - object_class->get_property = sysprof_proxy_aid_get_property; - object_class->set_property = sysprof_proxy_aid_set_property; - - aid_class->prepare = sysprof_proxy_aid_prepare; - - properties [PROP_OBJECT_PATH] = - g_param_spec_string ("object-path", NULL, NULL, - NULL, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_BUS_NAME] = - g_param_spec_string ("bus-name", NULL, NULL, - NULL, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_BUS_TYPE] = - g_param_spec_enum ("bus-type", NULL, NULL, - G_TYPE_BUS_TYPE, - G_BUS_TYPE_SESSION, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_proxy_aid_init (SysprofProxyAid *self) -{ - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - - priv->bus_type = G_BUS_TYPE_SESSION; - priv->object_path = g_strdup ("/org/gnome/Sysprof3/Profiler"); -} - -void -sysprof_proxy_aid_set_bus_type (SysprofProxyAid *self, - GBusType bus_type) -{ - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_PROXY_AID (self)); - g_return_if_fail (bus_type == G_BUS_TYPE_SESSION || bus_type == G_BUS_TYPE_SYSTEM); - - priv->bus_type = bus_type; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUS_TYPE]); -} - -void -sysprof_proxy_aid_set_bus_name (SysprofProxyAid *self, - const gchar *bus_name) -{ - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_PROXY_AID (self)); - - if (g_strcmp0 (bus_name, priv->bus_name) != 0) - { - g_free (priv->bus_name); - priv->bus_name = g_strdup (bus_name); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BUS_NAME]); - } -} - -void -sysprof_proxy_aid_set_object_path (SysprofProxyAid *self, - const gchar *object_path) -{ - SysprofProxyAidPrivate *priv = sysprof_proxy_aid_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_PROXY_AID (self)); - - if (g_strcmp0 (object_path, priv->object_path) != 0) - { - g_free (priv->object_path); - priv->object_path = g_strdup (object_path); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_OBJECT_PATH]); - } -} diff --git a/src/libsysprof-ui/sysprof-proxy-aid.h b/src/libsysprof-ui/sysprof-proxy-aid.h deleted file mode 100644 index 218ba117..00000000 --- a/src/libsysprof-ui/sysprof-proxy-aid.h +++ /dev/null @@ -1,46 +0,0 @@ -/* sysprof-proxy-aid.h - * - * Copyright 2019 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-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_PROXY_AID (sysprof_proxy_aid_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofProxyAid, sysprof_proxy_aid, SYSPROF, PROXY_AID, SysprofAid) - -struct _SysprofProxyAidClass -{ - SysprofAidClass parent_class; - - /*< private >*/ - gpointer _reserved[8]; -}; - -void sysprof_proxy_aid_set_bus_type (SysprofProxyAid *self, - GBusType bus_type); -void sysprof_proxy_aid_set_bus_name (SysprofProxyAid *self, - const gchar *bus_name); -void sysprof_proxy_aid_set_object_path (SysprofProxyAid *self, - const gchar *obj_path); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-rapl-aid.c b/src/libsysprof-ui/sysprof-rapl-aid.c deleted file mode 100644 index 9e2c88ee..00000000 --- a/src/libsysprof-ui/sysprof-rapl-aid.c +++ /dev/null @@ -1,253 +0,0 @@ -/* sysprof-rapl-aid.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-rapl-aid" - -#include "config.h" - -#include - -#include "sysprof-color-cycle.h" -#include "sysprof-rapl-aid.h" -#include "sysprof-line-visualizer.h" -#include "sysprof-proxy-aid.h" - -struct _SysprofRaplAid -{ - SysprofProxyAid parent_instance; -}; - -typedef struct -{ - SysprofCaptureCursor *cursor; - SysprofDisplay *display; - GArray *counters; -} Present; - -G_DEFINE_TYPE (SysprofRaplAid, sysprof_rapl_aid, SYSPROF_TYPE_PROXY_AID) - -static void -present_free (gpointer data) -{ - Present *p = data; - - g_clear_pointer (&p->cursor, sysprof_capture_cursor_unref); - g_clear_pointer (&p->counters, g_array_unref); - g_clear_object (&p->display); - g_slice_free (Present, p); -} - -/** - * sysprof_rapl_aid_new: - * - * Create a new #SysprofRaplAid. - * - * Returns: (transfer full): a newly created #SysprofRaplAid - * - * Since: 3.34 - */ -SysprofAid * -sysprof_rapl_aid_new (void) -{ - return g_object_new (SYSPROF_TYPE_RAPL_AID, NULL); -} - -static bool -collect_info (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - SysprofCaptureCounterDefine *def = (SysprofCaptureCounterDefine *)frame; - Present *p = user_data; - - g_assert (frame != NULL); - g_assert (p != NULL); - g_assert (p->counters != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF) - { - for (guint i = 0; i < def->n_counters; i++) - { - const SysprofCaptureCounter *counter = &def->counters[i]; - - if (g_str_has_prefix (counter->category, "RAPL")) - g_array_append_vals (p->counters, counter, 1); - } - } - - return TRUE; -} - -static void -sysprof_rapl_aid_present_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Present *present = task_data; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_RAPL_AID (source_object)); - g_assert (present != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - sysprof_capture_cursor_foreach (present->cursor, collect_info, present); - g_task_return_pointer (task, - g_steal_pointer (&present->counters), - (GDestroyNotify) g_array_unref); -} - -static void -sysprof_rapl_aid_present_async (SysprofAid *aid, - SysprofCaptureReader *reader, - SysprofDisplay *display, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - static const SysprofCaptureFrameType types[] = { SYSPROF_CAPTURE_FRAME_CTRDEF, }; - g_autoptr(SysprofCaptureCondition) condition = NULL; - g_autoptr(SysprofCaptureCursor) cursor = NULL; - g_autoptr(GTask) task = NULL; - Present present; - - g_assert (SYSPROF_IS_RAPL_AID (aid)); - g_assert (reader != NULL); - g_assert (SYSPROF_IS_DISPLAY (display)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - condition = sysprof_capture_condition_new_where_type_in (G_N_ELEMENTS (types), types); - cursor = sysprof_capture_cursor_new (reader); - sysprof_capture_cursor_add_condition (cursor, g_steal_pointer (&condition)); - - present.cursor = g_steal_pointer (&cursor); - present.display = g_object_ref (display); - present.counters = g_array_new (FALSE, FALSE, sizeof (SysprofCaptureCounter)); - - task = g_task_new (aid, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_rapl_aid_present_async); - g_task_set_task_data (task, - g_slice_dup (Present, &present), - present_free); - g_task_run_in_thread (task, sysprof_rapl_aid_present_worker); -} - -static gboolean -sysprof_rapl_aid_present_finish (SysprofAid *aid, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) counters = NULL; - Present *present; - - g_assert (SYSPROF_IS_AID (aid)); - g_assert (G_IS_TASK (result)); - - present = g_task_get_task_data (G_TASK (result)); - - if ((counters = g_task_propagate_pointer (G_TASK (result), error)) && counters->len) - { - g_autoptr(SysprofColorCycle) cycle = sysprof_color_cycle_new (); - g_autoptr(GHashTable) cat_to_row = g_hash_table_new (g_str_hash, g_str_equal); - SysprofVisualizerGroup *energy; - SysprofVisualizer *all; - guint found = 0; - - energy = g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, - "can-focus", TRUE, - "priority", -300, - "title", _("Energy Usage"), - "visible", TRUE, - NULL); - - all = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", _("Energy Usage (All)"), - "height-request", 35, - "visible", TRUE, - "y-lower", 0.0, - "units", "Watts", - NULL); - sysprof_visualizer_group_insert (energy, SYSPROF_VISUALIZER (all), 0, FALSE); - - for (guint i = 0; i < counters->len; i++) - { - const SysprofCaptureCounter *ctr = &g_array_index (counters, SysprofCaptureCounter, i); - - /* The pseudo counters (core:-1 cpu:-1) have "RAPL" as the group */ - if (g_strcmp0 (ctr->category, "RAPL") == 0) - { - GdkRGBA rgba; - - sysprof_color_cycle_next (cycle, &rgba); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (all), ctr->id, &rgba); - found++; - } - else if (g_str_has_prefix (ctr->category, "RAPL ")) - { - SysprofVisualizer *row; - GdkRGBA rgba; - - row = g_hash_table_lookup (cat_to_row, ctr->category); - - if (row == NULL) - { - row = g_object_new (SYSPROF_TYPE_LINE_VISUALIZER, - "title", ctr->category, - "height-request", 20, - "visible", FALSE, - "y-lower", 0.0, - "units", "Watts", - NULL); - g_hash_table_insert (cat_to_row, (gchar *)ctr->category, row); - sysprof_visualizer_group_insert (energy, SYSPROF_VISUALIZER (row), -1, TRUE); - } - - sysprof_color_cycle_next (cycle, &rgba); - sysprof_line_visualizer_add_counter (SYSPROF_LINE_VISUALIZER (row), ctr->id, &rgba); - found++; - } - } - - if (found > 0) - sysprof_display_add_group (present->display, energy); - else - g_object_unref (g_object_ref_sink (energy)); - } - - return counters != NULL; -} - -static void -sysprof_rapl_aid_class_init (SysprofRaplAidClass *klass) -{ - SysprofAidClass *aid_class = SYSPROF_AID_CLASS (klass); - - aid_class->present_async = sysprof_rapl_aid_present_async; - aid_class->present_finish = sysprof_rapl_aid_present_finish; -} - -static void -sysprof_rapl_aid_init (SysprofRaplAid *self) -{ - sysprof_aid_set_display_name (SYSPROF_AID (self), _("Energy Usage")); - sysprof_aid_set_icon_name (SYSPROF_AID (self), "battery-low-charging-symbolic"); - sysprof_proxy_aid_set_object_path (SYSPROF_PROXY_AID (self), "/org/gnome/Sysprof3/RAPL"); - sysprof_proxy_aid_set_bus_type (SYSPROF_PROXY_AID (self), G_BUS_TYPE_SYSTEM); - sysprof_proxy_aid_set_bus_name (SYSPROF_PROXY_AID (self), "org.gnome.Sysprof3"); -} diff --git a/src/libsysprof-ui/sysprof-rapl-aid.h b/src/libsysprof-ui/sysprof-rapl-aid.h deleted file mode 100644 index 8721c5dd..00000000 --- a/src/libsysprof-ui/sysprof-rapl-aid.h +++ /dev/null @@ -1,33 +0,0 @@ -/* sysprof-rapl-aid.h - * - * Copyright 2019 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-proxy-aid.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_RAPL_AID (sysprof_rapl_aid_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofRaplAid, sysprof_rapl_aid, SYSPROF, RAPL_AID, SysprofProxyAid) - -SysprofAid *sysprof_rapl_aid_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-recording-state-view.c b/src/libsysprof-ui/sysprof-recording-state-view.c deleted file mode 100644 index ea025a4b..00000000 --- a/src/libsysprof-ui/sysprof-recording-state-view.c +++ /dev/null @@ -1,202 +0,0 @@ -/* sysprof-recording-state-view.c - * - * Copyright 2016-2019 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-recording-state-view.h" -#include "sysprof-time-label.h" - -typedef struct -{ - SysprofProfiler *profiler; - SysprofTimeLabel *elapsed; - GtkLabel *samples; - gulong notify_elapsed_handler; -} SysprofRecordingStateViewPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofRecordingStateView, sysprof_recording_state_view, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_PROFILER, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -GtkWidget * -sysprof_recording_state_view_new (void) -{ - return g_object_new (SYSPROF_TYPE_RECORDING_STATE_VIEW, NULL); -} - -static void -sysprof_recording_state_view_notify_elapsed (SysprofRecordingStateView *self, - GParamSpec *pspec, - SysprofProfiler *profiler) -{ - SysprofRecordingStateViewPrivate *priv = sysprof_recording_state_view_get_instance_private (self); - SysprofCaptureWriter *writer; - gint64 elapsed; - - g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self)); - g_assert (SYSPROF_IS_PROFILER (profiler)); - - if ((writer = sysprof_profiler_get_writer (profiler))) - { - SysprofCaptureStat st; - g_autofree gchar *samples = NULL; - gint64 count; - - sysprof_capture_writer_stat (writer, &st); - count = st.frame_count[SYSPROF_CAPTURE_FRAME_SAMPLE] + - st.frame_count[SYSPROF_CAPTURE_FRAME_MARK] + - st.frame_count[SYSPROF_CAPTURE_FRAME_CTRSET]; - - samples = g_strdup_printf ("%"G_GINT64_FORMAT, count); - gtk_label_set_label (priv->samples, samples); - } - - elapsed = (gint64)sysprof_profiler_get_elapsed (profiler); - sysprof_time_label_set_duration (priv->elapsed, elapsed); -} - -static void -sysprof_recording_state_view_dispose (GObject *object) -{ - SysprofRecordingStateView *self = (SysprofRecordingStateView *)object; - SysprofRecordingStateViewPrivate *priv = sysprof_recording_state_view_get_instance_private (self); - GtkWidget *child; - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) - gtk_widget_unparent (child); - - if (priv->profiler != NULL) - { - g_clear_signal_handler (&priv->notify_elapsed_handler, priv->profiler); - g_clear_object (&priv->profiler); - } - - G_OBJECT_CLASS (sysprof_recording_state_view_parent_class)->dispose (object); -} - -static void -sysprof_recording_state_view_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofRecordingStateView *self = SYSPROF_RECORDING_STATE_VIEW (object); - SysprofRecordingStateViewPrivate *priv = sysprof_recording_state_view_get_instance_private (self); - - switch (prop_id) - { - case PROP_PROFILER: - g_value_set_object (value, priv->profiler); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_recording_state_view_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofRecordingStateView *self = SYSPROF_RECORDING_STATE_VIEW (object); - - switch (prop_id) - { - case PROP_PROFILER: - sysprof_recording_state_view_set_profiler (self, g_value_get_object (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_recording_state_view_class_init (SysprofRecordingStateViewClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_recording_state_view_dispose; - object_class->get_property = sysprof_recording_state_view_get_property; - object_class->set_property = sysprof_recording_state_view_set_property; - - properties [PROP_PROFILER] = - g_param_spec_object ("profiler", - "Profiler", - "Profiler", - SYSPROF_TYPE_PROFILER, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-recording-state-view.ui"); - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, elapsed); - gtk_widget_class_bind_template_child_private (widget_class, SysprofRecordingStateView, samples); - - g_type_ensure (SYSPROF_TYPE_TIME_LABEL); -} - -static void -sysprof_recording_state_view_init (SysprofRecordingStateView *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); -} - -void -sysprof_recording_state_view_set_profiler (SysprofRecordingStateView *self, - SysprofProfiler *profiler) -{ - SysprofRecordingStateViewPrivate *priv = sysprof_recording_state_view_get_instance_private (self); - - g_assert (SYSPROF_IS_RECORDING_STATE_VIEW (self)); - g_assert (!profiler || SYSPROF_IS_PROFILER (profiler)); - - sysprof_time_label_set_duration (priv->elapsed, 0); - - if (profiler != priv->profiler) - { - if (priv->profiler != NULL) - { - g_signal_handler_disconnect (priv->profiler, priv->notify_elapsed_handler); - g_clear_object (&priv->profiler); - } - - if (profiler != NULL) - { - priv->profiler = g_object_ref (profiler); - priv->notify_elapsed_handler = - g_signal_connect_object (profiler, - "notify::elapsed", - G_CALLBACK (sysprof_recording_state_view_notify_elapsed), - self, - G_CONNECT_SWAPPED); - } - } -} diff --git a/src/libsysprof-ui/sysprof-recording-state-view.h b/src/libsysprof-ui/sysprof-recording-state-view.h deleted file mode 100644 index b53481f4..00000000 --- a/src/libsysprof-ui/sysprof-recording-state-view.h +++ /dev/null @@ -1,41 +0,0 @@ -/* sysprof-recording-state-view.h - * - * Copyright 2016-2019 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 -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_RECORDING_STATE_VIEW (sysprof_recording_state_view_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofRecordingStateView, sysprof_recording_state_view, SYSPROF, RECORDING_STATE_VIEW, GtkWidget) - -struct _SysprofRecordingStateViewClass -{ - GtkWidgetClass parent; -}; - -GtkWidget *sysprof_recording_state_view_new (void); -void sysprof_recording_state_view_set_profiler (SysprofRecordingStateView *self, - SysprofProfiler *profiler); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-recording-state-view.ui b/src/libsysprof-ui/sysprof-recording-state-view.ui deleted file mode 100644 index 1885f885..00000000 --- a/src/libsysprof-ui/sysprof-recording-state-view.ui +++ /dev/null @@ -1,83 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-scrollmap.c b/src/libsysprof-ui/sysprof-scrollmap.c deleted file mode 100644 index 6dbddbb9..00000000 --- a/src/libsysprof-ui/sysprof-scrollmap.c +++ /dev/null @@ -1,333 +0,0 @@ -/* sysprof-scrollmap.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-scrollmap" - -#include "config.h" - -#include "sysprof-scrollmap.h" - -#define BOX_SIZE 4 - -struct _SysprofScrollmap -{ - GtkWidget parent_instance; - - GtkWidget *scrollbar; - - gint64 begin_time; - gint64 end_time; - - GArray *timings; - GArray *buckets; - GCancellable *cancellable; - - gint most; -}; - -typedef struct -{ - gint64 begin_time; - gint64 end_time; - GArray *timings; - gint width; - gint height; -} Recalculate; - -G_DEFINE_TYPE (SysprofScrollmap, sysprof_scrollmap, GTK_TYPE_WIDGET) - -static void -recalculate_free (gpointer data) -{ - Recalculate *state = data; - - g_clear_pointer (&state->timings, g_array_unref); - g_slice_free (Recalculate, state); -} - -static void -sysprof_scrollmap_recalculate_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - Recalculate *state = task_data; - g_autoptr(GArray) buckets = NULL; - gint64 duration; - gint n_buckets; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_SCROLLMAP (source_object)); - g_assert (state != NULL); - g_assert (state->timings != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - duration = state->end_time - state->begin_time; - n_buckets = MAX (10, state->width / (BOX_SIZE + 1)); - buckets = g_array_sized_new (FALSE, TRUE, sizeof (gint), n_buckets); - g_array_set_size (buckets, n_buckets); - - for (guint i = 0; i < state->timings->len; i++) - { - gint64 t = g_array_index (state->timings, gint64, i); - gint n; - - if (t < state->begin_time || t > state->end_time) - continue; - - n = MIN (n_buckets - 1, ((t - state->begin_time) / (gdouble)duration) * n_buckets); - - g_assert (n < n_buckets); - - g_array_index (buckets, gint, n)++; - } - - g_task_return_pointer (task, - g_steal_pointer (&buckets), - (GDestroyNotify) g_array_unref); -} - -static void -sysprof_scrollmap_recalculate_async (SysprofScrollmap *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_autoptr(GTask) task = NULL; - GtkAllocation alloc; - Recalculate state; - - g_assert (SYSPROF_IS_SCROLLMAP (self)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_scrollmap_recalculate_async); - - if (self->timings == NULL) - { - g_task_return_new_error (task, - G_IO_ERROR, - G_IO_ERROR_CANCELLED, - "The operation was cancelled"); - return; - } - - gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); - - state.begin_time = self->begin_time; - state.end_time = self->end_time; - state.width = alloc.width; - state.height = alloc.height; - state.timings = g_array_ref (self->timings); - - g_task_set_task_data (task, - g_slice_dup (Recalculate, &state), - recalculate_free); - g_task_run_in_thread (task, sysprof_scrollmap_recalculate_worker); -} - -static GArray * -sysprof_scrollmap_recalculate_finish (SysprofScrollmap *self, - GAsyncResult *result, - GError **error) -{ - g_assert (SYSPROF_IS_SCROLLMAP (self)); - g_assert (G_IS_TASK (result)); - - return g_task_propagate_pointer (G_TASK (result), error); -} - -static inline void -draw_boxes (const GtkAllocation *alloc, - GtkSnapshot *snapshot, - int x, - int n_boxes, - const GdkRGBA *color) -{ - int y = alloc->y + alloc->height - BOX_SIZE; - - for (int i = 0; i < n_boxes; i++) - { - gtk_snapshot_append_color (snapshot, color, &GRAPHENE_RECT_INIT (x, y, BOX_SIZE, -BOX_SIZE)); - y -= (BOX_SIZE + 1); - } -} - -static void -sysprof_scrollmap_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofScrollmap *self = (SysprofScrollmap *)widget; - GtkStyleContext *style_context; - GtkAllocation alloc; - GdkRGBA color; - int max_boxes; - - g_assert (SYSPROF_IS_SCROLLMAP (self)); - g_assert (GTK_IS_SNAPSHOT (snapshot)); - - if (self->buckets == NULL) - goto chainup; - - gtk_widget_get_allocation (widget, &alloc); - - alloc.y += 3; - alloc.height -= 6; - - max_boxes = alloc.height / (BOX_SIZE + 1) - 1; - - style_context = gtk_widget_get_style_context (widget); - gtk_style_context_get_color (style_context, &color); - - for (guint i = 0; i < self->buckets->len; i++) - { - int n = g_array_index (self->buckets, gint, i); - int x = 1 + i * (BOX_SIZE + 1); - int b = max_boxes * (n / (gdouble)self->most); - - if (n > 0) - b = MAX (b, 1); - - draw_boxes (&alloc, snapshot, x, b, &color); - } - -chainup: - GTK_WIDGET_CLASS (sysprof_scrollmap_parent_class)->snapshot (widget, snapshot); -} - -static void -sysprof_scrollmap_recalculate_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofScrollmap *self = (SysprofScrollmap *)object; - g_autoptr(GArray) buckets = NULL; - - g_assert (SYSPROF_IS_SCROLLMAP (self)); - g_assert (G_IS_ASYNC_RESULT (result)); - g_assert (user_data == NULL); - - if ((buckets = sysprof_scrollmap_recalculate_finish (self, result, NULL))) - { - self->most = 0; - - for (guint i = 0; i < buckets->len; i++) - { - gint n = g_array_index (buckets, gint, i); - self->most = MAX (self->most, n); - } - - g_clear_pointer (&self->buckets, g_array_unref); - self->buckets = g_steal_pointer (&buckets); - - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -sysprof_scrollmap_dispose (GObject *object) -{ - SysprofScrollmap *self = (SysprofScrollmap *)object; - - if (self->scrollbar) - { - gtk_widget_unparent (GTK_WIDGET (self->scrollbar)); - self->scrollbar = NULL; - } - - g_clear_pointer (&self->buckets, g_array_unref); - g_clear_pointer (&self->timings, g_array_unref); - - G_OBJECT_CLASS (sysprof_scrollmap_parent_class)->dispose (object); -} - -static void -sysprof_scrollmap_class_init (SysprofScrollmapClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_scrollmap_dispose; - - widget_class->snapshot = sysprof_scrollmap_snapshot; - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_set_css_name (widget_class, "scrollmap"); -} - -static void -sysprof_scrollmap_init (SysprofScrollmap *self) -{ - self->scrollbar = g_object_new (GTK_TYPE_SCROLLBAR, - "orientation", GTK_ORIENTATION_HORIZONTAL, - NULL); - gtk_widget_set_parent (GTK_WIDGET (self->scrollbar), GTK_WIDGET (self)); -} - -void -sysprof_scrollmap_set_timings (SysprofScrollmap *self, - GArray *timings) -{ - g_return_if_fail (SYSPROF_IS_SCROLLMAP (self)); - - if (timings != self->timings) - { - g_clear_pointer (&self->timings, g_array_unref); - self->timings = timings ? g_array_ref (timings) : NULL; - } -} - -void -sysprof_scrollmap_set_time_range (SysprofScrollmap *self, - gint64 begin_time, - gint64 end_time) -{ - g_return_if_fail (SYSPROF_IS_SCROLLMAP (self)); - - self->begin_time = begin_time; - self->end_time = end_time; - - g_cancellable_cancel (self->cancellable); - g_clear_object (&self->cancellable); - self->cancellable = g_cancellable_new (); - - sysprof_scrollmap_recalculate_async (self, - self->cancellable, - sysprof_scrollmap_recalculate_cb, - NULL); -} - -void -sysprof_scrollmap_set_adjustment (SysprofScrollmap *self, - GtkAdjustment *adjustment) -{ - g_return_if_fail (SYSPROF_IS_SCROLLMAP (self)); - g_return_if_fail (!adjustment || GTK_IS_ADJUSTMENT (adjustment)); - - gtk_scrollbar_set_adjustment (GTK_SCROLLBAR (self->scrollbar), adjustment); -} - -GtkAdjustment * -sysprof_scrollmap_get_adjustment (SysprofScrollmap *self) -{ - g_return_val_if_fail (SYSPROF_IS_SCROLLMAP (self), NULL); - - return gtk_scrollbar_get_adjustment (GTK_SCROLLBAR (self->scrollbar)); -} diff --git a/src/libsysprof-ui/sysprof-scrollmap.h b/src/libsysprof-ui/sysprof-scrollmap.h deleted file mode 100644 index 2fbe1721..00000000 --- a/src/libsysprof-ui/sysprof-scrollmap.h +++ /dev/null @@ -1,40 +0,0 @@ -/* sysprof-scrollmap.h - * - * Copyright 2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_SCROLLMAP (sysprof_scrollmap_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofScrollmap, sysprof_scrollmap, SYSPROF, SCROLLMAP, GtkWidget) - -GtkAdjustment *sysprof_scrollmap_get_adjustment (SysprofScrollmap *self); -void sysprof_scrollmap_set_adjustment (SysprofScrollmap *self, - GtkAdjustment *adjustment); -void sysprof_scrollmap_set_timings (SysprofScrollmap *self, - GArray *timings); -void sysprof_scrollmap_set_time_range (SysprofScrollmap *self, - gint64 begin_time, - gint64 end_time); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-tab.c b/src/libsysprof-ui/sysprof-tab.c deleted file mode 100644 index 8554cc71..00000000 --- a/src/libsysprof-ui/sysprof-tab.c +++ /dev/null @@ -1,158 +0,0 @@ -/* sysprof-tab.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-tab" - -#include "config.h" - -#include "sysprof-display-private.h" -#include "sysprof-tab.h" -#include "sysprof-ui-private.h" - -struct _SysprofTab -{ - GtkWidget parent_instance; - - GtkWidget *center_box; - GtkButton *close_button; - GtkLabel *title; - GtkImage *recording; - - SysprofDisplay *display; -}; - -G_DEFINE_TYPE (SysprofTab, sysprof_tab, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_DISPLAY, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -GtkWidget * -sysprof_tab_new (SysprofDisplay *display) -{ - return g_object_new (SYSPROF_TYPE_TAB, - "display", display, - NULL); -} - -static void -sysprof_tab_close_clicked (SysprofTab *self, - GtkButton *button) -{ - g_assert (SYSPROF_IS_TAB (self)); - g_assert (GTK_IS_BUTTON (button)); - - if (self->display) - _sysprof_display_destroy (self->display); -} - -static void -sysprof_tab_dispose (GObject *object) -{ - SysprofTab *self = (SysprofTab *)object; - - g_clear_pointer (&self->center_box, gtk_widget_unparent); - g_clear_weak_pointer (&self->display); - - G_OBJECT_CLASS (sysprof_tab_parent_class)->dispose (object); -} - -static void -sysprof_tab_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofTab *self = SYSPROF_TAB (object); - - switch (prop_id) - { - case PROP_DISPLAY: - g_value_set_object (value, self->display); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_tab_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofTab *self = SYSPROF_TAB (object); - - switch (prop_id) - { - case PROP_DISPLAY: - g_set_weak_pointer (&self->display, g_value_get_object (value)); - g_object_bind_property (self->display, "title", self->title, "label", G_BINDING_SYNC_CREATE); - g_object_bind_property (self->display, "recording", self->recording, "visible", G_BINDING_SYNC_CREATE); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_tab_class_init (SysprofTabClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_tab_dispose; - object_class->get_property = sysprof_tab_get_property; - object_class->set_property = sysprof_tab_set_property; - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-tab.ui"); - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_bind_template_child (widget_class, SysprofTab, center_box); - gtk_widget_class_bind_template_child (widget_class, SysprofTab, close_button); - gtk_widget_class_bind_template_child (widget_class, SysprofTab, recording); - gtk_widget_class_bind_template_child (widget_class, SysprofTab, title); - - properties [PROP_DISPLAY] = - g_param_spec_object ("display", - "Display", - "The display widget for the tab", - SYSPROF_TYPE_DISPLAY, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_tab_init (SysprofTab *self) -{ - gtk_widget_init_template (GTK_WIDGET (self)); - - g_signal_connect_object (self->close_button, - "clicked", - G_CALLBACK (sysprof_tab_close_clicked), - self, - G_CONNECT_SWAPPED); -} diff --git a/src/libsysprof-ui/sysprof-tab.h b/src/libsysprof-ui/sysprof-tab.h deleted file mode 100644 index 5aff386b..00000000 --- a/src/libsysprof-ui/sysprof-tab.h +++ /dev/null @@ -1,35 +0,0 @@ -/* sysprof-tab.h - * - * Copyright 2019 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 - -#include "sysprof-display.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_TAB (sysprof_tab_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofTab, sysprof_tab, SYSPROF, TAB, GtkWidget) - -GtkWidget *sysprof_tab_new (SysprofDisplay *display); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-tab.ui b/src/libsysprof-ui/sysprof-tab.ui deleted file mode 100644 index f57f717d..00000000 --- a/src/libsysprof-ui/sysprof-tab.ui +++ /dev/null @@ -1,36 +0,0 @@ - - - - diff --git a/src/libsysprof-ui/sysprof-theme-manager.c b/src/libsysprof-ui/sysprof-theme-manager.c deleted file mode 100644 index 3c07b27d..00000000 --- a/src/libsysprof-ui/sysprof-theme-manager.c +++ /dev/null @@ -1,269 +0,0 @@ -/* sysprof-theme-manager.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-theme-manager" - -#include "config.h" - -#include "sysprof-theme-manager.h" - -struct _SysprofThemeManager -{ - GObject parent_instance; - GHashTable *theme_resources; - guint reload_source; - guint registered_signals : 1; -}; - -typedef struct -{ - guint id; - gchar *key; - gchar *theme_name; - gchar *variant; - gchar *resource; - GtkCssProvider *provider; -} ThemeResource; - -G_DEFINE_TYPE (SysprofThemeManager, sysprof_theme_manager, G_TYPE_OBJECT) - -static void -theme_resource_free (gpointer data) -{ - ThemeResource *theme_resource = data; - - if (theme_resource != NULL) - { - g_clear_pointer (&theme_resource->key, g_free); - g_clear_pointer (&theme_resource->theme_name, g_free); - g_clear_pointer (&theme_resource->variant, g_free); - g_clear_pointer (&theme_resource->resource, g_free); - - if (theme_resource->provider != NULL) - { - gtk_style_context_remove_provider_for_display (gdk_display_get_default (), - GTK_STYLE_PROVIDER (theme_resource->provider)); - g_clear_object (&theme_resource->provider); - } - - g_slice_free (ThemeResource, theme_resource); - } -} - -static gboolean -theme_resource_matches (ThemeResource *theme_resource, - GtkSettings *settings) -{ - g_autofree gchar *theme_name = NULL; - gboolean dark_theme = FALSE; - - g_assert (theme_resource != NULL); - g_assert (GTK_IS_SETTINGS (settings)); - - if (theme_resource->theme_name == NULL) - return TRUE; - - g_object_get (settings, - "gtk-theme-name", &theme_name, - "gtk-application-prefer-dark-theme", &dark_theme, - NULL); - - if (g_strcmp0 (theme_name, theme_resource->theme_name) == 0) - { - if (dark_theme && g_strcmp0 ("dark", theme_resource->variant) == 0) - return TRUE; - - if (!dark_theme && (!theme_resource->variant || g_strcmp0 ("light", theme_resource->variant) == 0)) - return TRUE; - } - - return FALSE; -} - -static gboolean -sysprof_theme_manager_do_reload (gpointer data) -{ - SysprofThemeManager *self = data; - ThemeResource *theme_resource; - GHashTableIter iter; - GtkSettings *settings; - - g_assert (SYSPROF_IS_THEME_MANAGER (self)); - - self->reload_source = 0; - - settings = gtk_settings_get_default (); - - g_hash_table_iter_init (&iter, self->theme_resources); - - while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&theme_resource)) - { - if (theme_resource_matches (theme_resource, settings)) - { - if (theme_resource->provider == NULL) - { - theme_resource->provider = gtk_css_provider_new (); - gtk_css_provider_load_from_resource (theme_resource->provider, theme_resource->resource); - gtk_style_context_add_provider_for_display (gdk_display_get_default (), - GTK_STYLE_PROVIDER (theme_resource->provider), - GTK_STYLE_PROVIDER_PRIORITY_THEME+1); - } - } - else - { - if (theme_resource->provider != NULL) - { - gtk_style_context_remove_provider_for_display (gdk_display_get_default (), - GTK_STYLE_PROVIDER (theme_resource->provider)); - g_clear_object (&theme_resource->provider); - } - } - } - - return G_SOURCE_REMOVE; -} - -static void -sysprof_theme_manager_queue_reload (SysprofThemeManager *self) -{ - g_assert (SYSPROF_IS_THEME_MANAGER (self)); - - if (self->reload_source == 0) - self->reload_source = g_idle_add_full (G_PRIORITY_LOW, - sysprof_theme_manager_do_reload, - self, - NULL); -} - -static void -sysprof_theme_manager_finalize (GObject *object) -{ - SysprofThemeManager *self = (SysprofThemeManager *)object; - - if (self->reload_source != 0) - { - g_source_remove (self->reload_source); - self->reload_source = 0; - } - - g_clear_pointer (&self->theme_resources, g_hash_table_unref); - - G_OBJECT_CLASS (sysprof_theme_manager_parent_class)->finalize (object); -} - -static void -sysprof_theme_manager_class_init (SysprofThemeManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_theme_manager_finalize; -} - -static void -sysprof_theme_manager_init (SysprofThemeManager *self) -{ - self->theme_resources = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, theme_resource_free); - - gtk_icon_theme_add_resource_path (gtk_icon_theme_get_for_display (gdk_display_get_default ()), - "/org/gnome/sysprof/icons"); -} - -/** - * sysprof_theme_manager_get_default: - * - * Returns: (transfer none): An #SysprofThemeManager - */ -SysprofThemeManager * -sysprof_theme_manager_get_default (void) -{ - static SysprofThemeManager *instance; - - if (instance == NULL) - instance = g_object_new (SYSPROF_TYPE_THEME_MANAGER, NULL); - - return instance; -} - -guint -sysprof_theme_manager_register_resource (SysprofThemeManager *self, - const gchar *theme_name, - const gchar *variant, - const gchar *resource) -{ - ThemeResource *theme_resource; - static guint counter; - guint id; - - g_return_val_if_fail (SYSPROF_IS_THEME_MANAGER (self), 0); - - theme_resource = g_slice_new0 (ThemeResource); - theme_resource->id = id = ++counter; - theme_resource->key = g_strdup_printf ("%s-%s-%d", - theme_name ? theme_name : "shared", - variant ? variant : "light", - theme_resource->id); - theme_resource->theme_name = g_strdup (theme_name); - theme_resource->variant = g_strdup (variant); - theme_resource->resource = g_strdup (resource); - theme_resource->provider = NULL; - - g_hash_table_insert (self->theme_resources, theme_resource->key, theme_resource); - - if (!self->registered_signals) - { - self->registered_signals = TRUE; - g_signal_connect_object (gtk_settings_get_default (), - "notify::gtk-application-prefer-dark-theme", - G_CALLBACK (sysprof_theme_manager_queue_reload), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (gtk_settings_get_default (), - "notify::gtk-theme-name", - G_CALLBACK (sysprof_theme_manager_queue_reload), - self, - G_CONNECT_SWAPPED); - } - - sysprof_theme_manager_queue_reload (self); - - return id; -} - -void -sysprof_theme_manager_unregister (SysprofThemeManager *self, - guint registration_id) -{ - GHashTableIter iter; - ThemeResource *theme_resource; - - g_return_if_fail (SYSPROF_IS_THEME_MANAGER (self)); - - g_hash_table_iter_init (&iter, self->theme_resources); - - while (g_hash_table_iter_next (&iter, NULL, (gpointer *)&theme_resource)) - { - if (theme_resource->id == registration_id) - { - /* Provider is unregistered during destroy */ - g_hash_table_iter_remove (&iter); - break; - } - } -} diff --git a/src/libsysprof-ui/sysprof-theme-manager.h b/src/libsysprof-ui/sysprof-theme-manager.h deleted file mode 100644 index 3724628a..00000000 --- a/src/libsysprof-ui/sysprof-theme-manager.h +++ /dev/null @@ -1,47 +0,0 @@ -/* sysprof-theme-manager.h - * - * Copyright 2016-2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_THEME_MANAGER (sysprof_theme_manager_get_type()) - -G_GNUC_INTERNAL -G_DECLARE_FINAL_TYPE (SysprofThemeManager, sysprof_theme_manager, SYSPROF, THEME_MANAGER, GObject) - -G_GNUC_INTERNAL -SysprofThemeManager *sysprof_theme_manager_get_default (void); -G_GNUC_INTERNAL -void sysprof_theme_manager_unregister (SysprofThemeManager *self, - guint registration_id); -G_GNUC_INTERNAL -guint sysprof_theme_manager_register_resource (SysprofThemeManager *self, - const gchar *theme_name, - const gchar *variant, - const gchar *resource); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-time-label.c b/src/libsysprof-ui/sysprof-time-label.c deleted file mode 100644 index 7d129124..00000000 --- a/src/libsysprof-ui/sysprof-time-label.c +++ /dev/null @@ -1,117 +0,0 @@ -/* sysprof-time-label.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-time-label" - -#include "config.h" - -#include "sysprof-time-label.h" - -struct _SysprofTimeLabel -{ - GtkWidget parent_instance; - GtkCenterBox *box; - GtkLabel *minutes; - GtkLabel *seconds; -}; - -G_DEFINE_TYPE (SysprofTimeLabel, sysprof_time_label, GTK_TYPE_WIDGET) - -static void -sysprof_time_label_dispose (GObject *object) -{ - SysprofTimeLabel *self = (SysprofTimeLabel *)object; - - if (self->box) - { - gtk_widget_unparent (GTK_WIDGET (self->box)); - self->box = NULL; - } - - G_OBJECT_CLASS (sysprof_time_label_parent_class)->dispose (object); -} - -static void -sysprof_time_label_class_init (SysprofTimeLabelClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->dispose = sysprof_time_label_dispose; - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); -} - -static void -sysprof_time_label_init (SysprofTimeLabel *self) -{ - PangoAttrList *attrs = pango_attr_list_new (); - GtkWidget *sep; - - pango_attr_list_insert (attrs, pango_attr_scale_new (4)); - pango_attr_list_insert (attrs, pango_attr_weight_new (PANGO_WEIGHT_BOLD)); - - self->box = GTK_CENTER_BOX (gtk_center_box_new ()); - gtk_widget_set_parent (GTK_WIDGET (self->box), GTK_WIDGET (self)); - - self->minutes = g_object_new (GTK_TYPE_LABEL, - "attributes", attrs, - "xalign", 1.0f, - "hexpand", TRUE, - NULL); - gtk_center_box_set_start_widget (self->box, GTK_WIDGET (self->minutes)); - - sep = g_object_new (GTK_TYPE_LABEL, - "margin-start", 3, - "margin-end", 3, - "attributes", attrs, - "visible", TRUE, - "label", ":", - NULL); - gtk_center_box_set_center_widget (self->box, sep); - - self->seconds = g_object_new (GTK_TYPE_LABEL, - "attributes", attrs, - "visible", TRUE, - "xalign", 0.0f, - "hexpand", TRUE, - NULL); - gtk_center_box_set_end_widget (self->box, GTK_WIDGET (self->seconds)); -} - -void -sysprof_time_label_set_duration (SysprofTimeLabel *self, - guint duration) -{ - gchar minstr[12]; - gchar secstr[12]; - gint min, sec; - - g_return_if_fail (SYSPROF_IS_TIME_LABEL (self)); - - min = duration / 60; - sec = duration % 60; - - g_snprintf (minstr, sizeof minstr, "%02d", min); - g_snprintf (secstr, sizeof secstr, "%02d", sec); - - gtk_label_set_label (self->minutes, minstr); - gtk_label_set_label (self->seconds, secstr); -} diff --git a/src/libsysprof-ui/sysprof-time-label.h b/src/libsysprof-ui/sysprof-time-label.h deleted file mode 100644 index 7dfc5707..00000000 --- a/src/libsysprof-ui/sysprof-time-label.h +++ /dev/null @@ -1,34 +0,0 @@ -/* sysprof-time-label.h - * - * Copyright 2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_TIME_LABEL (sysprof_time_label_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofTimeLabel, sysprof_time_label, SYSPROF, TIME_LABEL, GtkWidget) - -void sysprof_time_label_set_duration (SysprofTimeLabel *self, - guint duration); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-time-visualizer.c b/src/libsysprof-ui/sysprof-time-visualizer.c deleted file mode 100644 index 58de9d35..00000000 --- a/src/libsysprof-ui/sysprof-time-visualizer.c +++ /dev/null @@ -1,543 +0,0 @@ -/* sysprof-time-visualizer.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-time-visualizer" - -#include "config.h" - -#include -#include -#include -#include - -#include "pointcache.h" -#include "sysprof-time-visualizer.h" - -typedef struct -{ - /* - * Our reader as assigned by the visualizer system. - */ - SysprofCaptureReader *reader; - - /* - * An array of LineInfo which contains information about the counters - * we need to render. - */ - GArray *lines; - - /* - * This is our set of cached points to render. Once it is assigned here, - * it is immutable (and therefore may be shared with worker processes - * that are rendering the points). - */ - PointCache *cache; - - /* - * If we have a new counter discovered or the reader is set, we might - * want to delay loading until we return to the main loop. This can - * help us avoid doing duplicate work. - */ - guint queued_load; -} SysprofTimeVisualizerPrivate; - -typedef struct -{ - guint id; - gdouble line_width; - GdkRGBA rgba; - guint use_default_style : 1; - guint use_dash : 1; -} LineInfo; - -typedef struct -{ - SysprofCaptureCursor *cursor; - GArray *lines; - PointCache *cache; - gint64 begin_time; - gint64 end_time; -} LoadData; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofTimeVisualizer, sysprof_time_visualizer, SYSPROF_TYPE_VISUALIZER) - -static void sysprof_time_visualizer_load_data_async (SysprofTimeVisualizer *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -static PointCache *sysprof_time_visualizer_load_data_finish (SysprofTimeVisualizer *self, - GAsyncResult *result, - GError **error); - -static gdouble dashes[] = { 1.0, 2.0 }; - -static void -load_data_free (gpointer data) -{ - LoadData *load = data; - - if (load != NULL) - { - g_clear_pointer (&load->lines, g_array_unref); - g_clear_pointer (&load->cursor, sysprof_capture_cursor_unref); - g_clear_pointer (&load->cache, point_cache_unref); - g_slice_free (LoadData, load); - } -} - -static GArray * -copy_array (GArray *ar) -{ - GArray *ret; - - ret = g_array_sized_new (FALSE, FALSE, g_array_get_element_size (ar), ar->len); - g_array_set_size (ret, ar->len); - memcpy (ret->data, ar->data, ar->len * g_array_get_element_size (ret)); - - return ret; -} - -static void -sysprof_time_visualizer_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofTimeVisualizer *self = (SysprofTimeVisualizer *)widget; - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - GtkStyleContext *style_context; - cairo_t *cr; - GtkAllocation alloc; - GdkRGBA foreground; - - g_assert (SYSPROF_IS_TIME_VISUALIZER (widget)); - g_assert (snapshot != NULL); - - gtk_widget_get_allocation (widget, &alloc); - - GTK_WIDGET_CLASS (sysprof_time_visualizer_parent_class)->snapshot (widget, snapshot); - - if (priv->cache == NULL) - return; - -#if 0 - if (!gdk_cairo_get_clip_rectangle (cr, &clip)) - return ret; -#else - alloc.x = 0; - alloc.y = 0; -#endif - - style_context = gtk_widget_get_style_context (widget); - gtk_style_context_get_color (style_context, &foreground); - - cr = gtk_snapshot_append_cairo (snapshot, &GRAPHENE_RECT_INIT (0, 0, alloc.width, alloc.height)); - - gdk_cairo_set_source_rgba (cr, &foreground); - - for (guint line = 0; line < priv->lines->len; line++) - { - g_autofree SysprofVisualizerAbsolutePoint *points = NULL; - const LineInfo *line_info = &g_array_index (priv->lines, LineInfo, line); - const Point *fpoints; - guint n_fpoints = 0; - - fpoints = point_cache_get_points (priv->cache, line_info->id, &n_fpoints); - - if (n_fpoints > 0) - { - guint last_x = G_MAXUINT; - - points = g_new0 (SysprofVisualizerAbsolutePoint, n_fpoints); - - sysprof_visualizer_translate_points (SYSPROF_VISUALIZER (self), - (const SysprofVisualizerRelativePoint *)fpoints, - n_fpoints, - points, - n_fpoints); - - cairo_set_line_width (cr, 1.0); - - for (guint i = 0; i < n_fpoints; i++) - { - if ((guint)points[i].x != last_x) - last_x = (guint)points[i].x; - else - continue; - - cairo_move_to (cr, (guint)points[i].x + .5, alloc.height / 3); - cairo_line_to (cr, (guint)points[i].x + .5, alloc.height / 3 * 2); - } - - if (line_info->use_dash) - cairo_set_dash (cr, dashes, G_N_ELEMENTS (dashes), 0); - - cairo_stroke (cr); - } - } - - cairo_destroy (cr); -} - -static void -sysprof_time_visualizer_load_data_cb (GObject *object, - GAsyncResult *result, - gpointer user_data) -{ - SysprofTimeVisualizer *self = (SysprofTimeVisualizer *)object; - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - g_autoptr(GError) error = NULL; - g_autoptr(PointCache) cache = NULL; - - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - - cache = sysprof_time_visualizer_load_data_finish (self, result, &error); - - if (cache == NULL) - { - g_warning ("%s", error->message); - return; - } - - g_clear_pointer (&priv->cache, point_cache_unref); - priv->cache = g_steal_pointer (&cache); - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static gboolean -sysprof_time_visualizer_do_reload (gpointer data) -{ - SysprofTimeVisualizer *self = data; - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - - priv->queued_load = 0; - if (priv->reader != NULL) - sysprof_time_visualizer_load_data_async (self, - NULL, - sysprof_time_visualizer_load_data_cb, - NULL); - - return G_SOURCE_REMOVE; -} - -static void -sysprof_time_visualizer_queue_reload (SysprofTimeVisualizer *self) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - - if (priv->queued_load == 0) - priv->queued_load = - g_idle_add_full (G_PRIORITY_LOW, - sysprof_time_visualizer_do_reload, - self, - NULL); -} - -static void -sysprof_time_visualizer_set_reader (SysprofVisualizer *row, - SysprofCaptureReader *reader) -{ - SysprofTimeVisualizer *self = (SysprofTimeVisualizer *)row; - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - - if (priv->reader != reader) - { - if (priv->reader != NULL) - { - sysprof_capture_reader_unref (priv->reader); - priv->reader = NULL; - } - - if (reader != NULL) - priv->reader = sysprof_capture_reader_ref (reader); - - sysprof_time_visualizer_queue_reload (self); - } -} - -static void -sysprof_time_visualizer_finalize (GObject *object) -{ - SysprofTimeVisualizer *self = (SysprofTimeVisualizer *)object; - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_clear_pointer (&priv->lines, g_array_unref); - g_clear_pointer (&priv->cache, point_cache_unref); - g_clear_pointer (&priv->reader, sysprof_capture_reader_unref); - - g_clear_handle_id (&priv->queued_load, g_source_remove); - - G_OBJECT_CLASS (sysprof_time_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_time_visualizer_class_init (SysprofTimeVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - SysprofVisualizerClass *visualizer_class = SYSPROF_VISUALIZER_CLASS (klass); - - object_class->finalize = sysprof_time_visualizer_finalize; - - widget_class->snapshot = sysprof_time_visualizer_snapshot; - - visualizer_class->set_reader = sysprof_time_visualizer_set_reader; -} - -static void -sysprof_time_visualizer_init (SysprofTimeVisualizer *self) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - priv->lines = g_array_new (FALSE, FALSE, sizeof (LineInfo)); -} - -void -sysprof_time_visualizer_add_counter (SysprofTimeVisualizer *self, - guint counter_id, - const GdkRGBA *color) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - LineInfo line_info = {0}; - - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - g_assert (priv->lines != NULL); - - line_info.id = counter_id; - line_info.line_width = 1.0; - - if (color != NULL) - { - line_info.rgba = *color; - line_info.use_default_style = FALSE; - } - else - { - line_info.use_default_style = TRUE; - } - - g_array_append_val (priv->lines, line_info); - - if (SYSPROF_TIME_VISUALIZER_GET_CLASS (self)->counter_added) - SYSPROF_TIME_VISUALIZER_GET_CLASS (self)->counter_added (self, counter_id); - - sysprof_time_visualizer_queue_reload (self); -} - -void -sysprof_time_visualizer_clear (SysprofTimeVisualizer *self) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_TIME_VISUALIZER (self)); - - if (priv->lines->len > 0) - g_array_remove_range (priv->lines, 0, priv->lines->len); - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static inline gboolean -contains_id (GArray *ar, - guint id) -{ - for (guint i = 0; i < ar->len; i++) - { - const LineInfo *info = &g_array_index (ar, LineInfo, i); - - if (info->id == id) - return TRUE; - } - - return FALSE; -} - -static inline gdouble -calc_x (gint64 lower, - gint64 upper, - gint64 value) -{ - return (gdouble)(value - lower) / (gdouble)(upper - lower); -} - -static bool -sysprof_time_visualizer_load_data_frame_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - LoadData *load = user_data; - - g_assert (frame != NULL); - g_assert (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET || - frame->type == SYSPROF_CAPTURE_FRAME_CTRDEF); - g_assert (load != NULL); - - if (frame->type == SYSPROF_CAPTURE_FRAME_CTRSET) - { - const SysprofCaptureCounterSet *set = (SysprofCaptureCounterSet *)frame; - gdouble x = calc_x (load->begin_time, load->end_time, frame->time); - - for (guint i = 0; i < set->n_values; i++) - { - const SysprofCaptureCounterValues *group = &set->values[i]; - - for (guint j = 0; j < G_N_ELEMENTS (group->ids); j++) - { - guint counter_id = group->ids[j]; - - if (counter_id != 0 && contains_id (load->lines, counter_id)) - point_cache_add_point_to_set (load->cache, counter_id, x, 0); - } - } - } - - return TRUE; -} - -static void -sysprof_time_visualizer_load_data_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - LoadData *load = task_data; - g_autoptr(GArray) counter_ids = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_TIME_VISUALIZER (source_object)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - counter_ids = g_array_new (FALSE, FALSE, sizeof (guint)); - - for (guint i = 0; i < load->lines->len; i++) - { - const LineInfo *line_info = &g_array_index (load->lines, LineInfo, i); - g_array_append_val (counter_ids, line_info->id); - } - - sysprof_capture_cursor_add_condition (load->cursor, - sysprof_capture_condition_new_where_counter_in (counter_ids->len, - (guint *)(gpointer)counter_ids->data)); - sysprof_capture_cursor_foreach (load->cursor, sysprof_time_visualizer_load_data_frame_cb, load); - g_task_return_pointer (task, g_steal_pointer (&load->cache), (GDestroyNotify)point_cache_unref); -} - -static void -sysprof_time_visualizer_load_data_async (SysprofTimeVisualizer *self, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - g_autoptr(GTask) task = NULL; - LoadData *load; - - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_priority (task, G_PRIORITY_LOW); - g_task_set_source_tag (task, sysprof_time_visualizer_load_data_async); - - if (priv->reader == NULL) - { - g_task_return_new_error (task, - G_IO_ERROR, - G_IO_ERROR_FAILED, - "No data loaded"); - return; - } - - load = g_slice_new0 (LoadData); - load->cache = point_cache_new (); - load->begin_time = sysprof_capture_reader_get_start_time (priv->reader); - load->end_time = sysprof_capture_reader_get_end_time (priv->reader); - load->cursor = sysprof_capture_cursor_new (priv->reader); - load->lines = copy_array (priv->lines); - - for (guint i = 0; i < load->lines->len; i++) - { - const LineInfo *line_info = &g_array_index (load->lines, LineInfo, i); - - point_cache_add_set (load->cache, line_info->id); - } - - g_task_set_task_data (task, load, load_data_free); - g_task_run_in_thread (task, sysprof_time_visualizer_load_data_worker); -} - -static PointCache * -sysprof_time_visualizer_load_data_finish (SysprofTimeVisualizer *self, - GAsyncResult *result, - GError **error) -{ - g_assert (SYSPROF_IS_TIME_VISUALIZER (self)); - g_assert (G_IS_TASK (result)); - - return g_task_propagate_pointer (G_TASK (result), error); -} - -void -sysprof_time_visualizer_set_line_width (SysprofTimeVisualizer *self, - guint counter_id, - gdouble width) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_TIME_VISUALIZER (self)); - - for (guint i = 0; i < priv->lines->len; i++) - { - LineInfo *info = &g_array_index (priv->lines, LineInfo, i); - - if (info->id == counter_id) - { - info->line_width = width; - sysprof_time_visualizer_queue_reload (self); - break; - } - } -} - -void -sysprof_time_visualizer_set_dash (SysprofTimeVisualizer *self, - guint counter_id, - gboolean use_dash) -{ - SysprofTimeVisualizerPrivate *priv = sysprof_time_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_TIME_VISUALIZER (self)); - - for (guint i = 0; i < priv->lines->len; i++) - { - LineInfo *info = &g_array_index (priv->lines, LineInfo, i); - - if (info->id == counter_id) - { - info->use_dash = !!use_dash; - sysprof_time_visualizer_queue_reload (self); - break; - } - } -} diff --git a/src/libsysprof-ui/sysprof-time-visualizer.h b/src/libsysprof-ui/sysprof-time-visualizer.h deleted file mode 100644 index 1b9160ac..00000000 --- a/src/libsysprof-ui/sysprof-time-visualizer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* sysprof-time-visualizer.h - * - * Copyright 2016-2019 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-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_TIME_VISUALIZER (sysprof_time_visualizer_get_type()) - -G_DECLARE_DERIVABLE_TYPE (SysprofTimeVisualizer, sysprof_time_visualizer, SYSPROF, TIME_VISUALIZER, SysprofVisualizer) - -struct _SysprofTimeVisualizerClass -{ - SysprofVisualizerClass parent_class; - - void (*counter_added) (SysprofTimeVisualizer *self, - guint counter_id); - - /*< private >*/ - gpointer _reserved[16]; -}; - -GtkWidget *sysprof_time_visualizer_new (void); -void sysprof_time_visualizer_clear (SysprofTimeVisualizer *self); -void sysprof_time_visualizer_add_counter (SysprofTimeVisualizer *self, - guint counter_id, - const GdkRGBA *color); -void sysprof_time_visualizer_set_line_width (SysprofTimeVisualizer *self, - guint counter_id, - gdouble width); -void sysprof_time_visualizer_set_dash (SysprofTimeVisualizer *self, - guint counter_id, - gboolean use_dash); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-ui-private.h b/src/libsysprof-ui/sysprof-ui-private.h deleted file mode 100644 index 0216d3ba..00000000 --- a/src/libsysprof-ui/sysprof-ui-private.h +++ /dev/null @@ -1,48 +0,0 @@ -/* sysprof-ui-private.h - * - * Copyright 2019 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-callgraph-page.h" -#include "sysprof-display.h" -#include "sysprof-profiler-assistant.h" - -G_BEGIN_DECLS - -void _sysprof_callgraph_page_set_failed (SysprofCallgraphPage *self); -void _sysprof_callgraph_page_set_loading (SysprofCallgraphPage *self, - gboolean loading); -void _sysprof_memory_page_set_failed (SysprofCallgraphPage *self); -void _sysprof_memory_page_set_loading (SysprofCallgraphPage *self, - gboolean loading); -void _sysprof_display_focus_record (SysprofDisplay *self); -void _sysprof_display_reload_page (SysprofDisplay *self, - SysprofPage *page); -void _sysprof_profiler_assistant_focus_record (SysprofProfilerAssistant *self); -gchar *_sysprof_format_duration (gint64 duration); - -#if !GLIB_CHECK_VERSION(2, 56, 0) -# define g_clear_weak_pointer(ptr) \ - (*(ptr) ? (g_object_remove_weak_pointer((GObject*)*(ptr), (gpointer*)ptr),*(ptr)=NULL,1) : 0) -# define g_set_weak_pointer(ptr,obj) \ - ((obj!=*(ptr))?(g_clear_weak_pointer(ptr),*(ptr)=obj,((obj)?g_object_add_weak_pointer((GObject*)obj,(gpointer*)ptr),NULL:NULL),1):0) -#endif - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-ui.h b/src/libsysprof-ui/sysprof-ui.h deleted file mode 100644 index 02513d51..00000000 --- a/src/libsysprof-ui/sysprof-ui.h +++ /dev/null @@ -1,41 +0,0 @@ -/* sysprof-ui.h - * - * Copyright 2016-2019 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 -#include - -G_BEGIN_DECLS - -#define SYSPROF_UI_INSIDE - -# include "sysprof-check.h" -# include "sysprof-display.h" -# include "sysprof-model-filter.h" -# include "sysprof-notebook.h" -# include "sysprof-page.h" -# include "sysprof-process-model-row.h" -# include "sysprof-visualizer-group.h" -# include "sysprof-visualizer.h" - -#undef SYSPROF_UI_INSIDE - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizer-group-header.c b/src/libsysprof-ui/sysprof-visualizer-group-header.c deleted file mode 100644 index 8dbadca6..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-group-header.c +++ /dev/null @@ -1,241 +0,0 @@ -/* sysprof-visualizer-group-header.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-visualizer-group-header" - -#include "config.h" - -#include - -#include "sysprof-visualizer.h" -#include "sysprof-visualizer-group.h" -#include "sysprof-visualizer-group-header.h" -#include "sysprof-visualizer-group-private.h" - -struct _SysprofVisualizerGroupHeader -{ - GtkListBoxRow parent_instance; - - SysprofVisualizerGroup *group; - GtkBox *box; -}; - -G_DEFINE_TYPE (SysprofVisualizerGroupHeader, sysprof_visualizer_group_header, GTK_TYPE_LIST_BOX_ROW) - -enum { - PROP_0, - PROP_GROUP, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_visualizer_group_header_dispose (GObject *object) -{ - SysprofVisualizerGroupHeader *self = (SysprofVisualizerGroupHeader *)object; - - if (self->box) - { - gtk_widget_unparent (GTK_WIDGET (self->box)); - self->box = NULL; - } - - G_OBJECT_CLASS (sysprof_visualizer_group_header_parent_class)->dispose (object); -} - -static void -sysprof_visualizer_group_header_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizerGroupHeader *self = SYSPROF_VISUALIZER_GROUP_HEADER (object); - - switch (prop_id) - { - case PROP_GROUP: - g_value_set_object (value, _sysprof_visualizer_group_header_get_group (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizer_group_header_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizerGroupHeader *self = SYSPROF_VISUALIZER_GROUP_HEADER (object); - - switch (prop_id) - { - case PROP_GROUP: - self->group = g_value_get_object (value); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizer_group_header_class_init (SysprofVisualizerGroupHeaderClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_visualizer_group_header_dispose; - object_class->get_property = sysprof_visualizer_group_header_get_property; - object_class->set_property = sysprof_visualizer_group_header_set_property; - - properties [PROP_GROUP] = - g_param_spec_object ("group", - "Group", - "The group", - SYSPROF_TYPE_VISUALIZER_GROUP, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); -} - -static void -sysprof_visualizer_group_header_init (SysprofVisualizerGroupHeader *self) -{ - self->box = g_object_new (GTK_TYPE_BOX, - "orientation", GTK_ORIENTATION_VERTICAL, - "visible", TRUE, - NULL); - gtk_widget_set_parent (GTK_WIDGET (self->box), GTK_WIDGET (self)); -} - -void -_sysprof_visualizer_group_header_add_row (SysprofVisualizerGroupHeader *self, - guint position, - const gchar *title, - GMenuModel *menu, - GtkWidget *widget) -{ - GtkWidget *sibling; - GtkBox *box; - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP_HEADER (self)); - g_return_if_fail (SYSPROF_IS_VISUALIZER (widget)); - g_return_if_fail (!menu || G_IS_MENU_MODEL (menu)); - - box = g_object_new (GTK_TYPE_BOX, - "orientation", GTK_ORIENTATION_HORIZONTAL, - "spacing", 6, - "visible", TRUE, - NULL); - g_object_bind_property (widget, "visible", box, "visible", G_BINDING_SYNC_CREATE); - - sibling = gtk_widget_get_first_child (GTK_WIDGET (self->box)); - for (; position > 1 && sibling; position--) - sibling = gtk_widget_get_next_sibling (sibling); - gtk_box_insert_child_after (self->box, GTK_WIDGET (box), sibling); - - if (title != NULL) - { - g_autoptr(GtkSizeGroup) size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL); - PangoAttrList *attrs = pango_attr_list_new (); - GtkLabel *label; - - pango_attr_list_insert (attrs, pango_attr_scale_new (0.83333)); - label = g_object_new (GTK_TYPE_LABEL, - "attributes", attrs, - "ellipsize", PANGO_ELLIPSIZE_MIDDLE, - "margin-top", 6, - "margin-bottom", 6, - "margin-start", 6, - "margin-end", 6, - "hexpand", TRUE, - "label", title, - "visible", TRUE, - "xalign", 0.0f, - NULL); - gtk_box_append (box, GTK_WIDGET (label)); - pango_attr_list_unref (attrs); - - gtk_size_group_add_widget (size_group, widget); - gtk_size_group_add_widget (size_group, GTK_WIDGET (box)); - } - - if (position == 0 && sysprof_visualizer_group_get_has_page (self->group)) - { - GtkImage *image; - - image = g_object_new (GTK_TYPE_IMAGE, - "icon-name", "view-paged-symbolic", - "tooltip-text", _("Select for more details"), - "pixel-size", 16, - "visible", TRUE, - NULL); - gtk_style_context_add_class (gtk_widget_get_style_context (GTK_WIDGET (image)), "dim-label"); - gtk_box_append (box, GTK_WIDGET (image)); - } - - if (menu != NULL) - { - GtkStyleContext *style_context; - GtkMenuButton *button; - - button = g_object_new (GTK_TYPE_MENU_BUTTON, - "child", g_object_new (GTK_TYPE_IMAGE, - "icon-name", "view-more-symbolic", - "visible", TRUE, - NULL), - "margin-end", 6, - "direction", GTK_ARROW_RIGHT, - "halign", GTK_ALIGN_CENTER, - "menu-model", menu, - "tooltip-text", _("Display supplemental graphs"), - "valign", GTK_ALIGN_CENTER, - "visible", TRUE, - NULL); - style_context = gtk_widget_get_style_context (GTK_WIDGET (button)); - gtk_style_context_add_class (style_context, "image-button"); - gtk_style_context_add_class (style_context, "small-button"); - gtk_style_context_add_class (style_context, "flat"); - - gtk_box_append (box, GTK_WIDGET (button)); - } -} - -SysprofVisualizerGroupHeader * -_sysprof_visualizer_group_header_new (SysprofVisualizerGroup *group) -{ - return g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP_HEADER, - "group", group, - NULL); -} - -SysprofVisualizerGroup * -_sysprof_visualizer_group_header_get_group (SysprofVisualizerGroupHeader *self) -{ - g_return_val_if_fail (SYSPROF_IS_VISUALIZER_GROUP_HEADER(self), NULL); - - return self->group; -} diff --git a/src/libsysprof-ui/sysprof-visualizer-group-header.h b/src/libsysprof-ui/sysprof-visualizer-group-header.h deleted file mode 100644 index 2a1e9c82..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-group-header.h +++ /dev/null @@ -1,31 +0,0 @@ -/* sysprof-visualizer-group-header.h - * - * Copyright 2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_VISUALIZER_GROUP_HEADER (sysprof_visualizer_group_header_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofVisualizerGroupHeader, sysprof_visualizer_group_header, SYSPROF, VISUALIZER_GROUP_HEADER, GtkListBoxRow) - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizer-group-private.h b/src/libsysprof-ui/sysprof-visualizer-group-private.h deleted file mode 100644 index a23b6127..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-group-private.h +++ /dev/null @@ -1,45 +0,0 @@ -/* sysprof-visualizers-group-private.h - * - * Copyright 2019 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 - -#include "sysprof-visualizer-group.h" -#include "sysprof-visualizer-group-header.h" - -G_BEGIN_DECLS - -void _sysprof_visualizer_group_set_reader (SysprofVisualizerGroup *self, - SysprofCaptureReader *reader); -SysprofVisualizerGroupHeader *_sysprof_visualizer_group_header_new (SysprofVisualizerGroup *group); -void _sysprof_visualizer_group_header_add_row (SysprofVisualizerGroupHeader *self, - guint position, - const gchar *title, - GMenuModel *menu, - GtkWidget *row); -void _sysprof_visualizer_group_header_remove_row (SysprofVisualizerGroupHeader *self, - guint row); -SysprofVisualizerGroup *_sysprof_visualizer_group_header_get_group (SysprofVisualizerGroupHeader *self); -void _sysprof_visualizer_group_set_header (SysprofVisualizerGroup *self, - SysprofVisualizerGroupHeader *header); - - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizer-group.c b/src/libsysprof-ui/sysprof-visualizer-group.c deleted file mode 100644 index 2053e036..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-group.c +++ /dev/null @@ -1,471 +0,0 @@ -/* sysprof-visualizer-group.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-visualizer-group" - -#include "config.h" - -#include - -#include "sysprof-visualizer.h" -#include "sysprof-visualizer-group.h" -#include "sysprof-visualizer-group-private.h" - -typedef struct -{ - /* Owned pointers */ - GMenuModel *menu; - GMenu *default_menu; - GMenu *rows_menu; - gchar *title; - GtkSizeGroup *size_group; - GSimpleActionGroup *actions; - - gint priority; - - guint has_page : 1; - - /* Weak pointers */ - SysprofVisualizerGroupHeader *header; - - /* Child Widgets */ - GtkBox *visualizers; -} SysprofVisualizerGroupPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofVisualizerGroup, sysprof_visualizer_group, GTK_TYPE_LIST_BOX_ROW) - -enum { - PROP_0, - PROP_HAS_PAGE, - PROP_MENU, - PROP_PRIORITY, - PROP_TITLE, - N_PROPS -}; - -enum { - GROUP_ACTIVATED, - N_SIGNALS -}; - -static GParamSpec *properties [N_PROPS]; -static guint signals [N_SIGNALS]; - -/** - * sysprof_visualizer_group_new: - * - * Create a new #SysprofVisualizerGroup. - * - * Returns: (transfer full): a newly created #SysprofVisualizerGroup - */ -SysprofVisualizerGroup * -sysprof_visualizer_group_new (void) -{ - return g_object_new (SYSPROF_TYPE_VISUALIZER_GROUP, NULL); -} - -const gchar * -sysprof_visualizer_group_get_title (SysprofVisualizerGroup *self) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self), NULL); - - return priv->title; -} - -void -sysprof_visualizer_group_set_title (SysprofVisualizerGroup *self, - const gchar *title) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - - if (g_strcmp0 (priv->title, title) != 0) - { - g_free (priv->title); - priv->title = g_strdup (title); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); - } -} - -/** - * sysprof_visualizer_group_get_menu: - * - * Gets the menu for the group. - * - * Returns: (transfer none) (nullable): a #GMenuModel or %NULL - * - * Since: 3.34 - */ -GMenuModel * -sysprof_visualizer_group_get_menu (SysprofVisualizerGroup *self) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self), NULL); - - return priv->menu; -} - -void -sysprof_visualizer_group_set_menu (SysprofVisualizerGroup *self, - GMenuModel *menu) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - g_return_if_fail (!menu || G_IS_MENU_MODEL (menu)); - - if (g_set_object (&priv->menu, menu)) - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MENU]); -} - -static gchar * -create_action_name (const gchar *str) -{ - GString *ret = g_string_new (NULL); - - for (; *str; str = g_utf8_next_char (str)) - { - gunichar ch = g_utf8_get_char (str); - - if (g_unichar_isalnum (ch)) - g_string_append_unichar (ret, ch); - else - g_string_append_c (ret, '_'); - } - - return g_string_free (ret, FALSE); -} - -static void -sysprof_visualizer_group_finalize (GObject *object) -{ - SysprofVisualizerGroup *self = (SysprofVisualizerGroup *)object; - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_clear_pointer (&priv->title, g_free); - g_clear_object (&priv->menu); - g_clear_object (&priv->size_group); - g_clear_object (&priv->default_menu); - g_clear_object (&priv->rows_menu); - g_clear_object (&priv->actions); - - g_clear_weak_pointer (&priv->header); - - G_OBJECT_CLASS (sysprof_visualizer_group_parent_class)->finalize (object); -} - -static void -sysprof_visualizer_group_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizerGroup *self = SYSPROF_VISUALIZER_GROUP (object); - - switch (prop_id) - { - case PROP_HAS_PAGE: - g_value_set_boolean (value, sysprof_visualizer_group_get_has_page (self)); - break; - - case PROP_MENU: - g_value_set_object (value, sysprof_visualizer_group_get_menu (self)); - break; - - case PROP_PRIORITY: - g_value_set_int (value, sysprof_visualizer_group_get_priority (self)); - break; - - case PROP_TITLE: - g_value_set_string (value, sysprof_visualizer_group_get_title (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizer_group_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizerGroup *self = SYSPROF_VISUALIZER_GROUP (object); - - switch (prop_id) - { - case PROP_HAS_PAGE: - sysprof_visualizer_group_set_has_page (self, g_value_get_boolean (value)); - break; - - case PROP_MENU: - sysprof_visualizer_group_set_menu (self, g_value_get_object (value)); - break; - - case PROP_PRIORITY: - sysprof_visualizer_group_set_priority (self, g_value_get_int (value)); - break; - - case PROP_TITLE: - sysprof_visualizer_group_set_title (self, g_value_get_string (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizer_group_class_init (SysprofVisualizerGroupClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->finalize = sysprof_visualizer_group_finalize; - object_class->get_property = sysprof_visualizer_group_get_property; - object_class->set_property = sysprof_visualizer_group_set_property; - - properties [PROP_HAS_PAGE] = - g_param_spec_boolean ("has-page", - "Has Page", - "Has Page", - FALSE, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_MENU] = - g_param_spec_object ("menu", - "Menu", - "Menu", - G_TYPE_MENU_MODEL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_PRIORITY] = - g_param_spec_int ("priority", - "Priority", - "The Priority of the group, used for sorting", - G_MININT, G_MAXINT, 0, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_TITLE] = - g_param_spec_string ("title", - "Title", - "The title of the row", - NULL, - (G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - signals [GROUP_ACTIVATED] = - g_signal_new ("group-activated", - G_TYPE_FROM_CLASS (klass), - G_SIGNAL_RUN_LAST, - 0, - NULL, NULL, - NULL, - G_TYPE_NONE, 0); - - gtk_widget_class_set_css_name (widget_class, "SysprofVisualizerGroup"); -} - -static void -sysprof_visualizer_group_init (SysprofVisualizerGroup *self) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - g_autoptr(GMenuItem) item = NULL; - - priv->actions = g_simple_action_group_new (); - - priv->default_menu = g_menu_new (); - priv->rows_menu = g_menu_new (); - - item = g_menu_item_new_section (NULL, G_MENU_MODEL (priv->rows_menu)); - g_menu_append_item (priv->default_menu, item); - - priv->menu = g_object_ref (G_MENU_MODEL (priv->default_menu)); - - priv->size_group = gtk_size_group_new (GTK_SIZE_GROUP_VERTICAL); - gtk_size_group_add_widget (priv->size_group, GTK_WIDGET (self)); - - priv->visualizers = g_object_new (GTK_TYPE_BOX, - "orientation", GTK_ORIENTATION_VERTICAL, - "visible", TRUE, - NULL); - gtk_list_box_row_set_child (GTK_LIST_BOX_ROW (self), GTK_WIDGET (priv->visualizers)); -} - -void -_sysprof_visualizer_group_set_header (SysprofVisualizerGroup *self, - SysprofVisualizerGroupHeader *header) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - g_return_if_fail (!header || SYSPROF_IS_VISUALIZER_GROUP_HEADER (header)); - - if (g_set_weak_pointer (&priv->header, header)) - { - if (header != NULL) - { - guint position = 0; - - gtk_widget_insert_action_group (GTK_WIDGET (header), - "group", - G_ACTION_GROUP (priv->actions)); - gtk_size_group_add_widget (priv->size_group, GTK_WIDGET (header)); - - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (priv->visualizers)); - child; - child = gtk_widget_get_next_sibling (child)) - { - SysprofVisualizer *vis = SYSPROF_VISUALIZER (child); - const gchar *title; - GMenuModel *menu = NULL; - - g_assert (SYSPROF_IS_VISUALIZER (vis)); - - if (position == 0) - menu = priv->menu; - - title = sysprof_visualizer_get_title (vis); - - if (title == NULL) - title = priv->title; - - _sysprof_visualizer_group_header_add_row (header, - position, - title, - menu, - GTK_WIDGET (vis)); - - position++; - } - } - } -} - -void -_sysprof_visualizer_group_set_reader (SysprofVisualizerGroup *self, - SysprofCaptureReader *reader) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - g_return_if_fail (reader != NULL); - - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (priv->visualizers)); - child; - child = gtk_widget_get_next_sibling (child)) - sysprof_visualizer_set_reader (SYSPROF_VISUALIZER (child), reader); -} - -void -sysprof_visualizer_group_insert (SysprofVisualizerGroup *self, - SysprofVisualizer *visualizer, - gint position, - gboolean can_toggle) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - GtkWidget *sibling = NULL; - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - g_return_if_fail (SYSPROF_IS_VISUALIZER (visualizer)); - - if (position > 0) - { - sibling = gtk_widget_get_first_child (GTK_WIDGET (priv->visualizers)); - while (position > 1 && sibling) - { - sibling = gtk_widget_get_next_sibling (sibling); - position--; - } - } - gtk_box_insert_child_after (priv->visualizers, GTK_WIDGET (visualizer), sibling); - - if (can_toggle) - { - const gchar *title = sysprof_visualizer_get_title (visualizer); - g_autofree gchar *action_name = create_action_name (title); - g_autofree gchar *full_action_name = g_strdup_printf ("group.%s", action_name); - g_autoptr(GMenuItem) item = g_menu_item_new (title, full_action_name); - g_autoptr(GPropertyAction) action = NULL; - - action = g_property_action_new (action_name, visualizer, "visible"); - g_action_map_add_action (G_ACTION_MAP (priv->actions), G_ACTION (action)); - g_menu_item_set_attribute (item, "role", "s", "check"); - g_menu_append_item (priv->rows_menu, item); - } -} - -gint -sysprof_visualizer_group_get_priority (SysprofVisualizerGroup *self) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self), 0); - - return priv->priority; -} - -void -sysprof_visualizer_group_set_priority (SysprofVisualizerGroup *self, - gint priority) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - - if (priv->priority != priority) - { - priv->priority = priority; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_PRIORITY]); - } -} - -gboolean -sysprof_visualizer_group_get_has_page (SysprofVisualizerGroup *self) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self), FALSE); - - return priv->has_page; -} - -void -sysprof_visualizer_group_set_has_page (SysprofVisualizerGroup *self, - gboolean has_page) -{ - SysprofVisualizerGroupPrivate *priv = sysprof_visualizer_group_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (self)); - - has_page = !!has_page; - - if (has_page != priv->has_page) - { - priv->has_page = has_page; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_HAS_PAGE]); - } -} diff --git a/src/libsysprof-ui/sysprof-visualizer-group.h b/src/libsysprof-ui/sysprof-visualizer-group.h deleted file mode 100644 index cac1c661..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-group.h +++ /dev/null @@ -1,76 +0,0 @@ -/* sysprof-visualizer-group.h - * - * Copyright 2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include - -#include "sysprof-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_VISUALIZER_GROUP (sysprof_visualizer_group_get_type()) - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofVisualizerGroup, sysprof_visualizer_group, SYSPROF, VISUALIZER_GROUP, GtkListBoxRow) - -struct _SysprofVisualizerGroupClass -{ - GtkListBoxRowClass parent_class; - - void (*group_activated) (SysprofVisualizerGroup *self); - - /*< private >*/ - gpointer _reserved[16]; -}; - -SYSPROF_AVAILABLE_IN_ALL -SysprofVisualizerGroup *sysprof_visualizer_group_new (void); -SYSPROF_AVAILABLE_IN_ALL -GMenuModel *sysprof_visualizer_group_get_menu (SysprofVisualizerGroup *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_group_set_menu (SysprofVisualizerGroup *self, - GMenuModel *menu); -SYSPROF_AVAILABLE_IN_ALL -gint sysprof_visualizer_group_get_priority (SysprofVisualizerGroup *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_group_set_priority (SysprofVisualizerGroup *self, - gint priority); -SYSPROF_AVAILABLE_IN_ALL -const gchar *sysprof_visualizer_group_get_title (SysprofVisualizerGroup *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_group_set_title (SysprofVisualizerGroup *self, - const gchar *title); -SYSPROF_AVAILABLE_IN_ALL -gboolean sysprof_visualizer_group_get_has_page (SysprofVisualizerGroup *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_group_set_has_page (SysprofVisualizerGroup *self, - gboolean has_page); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_group_insert (SysprofVisualizerGroup *self, - SysprofVisualizer *visualizer, - gint position, - gboolean can_toggle); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizer-ticks.c b/src/libsysprof-ui/sysprof-visualizer-ticks.c deleted file mode 100644 index 1f7049c8..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-ticks.c +++ /dev/null @@ -1,324 +0,0 @@ -/* sysprof-visualizer-ticks.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-visualizer-ticks" - -#include "config.h" - -#include -#include - -#include "sysprof-visualizer-ticks.h" - -#define NSEC_PER_DAY (SYSPROF_NSEC_PER_SEC * 60L * 60L * 24L) -#define NSEC_PER_HOUR (SYSPROF_NSEC_PER_SEC * 60L * 60L) -#define NSEC_PER_MIN (SYSPROF_NSEC_PER_SEC * 60L) -#define NSEC_PER_MSEC (SYSPROF_NSEC_PER_SEC/G_GINT64_CONSTANT(1000)) -#define MIN_TICK_DISTANCE 20 -#define LABEL_HEIGHT_PX 10 - -struct _SysprofVisualizerTicks -{ - SysprofVisualizer parent_instance; -}; - -enum { - TICK_MINUTES, - TICK_HALF_MINUTES, - TICK_FIVE_SECONDS, - TICK_SECONDS, - TICK_HALF_SECONDS, - TICK_QUARTER_SECONDS, - TICK_TENTHS, - TICK_HUNDREDTHS, - TICK_THOUSANDTHS, - TICK_TEN_THOUSANDTHS, - N_TICKS -}; - -struct { - gint width; - gint height; - gint64 span; -} tick_sizing[N_TICKS] = { - { 1, 12, SYSPROF_NSEC_PER_SEC * 60 }, - { 1, 11, SYSPROF_NSEC_PER_SEC * 30 }, - { 1, 10, SYSPROF_NSEC_PER_SEC * 5 }, - { 1, 9, SYSPROF_NSEC_PER_SEC }, - { 1, 8, SYSPROF_NSEC_PER_SEC / 2 }, - { 1, 6, SYSPROF_NSEC_PER_SEC / 4 }, - { 1, 5, SYSPROF_NSEC_PER_SEC / 10 }, - { 1, 4, SYSPROF_NSEC_PER_SEC / 100 }, - { 1, 3, SYSPROF_NSEC_PER_SEC / 1000 }, - { 1, 1, SYSPROF_NSEC_PER_SEC / 10000 }, -}; - -G_DEFINE_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, SYSPROF_TYPE_VISUALIZER) - -static void -update_label_text (PangoLayout *layout, - gint64 time, - gboolean want_msec) -{ - g_autofree gchar *str = NULL; - gint64 tmp; - gint msec = 0; - gint hours = 0; - gint min = 0; - gint sec = 0; - G_GNUC_UNUSED gint days = 0; - - g_assert (PANGO_IS_LAYOUT (layout)); - - tmp = time % SYSPROF_NSEC_PER_SEC; - time -= tmp; - msec = tmp / 100000L; - - if (time >= NSEC_PER_DAY) - { - days = time / NSEC_PER_DAY; - time %= NSEC_PER_DAY; - } - - if (time >= NSEC_PER_HOUR) - { - hours = time / NSEC_PER_HOUR; - time %= NSEC_PER_HOUR; - } - - if (time >= NSEC_PER_MIN) - { - min = time / NSEC_PER_MIN; - time %= NSEC_PER_MIN; - } - - if (time >= SYSPROF_NSEC_PER_SEC) - { - sec = time / SYSPROF_NSEC_PER_SEC; - time %= SYSPROF_NSEC_PER_SEC; - } - - if (want_msec || (!hours && !min && !sec && msec)) - { - if (hours > 0) - str = g_strdup_printf ("%02u:%02u:%02u.%04u", hours, min, sec, msec); - else - str = g_strdup_printf ("%02u:%02u.%04u", min, sec, msec); - } - else - { - if (hours > 0) - str = g_strdup_printf ("%02u:%02u:%02u", hours, min, sec); - else - str = g_strdup_printf ("%02u:%02u", min, sec); - } - - pango_layout_set_text (layout, str, -1); -} - -static gboolean -draw_ticks (SysprofVisualizerTicks *self, - GtkSnapshot *snapshot, - GtkAllocation *area, - gint ticks, - gboolean label_mode, - const GdkRGBA *color) -{ - GtkAllocation alloc; - gint64 begin_time, end_time; - gdouble half; - gint count = 0; - - g_assert (SYSPROF_IS_VISUALIZER_TICKS (self)); - g_assert (snapshot != NULL); - g_assert (area != NULL); - g_assert (ticks >= 0); - g_assert (ticks < N_TICKS); - - begin_time = sysprof_visualizer_get_begin_time (SYSPROF_VISUALIZER (self)); - end_time = sysprof_visualizer_get_end_time (SYSPROF_VISUALIZER (self)); - - /* - * If we are in label_model, we don't draw the ticks but only the labels. - * That way we can determine which tick level managed to draw a tick in - * the visible region so we only show labels for the largest tick level. - * (Returning true from this method indicates we successfully drew a tick). - */ - - half = tick_sizing[ticks].width / 2.0; - - gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); - - if G_UNLIKELY (label_mode) - { - PangoFontDescription *font_desc; - PangoLayout *layout; - gboolean want_msec; - gint last_x2 = G_MININT; - gint w, h; - - layout = gtk_widget_create_pango_layout (GTK_WIDGET (self), "00:10:00.0000"); - - font_desc = pango_font_description_new (); - pango_font_description_set_family_static (font_desc, "Monospace"); - pango_font_description_set_absolute_size (font_desc, LABEL_HEIGHT_PX * PANGO_SCALE); - pango_layout_set_font_description (layout, font_desc); - pango_font_description_free (font_desc); - - pango_layout_get_pixel_size (layout, &w, &h); - - /* If we are operating on smaller than seconds here, then we want - * to ensure we include msec with the timestamps. - */ - want_msec = tick_sizing[ticks].span < SYSPROF_NSEC_PER_SEC; - - for (gint64 t = begin_time; t <= end_time; t += tick_sizing[ticks].span) - { - gdouble x = sysprof_visualizer_get_x_for_time (SYSPROF_VISUALIZER (self), t); - - if (x < (last_x2 + MIN_TICK_DISTANCE)) - continue; - - update_label_text (layout, t - begin_time, want_msec); - pango_layout_get_pixel_size (layout, &w, &h); - - if (x + w <= alloc.width) - { - gtk_snapshot_save (snapshot); - gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT ((int)x + 2.5 - (int)half, 2)); - gtk_snapshot_append_layout (snapshot, layout, color); - gtk_snapshot_restore (snapshot); - } - - last_x2 = x + w; - } - - g_clear_object (&layout); - } - else - { - for (gint64 t = begin_time; t <= end_time; t += tick_sizing[ticks].span) - { - gdouble x = sysprof_visualizer_get_x_for_time (SYSPROF_VISUALIZER (self), t); - - gtk_snapshot_append_color (snapshot, color, - &GRAPHENE_RECT_INIT ((int)x - .5 - (int)half, - alloc.height, - (int)x - .5 - (int)half + tick_sizing[ticks].width, - alloc.height - tick_sizing[ticks].height)); - count++; - } - } - - return count > 2; -} - -static void -sysprof_visualizer_ticks_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofVisualizerTicks *self = SYSPROF_VISUALIZER_TICKS (widget); - GtkStyleContext *style; - GtkAllocation alloc; - gint64 timespan; - GdkRGBA color; - - g_assert (SYSPROF_IS_VISUALIZER_TICKS (self)); - g_assert (snapshot != NULL); - - timespan = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self)); - if (timespan == 0) - return; - - gtk_widget_get_allocation (GTK_WIDGET (self), &alloc); - alloc.x = 0; - alloc.y = 0; - - style = gtk_widget_get_style_context (widget); - gtk_style_context_get_color (style, &color); - - gtk_snapshot_render_background (snapshot, style, 0, 0, alloc.width, alloc.height); - - /* - * We need to discover up to what level we will draw tick marks. - * This is based on the width of the widget and the number of ticks - * to draw (which is determined from our timespan). We will skip a - * mark if they will end up less than MIN_TICK_DISTANCE px apart. - */ - - for (guint i = G_N_ELEMENTS (tick_sizing); i > 0; i--) - { - gint64 n_ticks = timespan / tick_sizing[i - 1].span; - gint largest_match = -1; - - if (n_ticks == 0 || (alloc.width / n_ticks) < MIN_TICK_DISTANCE) - continue; - - for (guint j = i; j > 0; j--) - { - if (draw_ticks (self, snapshot, &alloc, j - 1, FALSE, &color)) - largest_match = j - 1; - } - - if (largest_match != -1) - draw_ticks (self, snapshot, &alloc, largest_match, TRUE, &color); - - break; - } -} - -static void -sysprof_visualizer_ticks_measure (GtkWidget *widget, - GtkOrientation orientation, - int for_size, - int *minimum, - int *natural, - int *minimum_baseline, - int *natural_baseline) -{ - g_assert (SYSPROF_IS_VISUALIZER_TICKS (widget)); - - if (orientation == GTK_ORIENTATION_VERTICAL) - *minimum = *natural = tick_sizing[0].height + LABEL_HEIGHT_PX; - else - *minimum = *natural = 0; -} - -static void -sysprof_visualizer_ticks_class_init (SysprofVisualizerTicksClass *klass) -{ - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - widget_class->snapshot = sysprof_visualizer_ticks_snapshot; - widget_class->measure = sysprof_visualizer_ticks_measure; - - gtk_widget_class_set_css_name (widget_class, "SysprofVisualizerTicks"); -} - -static void -sysprof_visualizer_ticks_init (SysprofVisualizerTicks *self) -{ -} - -GtkWidget * -sysprof_visualizer_ticks_new (void) -{ - return g_object_new (SYSPROF_TYPE_VISUALIZER_TICKS, NULL); -} diff --git a/src/libsysprof-ui/sysprof-visualizer-ticks.h b/src/libsysprof-ui/sysprof-visualizer-ticks.h deleted file mode 100644 index cb4d6f5e..00000000 --- a/src/libsysprof-ui/sysprof-visualizer-ticks.h +++ /dev/null @@ -1,35 +0,0 @@ -/* sysprof-visualizer-ticks.h - * - * Copyright 2016-2019 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 - -#include "sysprof-visualizer.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_VISUALIZER_TICKS (sysprof_visualizer_ticks_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofVisualizerTicks, sysprof_visualizer_ticks, SYSPROF, VISUALIZER_TICKS, SysprofVisualizer) - -GtkWidget *sysprof_visualizer_ticks_new (void); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizer.c b/src/libsysprof-ui/sysprof-visualizer.c deleted file mode 100644 index 23cb75f0..00000000 --- a/src/libsysprof-ui/sysprof-visualizer.c +++ /dev/null @@ -1,289 +0,0 @@ -/* sysprof-visualizer.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-visualizer" - -#include "config.h" - -#include "sysprof-visualizer.h" - -typedef struct -{ - gchar *title; - - gint64 begin_time; - gint64 end_time; - gint64 duration; -} SysprofVisualizerPrivate; - -G_DEFINE_TYPE_WITH_PRIVATE (SysprofVisualizer, sysprof_visualizer, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_BEGIN_TIME, - PROP_END_TIME, - PROP_TITLE, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static void -sysprof_visualizer_finalize (GObject *object) -{ - SysprofVisualizer *self = (SysprofVisualizer *)object; - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_clear_pointer (&priv->title, g_free); - - G_OBJECT_CLASS (sysprof_visualizer_parent_class)->finalize (object); -} - -static void -sysprof_visualizer_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizer *self = SYSPROF_VISUALIZER (object); - - switch (prop_id) - { - case PROP_TITLE: - g_value_set_string (value, sysprof_visualizer_get_title (self)); - break; - - case PROP_BEGIN_TIME: - g_value_set_int64 (value, sysprof_visualizer_get_begin_time (self)); - break; - - case PROP_END_TIME: - g_value_set_int64 (value, sysprof_visualizer_get_end_time (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizer_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizer *self = SYSPROF_VISUALIZER (object); - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - switch (prop_id) - { - case PROP_TITLE: - sysprof_visualizer_set_title (self, g_value_get_string (value)); - break; - - case PROP_BEGIN_TIME: - priv->begin_time = g_value_get_int64 (value); - priv->duration = priv->end_time - priv->begin_time; - break; - - case PROP_END_TIME: - priv->end_time = g_value_get_int64 (value); - priv->duration = priv->end_time - priv->begin_time; - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizer_class_init (SysprofVisualizerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->finalize = sysprof_visualizer_finalize; - object_class->get_property = sysprof_visualizer_get_property; - object_class->set_property = sysprof_visualizer_set_property; - - properties [PROP_BEGIN_TIME] = - g_param_spec_int64 ("begin-time", - "Begin Time", - "Begin Time", - G_MININT64, - G_MAXINT64, - 0, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_END_TIME] = - g_param_spec_int64 ("end-time", - "End Time", - "End Time", - G_MININT64, - G_MAXINT64, - 0, - (G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS)); - - properties [PROP_TITLE] = - g_param_spec_string ("title", - "Title", - "The title for the row", - NULL, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - gtk_widget_class_set_css_name (widget_class, "SysprofVisualizer"); -} - -static void -sysprof_visualizer_init (SysprofVisualizer *self) -{ -} - -const gchar * -sysprof_visualizer_get_title (SysprofVisualizer *self) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER (self), 0); - - return priv->title; -} - -void -sysprof_visualizer_set_title (SysprofVisualizer *self, - const gchar *title) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER (self)); - - if (g_strcmp0 (priv->title, title) != 0) - { - g_free (priv->title); - priv->title = g_strdup (title); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_TITLE]); - } -} - -gint64 -sysprof_visualizer_get_begin_time (SysprofVisualizer *self) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER (self), 0); - - return priv->begin_time; -} - -gint64 -sysprof_visualizer_get_end_time (SysprofVisualizer *self) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_return_val_if_fail (SYSPROF_IS_VISUALIZER (self), 0); - - return priv->end_time; -} - -gint64 -sysprof_visualizer_get_duration (SysprofVisualizer *self) -{ - g_return_val_if_fail (SYSPROF_IS_VISUALIZER (self), 0); - - return sysprof_visualizer_get_end_time (self) - - sysprof_visualizer_get_begin_time (self); -} - -void -sysprof_visualizer_set_reader (SysprofVisualizer *self, - SysprofCaptureReader *reader) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER (self)); - g_return_if_fail (reader != NULL); - - if (priv->begin_time == 0 || priv->end_time == 0) - { - priv->begin_time = sysprof_capture_reader_get_start_time (reader); - priv->end_time = sysprof_capture_reader_get_end_time (reader); - priv->duration = priv->end_time - priv->begin_time; - } - - if (SYSPROF_VISUALIZER_GET_CLASS (self)->set_reader) - SYSPROF_VISUALIZER_GET_CLASS (self)->set_reader (self, reader); - - gtk_widget_queue_allocate (GTK_WIDGET (self)); -} - -void -sysprof_visualizer_translate_points (SysprofVisualizer *self, - const SysprofVisualizerRelativePoint *in_points, - guint n_in_points, - SysprofVisualizerAbsolutePoint *out_points, - guint n_out_points) -{ - int width; - int height; - - g_return_if_fail (SYSPROF_IS_VISUALIZER (self)); - g_return_if_fail (in_points != NULL); - g_return_if_fail (out_points != NULL); - g_return_if_fail (n_in_points == n_out_points); - - width = gtk_widget_get_width (GTK_WIDGET (self)); - height = gtk_widget_get_height (GTK_WIDGET (self)); - - for (guint i = 0; i < n_in_points; i++) - { - out_points[i].x = (in_points[i].x * width); - out_points[i].y = height - (ABS (in_points[i].y) * height); - } -} - -gint -sysprof_visualizer_get_x_for_time (SysprofVisualizer *self, - gint64 time) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - return ((time - priv->begin_time) / (gdouble)priv->duration) * gtk_widget_get_width (GTK_WIDGET (self)); -} - -void -sysprof_visualizer_set_time_range (SysprofVisualizer *self, - gint64 begin_time, - gint64 end_time) -{ - SysprofVisualizerPrivate *priv = sysprof_visualizer_get_instance_private (self); - - g_return_if_fail (SYSPROF_IS_VISUALIZER (self)); - - priv->begin_time = begin_time; - priv->end_time = end_time; - priv->duration = end_time - begin_time; - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_BEGIN_TIME]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_END_TIME]); - - gtk_widget_queue_allocate (GTK_WIDGET (self)); -} diff --git a/src/libsysprof-ui/sysprof-visualizer.h b/src/libsysprof-ui/sysprof-visualizer.h deleted file mode 100644 index 74b8a31c..00000000 --- a/src/libsysprof-ui/sysprof-visualizer.h +++ /dev/null @@ -1,88 +0,0 @@ -/* sysprof-visualizer.h - * - * Copyright 2019 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 - -#if !defined (SYSPROF_UI_INSIDE) && !defined (SYSPROF_UI_COMPILATION) -# error "Only can be included directly." -#endif - -#include -#include - -G_BEGIN_DECLS - -typedef struct -{ - gdouble x; - gdouble y; -} SysprofVisualizerRelativePoint; - -typedef struct -{ - gint x; - gint y; -} SysprofVisualizerAbsolutePoint; - -#define SYSPROF_TYPE_VISUALIZER (sysprof_visualizer_get_type()) - -SYSPROF_AVAILABLE_IN_ALL -G_DECLARE_DERIVABLE_TYPE (SysprofVisualizer, sysprof_visualizer, SYSPROF, VISUALIZER, GtkWidget) - -struct _SysprofVisualizerClass -{ - GtkWidgetClass parent_class; - - void (*set_reader) (SysprofVisualizer *self, - SysprofCaptureReader *reader); - - /*< private >*/ - gpointer _reserved[16]; -}; - -SYSPROF_AVAILABLE_IN_ALL -const gchar *sysprof_visualizer_get_title (SysprofVisualizer *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_set_title (SysprofVisualizer *self, - const gchar *title); -SYSPROF_AVAILABLE_IN_ALL -gint64 sysprof_visualizer_get_begin_time (SysprofVisualizer *self); -SYSPROF_AVAILABLE_IN_ALL -gint64 sysprof_visualizer_get_end_time (SysprofVisualizer *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_set_time_range (SysprofVisualizer *self, - gint64 begin_time, - gint64 end_time); -SYSPROF_AVAILABLE_IN_ALL -gint64 sysprof_visualizer_get_duration (SysprofVisualizer *self); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_set_reader (SysprofVisualizer *self, - SysprofCaptureReader *reader); -SYSPROF_AVAILABLE_IN_ALL -gint sysprof_visualizer_get_x_for_time (SysprofVisualizer *self, - gint64 time); -SYSPROF_AVAILABLE_IN_ALL -void sysprof_visualizer_translate_points (SysprofVisualizer *self, - const SysprofVisualizerRelativePoint *in_points, - guint n_in_points, - SysprofVisualizerAbsolutePoint *out_points, - guint n_out_points); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizers-frame.c b/src/libsysprof-ui/sysprof-visualizers-frame.c deleted file mode 100644 index 33af9ce3..00000000 --- a/src/libsysprof-ui/sysprof-visualizers-frame.c +++ /dev/null @@ -1,721 +0,0 @@ -/* sysprof-visualizers-frame.c - * - * Copyright 2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-visualizers-frame" - -#include "config.h" - -#include "sysprof-scrollmap.h" -#include "sysprof-visualizer-group-private.h" -#include "sysprof-visualizer-ticks.h" -#include "sysprof-visualizers-frame.h" -#include "sysprof-zoom-manager.h" - -struct _SysprofVisualizersFrame -{ - GtkWidget parent_instance; - - /* Drag selection tracking */ - SysprofSelection *selection; - gint64 drag_begin_at; - gint64 drag_selection_at; - guint button_pressed : 1; - - /* Help avoid over-resizing/allocating */ - GtkAllocation last_alloc; - gdouble last_zoom; - - /* Known time range from the capture */ - gint64 begin_time; - gint64 end_time; - - /* Template Widgets */ - GtkListBox *groups; - GtkListBox *visualizers; - SysprofScrollmap *hscrollbar; - SysprofVisualizerTicks *ticks; - GtkScrolledWindow *ticks_scroller; - GtkScrolledWindow *hscroller; - GtkScrolledWindow *vscroller; - SysprofZoomManager *zoom_manager; - GtkScale *zoom_scale; - GtkSizeGroup *left_column; - GtkViewport *ticks_viewport; - GtkViewport *visualizers_viewport; -}; - -typedef struct -{ - GtkListBox *list; - GtkStyleContext *style_context; - GtkSnapshot *snapshot; - int width; - int height; - gint64 begin_time; - gint64 duration; -} SelectionDraw; - -G_DEFINE_TYPE (SysprofVisualizersFrame, sysprof_visualizers_frame, GTK_TYPE_WIDGET) - -enum { - PROP_0, - PROP_SELECTED_GROUP, - PROP_SELECTION, - N_PROPS -}; - -static GParamSpec *properties [N_PROPS]; - -static gint64 -get_time_from_x (SysprofVisualizersFrame *self, - gdouble x) -{ - GtkAllocation alloc; - gdouble ratio; - gint64 duration; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - - gtk_widget_get_allocation (GTK_WIDGET (self->ticks), &alloc); - duration = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self->ticks)); - - if (alloc.width < 1) - return 0; - - ratio = x / alloc.width; - - return self->begin_time + (ratio * duration); -} - -static void -draw_selection_cb (SysprofSelection *selection, - gint64 range_begin, - gint64 range_end, - gpointer user_data) -{ - SelectionDraw *draw = user_data; - GdkRectangle area; - gdouble x, x2; - - g_assert (SYSPROF_IS_SELECTION (selection)); - g_assert (draw != NULL); - g_assert (draw->snapshot != NULL); - g_assert (GTK_IS_LIST_BOX (draw->list)); - - x = (range_begin - draw->begin_time) / (gdouble)draw->duration; - x2 = (range_end - draw->begin_time) / (gdouble)draw->duration; - - area.x = x * draw->width; - area.width = (x2 * draw->width) - area.x; - area.y = 0; - area.height = draw->height; - - if (area.width < 0) - { - area.width = ABS (area.width); - area.x -= area.width; - } - - gtk_snapshot_render_background (draw->snapshot, draw->style_context, area.x + 2, area.y + 2, area.width - 4, area.height - 4); -} - -static void -sysprof_visualizers_frame_snapshot (GtkWidget *widget, - GtkSnapshot *snapshot) -{ - SysprofVisualizersFrame *self = (SysprofVisualizersFrame *)widget; - SelectionDraw draw; - GtkAllocation alloc; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (GTK_IS_SNAPSHOT (snapshot)); - - GTK_WIDGET_CLASS (sysprof_visualizers_frame_parent_class)->snapshot (widget, snapshot); - - draw.duration = sysprof_visualizer_get_duration (SYSPROF_VISUALIZER (self->ticks)); - if (draw.duration == 0) - return; - - draw.style_context = gtk_widget_get_style_context (GTK_WIDGET (self->visualizers)); - draw.list = self->visualizers; - draw.snapshot = snapshot; - draw.begin_time = self->begin_time; - - gtk_widget_get_allocation (GTK_WIDGET (self->visualizers), &alloc); - draw.width = alloc.width; - draw.height = alloc.height; - - if (sysprof_selection_get_has_selection (self->selection) || self->button_pressed) - { - double x, y; - - gtk_snapshot_save (snapshot); - gtk_widget_translate_coordinates (GTK_WIDGET (self->visualizers), - GTK_WIDGET (self), - 0, 0, &x, &y); - gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (x, y)); - - gtk_style_context_add_class (draw.style_context, "selection"); - sysprof_selection_foreach (self->selection, draw_selection_cb, &draw); - if (self->button_pressed) - draw_selection_cb (self->selection, self->drag_begin_at, self->drag_selection_at, &draw); - gtk_style_context_remove_class (draw.style_context, "selection"); - - gtk_snapshot_restore (snapshot); - } -} - -static void -visualizers_button_press_event_cb (SysprofVisualizersFrame *self, - int n_presses, - double x, - double y, - GtkGestureClick *gesture) -{ - GdkModifierType state; - guint button; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (GTK_IS_GESTURE_CLICK (gesture)); - - button = gtk_gesture_single_get_button (GTK_GESTURE_SINGLE (gesture)); - - if (button != GDK_BUTTON_PRIMARY) - { - if (sysprof_selection_get_has_selection (self->selection)) - sysprof_selection_unselect_all (self->selection); - return; - } - - state = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER (gesture)); - - if ((state & GDK_SHIFT_MASK) == 0) - sysprof_selection_unselect_all (self->selection); - - self->button_pressed = TRUE; - - self->drag_begin_at = get_time_from_x (self, x); - self->drag_selection_at = self->drag_begin_at; - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static void -visualizers_button_release_event_cb (SysprofVisualizersFrame *self, - int n_release, - double x, - double y, - GtkGestureClick *gesture) -{ - guint button; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (GTK_IS_GESTURE_CLICK (gesture)); - - button = gtk_gesture_single_get_button (GTK_GESTURE_SINGLE (gesture)); - - if (!self->button_pressed || button != GDK_BUTTON_PRIMARY) - return; - - self->button_pressed = FALSE; - - if (self->drag_begin_at != self->drag_selection_at) - { - sysprof_selection_select_range (self->selection, - self->drag_begin_at, - self->drag_selection_at); - self->drag_begin_at = -1; - self->drag_selection_at = -1; - } - - gtk_widget_queue_draw (GTK_WIDGET (self)); -} - -static void -visualizers_motion_notify_event_cb (SysprofVisualizersFrame *self, - double x, - double y, - GtkEventControllerMotion *motion) -{ - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (GTK_IS_EVENT_CONTROLLER_MOTION (motion)); - - if (self->button_pressed) - { - self->drag_selection_at = get_time_from_x (self, x); - gtk_widget_queue_draw (GTK_WIDGET (self)); - } -} - -static void -set_children_width_request (GtkWidget *widget, - int width) -{ - for (GtkWidget *child = gtk_widget_get_first_child (widget); - child; - child = gtk_widget_get_next_sibling (child)) - gtk_widget_set_size_request (child, width, -1); -} - -static void -sysprof_visualizers_frame_notify_zoom (SysprofVisualizersFrame *self, - GParamSpec *pspec, - SysprofZoomManager *zoom_manager) -{ - gint64 duration; - gint data_width; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (SYSPROF_IS_ZOOM_MANAGER (zoom_manager)); - - duration = self->end_time - self->begin_time; - data_width = sysprof_zoom_manager_get_width_for_duration (self->zoom_manager, duration); - set_children_width_request (GTK_WIDGET (self->ticks_viewport), data_width); - set_children_width_request (GTK_WIDGET (self->visualizers_viewport), data_width); -} - -static gint -find_pos (SysprofVisualizersFrame *self, - const gchar *title, - gint priority) -{ - gint pos = 0; - - if (title == NULL) - return -1; - - for (GtkWidget *child = gtk_widget_get_first_child (GTK_WIDGET (self->visualizers)); - child; - child = gtk_widget_get_next_sibling (child)) - { - SysprofVisualizerGroup *group = SYSPROF_VISUALIZER_GROUP (child); - gint prio = sysprof_visualizer_group_get_priority (group); - const gchar *item = sysprof_visualizer_group_get_title (group); - - if (priority < prio || - (priority == prio && g_strcmp0 (title, item) < 0)) - break; - - pos++; - } - - return pos; -} - -void -sysprof_visualizers_frame_add_group (SysprofVisualizersFrame *self, - SysprofVisualizerGroup *group) -{ - SysprofVisualizerGroupHeader *header; - const char *title; - int priority; - int pos; - - g_return_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_return_if_fail (SYSPROF_IS_VISUALIZER_GROUP (group)); - - title = sysprof_visualizer_group_get_title (group); - priority = sysprof_visualizer_group_get_priority (group); - pos = find_pos (self, title, priority); - - gtk_list_box_insert (self->visualizers, GTK_WIDGET (group), pos); - - header = _sysprof_visualizer_group_header_new (group); - gtk_list_box_insert (self->groups, GTK_WIDGET (header), pos); - _sysprof_visualizer_group_set_header (group, header); - gtk_widget_show (GTK_WIDGET (header)); - - sysprof_visualizers_frame_notify_zoom (self, NULL, self->zoom_manager); -} - -static void -sysprof_visualizers_frame_selection_changed (SysprofVisualizersFrame *self, - SysprofSelection *selection) -{ - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (SYSPROF_IS_SELECTION (selection)); - - gtk_widget_queue_draw (GTK_WIDGET (self->visualizers)); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_SELECTION]); -} - -static void -sysprof_visualizers_frame_group_activated_cb (SysprofVisualizersFrame *self, - SysprofVisualizerGroupHeader *row, - GtkListBox *list) -{ - SysprofVisualizerGroup *group; - - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_assert (SYSPROF_IS_VISUALIZER_GROUP_HEADER (row)); - - group = _sysprof_visualizer_group_header_get_group (row); - g_assert (SYSPROF_IS_VISUALIZER_GROUP (group)); - - g_signal_emit_by_name (group, "group-activated"); -} - -static void -sysprof_visualizers_frame_dispose (GObject *object) -{ - SysprofVisualizersFrame *self = (SysprofVisualizersFrame *)object; - GtkWidget *child; - - while ((child = gtk_widget_get_first_child (GTK_WIDGET (self)))) - gtk_widget_unparent (child); - - g_clear_object (&self->selection); - - G_OBJECT_CLASS (sysprof_visualizers_frame_parent_class)->dispose (object); -} - -static void -sysprof_visualizers_frame_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofVisualizersFrame *self = SYSPROF_VISUALIZERS_FRAME (object); - - switch (prop_id) - { - case PROP_SELECTED_GROUP: - g_value_set_object (value, sysprof_visualizers_frame_get_selected_group (self)); - break; - - case PROP_SELECTION: - g_value_set_object (value, sysprof_visualizers_frame_get_selection (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_visualizers_frame_class_init (SysprofVisualizersFrameClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); - - object_class->dispose = sysprof_visualizers_frame_dispose; - object_class->get_property = sysprof_visualizers_frame_get_property; - - widget_class->snapshot = sysprof_visualizers_frame_snapshot; - - gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/sysprof/ui/sysprof-visualizers-frame.ui"); - gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); - gtk_widget_class_set_css_name (widget_class, "SysprofVisualizersFrame"); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, groups); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, hscrollbar); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, hscroller); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, left_column); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, ticks); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, ticks_scroller); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, visualizers); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, vscroller); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, zoom_manager); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, zoom_scale); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, ticks_viewport); - gtk_widget_class_bind_template_child (widget_class, SysprofVisualizersFrame, visualizers_viewport); - - properties [PROP_SELECTED_GROUP] = - g_param_spec_object ("selected-group", - "Selected Group", - "The selected group", - SYSPROF_TYPE_VISUALIZER_GROUP, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_SELECTION] = - g_param_spec_object ("selection", - "Selection", - "The time selection", - SYSPROF_TYPE_SELECTION, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); - - g_type_ensure (SYSPROF_TYPE_SCROLLMAP); - g_type_ensure (SYSPROF_TYPE_VISUALIZER_TICKS); - g_type_ensure (SYSPROF_TYPE_ZOOM_MANAGER); -} - -static void -sysprof_visualizers_frame_init (SysprofVisualizersFrame *self) -{ - GtkEventController *controller; - GtkAdjustment *hadj; - GtkAdjustment *zadj; - - gtk_widget_init_template (GTK_WIDGET (self)); - - gtk_widget_set_cursor_from_name (GTK_WIDGET (self->visualizers), "text"); - - controller = GTK_EVENT_CONTROLLER (gtk_gesture_click_new ()); - g_signal_connect_object (controller, - "pressed", - G_CALLBACK (visualizers_button_press_event_cb), - self, - G_CONNECT_SWAPPED); - g_signal_connect_object (controller, - "released", - G_CALLBACK (visualizers_button_release_event_cb), - self, - G_CONNECT_SWAPPED); - gtk_event_controller_set_propagation_phase (controller, GTK_PHASE_CAPTURE); - gtk_widget_add_controller (GTK_WIDGET (self->visualizers), controller); - - controller = gtk_event_controller_motion_new (); - g_signal_connect_object (controller, - "motion", - G_CALLBACK (visualizers_motion_notify_event_cb), - self, - G_CONNECT_SWAPPED); - gtk_widget_add_controller (GTK_WIDGET (self->visualizers), controller); - - self->selection = g_object_new (SYSPROF_TYPE_SELECTION, NULL); - - zadj = sysprof_zoom_manager_get_adjustment (self->zoom_manager); - hadj = gtk_scrolled_window_get_hadjustment (self->hscroller); - - gtk_scrolled_window_set_hadjustment (self->ticks_scroller, hadj); - sysprof_scrollmap_set_adjustment (self->hscrollbar, hadj); - gtk_range_set_adjustment (GTK_RANGE (self->zoom_scale), zadj); - - gtk_widget_insert_action_group (GTK_WIDGET (self), - "zoom", - G_ACTION_GROUP (self->zoom_manager)); - - g_signal_connect_object (self->groups, - "row-activated", - G_CALLBACK (sysprof_visualizers_frame_group_activated_cb), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->selection, - "changed", - G_CALLBACK (sysprof_visualizers_frame_selection_changed), - self, - G_CONNECT_SWAPPED); - - g_signal_connect_object (self->zoom_manager, - "notify::zoom", - G_CALLBACK (sysprof_visualizers_frame_notify_zoom), - self, - G_CONNECT_SWAPPED | G_CONNECT_AFTER); -} - -/** - * sysprof_visualizers_frame_get_selected_group: - * - * Gets the currently selected group. - * - * Returns: (transfer none) (nullable): the selected row - * - * Since: 3.34 - */ -SysprofVisualizerGroup * -sysprof_visualizers_frame_get_selected_group (SysprofVisualizersFrame *self) -{ - GtkListBoxRow *row; - - g_return_val_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self), NULL); - - row = gtk_list_box_get_selected_row (self->groups); - - return SYSPROF_VISUALIZER_GROUP (row); -} - -/** - * sysprof_visualizers_frame_get_selection: - * - * Get the time selection - * - * Returns: (transfer none): a #SysprofSelection - * - * Since: 3.34 - */ -SysprofSelection * -sysprof_visualizers_frame_get_selection (SysprofVisualizersFrame *self) -{ - g_return_val_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self), NULL); - - return self->selection; -} - -static gint -compare_gint64 (const gint64 *a, - const gint64 *b) -{ - if (*a < *b) - return -1; - else if (*a > *b) - return 1; - else - return 0; -} - -static bool -index_frame_times_frame_cb (const SysprofCaptureFrame *frame, - gpointer user_data) -{ - GArray *array = user_data; - - /* Track timing, but ignore some common types at startup */ - if (frame->type != SYSPROF_CAPTURE_FRAME_MAP && - frame->type != SYSPROF_CAPTURE_FRAME_PROCESS) - g_array_append_val (array, frame->time); - - return TRUE; -} - -static void -index_frame_times_worker (GTask *task, - gpointer source_object, - gpointer task_data, - GCancellable *cancellable) -{ - SysprofCaptureCursor *cursor = task_data; - GArray *timings = NULL; - - g_assert (G_IS_TASK (task)); - g_assert (SYSPROF_IS_VISUALIZERS_FRAME (source_object)); - g_assert (cursor != NULL); - g_assert (!cancellable || G_IS_CANCELLABLE (cancellable)); - - timings = g_array_new (FALSE, FALSE, sizeof (gint64)); - sysprof_capture_cursor_foreach (cursor, index_frame_times_frame_cb, timings); - g_array_sort (timings, (GCompareFunc) compare_gint64); - - g_task_return_pointer (task, - g_steal_pointer (&timings), - (GDestroyNotify) g_array_unref); -} - -void -sysprof_visualizers_frame_load_async (SysprofVisualizersFrame *self, - SysprofCaptureReader *reader, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - g_autoptr(GTask) task = NULL; - GtkAllocation alloc; - - g_return_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self)); - g_return_if_fail (reader != NULL); - g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable)); - - gtk_widget_get_allocation (GTK_WIDGET (self->ticks), &alloc); - - /* At this point, the SysprofDisplay should have already scanned the - * reader for all of the events and therefore we can trust the begin - * and end time for the capture. - */ - self->begin_time = sysprof_capture_reader_get_start_time (reader); - self->end_time = sysprof_capture_reader_get_end_time (reader); - - /* Now we need to run through the frames and index their times - * so that we can calculate the number of items per bucket when - * drawing the scrollbar. - */ - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_source_tag (task, sysprof_visualizers_frame_load_async); - g_task_set_task_data (task, - sysprof_capture_cursor_new (reader), - (GDestroyNotify) sysprof_capture_cursor_unref); - g_task_run_in_thread (task, index_frame_times_worker); -} - -gboolean -sysprof_visualizers_frame_load_finish (SysprofVisualizersFrame *self, - GAsyncResult *result, - GError **error) -{ - g_autoptr(GArray) timings = NULL; - - g_return_val_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self), FALSE); - g_return_val_if_fail (G_IS_TASK (result), FALSE); - - if ((timings = g_task_propagate_pointer (G_TASK (result), error))) - { - sysprof_scrollmap_set_timings (self->hscrollbar, timings); - sysprof_scrollmap_set_time_range (self->hscrollbar, self->begin_time, self->end_time); - sysprof_visualizer_set_time_range (SYSPROF_VISUALIZER (self->ticks), self->begin_time, self->end_time); - gtk_widget_queue_resize (GTK_WIDGET (self)); - - return TRUE; - } - - return FALSE; -} - -/** - * sysprof_visualizers_frame_get_zoom_manager: - * - * Gets the zoom manager for the frame. - * - * Returns: (transfer none): a #SysprofZoomManager - */ -SysprofZoomManager * -sysprof_visualizers_frame_get_zoom_manager (SysprofVisualizersFrame *self) -{ - g_return_val_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self), NULL); - - return self->zoom_manager; -} - -/** - * sysprof_visualizers_frame_get_size_group: - * - * gets the left column size group. - * - * Returns: (transfer none): a size group - */ -GtkSizeGroup * -sysprof_visualizers_frame_get_size_group (SysprofVisualizersFrame *self) -{ - g_return_val_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self), NULL); - - return self->left_column; -} - -/** - * sysprof_visualizers_frame_get_hadjustment: - * - * Gets the scroll adjustment used for horizontal scrolling - * - * Returns: (transfer none): a #GtkAdjustment - */ -GtkAdjustment * -sysprof_visualizers_frame_get_hadjustment (SysprofVisualizersFrame *self) -{ - g_return_val_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self), NULL); - - return sysprof_scrollmap_get_adjustment (self->hscrollbar); -} - -void -sysprof_visualizers_frame_unselect_row (SysprofVisualizersFrame *self) -{ - g_return_if_fail (SYSPROF_IS_VISUALIZERS_FRAME (self)); - - gtk_list_box_unselect_all (self->groups); -} diff --git a/src/libsysprof-ui/sysprof-visualizers-frame.h b/src/libsysprof-ui/sysprof-visualizers-frame.h deleted file mode 100644 index 3217ab57..00000000 --- a/src/libsysprof-ui/sysprof-visualizers-frame.h +++ /dev/null @@ -1,52 +0,0 @@ -/* sysprof-visualizers-frame.h - * - * Copyright 2019 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 -#include - -#include "sysprof-visualizer-group.h" -#include "sysprof-zoom-manager.h" - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_VISUALIZERS_FRAME (sysprof_visualizers_frame_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofVisualizersFrame, sysprof_visualizers_frame, SYSPROF, VISUALIZERS_FRAME, GtkWidget) - -void sysprof_visualizers_frame_add_group (SysprofVisualizersFrame *self, - SysprofVisualizerGroup *group); -SysprofSelection *sysprof_visualizers_frame_get_selection (SysprofVisualizersFrame *self); -SysprofVisualizerGroup *sysprof_visualizers_frame_get_selected_group (SysprofVisualizersFrame *self); -SysprofZoomManager *sysprof_visualizers_frame_get_zoom_manager (SysprofVisualizersFrame *self); -void sysprof_visualizers_frame_load_async (SysprofVisualizersFrame *self, - SysprofCaptureReader *reader, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data); -gboolean sysprof_visualizers_frame_load_finish (SysprofVisualizersFrame *self, - GAsyncResult *result, - GError **error); -GtkSizeGroup *sysprof_visualizers_frame_get_size_group (SysprofVisualizersFrame *self); -GtkAdjustment *sysprof_visualizers_frame_get_hadjustment (SysprofVisualizersFrame *self); -void sysprof_visualizers_frame_unselect_row (SysprofVisualizersFrame *self); - -G_END_DECLS diff --git a/src/libsysprof-ui/sysprof-visualizers-frame.ui b/src/libsysprof-ui/sysprof-visualizers-frame.ui deleted file mode 100644 index 4ff60076..00000000 --- a/src/libsysprof-ui/sysprof-visualizers-frame.ui +++ /dev/null @@ -1,242 +0,0 @@ - - - - - - - - - - - - vertical - - - - - - - - - - - - - diff --git a/src/libsysprof-ui/sysprof-zoom-manager.c b/src/libsysprof-ui/sysprof-zoom-manager.c deleted file mode 100644 index 679205e0..00000000 --- a/src/libsysprof-ui/sysprof-zoom-manager.c +++ /dev/null @@ -1,661 +0,0 @@ -/* sysprof-zoom-manager.c - * - * Copyright 2016-2019 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 - */ - -#define G_LOG_DOMAIN "sysprof-zoom-manager" - -#include "config.h" - -#include -#include -#include -#include - -#include "sysprof-zoom-manager.h" - -#define DEFAULT_PIXELS_PER_SEC (20.0) - -struct _SysprofZoomManager -{ - GObject parent_instance; - - GtkAdjustment *adjustment; - GSimpleActionGroup *actions; - - gdouble min_zoom; - gdouble max_zoom; - gdouble zoom; -} __attribute__((aligned(8))); - -enum { - PROP_0, - PROP_CAN_ZOOM_IN, - PROP_CAN_ZOOM_OUT, - PROP_MIN_ZOOM, - PROP_MAX_ZOOM, - PROP_ZOOM, - PROP_ZOOM_LABEL, - N_PROPS -}; - -static void action_group_iface_init (GActionGroupInterface *iface); - -G_DEFINE_TYPE_EXTENDED (SysprofZoomManager, sysprof_zoom_manager, G_TYPE_OBJECT, 0, - G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, action_group_iface_init)) - -static GParamSpec *properties [N_PROPS]; -static gdouble zoom_levels[] = { - 0.3, 0.5, 0.67, 0.80, 0.90, - 1.0, 1.5, 2.0, 2.5, 3.0, - 5.0, 10.0, 20.0, 30.0, 50.0, -}; - -static void -sysprof_zoom_manager_zoom_in_action (GSimpleAction *action, - GVariant *param, - gpointer user_data) -{ - SysprofZoomManager *self = user_data; - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - sysprof_zoom_manager_zoom_in (self); -} - -static void -sysprof_zoom_manager_zoom_out_action (GSimpleAction *action, - GVariant *param, - gpointer user_data) -{ - SysprofZoomManager *self = user_data; - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - sysprof_zoom_manager_zoom_out (self); -} - -static void -sysprof_zoom_manager_zoom_one_action (GSimpleAction *action, - GVariant *param, - gpointer user_data) -{ - SysprofZoomManager *self = user_data; - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - sysprof_zoom_manager_reset (self); -} - -static void -sysprof_zoom_manager_zoom_action (GSimpleAction *action, - GVariant *param, - gpointer user_data) -{ - SysprofZoomManager *self = user_data; - - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - g_assert (g_variant_is_of_type (param, G_VARIANT_TYPE_DOUBLE)); - - sysprof_zoom_manager_set_zoom (self, g_variant_get_double (param)); -} - -static void -sysprof_zoom_manager_value_changed_cb (SysprofZoomManager *self, - GtkAdjustment *adjustment) -{ - gdouble value; - - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - g_assert (GTK_IS_ADJUSTMENT (adjustment)); - - value = gtk_adjustment_get_value (adjustment); - - if (value == 0.0) - value = 1.0; - else if (value > 0.0) - value = (value + 1.0) * (value + 1.0); - else - value = 1.0 / ABS (value); - - sysprof_zoom_manager_set_zoom (self, value); -} - -static void -sysprof_zoom_manager_finalize (GObject *object) -{ - SysprofZoomManager *self = (SysprofZoomManager *)object; - - g_clear_object (&self->actions); - g_clear_object (&self->adjustment); - - G_OBJECT_CLASS (sysprof_zoom_manager_parent_class)->finalize (object); -} - -static void -sysprof_zoom_manager_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) -{ - SysprofZoomManager *self = SYSPROF_ZOOM_MANAGER (object); - - switch (prop_id) - { - case PROP_MIN_ZOOM: - g_value_set_double (value, sysprof_zoom_manager_get_min_zoom (self)); - break; - - case PROP_MAX_ZOOM: - g_value_set_double (value, sysprof_zoom_manager_get_max_zoom (self)); - break; - - case PROP_ZOOM: - g_value_set_double (value, sysprof_zoom_manager_get_zoom (self)); - break; - - case PROP_ZOOM_LABEL: - g_value_take_string (value, sysprof_zoom_manager_get_zoom_label (self)); - break; - - case PROP_CAN_ZOOM_IN: - g_value_set_boolean (value, sysprof_zoom_manager_get_can_zoom_in (self)); - break; - - case PROP_CAN_ZOOM_OUT: - g_value_set_boolean (value, sysprof_zoom_manager_get_can_zoom_out (self)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_zoom_manager_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) -{ - SysprofZoomManager *self = SYSPROF_ZOOM_MANAGER (object); - - switch (prop_id) - { - case PROP_MIN_ZOOM: - sysprof_zoom_manager_set_min_zoom (self, g_value_get_double (value)); - break; - - case PROP_MAX_ZOOM: - sysprof_zoom_manager_set_max_zoom (self, g_value_get_double (value)); - break; - - case PROP_ZOOM: - sysprof_zoom_manager_set_zoom (self, g_value_get_double (value)); - break; - - default: - G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); - } -} - -static void -sysprof_zoom_manager_class_init (SysprofZoomManagerClass *klass) -{ - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - object_class->finalize = sysprof_zoom_manager_finalize; - object_class->get_property = sysprof_zoom_manager_get_property; - object_class->set_property = sysprof_zoom_manager_set_property; - - properties [PROP_CAN_ZOOM_IN] = - g_param_spec_boolean ("can-zoom-in", - "Can Zoom In", - "Can Zoom In", - TRUE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_CAN_ZOOM_OUT] = - g_param_spec_boolean ("can-zoom-out", - "Can Zoom Out", - "Can Zoom Out", - TRUE, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_MIN_ZOOM] = - g_param_spec_double ("min-zoom", - "Min Zoom", - "The minimum zoom to apply", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_MAX_ZOOM] = - g_param_spec_double ("max-zoom", - "Max Zoom", - "The maximum zoom to apply", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 0.0, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_ZOOM] = - g_param_spec_double ("zoom", - "Zoom", - "The current zoom level", - -G_MAXDOUBLE, - G_MAXDOUBLE, - 1.0, - (G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS)); - - properties [PROP_ZOOM_LABEL] = - g_param_spec_string ("zoom-label", NULL, NULL, - NULL, - (G_PARAM_READABLE | G_PARAM_STATIC_STRINGS)); - - g_object_class_install_properties (object_class, N_PROPS, properties); -} - -static void -sysprof_zoom_manager_init (SysprofZoomManager *self) -{ - static const GActionEntry entries[] = { - { "zoom-in", sysprof_zoom_manager_zoom_in_action }, - { "zoom-out", sysprof_zoom_manager_zoom_out_action }, - { "zoom-one", sysprof_zoom_manager_zoom_one_action }, - { "zoom", NULL, "d", "1.0", sysprof_zoom_manager_zoom_action }, - }; - GAction *action; - - self->min_zoom = 0.00001; - self->max_zoom = 10000.0; - self->zoom = 1.0; - - self->adjustment = g_object_ref_sink (gtk_adjustment_new (0, -10, 10, 1, 3, 0)); - - g_signal_connect_object (self->adjustment, - "value-changed", - G_CALLBACK (sysprof_zoom_manager_value_changed_cb), - self, - G_CONNECT_SWAPPED); - - self->actions = g_simple_action_group_new (); - g_action_map_add_action_entries (G_ACTION_MAP (self->actions), - entries, - G_N_ELEMENTS (entries), - self); - - action = g_action_map_lookup_action (G_ACTION_MAP (self->actions), "zoom-in"); - g_object_bind_property (self, "can-zoom-in", action, "enabled", G_BINDING_SYNC_CREATE); - - action = g_action_map_lookup_action (G_ACTION_MAP (self->actions), "zoom-out"); - g_object_bind_property (self, "can-zoom-out", action, "enabled", G_BINDING_SYNC_CREATE); -} - -SysprofZoomManager * -sysprof_zoom_manager_new (void) -{ - return g_object_new (SYSPROF_TYPE_ZOOM_MANAGER, NULL); -} - -gboolean -sysprof_zoom_manager_get_can_zoom_in (SysprofZoomManager *self) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), FALSE); - - return self->max_zoom == 0.0 || self->zoom < self->max_zoom; -} - -gboolean -sysprof_zoom_manager_get_can_zoom_out (SysprofZoomManager *self) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), FALSE); - - return self->min_zoom == 0.0 || self->zoom > self->min_zoom; -} - -gboolean -sysprof_zoom_manager_get_min_zoom (SysprofZoomManager *self) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), FALSE); - - return self->min_zoom; -} - -gboolean -sysprof_zoom_manager_get_max_zoom (SysprofZoomManager *self) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), FALSE); - - return self->max_zoom; -} - -void -sysprof_zoom_manager_set_min_zoom (SysprofZoomManager *self, - gdouble min_zoom) -{ - g_return_if_fail (SYSPROF_IS_ZOOM_MANAGER (self)); - - if (min_zoom != self->min_zoom) - { - self->min_zoom = min_zoom; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MIN_ZOOM]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_ZOOM_OUT]); - } -} - -void -sysprof_zoom_manager_set_max_zoom (SysprofZoomManager *self, - gdouble max_zoom) -{ - g_return_if_fail (SYSPROF_IS_ZOOM_MANAGER (self)); - - if (max_zoom != self->max_zoom) - { - self->max_zoom = max_zoom; - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_MAX_ZOOM]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_ZOOM_IN]); - } -} - -void -sysprof_zoom_manager_zoom_in (SysprofZoomManager *self) -{ - gdouble zoom; - - g_return_if_fail (SYSPROF_IS_ZOOM_MANAGER (self)); - - if (!sysprof_zoom_manager_get_can_zoom_in (self)) - return; - - zoom = self->zoom; - - for (guint i = 0; i < G_N_ELEMENTS (zoom_levels); i++) - { - if (zoom_levels[i] > zoom) - { - zoom = zoom_levels[i]; - break; - } - } - - if (zoom == self->zoom) - zoom *= 2; - - sysprof_zoom_manager_set_zoom (self, zoom); -} - -void -sysprof_zoom_manager_zoom_out (SysprofZoomManager *self) -{ - gdouble zoom; - - g_return_if_fail (SYSPROF_IS_ZOOM_MANAGER (self)); - - if (!sysprof_zoom_manager_get_can_zoom_out (self)) - return; - - zoom = self->zoom; - - for (guint i = G_N_ELEMENTS (zoom_levels); i > 0; i--) - { - if (zoom_levels[i-1] < zoom) - { - zoom = zoom_levels[i-1]; - break; - } - } - - if (zoom == self->zoom) - zoom /= 2.0; - - sysprof_zoom_manager_set_zoom (self, zoom); -} - -void -sysprof_zoom_manager_reset (SysprofZoomManager *self) -{ - g_return_if_fail (SYSPROF_IS_ZOOM_MANAGER (self)); - - sysprof_zoom_manager_set_zoom (self, 1.0); -} - -gdouble -sysprof_zoom_manager_get_zoom (SysprofZoomManager *self) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0.0); - - return self->zoom; -} - -void -sysprof_zoom_manager_set_zoom (SysprofZoomManager *self, - gdouble zoom) -{ - gdouble min_zoom; - gdouble max_zoom; - - g_return_if_fail (SYSPROF_IS_ZOOM_MANAGER (self)); - - min_zoom = (self->min_zoom == 0.0) ? -G_MAXDOUBLE : self->min_zoom; - max_zoom = (self->max_zoom == 0.0) ? G_MAXDOUBLE : self->max_zoom; - - zoom = CLAMP (zoom, min_zoom, max_zoom); - - if (zoom == 0.0) - zoom = 1.0; - - if (zoom != self->zoom) - { - g_autoptr(GVariant) state = NULL; - gdouble adj; - - self->zoom = zoom; - state = g_variant_take_ref (g_variant_new_double (zoom)); - - g_object_set (g_action_map_lookup_action (G_ACTION_MAP (self->actions), "zoom"), - "state", state, - NULL); - - /* Convert to form used by adjustment */ - if (zoom == 1.0) - adj = 0.0; - else if (zoom > 1.0) - adj = sqrt (zoom) - 1.0; - else - adj = -1 / zoom; - - g_signal_handlers_block_matched (self->adjustment, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, - sysprof_zoom_manager_value_changed_cb, self); - gtk_adjustment_set_value (self->adjustment, adj); - g_signal_handlers_unblock_matched (self->adjustment, G_SIGNAL_MATCH_FUNC, 0, 0, NULL, - sysprof_zoom_manager_value_changed_cb, self); - - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_ZOOM_IN]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_CAN_ZOOM_OUT]); - g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_ZOOM_LABEL]); - } -} - -static gchar ** -sysprof_zoom_manager_list_actions (GActionGroup *action_group) -{ - SysprofZoomManager *self = (SysprofZoomManager *)action_group; - - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - - return g_action_group_list_actions (G_ACTION_GROUP (self->actions)); -} - -static gboolean -sysprof_zoom_manager_query_action (GActionGroup *action_group, - const gchar *action_name, - gboolean *enabled, - const GVariantType **parameter_type, - const GVariantType **state_type, - GVariant **state_hint, - GVariant **state) -{ - SysprofZoomManager *self = (SysprofZoomManager *)action_group; - - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - g_assert (action_name != NULL); - - return g_action_group_query_action (G_ACTION_GROUP (self->actions), - action_name, - enabled, - parameter_type, - state_type, - state_hint, - state); -} - -static void -sysprof_zoom_manager_change_action_state (GActionGroup *action_group, - const gchar *action_name, - GVariant *value) -{ - SysprofZoomManager *self = (SysprofZoomManager *)action_group; - - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - g_assert (action_name != NULL); - - g_action_group_change_action_state (G_ACTION_GROUP (self->actions), action_name, value); -} - -static void -sysprof_zoom_manager_activate_action (GActionGroup *action_group, - const gchar *action_name, - GVariant *parameter) -{ - SysprofZoomManager *self = (SysprofZoomManager *)action_group; - - g_assert (SYSPROF_IS_ZOOM_MANAGER (self)); - g_assert (action_name != NULL); - - g_action_group_activate_action (G_ACTION_GROUP (self->actions), action_name, parameter); -} - -static void -action_group_iface_init (GActionGroupInterface *iface) -{ - iface->list_actions = sysprof_zoom_manager_list_actions; - iface->query_action = sysprof_zoom_manager_query_action; - iface->change_action_state = sysprof_zoom_manager_change_action_state; - iface->activate_action = sysprof_zoom_manager_activate_action; -} - -/** - * sysprof_zoom_manager_get_zoom_level: - * @self: a #SysprofZoomManager - * - * Returns: (transfer full): a string containing the zoom percentage label - * - * Since: 3.34 - */ -gchar * -sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self) -{ - gdouble percent; - - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), NULL); - - percent = self->zoom * 100.0; - - if (percent < 1.0) - return g_strdup_printf ("%0.2lf%%", percent); - else - return g_strdup_printf ("%d%%", (gint)percent); -} - -gint64 -sysprof_zoom_manager_get_duration_for_width (SysprofZoomManager *self, - gint width) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0); - - return SYSPROF_NSEC_PER_SEC * ((gdouble)width / (DEFAULT_PIXELS_PER_SEC * self->zoom)); -} - -gint -sysprof_zoom_manager_get_width_for_duration (SysprofZoomManager *self, - gint64 duration) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0); - - return (gdouble)duration / (gdouble)SYSPROF_NSEC_PER_SEC * DEFAULT_PIXELS_PER_SEC * self->zoom; -} - -gdouble -sysprof_zoom_manager_fit_zoom_for_duration (SysprofZoomManager *self, - gint64 duration, - gint width) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 1.0); - g_return_val_if_fail (duration >= 0, 1.0); - g_return_val_if_fail (width >= 0, 1.0); - - return (width / DEFAULT_PIXELS_PER_SEC) / (duration / (gdouble)SYSPROF_NSEC_PER_SEC); -} - -gdouble -sysprof_zoom_manager_get_offset_at_time (SysprofZoomManager *self, - gint64 offset, - gint width) -{ - gint64 full_duration; - gdouble ratio; - - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), 0.0); - - full_duration = sysprof_zoom_manager_get_duration_for_width (self, width); - ratio = offset / (gdouble)full_duration; - return ratio * width; -} - -gchar * -_sysprof_format_duration (gint64 duration) -{ - gboolean negative = duration < 0; - - if (duration == 0) - return g_strdup ("0"); - - duration = ABS (duration); - - if (duration < SYSPROF_NSEC_PER_SEC) - return g_strdup_printf ("%s%.3lf msec", - negative ? "-" : "", - (duration / (gdouble)SYSPROF_NSEC_PER_SEC * 1000L)); - else - return g_strdup_printf ("%s%.4lf seconds", - negative ? "-" : "", - (duration / (gdouble)SYSPROF_NSEC_PER_SEC)); -} - -/** - * sysprof_zoom_manager_get_adjustment: - * - * Gets an adjustment for zoom controls. - * - * Returns: (transfer none): a #GtkAdjustment - * - * Since: 3.34 - */ -GtkAdjustment * -sysprof_zoom_manager_get_adjustment (SysprofZoomManager *self) -{ - g_return_val_if_fail (SYSPROF_IS_ZOOM_MANAGER (self), NULL); - - return self->adjustment; -} diff --git a/src/libsysprof-ui/sysprof-zoom-manager.h b/src/libsysprof-ui/sysprof-zoom-manager.h deleted file mode 100644 index d25742f0..00000000 --- a/src/libsysprof-ui/sysprof-zoom-manager.h +++ /dev/null @@ -1,59 +0,0 @@ -/* sysprof-zoom-manager.h - * - * Copyright 2016-2019 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 - -G_BEGIN_DECLS - -#define SYSPROF_TYPE_ZOOM_MANAGER (sysprof_zoom_manager_get_type()) - -G_DECLARE_FINAL_TYPE (SysprofZoomManager, sysprof_zoom_manager, SYSPROF, ZOOM_MANAGER, GObject) - -SysprofZoomManager *sysprof_zoom_manager_new (void); -GtkAdjustment *sysprof_zoom_manager_get_adjustment (SysprofZoomManager *self); -gboolean sysprof_zoom_manager_get_can_zoom_in (SysprofZoomManager *self); -gboolean sysprof_zoom_manager_get_can_zoom_out (SysprofZoomManager *self); -gboolean sysprof_zoom_manager_get_min_zoom (SysprofZoomManager *self); -gboolean sysprof_zoom_manager_get_max_zoom (SysprofZoomManager *self); -void sysprof_zoom_manager_set_min_zoom (SysprofZoomManager *self, - gdouble min_zoom); -void sysprof_zoom_manager_set_max_zoom (SysprofZoomManager *self, - gdouble max_zoom); -void sysprof_zoom_manager_zoom_in (SysprofZoomManager *self); -void sysprof_zoom_manager_zoom_out (SysprofZoomManager *self); -void sysprof_zoom_manager_reset (SysprofZoomManager *self); -gdouble sysprof_zoom_manager_get_zoom (SysprofZoomManager *self); -void sysprof_zoom_manager_set_zoom (SysprofZoomManager *self, - gdouble zoom); -gchar *sysprof_zoom_manager_get_zoom_label (SysprofZoomManager *self); -gint sysprof_zoom_manager_get_width_for_duration (SysprofZoomManager *self, - gint64 duration); -gint64 sysprof_zoom_manager_get_duration_for_width (SysprofZoomManager *self, - gint width); -gdouble sysprof_zoom_manager_fit_zoom_for_duration (SysprofZoomManager *self, - gint64 duration, - gint width); -gdouble sysprof_zoom_manager_get_offset_at_time (SysprofZoomManager *self, - gint64 offset, - gint width); - -G_END_DECLS diff --git a/src/meson.build b/src/meson.build index a2a841c5..f19e2ddc 100644 --- a/src/meson.build +++ b/src/meson.build @@ -74,7 +74,6 @@ if get_option('libsysprof') or get_option('agent') subdir('libsysprof') endif if get_option('gtk') and get_option('libsysprof') - subdir('libsysprof-ui') subdir('libsysprof-gtk') endif if get_option('gtk') and get_option('libsysprof') diff --git a/src/tests/meson.build b/src/tests/meson.build index 611ff260..689bd110 100644 --- a/src/tests/meson.build +++ b/src/tests/meson.build @@ -112,37 +112,4 @@ if get_option('libsysprof') dependencies: [libsysprof_static_dep], include_directories: include_directories('..'), ) - - if get_option('gtk') - test_ui_deps = [ - libsysprof_dep, - libsysprof_ui_dep, - dependency('gtk4', version: gtk_req_version), - dependency('pangoft2', required: false), - ] - - test_model_filter = executable('test-model-filter', 'test-model-filter.c', - c_args: test_cflags, - dependencies: test_ui_deps, - ) - - test_process_model = executable('test-process-model', 'test-process-model.c', - c_args: test_cflags, - dependencies: test_ui_deps, - ) - - test_zoom = executable('test-zoom', - ['test-zoom.c', '../libsysprof-ui/sysprof-zoom-manager.c'], - c_args: test_cflags, - dependencies: test_ui_deps, - ) - - test_capture_view = executable('test-capture-view', 'test-capture-view.c', - c_args: test_cflags, - dependencies: test_ui_deps, - ) - - test('test-model-filter', test_model_filter, env: test_env) - test('test-zoom', test_zoom, env: test_env) - endif endif